diff --git a/paddle/fluid/inference/tensorrt/engine.h b/paddle/fluid/inference/tensorrt/engine.h index 0a4cffbe7ebb78b7dcb7f461cb9484c3ace4c2ca..0e399578fa446793756a23e76013c3ed9a8bb9c4 100644 --- a/paddle/fluid/inference/tensorrt/engine.h +++ b/paddle/fluid/inference/tensorrt/engine.h @@ -81,10 +81,35 @@ nvinfer1::Dims Vec2TRT_Dims(const std::vector& shape, std::string input, "TensorRT's tensor input requires at most 4 " "dimensions, but input %s has %d dims.", input, shape.size())); + auto ShapeStr = [](const std::vector& shape) { + std::ostringstream os; + os << "["; + for (size_t i = 0; i < shape.size(); ++i) { + if (i == shape.size() - 1) { + os << shape[i]; + } else { + os << shape[i] << ","; + } + } + os << "]"; + return os.str(); + }; if (!with_dynamic_shape) { if (shape.size() == 4UL) { + if (shape[2] == -1 || shape[3] == -1) { + PADDLE_THROW(platform::errors::InvalidArgument( + "The input [%s] shape of trt subgraph is %s, please enable " + "trt dynamic_shape mode by SetTRTDynamicShapeInfo.", + input, ShapeStr(shape))); + } return nvinfer1::DimsCHW(shape[1], shape[2], shape[3]); } else if (shape.size() == 3UL) { + if (shape[1] == -1 || shape[2] == -1) { + PADDLE_THROW(platform::errors::InvalidArgument( + "The input [%s] shape of trt subgraph is %s, please enable " + "trt dynamic_shape mode by SetTRTDynamicShapeInfo.", + input, ShapeStr(shape))); + } return nvinfer1::Dims2(shape[1], shape[2]); } return nvinfer1::DimsCHW(shape[1], 1, 1);