diff --git a/paddle/fluid/inference/api/analysis_predictor.cc b/paddle/fluid/inference/api/analysis_predictor.cc index 81b6f9206e4cc413ea2e6d2182ce9c4653c47fc8..2c1e6ba95dd0d7a6e95267c43bf50141c44c5d8c 100644 --- a/paddle/fluid/inference/api/analysis_predictor.cc +++ b/paddle/fluid/inference/api/analysis_predictor.cc @@ -2350,7 +2350,9 @@ USE_TRT_CONVERTER(reshape2); USE_TRT_CONVERTER(gather_nd); USE_TRT_CONVERTER(reduce_mean); USE_TRT_CONVERTER(reduce_max); +USE_TRT_CONVERTER(reduce_min); USE_TRT_CONVERTER(reduce_sum); +USE_TRT_CONVERTER(reduce_prod); USE_TRT_CONVERTER(tile); USE_TRT_CONVERTER(conv3d); USE_TRT_CONVERTER(conv3d_transpose); diff --git a/paddle/fluid/inference/tensorrt/convert/reduce_op.cc b/paddle/fluid/inference/tensorrt/convert/reduce_op.cc index e6eed80e9059745b377ee1880486ebb80bd6fe8e..637b0a662f79a268491b563b53fd4c35ee7abdb7 100644 --- a/paddle/fluid/inference/tensorrt/convert/reduce_op.cc +++ b/paddle/fluid/inference/tensorrt/convert/reduce_op.cc @@ -43,7 +43,6 @@ class ReduceOpConverter : public OpConverter { VLOG(4) << "convert a paddle " << op_type << " op to tensorrt reduce layer"; framework::OpDesc op_desc(op, nullptr); auto reduce_type = ops_.find(op_type); - auto* x = engine_->GetITensor(op_desc.Input("X").front()); nvinfer1::Dims input_shape = x->getDimensions(); int input_dims = input_shape.nbDims; @@ -104,6 +103,8 @@ const std::unordered_map> {"reduce_mean", {nvinfer1::ReduceOperation::kAVG}}, {"reduce_sum", {nvinfer1::ReduceOperation::kSUM}}, {"reduce_max", {nvinfer1::ReduceOperation::kMAX}}, + {"reduce_min", {nvinfer1::ReduceOperation::kMIN}}, + {"reduce_prod", {nvinfer1::ReduceOperation::kPROD}}, }; class ReduceSumOpConverter : public ReduceOpConverter { @@ -120,6 +121,17 @@ class ReduceMaxOpConverter : public ReduceOpConverter { public: ReduceMaxOpConverter() { op_type = "reduce_max"; } }; + +class ReduceMinOpConverter : public ReduceOpConverter { + public: + ReduceMinOpConverter() { op_type = "reduce_min"; } +}; + +class ReduceProdOpConverter : public ReduceOpConverter { + public: + ReduceProdOpConverter() { op_type = "reduce_prod"; } +}; + } // namespace tensorrt } // namespace inference } // namespace paddle @@ -127,3 +139,5 @@ class ReduceMaxOpConverter : public ReduceOpConverter { REGISTER_TRT_OP_CONVERTER(reduce_sum, ReduceSumOpConverter); REGISTER_TRT_OP_CONVERTER(reduce_mean, ReduceMeanOpConverter); REGISTER_TRT_OP_CONVERTER(reduce_max, ReduceMaxOpConverter); +REGISTER_TRT_OP_CONVERTER(reduce_min, ReduceMinOpConverter); +REGISTER_TRT_OP_CONVERTER(reduce_prod, ReduceProdOpConverter); diff --git a/paddle/fluid/inference/tensorrt/op_teller.cc b/paddle/fluid/inference/tensorrt/op_teller.cc index b8fa355c66f988c084854c692ad0df30077d2c2c..04ed688c27c5e359edc393cd2a6b26d5b6945d25 100644 --- a/paddle/fluid/inference/tensorrt/op_teller.cc +++ b/paddle/fluid/inference/tensorrt/op_teller.cc @@ -2088,7 +2088,8 @@ struct SimpleOpTypeSetTeller : public Teller { } if (op_type == "reduce_sum" || op_type == "reduce_mean" || - op_type == "reduce_max") { + op_type == "reduce_max" || op_type == "reduce_min" || + op_type == "reduce_prod") { if (!desc.HasAttr("dim", /*with_attr_var=*/false)) { VLOG(3) << "Skip to convert into TRT while found Attribute('dim') is " "Variable type in " diff --git a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_reduce.py b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_reduce.py index ba94e2fcd49cf432ace56fb563fad1ae04bd0d0b..67580b6d7c3235da8e6734fdeca938fc1db7c292 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_reduce.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_reduce.py @@ -68,10 +68,12 @@ class TrtConvertReduceTest(TrtLayerAutoScanTest): for out_dtype in [-1, 2, 5]: for op_type in [ "reduce_max", + "reduce_min", "reduce_mean", "reduce_sum", + "reduce_prod", ]: - dics = [ + dics1 = [ { "keep_dim": keep_dim, "dim": dim, @@ -81,36 +83,43 @@ class TrtConvertReduceTest(TrtLayerAutoScanTest): }, {}, ] - - ops_config = [ + dics2 = [ { - "op_type": op_type, - "op_inputs": {"X": ["input_data"]}, - "op_outputs": { - "Out": ["reduce_output_data"] - }, - "op_attrs": dics[0], - } + "out_dtype": out_dtype, + "in_dtype": out_dtype, + }, + {}, ] - ops = self.generate_op_config(ops_config) - - program_config = ProgramConfig( - ops=ops, - weights={}, - inputs={ - "input_data": TensorConfig( - data_gen=partial( - generate_input1, out_dtype, dics + for dics in [dics1, dics2]: + ops_config = [ + { + "op_type": op_type, + "op_inputs": {"X": ["input_data"]}, + "op_outputs": { + "Out": ["reduce_output_data"] + }, + "op_attrs": dics[0], + } + ] + ops = self.generate_op_config(ops_config) + + program_config = ProgramConfig( + ops=ops, + weights={}, + inputs={ + "input_data": TensorConfig( + data_gen=partial( + generate_input1, out_dtype, dics + ) ) - ) - }, - outputs=["reduce_output_data"], - ) + }, + outputs=["reduce_output_data"], + ) - if not self.is_program_valid(program_config): - continue + if not self.is_program_valid(program_config): + continue - yield program_config + yield program_config def sample_predictor_configs( self, program_config