diff --git a/onnxruntime/core/providers/tensorrt/tensorrt_execution_provider.cc b/onnxruntime/core/providers/tensorrt/tensorrt_execution_provider.cc index 028a34e09d..1a56b8229e 100644 --- a/onnxruntime/core/providers/tensorrt/tensorrt_execution_provider.cc +++ b/onnxruntime/core/providers/tensorrt/tensorrt_execution_provider.cc @@ -676,7 +676,7 @@ common::Status TensorrtExecutionProvider::Compile(const std::vectorbuilder; - auto trt_profile = trt_builder->createOptimizationProfile(); + nvinfer1::IOptimizationProfile* trt_profile = nullptr; for (int i = 0, end = num_binding_inputs; i < end; ++i) { // TODO: check if getInput indexing is same with binding index auto input = trt_state->network->getInput(i); @@ -714,6 +714,9 @@ common::Status TensorrtExecutionProvider::Compile(const std::vectorcreateOptimizationProfile(); + } if (engine.isShapeBinding(i)) { std::vector shapes_min(nb_dims), shapes_opt(nb_dims), shapes_max(nb_dims); for (int j = 0, end = nb_dims; j < end; ++j) { @@ -733,7 +736,7 @@ common::Status TensorrtExecutionProvider::Compile(const std::vectorsetDimensions(input->getName(), nvinfer1::OptProfileSelector::kMIN, dims_min); trt_profile->setDimensions(input->getName(), nvinfer1::OptProfileSelector::kOPT, dims_opt); trt_profile->setDimensions(input->getName(), nvinfer1::OptProfileSelector::kMAX, dims_max); @@ -746,10 +749,13 @@ common::Status TensorrtExecutionProvider::Compile(const std::vector(trt_builder->createBuilderConfig()); trt_config->addOptimizationProfile(trt_profile); trt_state->engine = trt_builder->buildEngineWithConfig(*trt_state->network, *trt_config); - ORT_ENFORCE(trt_state->engine != nullptr); - + if (trt_state->engine == nullptr) { + return ORT_MAKE_STATUS(ONNXRUNTIME, EP_FAIL, "TensorRT EP Failed to Build Engine."); + } trt_state->context = trt_state->engine->createExecutionContext(); - ORT_ENFORCE(trt_state->context != nullptr); + if (trt_state->context == nullptr) { + return ORT_MAKE_STATUS(ONNXRUNTIME, EP_FAIL, "TensorRT EP Failed to Create Context."); + } trt_context = trt_state->context; }