diff --git a/paddle/fluid/inference/tensorrt/convert/conv2d_op.cc b/paddle/fluid/inference/tensorrt/convert/conv2d_op.cc index 6871d53f42ccde6b67a050242c3870dac6b3cd5c..5515cd35daedc70b6ecad44f4295084546386b96 100644 --- a/paddle/fluid/inference/tensorrt/convert/conv2d_op.cc +++ b/paddle/fluid/inference/tensorrt/convert/conv2d_op.cc @@ -97,6 +97,10 @@ void ConvertConv2d(TensorRTEngine* engine, const framework::proto::OpDesc& op, BOOST_GET_CONST(std::vector, op_desc.GetAttr("strides")); const std::vector paddings = BOOST_GET_CONST(std::vector, op_desc.GetAttr("paddings")); + std::string padding_algorithm = "EXPLICIT"; + if (op_desc.HasAttr("padding_algorithm")) + padding_algorithm = + BOOST_GET_CONST(std::string, op_desc.GetAttr("padding_algorithm")); nvinfer1::DimsHW nv_ksize(filter_h, filter_w); nvinfer1::DimsHW nv_dilations(dilations[0], dilations[1]); @@ -126,6 +130,9 @@ void ConvertConv2d(TensorRTEngine* engine, const framework::proto::OpDesc& op, layer->setStride(nv_strides); layer->setPadding(nv_paddings); layer->setNbGroups(groups); + if (padding_algorithm == "SAME") { + layer->setPaddingMode(nvinfer1::PaddingMode::kSAME_UPPER); + } // set dilations fset_dilation(layer, nv_dilations); diff --git a/paddle/fluid/inference/tensorrt/op_teller.cc b/paddle/fluid/inference/tensorrt/op_teller.cc index 6f000fbccfa08fa70941f76e7ef1ba67a0758604..052d17878a5a9dfb3c2b2cae4644b3d4dda2942f 100644 --- a/paddle/fluid/inference/tensorrt/op_teller.cc +++ b/paddle/fluid/inference/tensorrt/op_teller.cc @@ -129,13 +129,7 @@ bool OpTeller::Tell(const framework::ir::Node* node, bool use_no_calib_int8, std::vector paddings = BOOST_GET_CONST(std::vector, desc.GetAttr("paddings")); - std::string padding_algorithm = "EXPLICIT"; - if (desc.HasAttr("padding_algorithm")) - padding_algorithm = - BOOST_GET_CONST(std::string, desc.GetAttr("padding_algorithm")); - if (paddings.size() > 2 || - (padding_algorithm == "SAME" && op_type != "pool2d")) - return false; + if (paddings.size() > 2) return false; } if (op_type == "matmul") { auto* block = desc.Block(); diff --git a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_conv_pass.py b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_conv_pass.py index 0de37fce0ae1a2f11547f090c41c2a1875774520..0821b390e5e6ae08c4791dcaa628c4a48e8d024f 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_conv_pass.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_conv_pass.py @@ -67,15 +67,12 @@ class TensorRTSubgraphPassConvValidPaddingTest(TensorRTSubgraphPassConvTest): self.conv_padding = 'VALID' -''' -# conv2d padded in 'SAME' mode is not yet supported in TRT, reopen this when support is complete. class TensorRTSubgraphPassConvSamePaddingTest(InferencePassTest): def set_params(self): self.conv_num_filters = 6 self.conv_filter_size = 6 self.conv_groups = 3 self.conv_padding = 'SAME' -''' class TensorRTSubgraphPassDepthwiseConvTest(TensorRTSubgraphPassConvTest): @@ -131,15 +128,13 @@ class TensorRTSubgraphPassConvTransposeValidPaddingTest( self.conv_padding = 'VALID' -''' -# conv2d_transpose padded in 'SAME' mode is not yet supported in TRT, reopen this when support is complete. -class TensorRTSubgraphPassConvTransposeSamePaddingTest(TensorRTSubgraphPassConvTransposeTest): +class TensorRTSubgraphPassConvTransposeSamePaddingTest( + TensorRTSubgraphPassConvTransposeTest): def set_params(self): self.conv_num_filters = 6 self.conv_filter_size = 6 self.conv_groups = 1 self.conv_padding = 'SAME' -''' class TensorRTSubgraphPassDepthwiseConvTransposeTest(