Repository navigation
Improve TensorRT binding index query - #36434
Conversation
| } | ||
| } | ||
|
|
||
| // Get the binding index of a tensor in an engine. |
There was a problem hiding this comment.
Gets. Also please add a blank line after this line.
| Status GetTrtBindingIndex(const char* tensor_name, int profile_idx, | ||
| const nvinfer1::ICudaEngine* cuda_engine, | ||
| int* binding_idx) { | ||
| *binding_idx = cuda_engine->getBindingIndex(tensor_name); |
There was a problem hiding this comment.
Can we add this comment?
// This is binding_index_within_profile.
There was a problem hiding this comment.
Described the binding index numbering scheme and explained what getBindingIndex returns.
| // If we have more then one optimization profiles then the binding idx | ||
| // depends on the profile number |
There was a problem hiding this comment.
Can we replace this comment with this:
binding_index_within_engine = binding_index_within_profile + profile_index * bindings_per_profile
| StrCat("Input node ", input_name, " not found, at ", name()); | ||
| LOG(ERROR) << msg; | ||
| ctx->SetStatus(errors::NotFound(msg)); | ||
| int binding_index = -1; |
There was a problem hiding this comment.
Do we have to initialize binding_index here?
There was a problem hiding this comment.
No, it is not absolutely necessary. I have removed the initialization.
| // Get the binding index of a tensor in an engine. | ||
| // The binding index is looked up using the tensor's name and the profile idx. | ||
| // Profile idx should be set to zero, if we do not have optimization profiles. | ||
| Status GetTrtBindingIndex(const char* tensor_name, int profile_idx, |
There was a problem hiding this comment.
Let's replace 'idx' with index so that we use index consistently.
| } | ||
| } | ||
|
|
||
| // Get the binding index of a tensor in an engine. |
| // Get the binding index of a tensor in an engine. | ||
| // The binding index is looked up using the tensor's name and the profile idx. | ||
| // Profile idx should be set to zero, if we do not have optimization profiles. | ||
| Status GetTrtBindingIndex(const char* tensor_name, int profile_idx, |
| Status GetTrtBindingIndex(const char* tensor_name, int profile_idx, | ||
| const nvinfer1::ICudaEngine* cuda_engine, | ||
| int* binding_idx) { | ||
| *binding_idx = cuda_engine->getBindingIndex(tensor_name); |
There was a problem hiding this comment.
Described the binding index numbering scheme and explained what getBindingIndex returns.
| // If we have more then one optimization profiles then the binding idx | ||
| // depends on the profile number |
| StrCat("Input node ", input_name, " not found, at ", name()); | ||
| LOG(ERROR) << msg; | ||
| ctx->SetStatus(errors::NotFound(msg)); | ||
| int binding_index = -1; |
There was a problem hiding this comment.
No, it is not absolutely necessary. I have removed the initialization.
PiperOrigin-RevId: 293660474 Change-Id: I7868bb49ddd32ade542c8562cf89841fcdf8bf98
This PR improves the TensorRT binding index query in a way that makes it compatible with optimization profiles.
Currently profiles are not used in TF-TRT, therefore this PR does not change any existing behavior. It is just a preparatory step to implement dynamic shapes with profiles.
TensorRT bindings are an array of pointers to input and output buffers for the network.
To execute TensorRT inference we have to specify the bindings.
To specify the pointers for the bindings, we have to query the binding index for each input and output tensor, and fill the data pointer in the bindings array at the correct location specified by the binding index.
Since TensorRT 6, an engine can have a optimization profiles, and each profile has it's own set of bindings. This PR make binding index query compatible with multiple optimization profiles.