Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/conversion/conversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void AddInputs(
ctx->input_is_dynamic = true;
}

ctx->value_tensor_map[in] = trt_in;
ctx->RecordNewITensor(in, trt_in);
ctx->num_inputs += 1;
}

Expand Down
13 changes: 11 additions & 2 deletions core/conversion/conversionctx/ConversionCtx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ ConversionCtx::~ConversionCtx() {
}

nvinfer1::ITensor* ConversionCtx::AssociateValueAndTensor(const torch::jit::Value* value, nvinfer1::ITensor* tensor) {
tensor->setName(value->debugName().c_str());
this->value_tensor_map[value] = tensor;
RecordNewITensor(value, tensor);

return tensor;
}

Expand All @@ -153,6 +153,15 @@ torch::jit::IValue* ConversionCtx::AssociateValueAndIValue(const torch::jit::Val
return &this->evaluated_value_map[value];
}

void ConversionCtx::RecordNewITensor(const torch::jit::Value* value, nvinfer1::ITensor* tensor) {
value_tensor_map[value] = tensor;
auto ret = seen_itensors.insert(tensor);
if (!ret.second) {
LOG_WARNING(
"Trying to record the value " << value->debugName() << " with the ITensor " << tensor->getName() << " again.");
}
}

std::string ConversionCtx::SerializeEngine() {
#if NV_TENSORRT_MAJOR > 7
auto serialized_network = builder->buildSerializedNetwork(*net, *cfg);
Expand Down
4 changes: 4 additions & 0 deletions core/conversion/conversionctx/ConversionCtx.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct ConversionCtx {
ConversionCtx(BuilderSettings settings);
std::string SerializeEngine();
nvinfer1::ITensor* AssociateValueAndTensor(const torch::jit::Value* value, nvinfer1::ITensor* tensor);
void RecordNewITensor(const torch::jit::Value* value, nvinfer1::ITensor* tensor);
torch::jit::IValue* AssociateValueAndIValue(const torch::jit::Value* value, torch::jit::IValue tensor);
bool CheckLayerAddition(const torch::jit::Node* n);

Expand All @@ -71,6 +72,9 @@ struct ConversionCtx {

std::unordered_map<const torch::jit::Value*, nvinfer1::ITensor*> value_tensor_map;
std::unordered_map<const torch::jit::Value*, torch::jit::IValue> evaluated_value_map;

// record already named ITensors to prevent rewriting another name to the same tensor
std::unordered_set<nvinfer1::ITensor*> seen_itensors;
};

} // namespace conversion
Expand Down