Skip to content

Commit

Permalink
[TensorRT EP] Add null_ptr check to avoid crash when running session …
Browse files Browse the repository at this point in the history
…which was failed to generate trt_engine previously (#21621)

### Description
<!-- Describe your changes. -->
Add null_ptr check to avoid crash when running session which was failed
to generate trt_engine previously


### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->

Reported and verified by
#21567
  • Loading branch information
yf711 authored Aug 9, 2024
1 parent 8878847 commit 906ae77
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions onnxruntime/core/providers/tensorrt/tensorrt_execution_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3752,6 +3752,11 @@ Status TensorrtExecutionProvider::CreateNodeComputeInfoFromGraph(const GraphView
trt_context = trt_state->context->get();
}

// Check before using trt_engine
if (trt_engine == nullptr) {
return ORT_MAKE_STATUS(ONNXRUNTIME, EP_FAIL, "No engine is found.");
}

// Get input and output binding names
int total_bindings = trt_engine->getNbIOTensors();
std::vector<char const*> input_binding_names, output_binding_names;
Expand Down Expand Up @@ -4075,6 +4080,11 @@ Status TensorrtExecutionProvider::CreateNodeComputeInfoFromPrecompiledEngine(con
Ort::ThrowOnError(api->KernelContext_GetGPUComputeStream(context, &cuda_stream));
cudaStream_t stream = static_cast<cudaStream_t>(cuda_stream);

// Check before using trt_engine
if (trt_engine == nullptr) {
return ORT_MAKE_STATUS(ONNXRUNTIME, EP_FAIL, "No engine is found.");
}

// Get input and output binding names
int total_bindings = trt_engine->getNbIOTensors();
std::vector<char const*> input_binding_names, output_binding_names;
Expand Down

0 comments on commit 906ae77

Please sign in to comment.