From a9ba11a9b4205b4c5bca8a4f07a115b795f9933d Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Tue, 23 May 2023 21:56:51 +0800 Subject: [PATCH 01/24] [phi] autogen code pool2d --- paddle/fluid/operators/pool_op.cc | 211 ----------------------- paddle/fluid/operators/pool_op.h | 5 - paddle/phi/api/yaml/legacy_backward.yaml | 24 --- paddle/phi/api/yaml/legacy_ops.yaml | 11 -- paddle/phi/api/yaml/op_compat.yaml | 8 + paddle/phi/api/yaml/static_backward.yaml | 24 +++ paddle/phi/api/yaml/static_ops.yaml | 11 ++ paddle/phi/ops/compat/pool_sig.cc | 56 ------ 8 files changed, 43 insertions(+), 307 deletions(-) diff --git a/paddle/fluid/operators/pool_op.cc b/paddle/fluid/operators/pool_op.cc index f6ba1c624b5c6e..38cc1c9855c57f 100644 --- a/paddle/fluid/operators/pool_op.cc +++ b/paddle/fluid/operators/pool_op.cc @@ -105,190 +105,6 @@ phi::KernelKey PoolOpGrad::GetKernelTypeForVar( tensor.place(), tensor.layout(), expected_kernel_type.dtype()); } -void Pool2dOpMaker::Make() { - AddInput( - "X", - "(phi::DenseTensor) The input tensor of pooling operator. " - "The format of input tensor is NCHW, where N is batch size, C is the " - "number of channels, H is the height of the feature, " - "and W is the width of the feature."); - AddOutput("Out", - "(phi::DenseTensor) The output tensor of pooling operator. " - "The format of output tensor is also NCHW, " - "where N is batch size, C is the number of channels, " - "H is the height of the feature, " - "and W is the width of the feature."); - - AddAttr("pooling_type", - "(string), pooling type, can be \"max\" for max-pooling " - "and \"avg\" for average-pooling.") - .InEnum({"max", "avg"}); - AddAttr>("ksize", - "(vector) The pooling window " - "size(height, width) of the pooling operator. " - "If global_pooling = true, ksize and paddings will " - "be ignored.") - .SupportTensor(); - AddAttr( - "global_pooling", - "(bool) Whether to use the global pooling. " - "If global_pooling = true, kernel size and paddings will be ignored. " - "Default False.") - .SetDefault(false); - AddAttr>("strides", - "(vector, default {1, 1}), strides(height, " - "width) of pooling operator.") - .SetDefault({1, 1}); - // TODO(Chengduo): Add checker. (Currently, - // TypedAttrChecker don't support vector type.) - AddAttr>( - "paddings", - "(vector, default {0,0}), paddings(height_top, height_bottom, " - "width_left, wifth_right) of pooling operator." - "If global_pooling = true, paddings and kernel size will be ignored.") - .SetDefault({0, 0}); - AddAttr( - "exclusive", - "(bool) When true, will exclude the zero-padding in the " - "averaging calculating, otherwise, include the zero-padding. Note, it " - "is only used when pooling_type is avg. The default is True. " - "Default True.") - .SetDefault(true); - AddAttr( - "adaptive", - "(bool) When true, will perform adaptive pooling instead, " - "output shape in H and W dimensions will be same as ksize, input data " - "will be divided into grids specify by ksize averagely and perform " - "pooling in each grid area to get output pooling value. " - "Default False.") - .SetDefault(false); - AddAttr( - "ceil_mode", - "(bool) Whether to use the ceil function to calculate " - "output height and width. False is the default. If it is set to False, " - "the floor function will be used. Default False") - .SetDefault(false); - AddAttr( - "data_format", - "(string, default NCHW) Only used in " - "An optional string from: \"NHWC\", \"NCHW\". " - "Defaults to \"NHWC\". Specify the data format of the output data, " - "the input will be transformed automatically. ") - .SetDefault("NCHW"); - AddAttr( - "padding_algorithm", - "(string, default \"EXPLICIT\") An optional string from: \"EXPLICIT\"," - "\"SAME\",\"VALID\". Set to \"EXPLICIT\" for explicit padding. " - "Set to \"SAME\" or \"VALID\" for algorithm of padding. ") - .SetDefault("EXPLICIT"); - // TODO(dzhwinter): need to registered layout transform function - AddAttr( - "use_cudnn", - "(bool) Only used in cudnn kernel, need install cudnn. Default False") - .SetDefault(false) - .AsExtra(); - AddComment(R"DOC( -This operation calculates the pooling output based on -the input, pooling_type and pool_size, pool_stride, pool_padding parameters. -Input(X) and Output(Out) are in NCHW or NHWC format, where N is batch size, C is the -number of channels, H is the height of the feature, and W is the width of the feature. -Parameters(pool_size, pool_stride, pool_padding) hold two integer elements. -These two elements represent height and width, respectively. -The input(X) size and output(Out) size may be different. - -Example: - - Input: - - X shape: $(N, C, H_{in}, W_{in})$ - - Output: - - Out shape: $(N, C, H_{out}, W_{out})$ - - For pool_padding = "SAME": - $$ - H_{out} = \\frac{(H_{in} + strides[0] - 1)}{strides[0]} - $$ - $$ - W_{out} = \\frac{(W_{in} + strides[1] - 1)}{strides[1]} - $$ - - For pool_padding = "VALID": - $$ - H_{out} = \\frac{(H_{in} - ksize[0] + strides[0])}{strides[0]} - $$ - $$ - W_{out} = \\frac{(W_{in} - ksize[1] + strides[1])}{strides[1]} - $$ - - For ceil_mode = false: - $$ - H_{out} = \\frac{(H_{in} - ksize[0] + pad_height_top + pad_height_bottom}{strides[0]} + 1 - $$ - $$ - W_{out} = \\frac{(W_{in} - ksize[1] + pad_width_left + pad_width_right}{strides[1]} + 1 - $$ - - For ceil_mode = true: - $$ - H_{out} = \\frac{(H_{in} - ksize[0] + pad_height_top + pad_height_bottom + strides[0] - 1)}{strides[0]} + 1 - $$ - $$ - W_{out} = \\frac{(W_{in} - ksize[1] + pad_width_left + pad_width_right + strides[1] - 1)}{strides[1]} + 1 - $$ - - For exclusive = false: - $$ - hstart = i * strides[0] - pad_height_top - $$ - $$ - hend = hstart + ksize[0] - $$ - $$ - wstart = j * strides[1] - pad_width_left - $$ - $$ - wend = wstart + ksize[1] - $$ - $$ - Output(i ,j) = \\frac{sum(Input[hstart:hend, wstart:wend])}{ksize[0] * ksize[1]} - $$ - - For exclusive = true: - $$ - hstart = max(0, i * strides[0] - pad_height_top) - $$ - $$ - hend = min(H, hstart + ksize[0]) - $$ - $$ - wstart = max(0, j * strides[1] - pad_width_left) - $$ - $$ - wend = min(W, wstart + ksize[1]) - $$ - $$ - Output(i ,j) = \\frac{sum(Input[hstart:hend, wstart:wend])}{(hend - hstart) * (wend - wstart)} - $$ - -)DOC"); -} - -template -class Pool2dOpGradGradMaker : public framework::SingleGradOpMaker { - public: - using framework::SingleGradOpMaker::SingleGradOpMaker; - - protected: - void Apply(GradOpPtr grad_op) const override { - grad_op->SetType("pool2d_double_grad"); - grad_op->SetInput("X", this->OutputGrad(framework::GradVarName("X"))); - grad_op->SetOutput("Out", this->InputGrad(framework::GradVarName("Out"))); - grad_op->SetAttrMap(this->Attrs()); - } -}; - class PoolOpInferVarType : public framework::PassInDtypeAndVarTypeToOutput { protected: std::unordered_map& GetInputOutputWithSameType() @@ -494,33 +310,6 @@ width, respectively. The input(X) size and output(Out) size may be different. namespace ops = paddle::operators; -DECLARE_INFER_SHAPE_FUNCTOR(pool2d, - Pool2dInferShapeFunctor, - PD_INFER_META(phi::Pool2DInferMeta)); -DECLARE_INFER_SHAPE_FUNCTOR(pool2d_grad, - Pool2dGradInferShapeFunctor, - PD_INFER_META(phi::UnchangedInferMeta)); -DECLARE_INFER_SHAPE_FUNCTOR(pool2d_double_grad, - Pool2dDoubleGradInferShapeFunctor, - PD_INFER_META(phi::Pool2DInferMeta)); - -REGISTER_OPERATOR( - pool2d, - ops::PoolOp, - ops::Pool2dOpMaker, - ops::PoolOpInferVarType, - paddle::framework::DefaultGradOpMaker, - paddle::framework::DefaultGradOpMaker, - Pool2dInferShapeFunctor); -REGISTER_OPERATOR(pool2d_grad, - ops::PoolOpGrad, - ops::Pool2dOpGradGradMaker, - ops::Pool2dOpGradGradMaker, - Pool2dGradInferShapeFunctor); -REGISTER_OPERATOR(pool2d_double_grad, - ops::PoolOp, - Pool2dDoubleGradInferShapeFunctor); - DECLARE_INFER_SHAPE_FUNCTOR(pool3d, Pool3dInferShapeFunctor, PD_INFER_META(phi::PoolInferMeta)); diff --git a/paddle/fluid/operators/pool_op.h b/paddle/fluid/operators/pool_op.h index a935c6b14fd5ab..8add637cb346f9 100644 --- a/paddle/fluid/operators/pool_op.h +++ b/paddle/fluid/operators/pool_op.h @@ -47,11 +47,6 @@ class PoolOpGrad : public framework::OperatorWithKernel { const phi::KernelKey& expected_kernel_type) const override; }; -class Pool2dOpMaker : public framework::OpProtoAndCheckerMaker { - public: - void Make() override; -}; - class Pool3dOpMaker : public framework::OpProtoAndCheckerMaker { public: void Make() override; diff --git a/paddle/phi/api/yaml/legacy_backward.yaml b/paddle/phi/api/yaml/legacy_backward.yaml index 3e625667cf445d..3d1e7e2e87dfac 100755 --- a/paddle/phi/api/yaml/legacy_backward.yaml +++ b/paddle/phi/api/yaml/legacy_backward.yaml @@ -615,30 +615,6 @@ composite : pad_grad(x, out_grad, paddings, pad_value, x_grad) backward : pad_double_grad -- backward_op : pool2d_double_grad - forward : pool2d_grad(Tensor x, Tensor out, Tensor grad_out, IntArray kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) -> Tensor(grad_x) - args : (Tensor x, Tensor grad_x_grad, IntArray kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) - output : Tensor(grad_out_grad) - infer_meta : - func : Pool2DInferMeta - param : [grad_x_grad, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm] - kernel : - func : pool2d_double_grad - param : [grad_x_grad, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm] - no_need_buffer : x - -- backward_op : pool2d_grad - forward : pool2d(Tensor x, IntArray kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) -> Tensor(out) - args : (Tensor x, Tensor out, Tensor out_grad, IntArray kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) - output : Tensor(x_grad) - infer_meta : - func : UnchangedInferMeta - param: [x] - kernel : - func : pool2d_grad - param : [x, out, out_grad, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm] - backward : pool2d_double_grad - - backward_op : pool3d_grad forward : pool3d(Tensor x, int[] kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) -> Tensor(out) args : (Tensor x, Tensor out, Tensor out_grad, int[] kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) diff --git a/paddle/phi/api/yaml/legacy_ops.yaml b/paddle/phi/api/yaml/legacy_ops.yaml index 4dba3fdd74ec80..876ee1d613325f 100755 --- a/paddle/phi/api/yaml/legacy_ops.yaml +++ b/paddle/phi/api/yaml/legacy_ops.yaml @@ -771,17 +771,6 @@ func : pad backward : pad_grad -- op : pool2d - args : (Tensor x, IntArray kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) - output : Tensor(out) - infer_meta : - func : Pool2DInferMeta - param : [x, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm] - kernel : - func : pool2d - param : [x, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm] - backward : pool2d_grad - - op : pool3d args : (Tensor x, int[] kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) output : Tensor(out) diff --git a/paddle/phi/api/yaml/op_compat.yaml b/paddle/phi/api/yaml/op_compat.yaml index 0d77b08acbadd5..30608f8e0c8cb7 100755 --- a/paddle/phi/api/yaml/op_compat.yaml +++ b/paddle/phi/api/yaml/op_compat.yaml @@ -1775,6 +1775,14 @@ - op : pool2d backward : pool2d_grad + inputs : + {x : X} + outputs : + {out : Out} + int_array: + ksize : + data_type : int + support_tensor : true extra : attrs : [bool use_mkldnn = false, bool use_quantizer = false, str mkldnn_data_type = "float32", bool is_test = false] diff --git a/paddle/phi/api/yaml/static_backward.yaml b/paddle/phi/api/yaml/static_backward.yaml index 27b2589ce9bc06..d330f0cb4ffd50 100755 --- a/paddle/phi/api/yaml/static_backward.yaml +++ b/paddle/phi/api/yaml/static_backward.yaml @@ -43,6 +43,30 @@ func : frobenius_norm_grad param : [x, out, out_grad, axis, keepdim, reduce_all] +- backward_op : pool2d_double_grad + forward : pool2d_grad (Tensor x, str pooling_type, IntArray ksize, bool global_pooling = false, int[] strides = {1,1}, int[] paddings = {0,0}, bool exclusive = true, bool adaptive = false, bool ceil_mode = false, str data_format = "NCHW", str padding_algorithm = "EXPLICIT",bool use_cudnn = false) -> Tensor(grad_x) + args : (Tensor x, Tensor out, Tensor out_grad, str pooling_type, IntArray ksize, bool global_pooling, int[] strides, int[] paddings, bool exclusive, bool adaptive, bool ceil_mode, str data_format, str padding_algorithm, bool use_cudnn) + output : Tensor(grad_out_grad) + infer_meta : + func : Pool2DInferMeta + param : [grad_x_grad, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm] + kernel : + func : pool2d_double_grad + param : [grad_x_grad, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm] + no_need_buffer : x + +- backward_op : pool2d_grad + forward : pool2d (Tensor x, str pooling_type, IntArray ksize, bool global_pooling = false, int[] strides = {1,1}, int[] paddings = {0,0}, bool exclusive = true, bool adaptive = false, bool ceil_mode = false, str data_format = "NCHW", str padding_algorithm = "EXPLICIT",bool use_cudnn = false) -> Tensor(out) + args : (Tensor x, Tensor out, Tensor out_grad, str pooling_type, IntArray ksize, bool global_pooling, int[] strides, int[] paddings, bool exclusive, bool adaptive, bool ceil_mode, str data_format, str padding_algorithm, bool use_cudnn) + output : Tensor(x_grad) + infer_meta : + func : UnchangedInferMeta + param: [x] + kernel : + func : pool2d_grad + param : [x, out, out_grad, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm] + backward : pool2d_double_grad + - backward_op : rnn_grad forward : rnn (Tensor x, Tensor[] pre_state, Tensor[] weight_list, Tensor sequence_length, float dropout_prob=0.0, bool is_bidirec=false, int input_size=10, int hidden_size=100, int num_layers=1, str mode="RNN_TANH", int seed=0, bool is_test=false) -> Tensor(out), Tensor(dropout_state_out), Tensor[](state), Tensor(reserve) args : (Tensor x, Tensor[] pre_state, Tensor[] weight_list, Tensor sequence_length, Tensor out, Tensor dropout_state_out, Tensor reserve, Tensor out_grad, Tensor[] state_grad, float dropout_prob, bool is_bidirec, int input_size, int hidden_size, int num_layers, str mode, int seed, bool is_test) diff --git a/paddle/phi/api/yaml/static_ops.yaml b/paddle/phi/api/yaml/static_ops.yaml index 095bb89836e7e9..688c58d762c447 100755 --- a/paddle/phi/api/yaml/static_ops.yaml +++ b/paddle/phi/api/yaml/static_ops.yaml @@ -271,6 +271,17 @@ func : p_recv_array param : [peer, dtype, out_shape] +- op : pool2d + args : (Tensor x, str pooling_type, IntArray ksize, bool global_pooling = false, int[] strides = {1,1}, int[] paddings = {0,0}, bool exclusive = true, bool adaptive = false, bool ceil_mode = false, str data_format = "NCHW", str padding_algorithm = "EXPLICIT",bool use_cudnn = false) + output : Tensor(out) + infer_meta : + func : Pool2DInferMeta + param : [x, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm] + kernel : + func : pool2d + param : [x, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm] + backward : pool2d_grad + - op : randint args : (int low, int high, IntArray shape = {}, DataType dtype = DataType::INT64, int seed = 0) output : Tensor(out) diff --git a/paddle/phi/ops/compat/pool_sig.cc b/paddle/phi/ops/compat/pool_sig.cc index 9d5fda52cf2e32..21b3f792a221c6 100644 --- a/paddle/phi/ops/compat/pool_sig.cc +++ b/paddle/phi/ops/compat/pool_sig.cc @@ -16,57 +16,6 @@ namespace phi { -KernelSignature Pool2dOpArgumentMapping( - const ArgumentMappingContext& ctx UNUSED) { - return KernelSignature("pool2d", - {"X"}, - {"ksize", - "strides", - "paddings", - "ceil_mode", - "exclusive", - "data_format", - "pooling_type", - "global_pooling", - "adaptive", - "padding_algorithm"}, - {"Out"}); -} - -KernelSignature Pool2dGradOpArgumentMapping( - const ArgumentMappingContext& ctx UNUSED) { - return KernelSignature("pool2d_grad", - {"X", "Out", "Out@GRAD"}, - {"ksize", - "strides", - "paddings", - "ceil_mode", - "exclusive", - "data_format", - "pooling_type", - "global_pooling", - "adaptive", - "padding_algorithm"}, - {"X@GRAD"}); -} - -KernelSignature Pool2dDoubleGradOpArgumentMapping( - const ArgumentMappingContext& ctx UNUSED) { - return KernelSignature("pool2d_double_grad", - {"X"}, - {"ksize", - "strides", - "paddings", - "ceil_mode", - "exclusive", - "data_format", - "pooling_type", - "global_pooling", - "adaptive", - "padding_algorithm"}, - {"Out"}); -} - KernelSignature Pool3dOpArgumentMapping( const ArgumentMappingContext& ctx UNUSED) { return KernelSignature("pool3d", @@ -103,10 +52,5 @@ KernelSignature Pool3dGradOpArgumentMapping( } // namespace phi -PD_REGISTER_ARG_MAPPING_FN(pool2d, phi::Pool2dOpArgumentMapping); -PD_REGISTER_ARG_MAPPING_FN(pool2d_grad, phi::Pool2dGradOpArgumentMapping); -PD_REGISTER_ARG_MAPPING_FN(pool2d_double_grad, - phi::Pool2dDoubleGradOpArgumentMapping); - PD_REGISTER_ARG_MAPPING_FN(pool3d, phi::Pool3dOpArgumentMapping); PD_REGISTER_ARG_MAPPING_FN(pool3d_grad, phi::Pool3dGradOpArgumentMapping); From 01f4c462cd7745e30420e703d00e0bd3d0ba1e84 Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Tue, 23 May 2023 23:57:02 +0800 Subject: [PATCH 02/24] [phi] move poolop GetExpectedKernelType and GetKernelTypeForVar --- .../generator/get_expected_kernel_func.cc | 39 +++++++++ .../generator/get_expected_kernel_func.h | 8 ++ paddle/fluid/operators/pool_op.cc | 85 ------------------- paddle/fluid/operators/pool_op.h | 28 ------ paddle/phi/api/yaml/static_backward.yaml | 2 +- paddle/phi/kernels/onednn/pool_grad_kernel.cc | 20 +++++ paddle/phi/kernels/onednn/pool_kernel.cc | 28 +++++- 7 files changed, 95 insertions(+), 115 deletions(-) diff --git a/paddle/fluid/operators/generator/get_expected_kernel_func.cc b/paddle/fluid/operators/generator/get_expected_kernel_func.cc index 0520af7c505b72..3280d7d58dde64 100644 --- a/paddle/fluid/operators/generator/get_expected_kernel_func.cc +++ b/paddle/fluid/operators/generator/get_expected_kernel_func.cc @@ -61,6 +61,20 @@ static bool ReduceOpHasOptimizedOneDNNKernel( return true; } +// only poolop +bool CanMKLDNNSupportPool(const framework::ExecutionContext& ctx) { + if (ctx.Attr("adaptive") == false) return true; + // oneDNN is supporting only unchangable in size pool window + auto src_tz = phi::vectorize(ctx.Input("X")->dims()); + if (!ctx.HasAttr("ksize")) { + return false; + } + std::vector ksize = ctx.Attr>("ksize"); + // Fast but not exhustive check + return ((src_tz[src_tz.size() - 1] % ksize[1] == 0) && + (src_tz[src_tz.size() - 2] % ksize[0] == 0)); +} + phi::KernelKey GetReduceExpectedKernelType( const framework::ExecutionContext& ctx, const framework::OperatorWithKernel* op_ptr) { @@ -117,6 +131,31 @@ phi::KernelKey GetAssignExpectedKernelType( ctx.device_context().GetPlace()); } +phi::KernelKey GetPoolExpectedKernelType( + const framework::ExecutionContext& ctx, + const framework::OperatorWithKernel* op_ptr) { + auto data_type = op_ptr->OperatorWithKernel::IndicateVarDataType(ctx, "X"); + + // NOTE(jiahongyu): Below codes originally enclosed by PADDLE_WITH_MKLDNN + this->SetDnnFallback(!CanMKLDNNSupportPool(ctx)); + // NOTE(jiahongyu) END: Above codes originally enclosed by PADDLE_WITH_MKLDNN + + return phi::KernelKey(data_type, ctx.GetPlace()); +} + +phi::KernelKey PoolOpGrad::GetExpectedKernelType( + const framework::ExecutionContext& ctx, + const framework::OperatorWithKernel* op_ptr) { + auto input_data_type = + op_ptr->OperatorWithKernel::IndicateVarDataType(ctx, "X"); + + // NOTE(jiahongyu): Below codes originally enclosed by PADDLE_WITH_MKLDNN + this->SetDnnFallback(!CanMKLDNNSupportPool(ctx)); + // NOTE(jiahongyu): Above codes originally enclosed by PADDLE_WITH_MKLDNN + + return phi::KernelKey(input_data_type, ctx.GetPlace()); +} + phi::KernelKey GetSgdExpectedKernelType( const framework::ExecutionContext& ctx, const framework::OperatorWithKernel* op_ptr) { diff --git a/paddle/fluid/operators/generator/get_expected_kernel_func.h b/paddle/fluid/operators/generator/get_expected_kernel_func.h index bf7c691fffa461..11140066a2650d 100644 --- a/paddle/fluid/operators/generator/get_expected_kernel_func.h +++ b/paddle/fluid/operators/generator/get_expected_kernel_func.h @@ -32,6 +32,14 @@ phi::KernelKey GetAssignExpectedKernelType( const framework::ExecutionContext& ctx, const framework::OperatorWithKernel* op_ptr); +phi::KernelKey GetPoolExpectedKernelType( + const framework::ExecutionContext& ctx, + const framework::OperatorWithKernel* op_ptr); + +phi::KernelKey GetPoolGradExpectedKernelType( + const framework::ExecutionContext& ctx, + const framework::OperatorWithKernel* op_ptr); + phi::KernelKey GetSgdExpectedKernelType( const framework::ExecutionContext& ctx, const framework::OperatorWithKernel* op_ptr); diff --git a/paddle/fluid/operators/pool_op.cc b/paddle/fluid/operators/pool_op.cc index 38cc1c9855c57f..5a8d93120be761 100644 --- a/paddle/fluid/operators/pool_op.cc +++ b/paddle/fluid/operators/pool_op.cc @@ -29,91 +29,6 @@ limitations under the License. */ namespace paddle { namespace operators { -bool CanMKLDNNSupportPool(const framework::ExecutionContext& ctx) { - if (ctx.Attr("adaptive") == false) return true; - // oneDNN is supporting only unchangable in size pool window - auto src_tz = phi::vectorize(ctx.Input("X")->dims()); - if (!ctx.HasAttr("ksize")) { - return false; - } - std::vector ksize = ctx.Attr>("ksize"); - // Fast but not exhustive check - return ((src_tz[src_tz.size() - 1] % ksize[1] == 0) && - (src_tz[src_tz.size() - 2] % ksize[0] == 0)); -} - -phi::KernelKey PoolOp::GetExpectedKernelType( - const framework::ExecutionContext& ctx) const { - auto data_type = OperatorWithKernel::IndicateVarDataType(ctx, "X"); - - // NOTE(jiahongyu): Below codes originally enclosed by PADDLE_WITH_MKLDNN - this->SetDnnFallback(!CanMKLDNNSupportPool(ctx)); - // NOTE(jiahongyu) END: Above codes originally enclosed by PADDLE_WITH_MKLDNN - - return phi::KernelKey(data_type, ctx.GetPlace()); -} - -phi::KernelKey PoolOp::GetKernelTypeForVar( - const std::string& var_name, - const phi::DenseTensor& tensor, - const phi::KernelKey& expected_kernel_type) const { -#ifdef PADDLE_WITH_MKLDNN - if ((expected_kernel_type.layout() == phi::DataLayout::ONEDNN) && - (tensor.layout() != phi::DataLayout::ONEDNN)) { - auto attrs = Attrs(); - auto ar = paddle::framework::AttrReader(attrs); - const std::string data_format = ar.Get("data_format"); - auto dl = phi::StringToDataLayout(data_format); - // Some models may have intentionally set "AnyLayout" for pool - // op. Treat this as NCHW (default data_format value) - if (dl != phi::DataLayout::kAnyLayout) { - return phi::KernelKey(tensor.place(), dl, expected_kernel_type.dtype()); - } - } -#endif - return phi::KernelKey( - tensor.place(), tensor.layout(), expected_kernel_type.dtype()); -} - -phi::KernelKey PoolOpGrad::GetExpectedKernelType( - const framework::ExecutionContext& ctx) const { - auto input_data_type = OperatorWithKernel::IndicateVarDataType(ctx, "X"); - - // NOTE(jiahongyu): Below codes originally enclosed by PADDLE_WITH_MKLDNN - this->SetDnnFallback(!CanMKLDNNSupportPool(ctx)); - // NOTE(jiahongyu): Above codes originally enclosed by PADDLE_WITH_MKLDNN - - return phi::KernelKey(input_data_type, ctx.GetPlace()); -} - -phi::KernelKey PoolOpGrad::GetKernelTypeForVar( - const std::string& var_name, - const phi::DenseTensor& tensor, - const phi::KernelKey& expected_kernel_type) const { -#ifdef PADDLE_WITH_MKLDNN - if ((expected_kernel_type.layout() == phi::DataLayout::ONEDNN) && - (tensor.layout() != phi::DataLayout::ONEDNN)) { - auto attrs = Attrs(); - auto ar = paddle::framework::AttrReader(attrs); - const std::string data_format = ar.Get("data_format"); - return phi::KernelKey(tensor.place(), - phi::StringToDataLayout(data_format), - expected_kernel_type.dtype()); - } -#endif - return phi::KernelKey( - tensor.place(), tensor.layout(), expected_kernel_type.dtype()); -} - -class PoolOpInferVarType : public framework::PassInDtypeAndVarTypeToOutput { - protected: - std::unordered_map& GetInputOutputWithSameType() - const override { - static std::unordered_map m{{"X", /*->*/ "Out"}}; - return m; - } -}; - void Pool3dOpMaker::Make() { AddInput("X", "(phi::DenseTensor) The input tensor of pooling operator. " diff --git a/paddle/fluid/operators/pool_op.h b/paddle/fluid/operators/pool_op.h index 8add637cb346f9..fe77537698ff00 100644 --- a/paddle/fluid/operators/pool_op.h +++ b/paddle/fluid/operators/pool_op.h @@ -19,34 +19,6 @@ limitations under the License. */ namespace paddle { namespace operators { -class PoolOp : public framework::OperatorWithKernel { - public: - using framework::OperatorWithKernel::OperatorWithKernel; - - protected: - phi::KernelKey GetExpectedKernelType( - const framework::ExecutionContext& ctx) const override; - - phi::KernelKey GetKernelTypeForVar( - const std::string& var_name, - const phi::DenseTensor& tensor, - const phi::KernelKey& expected_kernel_type) const override; -}; - -class PoolOpGrad : public framework::OperatorWithKernel { - public: - using framework::OperatorWithKernel::OperatorWithKernel; - - protected: - phi::KernelKey GetExpectedKernelType( - const framework::ExecutionContext& ctx) const override; - - phi::KernelKey GetKernelTypeForVar( - const std::string& var_name, - const phi::DenseTensor& tensor, - const phi::KernelKey& expected_kernel_type) const override; -}; - class Pool3dOpMaker : public framework::OpProtoAndCheckerMaker { public: void Make() override; diff --git a/paddle/phi/api/yaml/static_backward.yaml b/paddle/phi/api/yaml/static_backward.yaml index d330f0cb4ffd50..2d313241efe46a 100755 --- a/paddle/phi/api/yaml/static_backward.yaml +++ b/paddle/phi/api/yaml/static_backward.yaml @@ -44,7 +44,7 @@ param : [x, out, out_grad, axis, keepdim, reduce_all] - backward_op : pool2d_double_grad - forward : pool2d_grad (Tensor x, str pooling_type, IntArray ksize, bool global_pooling = false, int[] strides = {1,1}, int[] paddings = {0,0}, bool exclusive = true, bool adaptive = false, bool ceil_mode = false, str data_format = "NCHW", str padding_algorithm = "EXPLICIT",bool use_cudnn = false) -> Tensor(grad_x) + forward : pool2d_grad (Tensor x, Tensor out, Tensor out_grad, str pooling_type, IntArray ksize, bool global_pooling, int[] strides, int[] paddings, bool exclusive, bool adaptive, bool ceil_mode, str data_format, str padding_algorithm, bool use_cudnn) -> Tensor(grad_x) args : (Tensor x, Tensor out, Tensor out_grad, str pooling_type, IntArray ksize, bool global_pooling, int[] strides, int[] paddings, bool exclusive, bool adaptive, bool ceil_mode, str data_format, str padding_algorithm, bool use_cudnn) output : Tensor(grad_out_grad) infer_meta : diff --git a/paddle/phi/kernels/onednn/pool_grad_kernel.cc b/paddle/phi/kernels/onednn/pool_grad_kernel.cc index df68de6a059129..61cb4acbcfc37c 100644 --- a/paddle/phi/kernels/onednn/pool_grad_kernel.cc +++ b/paddle/phi/kernels/onednn/pool_grad_kernel.cc @@ -71,6 +71,26 @@ void Pool2dGradKernel(const Context& dev_ctx, dx->set_mem_desc(diff_src_memory->get_desc()); } + +phi::KernelKey PoolOpGradGetKernelTypeForVar( + const std::string& var_name, + const phi::DenseTensor& tensor, + const phi::KernelKey& expected_kernel_type) const { +#ifdef PADDLE_WITH_MKLDNN + if ((expected_kernel_type.layout() == phi::DataLayout::ONEDNN) && + (tensor.layout() != phi::DataLayout::ONEDNN)) { + auto attrs = Attrs(); + auto ar = paddle::framework::AttrReader(attrs); + const std::string data_format = ar.Get("data_format"); + return phi::KernelKey(tensor.place(), + phi::StringToDataLayout(data_format), + expected_kernel_type.dtype()); + } +#endif + return phi::KernelKey( + tensor.place(), tensor.layout(), expected_kernel_type.dtype()); +} + } // namespace phi PD_REGISTER_KERNEL(pool2d_grad, diff --git a/paddle/phi/kernels/onednn/pool_kernel.cc b/paddle/phi/kernels/onednn/pool_kernel.cc index 726014396b1241..2da962f1a1d37a 100644 --- a/paddle/phi/kernels/onednn/pool_kernel.cc +++ b/paddle/phi/kernels/onednn/pool_kernel.cc @@ -70,6 +70,30 @@ void Pool2dKernel(const Context& dev_ctx, out->set_mem_desc(dst_memory->get_desc()); } + +phi::KernelKey PoolOpGetKernelTypeForVar( + const GetKernelTypeForVarContext* ctx) { + const std::string& var_name = ctx->GetVarName(); + const phi::DenseTensor& tensor = ctx->GetTensor(); + const phi::KernelKey& expected_kernel_type = ctx->GetKernelKey(); +#ifdef PADDLE_WITH_MKLDNN + if ((expected_kernel_type.layout() == phi::DataLayout::ONEDNN) && + (tensor.layout() != phi::DataLayout::ONEDNN)) { + auto attrs = Attrs(); + auto ar = paddle::framework::AttrReader(attrs); + const std::string data_format = ar.Get("data_format"); + auto dl = phi::StringToDataLayout(data_format); + // Some models may have intentionally set "AnyLayout" for pool + // op. Treat this as NCHW (default data_format value) + if (dl != phi::DataLayout::kAnyLayout) { + return phi::KernelKey(tensor.place(), dl, expected_kernel_type.dtype()); + } + } +#endif + return phi::KernelKey( + tensor.place(), tensor.layout(), expected_kernel_type.dtype()); +} + } // namespace phi PD_REGISTER_KERNEL(pool2d, @@ -79,4 +103,6 @@ PD_REGISTER_KERNEL(pool2d, float, int8_t, uint8_t, - phi::dtype::bfloat16) {} + phi::dtype::bfloat16) { + kernel->get_kerneltype_forvar_fn_ = phi::PoolOpGetKernelTypeForVar; +} From 7f7fabc9597a95bc1c27626f38ad87a8358e0c11 Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Wed, 24 May 2023 00:08:15 +0800 Subject: [PATCH 03/24] [phi] fix move GetExpectedKernelType --- .../operators/generator/get_expected_kernel_func.cc | 2 +- paddle/phi/api/yaml/op_compat.yaml | 4 ++++ paddle/phi/kernels/onednn/pool_grad_kernel.cc | 11 +++++++---- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/paddle/fluid/operators/generator/get_expected_kernel_func.cc b/paddle/fluid/operators/generator/get_expected_kernel_func.cc index 3280d7d58dde64..1a9b8d00c373bb 100644 --- a/paddle/fluid/operators/generator/get_expected_kernel_func.cc +++ b/paddle/fluid/operators/generator/get_expected_kernel_func.cc @@ -143,7 +143,7 @@ phi::KernelKey GetPoolExpectedKernelType( return phi::KernelKey(data_type, ctx.GetPlace()); } -phi::KernelKey PoolOpGrad::GetExpectedKernelType( +phi::KernelKey GetPoolOpGradExpectedKernelType( const framework::ExecutionContext& ctx, const framework::OperatorWithKernel* op_ptr) { auto input_data_type = diff --git a/paddle/phi/api/yaml/op_compat.yaml b/paddle/phi/api/yaml/op_compat.yaml index 30608f8e0c8cb7..d0c4cba086b830 100755 --- a/paddle/phi/api/yaml/op_compat.yaml +++ b/paddle/phi/api/yaml/op_compat.yaml @@ -1783,6 +1783,10 @@ ksize : data_type : int support_tensor : true + get_expected_kernel_type : + pool2d : GetPoolExpectedKernelType + pool2d_grad : GetPoolOpGradExpectedKernelType + pool2d_double_grad : GetPoolExpectedKernelType extra : attrs : [bool use_mkldnn = false, bool use_quantizer = false, str mkldnn_data_type = "float32", bool is_test = false] diff --git a/paddle/phi/kernels/onednn/pool_grad_kernel.cc b/paddle/phi/kernels/onednn/pool_grad_kernel.cc index 61cb4acbcfc37c..481a8fd73aa5dd 100644 --- a/paddle/phi/kernels/onednn/pool_grad_kernel.cc +++ b/paddle/phi/kernels/onednn/pool_grad_kernel.cc @@ -73,9 +73,10 @@ void Pool2dGradKernel(const Context& dev_ctx, } phi::KernelKey PoolOpGradGetKernelTypeForVar( - const std::string& var_name, - const phi::DenseTensor& tensor, - const phi::KernelKey& expected_kernel_type) const { + const GetKernelTypeForVarContext* ctx) { + const std::string& var_name = ctx->GetVarName(); + const DenseTensor& tensor = ctx->GetTensor(); + const KernelKey& expected_kernel_type = ctx->GetKernelKey(); #ifdef PADDLE_WITH_MKLDNN if ((expected_kernel_type.layout() == phi::DataLayout::ONEDNN) && (tensor.layout() != phi::DataLayout::ONEDNN)) { @@ -98,4 +99,6 @@ PD_REGISTER_KERNEL(pool2d_grad, ONEDNN, phi::Pool2dGradKernel, float, - phi::dtype::bfloat16) {} + phi::dtype::bfloat16) { + kernel->get_kerneltype_forvar_fn_ = phi::PoolOpGradGetKernelTypeForVar; +} From fc3dbc7c46cf7023a04876f7cc7f9c5c208aa961 Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Wed, 24 May 2023 00:52:00 +0800 Subject: [PATCH 04/24] [phi] autogen code pool3d --- paddle/fluid/operators/pool_op.cc | 243 ----------------------- paddle/fluid/operators/pool_op.h | 28 --- paddle/phi/api/yaml/legacy_backward.yaml | 11 - paddle/phi/api/yaml/legacy_ops.yaml | 11 - paddle/phi/api/yaml/op_compat.yaml | 7 + paddle/phi/api/yaml/static_backward.yaml | 19 +- paddle/phi/api/yaml/static_ops.yaml | 13 +- paddle/phi/ops/compat/pool_sig.cc | 56 ------ 8 files changed, 34 insertions(+), 354 deletions(-) delete mode 100644 paddle/fluid/operators/pool_op.cc delete mode 100644 paddle/fluid/operators/pool_op.h delete mode 100644 paddle/phi/ops/compat/pool_sig.cc diff --git a/paddle/fluid/operators/pool_op.cc b/paddle/fluid/operators/pool_op.cc deleted file mode 100644 index 5a8d93120be761..00000000000000 --- a/paddle/fluid/operators/pool_op.cc +++ /dev/null @@ -1,243 +0,0 @@ -/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. */ - -#include "paddle/fluid/operators/pool_op.h" - -#include - -#include "paddle/fluid/framework/infershape_utils.h" -#include "paddle/fluid/framework/op_registry.h" -#include "paddle/fluid/platform/device/gpu/gpu_dnn.h" -#include "paddle/phi/core/infermeta_utils.h" -#include "paddle/phi/infermeta/backward.h" -#include "paddle/phi/infermeta/unary.h" -#ifdef PADDLE_WITH_MKLDNN -#include "paddle/fluid/platform/mkldnn_helper.h" -#endif - -namespace paddle { -namespace operators { - -void Pool3dOpMaker::Make() { - AddInput("X", - "(phi::DenseTensor) The input tensor of pooling operator. " - "The format of input tensor is NCDHW or NDHWC, where N is batch " - "size, C is " - "the number of channels, and D, H and W is the depth, height and " - "width of " - "the feature, respectively."); - AddOutput("Out", - "(phi::DenseTensor) The output tensor of pooling operator." - "The format of output tensor is also NCDHW or NDHWC, " - "where N is batch size, C is " - "the number of channels, and D, H and W is the depth, height and " - "width of the feature, respectively."); - - AddAttr("pooling_type", - "(string) Pooling type, can be \"max\" for max-pooling " - "and \"avg\" for average-pooling.") - .InEnum({"max", "avg"}); - AddAttr>( - "ksize", - "(vector) The pooling window size(depth, height, " - "width) of pooling operator. " - "If global_pooling = true, ksize and paddings will " - "be ignored."); - AddAttr( - "global_pooling", - "(bool) Whether to use the global pooling. " - "If global_pooling = true, kernel size and paddings will be ignored. " - "Default False") - .SetDefault(false); - AddAttr>( - "strides", - "(vector, default {1,1,1}) Strides(depth, height, " - "width) of the pooling operator.") - .SetDefault({1, 1, 1}); // TODO(Chengduo): Add checker. (Currently, - // TypedAttrChecker don't support vector type.) - AddAttr>( - "paddings", - "(vector, default {0,0,0}), paddings(pad_depth_front, " - "pad_depth_back, " - "pad_height_top, pad_height_bottom, pad_width_left, pad_width_right" - ") of pooling operator. " - "If global_pooling = true, ksize and paddings will be ignored.") - .SetDefault({0, 0, 0}); // TODO(Chengduo): Add checker. (Currently, - // TypedAttrChecker don't support vector type.) - AddAttr( - "exclusive", - "(bool) When true, will exclude the zero-padding in the " - "averaging calculating, otherwise, include the zero-padding. Note, it " - "is only used when pooling_type is avg. The default is True. " - "Default True") - .SetDefault(true); - AddAttr( - "adaptive", - "(bool) When true, will perform adaptive pooling instead, " - "output shape in H and W dimensions will be same as ksize, input data " - "will be divided into grids specify by ksize averagely and perform " - "pooling in each grid area to get output pooling value. " - "Default False") - .SetDefault(false); - AddAttr( - "ceil_mode", - "(bool) Whether to use the ceil function to calculate " - "output height and width. False is the default. If it is set to False, " - "the floor function will be used. Default False") - .SetDefault(false); - AddAttr( - "data_format", - "(string, default NCDHW) Only used in " - "An optional string from: \"NDHWC\", \"NCDHW\". " - "Defaults to \"NDHWC\". Specify the data format of the output data, " - "the input will be transformed automatically. ") - .SetDefault("NCDHW"); - AddAttr( - "padding_algorithm", - "(string, default \"EXPLICIT\") An optional string from: \"EXPLICIT\"," - "\"SAME\",\"VALID\". Set to \"EXPLICIT\" for explicit padding. " - "Set to \"SAME\" or \"VALID\" for algorithm of padding. ") - .SetDefault("EXPLICIT"); - AddAttr( - "use_cudnn", - "(bool) Only used in cudnn kernel, need install cudnn. Default False") - .SetDefault(false) - .AsExtra(); - AddComment(R"DOC( -This operation calculates the output based on -the input, pooling_type, pool_size, pool_stride, and pool_padding parameters. -Input(X) and output(Out) are in NCDHW or NDHWC format, where N is batch -size, C is the number of channels, and D, H and W are the depth, height and -width of the feature, respectively. Parameters(pool_size, pool_stride, pool_padding) -hold three integer elements. These three elements represent depth, height and -width, respectively. The input(X) size and output(Out) size may be different. - -Example: - Input: - X shape: $(N, C, D_{in}, H_{in}, W_{in})$ - Output: - Out shape: $(N, C, D_{out}, H_{out}, W_{out})$ - - For pool_padding = "SAME": - $$ - D_{out} = \\frac{(D_{in} + strides[0] - 1)}{strides[0]} - $$ - $$ - H_{out} = \\frac{(H_{in} + strides[1] - 1)}{strides[1]} - $$ - $$ - W_{out} = \\frac{(W_{in} + strides[2] - 1)}{strides[2]} - $$ - - For pool_padding = "VALID": - $$ - D_{out} = \\frac{(D_{in} - ksize[0] + strides[0])}{strides[0]} - $$ - $$ - H_{out} = \\frac{(H_{in} - ksize[1] + strides[1])}{strides[1]} - $$ - $$ - W_{out} = \\frac{(W_{in} - ksize[2] + strides[2])}{strides[2]} - $$ - - For ceil_mode = false: - $$ - D_{out} = \\frac{(D_{in} - ksize[0] + pad_depth_front + pad_depth_back)}{strides[0]} + 1 - $$ - $$ - H_{out} = \\frac{(H_{in} - ksize[1] + pad_height_top + pad_height_bottom)}{strides[1]} + 1 - $$ - $$ - W_{out} = \\frac{(W_{in} - ksize[2] + pad_width_left + pad_width_right)}{strides[2]} + 1 - $$ - For ceil_mode = true: - $$ - D_{out} = \\frac{(D_{in} - ksize[0] + pad_depth_front + pad_depth_back + strides[0] -1)}{strides[0]} + 1 - $$ - $$ - H_{out} = \\frac{(H_{in} - ksize[1] + pad_height_top + pad_height_bottom + strides[1] -1)}{strides[1]} + 1 - $$ - $$ - W_{out} = \\frac{(W_{in} - ksize[2] + pad_width_left + pad_width_right + strides[2] -1)}{strides[2]} + 1 - $$ - - For exclusive = false: - $$ - dstart = i * strides[0] - pad_depth_front - $$ - $$ - dend = dstart + ksize[0] - $$ - $$ - hstart = j * strides[1] - pad_height_top - $$ - $$ - hend = hstart + ksize[1] - $$ - $$ - wstart = k * strides[2] - pad_width_left - $$ - $$ - wend = wstart + ksize[2] - $$ - $$ - Output(i ,j, k) = \\frac{sum(Input[dstart:dend, hstart:hend, wstart:wend])}{ksize[0] * ksize[1] * ksize[2]} - $$ - - For exclusive = true: - $$ - dstart = max(0, i * strides[0] - pad_depth_front) - $$ - $$ - dend = min(D, dstart + ksize[0]) - $$ - $$ - hstart = max(0, j * strides[1] - pad_height_top) - $$ - $$ - hend = min(H, hstart + ksize[1]) - $$ - $$ - wstart = max(0, k * strides[2] - pad_width_left) - $$ - $$ - wend = min(W, wstart + ksize[2]) - $$ - $$ - Output(i ,j, k) = \\frac{sum(Input[dstart:dend, hstart:hend, wstart:wend])}{(dend - dstart) * (hend - hstart) * (wend - wstart)} - $$ - -)DOC"); -} -} // namespace operators -} // namespace paddle - -namespace ops = paddle::operators; - -DECLARE_INFER_SHAPE_FUNCTOR(pool3d, - Pool3dInferShapeFunctor, - PD_INFER_META(phi::PoolInferMeta)); -DECLARE_INFER_SHAPE_FUNCTOR(pool3d_grad, - Pool3dGradInferShapeFunctor, - PD_INFER_META(phi::UnchangedInferMeta)); - -REGISTER_OPERATOR( - pool3d, - ops::PoolOp, - ops::Pool3dOpMaker, - ops::PoolOpInferVarType, - paddle::framework::DefaultGradOpMaker, - paddle::framework::DefaultGradOpMaker, - Pool3dInferShapeFunctor); -REGISTER_OPERATOR(pool3d_grad, ops::PoolOpGrad, Pool3dGradInferShapeFunctor); diff --git a/paddle/fluid/operators/pool_op.h b/paddle/fluid/operators/pool_op.h deleted file mode 100644 index fe77537698ff00..00000000000000 --- a/paddle/fluid/operators/pool_op.h +++ /dev/null @@ -1,28 +0,0 @@ -/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. */ - -#pragma once - -#include "paddle/fluid/framework/op_registry.h" - -namespace paddle { -namespace operators { - -class Pool3dOpMaker : public framework::OpProtoAndCheckerMaker { - public: - void Make() override; -}; - -} // namespace operators -} // namespace paddle diff --git a/paddle/phi/api/yaml/legacy_backward.yaml b/paddle/phi/api/yaml/legacy_backward.yaml index 3d1e7e2e87dfac..79f0c7546dccef 100755 --- a/paddle/phi/api/yaml/legacy_backward.yaml +++ b/paddle/phi/api/yaml/legacy_backward.yaml @@ -615,17 +615,6 @@ composite : pad_grad(x, out_grad, paddings, pad_value, x_grad) backward : pad_double_grad -- backward_op : pool3d_grad - forward : pool3d(Tensor x, int[] kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) -> Tensor(out) - args : (Tensor x, Tensor out, Tensor out_grad, int[] kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) - output : Tensor(x_grad) - infer_meta : - func : UnchangedInferMeta - param: [x] - kernel : - func : pool3d_grad - param : [x, out, out_grad, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm] - - backward_op : prod_grad forward : prod (Tensor x, IntArray dims, bool keep_dim, bool reduce_all) -> Tensor(out) args : (Tensor x, Tensor out, Tensor out_grad, IntArray dims, bool keep_dim, bool reduce_all) diff --git a/paddle/phi/api/yaml/legacy_ops.yaml b/paddle/phi/api/yaml/legacy_ops.yaml index 876ee1d613325f..01b1d21372f142 100755 --- a/paddle/phi/api/yaml/legacy_ops.yaml +++ b/paddle/phi/api/yaml/legacy_ops.yaml @@ -771,17 +771,6 @@ func : pad backward : pad_grad -- op : pool3d - args : (Tensor x, int[] kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) - output : Tensor(out) - infer_meta : - func : PoolInferMeta - param : [x, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm] - kernel : - func : pool3d - param : [x, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm] - backward : pool3d_grad - - op : prior_box args : (Tensor input, Tensor image, float[] min_sizes, float[] max_sizes = {}, float[] aspect_ratios = {}, float[] variances = {}, bool flip=true, bool clip=true, float step_w=0.0, float step_h=0.0, float offset=0.5, bool min_max_aspect_ratios_order=false) output : Tensor(out), Tensor(var) diff --git a/paddle/phi/api/yaml/op_compat.yaml b/paddle/phi/api/yaml/op_compat.yaml index d0c4cba086b830..cc87ba7b21a944 100755 --- a/paddle/phi/api/yaml/op_compat.yaml +++ b/paddle/phi/api/yaml/op_compat.yaml @@ -1793,6 +1793,13 @@ - op : pool3d backward : pool3d_grad + inputs : + {x : X} + outputs : + {out : Out} + get_expected_kernel_type : + pool3d : GetPoolExpectedKernelType + pool3d_grad : GetPoolOpGradExpectedKernelType extra : attrs : [bool use_mkldnn = false] diff --git a/paddle/phi/api/yaml/static_backward.yaml b/paddle/phi/api/yaml/static_backward.yaml index 2d313241efe46a..14b37528cb1817 100755 --- a/paddle/phi/api/yaml/static_backward.yaml +++ b/paddle/phi/api/yaml/static_backward.yaml @@ -44,8 +44,8 @@ param : [x, out, out_grad, axis, keepdim, reduce_all] - backward_op : pool2d_double_grad - forward : pool2d_grad (Tensor x, Tensor out, Tensor out_grad, str pooling_type, IntArray ksize, bool global_pooling, int[] strides, int[] paddings, bool exclusive, bool adaptive, bool ceil_mode, str data_format, str padding_algorithm, bool use_cudnn) -> Tensor(grad_x) - args : (Tensor x, Tensor out, Tensor out_grad, str pooling_type, IntArray ksize, bool global_pooling, int[] strides, int[] paddings, bool exclusive, bool adaptive, bool ceil_mode, str data_format, str padding_algorithm, bool use_cudnn) + forward : pool2d_grad (Tensor x, Tensor out, Tensor out_grad, str pooling_type, IntArray ksize, bool global_pooling, int[] strides, int[] paddings, bool exclusive, bool adaptive, bool ceil_mode, str data_format, str padding_algorithm) -> Tensor(grad_x) + args : (Tensor x, Tensor out, Tensor out_grad, str pooling_type, IntArray ksize, bool global_pooling, int[] strides, int[] paddings, bool exclusive, bool adaptive, bool ceil_mode, str data_format, str padding_algorithm) output : Tensor(grad_out_grad) infer_meta : func : Pool2DInferMeta @@ -56,8 +56,8 @@ no_need_buffer : x - backward_op : pool2d_grad - forward : pool2d (Tensor x, str pooling_type, IntArray ksize, bool global_pooling = false, int[] strides = {1,1}, int[] paddings = {0,0}, bool exclusive = true, bool adaptive = false, bool ceil_mode = false, str data_format = "NCHW", str padding_algorithm = "EXPLICIT",bool use_cudnn = false) -> Tensor(out) - args : (Tensor x, Tensor out, Tensor out_grad, str pooling_type, IntArray ksize, bool global_pooling, int[] strides, int[] paddings, bool exclusive, bool adaptive, bool ceil_mode, str data_format, str padding_algorithm, bool use_cudnn) + forward : pool2d (Tensor x, str pooling_type, IntArray ksize, bool global_pooling = false, int[] strides = {1,1}, int[] paddings = {0,0}, bool exclusive = true, bool adaptive = false, bool ceil_mode = false, str data_format = "NCHW", str padding_algorithm = "EXPLICIT") -> Tensor(out) + args : (Tensor x, Tensor out, Tensor out_grad, str pooling_type, IntArray ksize, bool global_pooling, int[] strides, int[] paddings, bool exclusive, bool adaptive, bool ceil_mode, str data_format, str padding_algorithm) output : Tensor(x_grad) infer_meta : func : UnchangedInferMeta @@ -67,6 +67,17 @@ param : [x, out, out_grad, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm] backward : pool2d_double_grad +- backward_op : pool3d_grad + forward : pool3d(Tensor x,str pooling_type, int[] ksize, int[] strides = {1,1,1}, int[] paddings = {0,0,0}, bool ceil_mode = false, bool exclusive = true, str data_format = "NCDHW", bool global_pooling = false, bool adaptive = false, str padding_algorithm = "EXPLICIT") -> Tensor(out) + args : (Tensor x, Tensor out, Tensor out_grad, str pooling_type, int[] ksize, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, bool global_pooling, bool adaptive, str padding_algorithm) + output : Tensor(x_grad) + infer_meta : + func : UnchangedInferMeta + param: [x] + kernel : + func : pool3d_grad + param : [x, out, out_grad, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm] + - backward_op : rnn_grad forward : rnn (Tensor x, Tensor[] pre_state, Tensor[] weight_list, Tensor sequence_length, float dropout_prob=0.0, bool is_bidirec=false, int input_size=10, int hidden_size=100, int num_layers=1, str mode="RNN_TANH", int seed=0, bool is_test=false) -> Tensor(out), Tensor(dropout_state_out), Tensor[](state), Tensor(reserve) args : (Tensor x, Tensor[] pre_state, Tensor[] weight_list, Tensor sequence_length, Tensor out, Tensor dropout_state_out, Tensor reserve, Tensor out_grad, Tensor[] state_grad, float dropout_prob, bool is_bidirec, int input_size, int hidden_size, int num_layers, str mode, int seed, bool is_test) diff --git a/paddle/phi/api/yaml/static_ops.yaml b/paddle/phi/api/yaml/static_ops.yaml index 688c58d762c447..6a8b782fbbaf28 100755 --- a/paddle/phi/api/yaml/static_ops.yaml +++ b/paddle/phi/api/yaml/static_ops.yaml @@ -272,7 +272,7 @@ param : [peer, dtype, out_shape] - op : pool2d - args : (Tensor x, str pooling_type, IntArray ksize, bool global_pooling = false, int[] strides = {1,1}, int[] paddings = {0,0}, bool exclusive = true, bool adaptive = false, bool ceil_mode = false, str data_format = "NCHW", str padding_algorithm = "EXPLICIT",bool use_cudnn = false) + args : (Tensor x, str pooling_type, IntArray ksize, bool global_pooling = false, int[] strides = {1,1}, int[] paddings = {0,0}, bool exclusive = true, bool adaptive = false, bool ceil_mode = false, str data_format = "NCHW", str padding_algorithm = "EXPLICIT") output : Tensor(out) infer_meta : func : Pool2DInferMeta @@ -282,6 +282,17 @@ param : [x, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm] backward : pool2d_grad +- op : pool3d + args : (Tensor x,str pooling_type, int[] ksize, int[] strides = {1,1,1}, int[] paddings = {0,0,0}, bool ceil_mode = false, bool exclusive = true, str data_format = "NCDHW", bool global_pooling = false, bool adaptive = false, str padding_algorithm = "EXPLICIT") + output : Tensor(out) + infer_meta : + func : PoolInferMeta + param : [x, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm] + kernel : + func : pool3d + param : [x, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm] + backward : pool3d_grad + - op : randint args : (int low, int high, IntArray shape = {}, DataType dtype = DataType::INT64, int seed = 0) output : Tensor(out) diff --git a/paddle/phi/ops/compat/pool_sig.cc b/paddle/phi/ops/compat/pool_sig.cc deleted file mode 100644 index 21b3f792a221c6..00000000000000 --- a/paddle/phi/ops/compat/pool_sig.cc +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "paddle/phi/core/compat/op_utils.h" - -namespace phi { - -KernelSignature Pool3dOpArgumentMapping( - const ArgumentMappingContext& ctx UNUSED) { - return KernelSignature("pool3d", - {"X"}, - {"ksize", - "strides", - "paddings", - "ceil_mode", - "exclusive", - "data_format", - "pooling_type", - "global_pooling", - "adaptive", - "padding_algorithm"}, - {"Out"}); -} - -KernelSignature Pool3dGradOpArgumentMapping( - const ArgumentMappingContext& ctx UNUSED) { - return KernelSignature("pool3d_grad", - {"X", "Out", "Out@GRAD"}, - {"ksize", - "strides", - "paddings", - "ceil_mode", - "exclusive", - "data_format", - "pooling_type", - "global_pooling", - "adaptive", - "padding_algorithm"}, - {"X@GRAD"}); -} - -} // namespace phi - -PD_REGISTER_ARG_MAPPING_FN(pool3d, phi::Pool3dOpArgumentMapping); -PD_REGISTER_ARG_MAPPING_FN(pool3d_grad, phi::Pool3dGradOpArgumentMapping); From dbda093e7d915aa1f1facd89549a4e78f8241be3 Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Wed, 24 May 2023 08:58:45 +0800 Subject: [PATCH 05/24] [fluid] fix get_expected_kernel_func --- paddle/fluid/operators/generator/get_expected_kernel_func.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/paddle/fluid/operators/generator/get_expected_kernel_func.cc b/paddle/fluid/operators/generator/get_expected_kernel_func.cc index 1a9b8d00c373bb..efa48c9c8b9dd4 100644 --- a/paddle/fluid/operators/generator/get_expected_kernel_func.cc +++ b/paddle/fluid/operators/generator/get_expected_kernel_func.cc @@ -137,7 +137,7 @@ phi::KernelKey GetPoolExpectedKernelType( auto data_type = op_ptr->OperatorWithKernel::IndicateVarDataType(ctx, "X"); // NOTE(jiahongyu): Below codes originally enclosed by PADDLE_WITH_MKLDNN - this->SetDnnFallback(!CanMKLDNNSupportPool(ctx)); + op_ptr->SetDnnFallback(!CanMKLDNNSupportPool(ctx)); // NOTE(jiahongyu) END: Above codes originally enclosed by PADDLE_WITH_MKLDNN return phi::KernelKey(data_type, ctx.GetPlace()); @@ -150,7 +150,7 @@ phi::KernelKey GetPoolOpGradExpectedKernelType( op_ptr->OperatorWithKernel::IndicateVarDataType(ctx, "X"); // NOTE(jiahongyu): Below codes originally enclosed by PADDLE_WITH_MKLDNN - this->SetDnnFallback(!CanMKLDNNSupportPool(ctx)); + op_ptr->SetDnnFallback(!CanMKLDNNSupportPool(ctx)); // NOTE(jiahongyu): Above codes originally enclosed by PADDLE_WITH_MKLDNN return phi::KernelKey(input_data_type, ctx.GetPlace()); From 1399e2a9941c87e707f835c6e68ac0b7c0d5cca8 Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Wed, 24 May 2023 10:36:20 +0800 Subject: [PATCH 06/24] [fluid] fix get_expected_kernel_func --- paddle/fluid/operators/generator/get_expected_kernel_func.cc | 2 +- paddle/phi/api/yaml/op_compat.yaml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/paddle/fluid/operators/generator/get_expected_kernel_func.cc b/paddle/fluid/operators/generator/get_expected_kernel_func.cc index efa48c9c8b9dd4..d13fcd4ea15b9b 100644 --- a/paddle/fluid/operators/generator/get_expected_kernel_func.cc +++ b/paddle/fluid/operators/generator/get_expected_kernel_func.cc @@ -143,7 +143,7 @@ phi::KernelKey GetPoolExpectedKernelType( return phi::KernelKey(data_type, ctx.GetPlace()); } -phi::KernelKey GetPoolOpGradExpectedKernelType( +phi::KernelKey GetPoolGradExpectedKernelType( const framework::ExecutionContext& ctx, const framework::OperatorWithKernel* op_ptr) { auto input_data_type = diff --git a/paddle/phi/api/yaml/op_compat.yaml b/paddle/phi/api/yaml/op_compat.yaml index cc87ba7b21a944..666c8806a24147 100755 --- a/paddle/phi/api/yaml/op_compat.yaml +++ b/paddle/phi/api/yaml/op_compat.yaml @@ -1785,7 +1785,7 @@ support_tensor : true get_expected_kernel_type : pool2d : GetPoolExpectedKernelType - pool2d_grad : GetPoolOpGradExpectedKernelType + pool2d_grad : GetPoolGradExpectedKernelType pool2d_double_grad : GetPoolExpectedKernelType extra : attrs : [bool use_mkldnn = false, bool use_quantizer = false, @@ -1799,7 +1799,7 @@ {out : Out} get_expected_kernel_type : pool3d : GetPoolExpectedKernelType - pool3d_grad : GetPoolOpGradExpectedKernelType + pool3d_grad : GetPoolGradExpectedKernelType extra : attrs : [bool use_mkldnn = false] From ddf15ba87077c535bf4c403ebdc0e6d70bba9aca Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Wed, 24 May 2023 11:12:30 +0800 Subject: [PATCH 07/24] [phi][yml] fix args --- paddle/phi/api/yaml/static_backward.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/paddle/phi/api/yaml/static_backward.yaml b/paddle/phi/api/yaml/static_backward.yaml index 14b37528cb1817..60582c3b35f9b1 100755 --- a/paddle/phi/api/yaml/static_backward.yaml +++ b/paddle/phi/api/yaml/static_backward.yaml @@ -45,8 +45,8 @@ - backward_op : pool2d_double_grad forward : pool2d_grad (Tensor x, Tensor out, Tensor out_grad, str pooling_type, IntArray ksize, bool global_pooling, int[] strides, int[] paddings, bool exclusive, bool adaptive, bool ceil_mode, str data_format, str padding_algorithm) -> Tensor(grad_x) - args : (Tensor x, Tensor out, Tensor out_grad, str pooling_type, IntArray ksize, bool global_pooling, int[] strides, int[] paddings, bool exclusive, bool adaptive, bool ceil_mode, str data_format, str padding_algorithm) - output : Tensor(grad_out_grad) + args : (Tensor x, str pooling_type, IntArray ksize, bool global_pooling, int[] strides, int[] paddings, bool exclusive, bool adaptive, bool ceil_mode, str data_format, str padding_algorithm) + output : Tensor(out_grad) infer_meta : func : Pool2DInferMeta param : [grad_x_grad, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm] From e81a123edee96f5b7617a615d1fc76208deee25e Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Wed, 24 May 2023 11:22:51 +0800 Subject: [PATCH 08/24] [fluid] rm pool_op cmake --- paddle/fluid/operators/unity_build_rule.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/paddle/fluid/operators/unity_build_rule.cmake b/paddle/fluid/operators/unity_build_rule.cmake index 10439807a9bb2a..074df24b882998 100644 --- a/paddle/fluid/operators/unity_build_rule.cmake +++ b/paddle/fluid/operators/unity_build_rule.cmake @@ -202,7 +202,6 @@ register_unity_group( cc partial_sum_op.cc pixel_shuffle_op.cc - pool_op.cc pool_with_index_op.cc positive_negative_pair_op.cc prelu_op.cc From 94eabd3414c210a61ddbfeb698f3ed3a7f1e4f75 Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Wed, 24 May 2023 22:10:55 +0800 Subject: [PATCH 09/24] [phi] fix GetKernelTypeForVar --- paddle/phi/kernels/onednn/pool_grad_kernel.cc | 7 +++---- paddle/phi/kernels/onednn/pool_kernel.cc | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/paddle/phi/kernels/onednn/pool_grad_kernel.cc b/paddle/phi/kernels/onednn/pool_grad_kernel.cc index 481a8fd73aa5dd..5c735ac48c6d69 100644 --- a/paddle/phi/kernels/onednn/pool_grad_kernel.cc +++ b/paddle/phi/kernels/onednn/pool_grad_kernel.cc @@ -74,15 +74,14 @@ void Pool2dGradKernel(const Context& dev_ctx, phi::KernelKey PoolOpGradGetKernelTypeForVar( const GetKernelTypeForVarContext* ctx) { - const std::string& var_name = ctx->GetVarName(); const DenseTensor& tensor = ctx->GetTensor(); const KernelKey& expected_kernel_type = ctx->GetKernelKey(); #ifdef PADDLE_WITH_MKLDNN if ((expected_kernel_type.layout() == phi::DataLayout::ONEDNN) && (tensor.layout() != phi::DataLayout::ONEDNN)) { - auto attrs = Attrs(); - auto ar = paddle::framework::AttrReader(attrs); - const std::string data_format = ar.Get("data_format"); + const AttributeMap& attrs = ctx->GetAttrs(); + auto it = attrs.find("data_format"); + const std::string data_format = PADDLE_GET_CONST(std::string, it->second); return phi::KernelKey(tensor.place(), phi::StringToDataLayout(data_format), expected_kernel_type.dtype()); diff --git a/paddle/phi/kernels/onednn/pool_kernel.cc b/paddle/phi/kernels/onednn/pool_kernel.cc index 2da962f1a1d37a..d4605e3d818b6d 100644 --- a/paddle/phi/kernels/onednn/pool_kernel.cc +++ b/paddle/phi/kernels/onednn/pool_kernel.cc @@ -73,15 +73,14 @@ void Pool2dKernel(const Context& dev_ctx, phi::KernelKey PoolOpGetKernelTypeForVar( const GetKernelTypeForVarContext* ctx) { - const std::string& var_name = ctx->GetVarName(); const phi::DenseTensor& tensor = ctx->GetTensor(); const phi::KernelKey& expected_kernel_type = ctx->GetKernelKey(); #ifdef PADDLE_WITH_MKLDNN if ((expected_kernel_type.layout() == phi::DataLayout::ONEDNN) && (tensor.layout() != phi::DataLayout::ONEDNN)) { - auto attrs = Attrs(); - auto ar = paddle::framework::AttrReader(attrs); - const std::string data_format = ar.Get("data_format"); + const AttributeMap& attrs = ctx->GetAttrs(); + auto it = attrs.find("data_format"); + const std::string data_format = PADDLE_GET_CONST(std::string, it->second); auto dl = phi::StringToDataLayout(data_format); // Some models may have intentionally set "AnyLayout" for pool // op. Treat this as NCHW (default data_format value) From a0399b10ffca909ef0d65f02ef64467419e8fab5 Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Thu, 25 May 2023 13:53:37 +0800 Subject: [PATCH 10/24] [phi] fix args; reduction legacy --- paddle/phi/api/yaml/legacy_backward.yaml | 24 ++++++++++++++++++++++++ paddle/phi/api/yaml/legacy_ops.yaml | 11 +++++++++++ paddle/phi/api/yaml/op_compat.yaml | 21 ++++++++++++++++++++- paddle/phi/api/yaml/static_backward.yaml | 6 +++--- paddle/phi/api/yaml/static_ops.yaml | 2 +- 5 files changed, 59 insertions(+), 5 deletions(-) diff --git a/paddle/phi/api/yaml/legacy_backward.yaml b/paddle/phi/api/yaml/legacy_backward.yaml index 79f0c7546dccef..74a401d4bef403 100755 --- a/paddle/phi/api/yaml/legacy_backward.yaml +++ b/paddle/phi/api/yaml/legacy_backward.yaml @@ -615,6 +615,30 @@ composite : pad_grad(x, out_grad, paddings, pad_value, x_grad) backward : pad_double_grad +- backward_op : pool2d_double_grad + forward : pool2d_grad(Tensor x, Tensor out, Tensor grad_out, IntArray kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) -> Tensor(grad_x) + args : (Tensor x, Tensor grad_x_grad, IntArray kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) + output : Tensor(grad_out_grad) + infer_meta : + func : Pool2DInferMeta + param : [grad_x_grad, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm] + kernel : + func : pool2d_double_grad + param : [grad_x_grad, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm] + no_need_buffer : x + +- backward_op : pool2d_grad + forward : pool2d(Tensor x, IntArray kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) -> Tensor(out) + args : (Tensor x, Tensor out, Tensor out_grad, IntArray kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) + output : Tensor(x_grad) + infer_meta : + func : UnchangedInferMeta + param: [x] + kernel : + func : pool2d_grad + param : [x, out, out_grad, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm] + backward : pool2d_double_grad + - backward_op : prod_grad forward : prod (Tensor x, IntArray dims, bool keep_dim, bool reduce_all) -> Tensor(out) args : (Tensor x, Tensor out, Tensor out_grad, IntArray dims, bool keep_dim, bool reduce_all) diff --git a/paddle/phi/api/yaml/legacy_ops.yaml b/paddle/phi/api/yaml/legacy_ops.yaml index 01b1d21372f142..bc33637caf7845 100755 --- a/paddle/phi/api/yaml/legacy_ops.yaml +++ b/paddle/phi/api/yaml/legacy_ops.yaml @@ -771,6 +771,17 @@ func : pad backward : pad_grad +- op : pool2d + args : (Tensor x, IntArray kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) + output : Tensor(out) + infer_meta : + func : Pool2DInferMeta + param : [x, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm] + kernel : + func : pool2d + param : [x, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm] + backward : pool2d_grad + - op : prior_box args : (Tensor input, Tensor image, float[] min_sizes, float[] max_sizes = {}, float[] aspect_ratios = {}, float[] variances = {}, bool flip=true, bool clip=true, float step_w=0.0, float step_h=0.0, float offset=0.5, bool min_max_aspect_ratios_order=false) output : Tensor(out), Tensor(var) diff --git a/paddle/phi/api/yaml/op_compat.yaml b/paddle/phi/api/yaml/op_compat.yaml index 666c8806a24147..73fee13dbd23fd 100755 --- a/paddle/phi/api/yaml/op_compat.yaml +++ b/paddle/phi/api/yaml/op_compat.yaml @@ -14,6 +14,24 @@ # extra : # attrs : [bool is_test = false] +# - op : pool2d +# backward : pool2d_double_grad +# inputs : +# {x : X} +# outputs : +# {out : Out} +# int_array: +# ksize : +# data_type : int +# support_tensor : true +# get_expected_kernel_type : +# pool2d : GetPoolExpectedKernelType +# pool2d_grad : GetPoolGradExpectedKernelType +# pool2d_double_grad : GetPoolExpectedKernelType +# extra : +# attrs : [bool use_mkldnn = false, bool use_quantizer = false, +# str mkldnn_data_type = "float32", bool is_test = false] + - op : abs backward : abs_grad inputs : @@ -1780,8 +1798,9 @@ outputs : {out : Out} int_array: - ksize : + kernel_size : data_type : int + tensor_name : Ksize support_tensor : true get_expected_kernel_type : pool2d : GetPoolExpectedKernelType diff --git a/paddle/phi/api/yaml/static_backward.yaml b/paddle/phi/api/yaml/static_backward.yaml index 60582c3b35f9b1..f2c2af4457d6fc 100755 --- a/paddle/phi/api/yaml/static_backward.yaml +++ b/paddle/phi/api/yaml/static_backward.yaml @@ -44,7 +44,7 @@ param : [x, out, out_grad, axis, keepdim, reduce_all] - backward_op : pool2d_double_grad - forward : pool2d_grad (Tensor x, Tensor out, Tensor out_grad, str pooling_type, IntArray ksize, bool global_pooling, int[] strides, int[] paddings, bool exclusive, bool adaptive, bool ceil_mode, str data_format, str padding_algorithm) -> Tensor(grad_x) + forward : pool2d_grad(Tensor x, Tensor out, Tensor out_grad, IntArray kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) -> Tensor(grad_x) args : (Tensor x, str pooling_type, IntArray ksize, bool global_pooling, int[] strides, int[] paddings, bool exclusive, bool adaptive, bool ceil_mode, str data_format, str padding_algorithm) output : Tensor(out_grad) infer_meta : @@ -56,8 +56,8 @@ no_need_buffer : x - backward_op : pool2d_grad - forward : pool2d (Tensor x, str pooling_type, IntArray ksize, bool global_pooling = false, int[] strides = {1,1}, int[] paddings = {0,0}, bool exclusive = true, bool adaptive = false, bool ceil_mode = false, str data_format = "NCHW", str padding_algorithm = "EXPLICIT") -> Tensor(out) - args : (Tensor x, Tensor out, Tensor out_grad, str pooling_type, IntArray ksize, bool global_pooling, int[] strides, int[] paddings, bool exclusive, bool adaptive, bool ceil_mode, str data_format, str padding_algorithm) + forward : pool2d(Tensor x, IntArray kernel_size, int[] strides = {1,1}, int[] paddings = {0,0}, bool ceil_mode = false, bool exclusive = true, str data_format = "NCHW", str pooling_type = "", bool global_pooling = false, bool adaptive = false, str padding_algorithm = "EXPLICIT") -> Tensor(out) + args : (Tensor x, Tensor out, Tensor out_grad, IntArray kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) output : Tensor(x_grad) infer_meta : func : UnchangedInferMeta diff --git a/paddle/phi/api/yaml/static_ops.yaml b/paddle/phi/api/yaml/static_ops.yaml index 6a8b782fbbaf28..409911c08ca14a 100755 --- a/paddle/phi/api/yaml/static_ops.yaml +++ b/paddle/phi/api/yaml/static_ops.yaml @@ -272,7 +272,7 @@ param : [peer, dtype, out_shape] - op : pool2d - args : (Tensor x, str pooling_type, IntArray ksize, bool global_pooling = false, int[] strides = {1,1}, int[] paddings = {0,0}, bool exclusive = true, bool adaptive = false, bool ceil_mode = false, str data_format = "NCHW", str padding_algorithm = "EXPLICIT") + args : (Tensor x, IntArray kernel_size, int[] strides = {1,1}, int[] paddings = {0,0}, bool ceil_mode = false, bool exclusive = true, str data_format = "NCHW", str pooling_type = "", bool global_pooling = false, bool adaptive = false, str padding_algorithm = "EXPLICIT") output : Tensor(out) infer_meta : func : Pool2DInferMeta From 2099624dc5c2453d8bb99b81f91b9c64d8765198 Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Thu, 25 May 2023 14:23:11 +0800 Subject: [PATCH 11/24] [phi] fix pool2d_double_grad args --- paddle/phi/api/yaml/static_backward.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paddle/phi/api/yaml/static_backward.yaml b/paddle/phi/api/yaml/static_backward.yaml index f2c2af4457d6fc..ec8b141075ff84 100755 --- a/paddle/phi/api/yaml/static_backward.yaml +++ b/paddle/phi/api/yaml/static_backward.yaml @@ -45,7 +45,7 @@ - backward_op : pool2d_double_grad forward : pool2d_grad(Tensor x, Tensor out, Tensor out_grad, IntArray kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) -> Tensor(grad_x) - args : (Tensor x, str pooling_type, IntArray ksize, bool global_pooling, int[] strides, int[] paddings, bool exclusive, bool adaptive, bool ceil_mode, str data_format, str padding_algorithm) + args : (Tensor x, Tensor grad_x_grad, IntArray kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) output : Tensor(out_grad) infer_meta : func : Pool2DInferMeta From 010194d9e2ccade07fd1a7aa2c0dbafb1041ca51 Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Thu, 25 May 2023 14:55:17 +0800 Subject: [PATCH 12/24] [phi] fix pool3d args; reduction pool3d legacy; fix test --- paddle/phi/api/yaml/legacy_backward.yaml | 11 +++++++++++ paddle/phi/api/yaml/legacy_ops.yaml | 11 +++++++++++ paddle/phi/api/yaml/static_backward.yaml | 4 ++-- paddle/phi/api/yaml/static_ops.yaml | 2 +- test/cpp/fluid/mkldnn/CMakeLists.txt | 2 +- 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/paddle/phi/api/yaml/legacy_backward.yaml b/paddle/phi/api/yaml/legacy_backward.yaml index 74a401d4bef403..3e625667cf445d 100755 --- a/paddle/phi/api/yaml/legacy_backward.yaml +++ b/paddle/phi/api/yaml/legacy_backward.yaml @@ -639,6 +639,17 @@ param : [x, out, out_grad, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm] backward : pool2d_double_grad +- backward_op : pool3d_grad + forward : pool3d(Tensor x, int[] kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) -> Tensor(out) + args : (Tensor x, Tensor out, Tensor out_grad, int[] kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) + output : Tensor(x_grad) + infer_meta : + func : UnchangedInferMeta + param: [x] + kernel : + func : pool3d_grad + param : [x, out, out_grad, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm] + - backward_op : prod_grad forward : prod (Tensor x, IntArray dims, bool keep_dim, bool reduce_all) -> Tensor(out) args : (Tensor x, Tensor out, Tensor out_grad, IntArray dims, bool keep_dim, bool reduce_all) diff --git a/paddle/phi/api/yaml/legacy_ops.yaml b/paddle/phi/api/yaml/legacy_ops.yaml index bc33637caf7845..4dba3fdd74ec80 100755 --- a/paddle/phi/api/yaml/legacy_ops.yaml +++ b/paddle/phi/api/yaml/legacy_ops.yaml @@ -782,6 +782,17 @@ param : [x, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm] backward : pool2d_grad +- op : pool3d + args : (Tensor x, int[] kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) + output : Tensor(out) + infer_meta : + func : PoolInferMeta + param : [x, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm] + kernel : + func : pool3d + param : [x, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm] + backward : pool3d_grad + - op : prior_box args : (Tensor input, Tensor image, float[] min_sizes, float[] max_sizes = {}, float[] aspect_ratios = {}, float[] variances = {}, bool flip=true, bool clip=true, float step_w=0.0, float step_h=0.0, float offset=0.5, bool min_max_aspect_ratios_order=false) output : Tensor(out), Tensor(var) diff --git a/paddle/phi/api/yaml/static_backward.yaml b/paddle/phi/api/yaml/static_backward.yaml index ec8b141075ff84..406f9418e1bf8e 100755 --- a/paddle/phi/api/yaml/static_backward.yaml +++ b/paddle/phi/api/yaml/static_backward.yaml @@ -68,8 +68,8 @@ backward : pool2d_double_grad - backward_op : pool3d_grad - forward : pool3d(Tensor x,str pooling_type, int[] ksize, int[] strides = {1,1,1}, int[] paddings = {0,0,0}, bool ceil_mode = false, bool exclusive = true, str data_format = "NCDHW", bool global_pooling = false, bool adaptive = false, str padding_algorithm = "EXPLICIT") -> Tensor(out) - args : (Tensor x, Tensor out, Tensor out_grad, str pooling_type, int[] ksize, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, bool global_pooling, bool adaptive, str padding_algorithm) + forward : pool3d(Tensor x, int[] ksize, int[] strides = {1,1,1}, int[] paddings = {0,0,0}, bool ceil_mode = false, bool exclusive = true, str data_format = "NCDHW", str pooling_type = "", bool global_pooling = false, bool adaptive = false, str padding_algorithm = "EXPLICIT") -> Tensor(out) + args : (Tensor x, Tensor out, Tensor out_grad, int[] ksize, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) output : Tensor(x_grad) infer_meta : func : UnchangedInferMeta diff --git a/paddle/phi/api/yaml/static_ops.yaml b/paddle/phi/api/yaml/static_ops.yaml index 409911c08ca14a..d904fb2adf6d7f 100755 --- a/paddle/phi/api/yaml/static_ops.yaml +++ b/paddle/phi/api/yaml/static_ops.yaml @@ -283,7 +283,7 @@ backward : pool2d_grad - op : pool3d - args : (Tensor x,str pooling_type, int[] ksize, int[] strides = {1,1,1}, int[] paddings = {0,0,0}, bool ceil_mode = false, bool exclusive = true, str data_format = "NCDHW", bool global_pooling = false, bool adaptive = false, str padding_algorithm = "EXPLICIT") + args : (Tensor x, int[] ksize, int[] strides = {1,1,1}, int[] paddings = {0,0,0}, bool ceil_mode = false, bool exclusive = true, str data_format = "NCDHW", str pooling_type = "", bool global_pooling = false, bool adaptive = false, str padding_algorithm = "EXPLICIT") output : Tensor(out) infer_meta : func : PoolInferMeta diff --git a/test/cpp/fluid/mkldnn/CMakeLists.txt b/test/cpp/fluid/mkldnn/CMakeLists.txt index dae56ea5eb6d3b..47d481fcdeeb61 100644 --- a/test/cpp/fluid/mkldnn/CMakeLists.txt +++ b/test/cpp/fluid/mkldnn/CMakeLists.txt @@ -39,7 +39,7 @@ cc_test_old( test_mkldnn_op_nhwc.cc DEPS op_registry - pool_op + static_generated_op shape_op crop_op activation_op From 6f615f05ea2fe1ea7f271c23e53029f0f75592c2 Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Thu, 25 May 2023 14:57:21 +0800 Subject: [PATCH 13/24] clean --- paddle/phi/api/yaml/op_compat.yaml | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/paddle/phi/api/yaml/op_compat.yaml b/paddle/phi/api/yaml/op_compat.yaml index 73fee13dbd23fd..bb53e0c5efabbd 100755 --- a/paddle/phi/api/yaml/op_compat.yaml +++ b/paddle/phi/api/yaml/op_compat.yaml @@ -14,24 +14,6 @@ # extra : # attrs : [bool is_test = false] -# - op : pool2d -# backward : pool2d_double_grad -# inputs : -# {x : X} -# outputs : -# {out : Out} -# int_array: -# ksize : -# data_type : int -# support_tensor : true -# get_expected_kernel_type : -# pool2d : GetPoolExpectedKernelType -# pool2d_grad : GetPoolGradExpectedKernelType -# pool2d_double_grad : GetPoolExpectedKernelType -# extra : -# attrs : [bool use_mkldnn = false, bool use_quantizer = false, -# str mkldnn_data_type = "float32", bool is_test = false] - - op : abs backward : abs_grad inputs : From 83ffe1d841b52c237a382fc854e9054866f7a2a9 Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Thu, 25 May 2023 16:53:59 +0800 Subject: [PATCH 14/24] [phi] fix yaml add attrs ; [test] fix cmake --- paddle/phi/api/yaml/op_compat.yaml | 3 ++- test/cpp/fluid/mkldnn/CMakeLists.txt | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/paddle/phi/api/yaml/op_compat.yaml b/paddle/phi/api/yaml/op_compat.yaml index bb53e0c5efabbd..bacc15a77049cd 100755 --- a/paddle/phi/api/yaml/op_compat.yaml +++ b/paddle/phi/api/yaml/op_compat.yaml @@ -1779,10 +1779,11 @@ {x : X} outputs : {out : Out} + attrs : + {kernel_size : ksize} int_array: kernel_size : data_type : int - tensor_name : Ksize support_tensor : true get_expected_kernel_type : pool2d : GetPoolExpectedKernelType diff --git a/test/cpp/fluid/mkldnn/CMakeLists.txt b/test/cpp/fluid/mkldnn/CMakeLists.txt index 47d481fcdeeb61..403de85fb27684 100644 --- a/test/cpp/fluid/mkldnn/CMakeLists.txt +++ b/test/cpp/fluid/mkldnn/CMakeLists.txt @@ -39,7 +39,7 @@ cc_test_old( test_mkldnn_op_nhwc.cc DEPS op_registry - static_generated_op + generated_static_op shape_op crop_op activation_op From 19444d380ba939c0e23bc87b2c8ed9c1243f093b Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Thu, 25 May 2023 18:15:20 +0800 Subject: [PATCH 15/24] [phi] fix pool3d args --- paddle/phi/api/yaml/op_compat.yaml | 2 ++ paddle/phi/api/yaml/static_backward.yaml | 2 +- paddle/phi/api/yaml/static_ops.yaml | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/paddle/phi/api/yaml/op_compat.yaml b/paddle/phi/api/yaml/op_compat.yaml index bacc15a77049cd..9d338c2a15537a 100755 --- a/paddle/phi/api/yaml/op_compat.yaml +++ b/paddle/phi/api/yaml/op_compat.yaml @@ -1799,6 +1799,8 @@ {x : X} outputs : {out : Out} + attrs : + {kernel_size : ksize} get_expected_kernel_type : pool3d : GetPoolExpectedKernelType pool3d_grad : GetPoolGradExpectedKernelType diff --git a/paddle/phi/api/yaml/static_backward.yaml b/paddle/phi/api/yaml/static_backward.yaml index 406f9418e1bf8e..1edd9815fab490 100755 --- a/paddle/phi/api/yaml/static_backward.yaml +++ b/paddle/phi/api/yaml/static_backward.yaml @@ -68,7 +68,7 @@ backward : pool2d_double_grad - backward_op : pool3d_grad - forward : pool3d(Tensor x, int[] ksize, int[] strides = {1,1,1}, int[] paddings = {0,0,0}, bool ceil_mode = false, bool exclusive = true, str data_format = "NCDHW", str pooling_type = "", bool global_pooling = false, bool adaptive = false, str padding_algorithm = "EXPLICIT") -> Tensor(out) + forward : pool3d(Tensor x, int[] kernel_size, int[] strides = {1,1,1}, int[] paddings = {0,0,0}, bool ceil_mode = false, bool exclusive = true, str data_format = "NCDHW", str pooling_type = "", bool global_pooling = false, bool adaptive = false, str padding_algorithm = "EXPLICIT") -> Tensor(out) args : (Tensor x, Tensor out, Tensor out_grad, int[] ksize, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) output : Tensor(x_grad) infer_meta : diff --git a/paddle/phi/api/yaml/static_ops.yaml b/paddle/phi/api/yaml/static_ops.yaml index d904fb2adf6d7f..512e68bdf0ed2d 100755 --- a/paddle/phi/api/yaml/static_ops.yaml +++ b/paddle/phi/api/yaml/static_ops.yaml @@ -283,7 +283,7 @@ backward : pool2d_grad - op : pool3d - args : (Tensor x, int[] ksize, int[] strides = {1,1,1}, int[] paddings = {0,0,0}, bool ceil_mode = false, bool exclusive = true, str data_format = "NCDHW", str pooling_type = "", bool global_pooling = false, bool adaptive = false, str padding_algorithm = "EXPLICIT") + args : (Tensor x, int[] kernel_size, int[] strides = {1,1,1}, int[] paddings = {0,0,0}, bool ceil_mode = false, bool exclusive = true, str data_format = "NCDHW", str pooling_type = "", bool global_pooling = false, bool adaptive = false, str padding_algorithm = "EXPLICIT") output : Tensor(out) infer_meta : func : PoolInferMeta From b8ab81c85589a165cdebbd9bd09af4d0c8185d60 Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Thu, 25 May 2023 19:06:22 +0800 Subject: [PATCH 16/24] [phi] fix pool2d_double_grad args --- paddle/phi/api/yaml/static_backward.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paddle/phi/api/yaml/static_backward.yaml b/paddle/phi/api/yaml/static_backward.yaml index 1edd9815fab490..78152ad76a2421 100755 --- a/paddle/phi/api/yaml/static_backward.yaml +++ b/paddle/phi/api/yaml/static_backward.yaml @@ -44,7 +44,7 @@ param : [x, out, out_grad, axis, keepdim, reduce_all] - backward_op : pool2d_double_grad - forward : pool2d_grad(Tensor x, Tensor out, Tensor out_grad, IntArray kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) -> Tensor(grad_x) + forward : pool2d_grad(Tensor x, Tensor out, Tensor grad_out, IntArray kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) -> Tensor(grad_x) args : (Tensor x, Tensor grad_x_grad, IntArray kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) output : Tensor(out_grad) infer_meta : From ec9cfe5c44ad341b63bb232528fcd2543c0e4821 Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Mon, 29 May 2023 11:21:11 +0800 Subject: [PATCH 17/24] [phi] op_compat add keep_signature; RollBACK pool_sig --- paddle/phi/api/yaml/op_compat.yaml | 4 +- paddle/phi/ops/compat/pool_sig.cc | 112 +++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 paddle/phi/ops/compat/pool_sig.cc diff --git a/paddle/phi/api/yaml/op_compat.yaml b/paddle/phi/api/yaml/op_compat.yaml index e7736225021170..9e93d40d2ed044 100755 --- a/paddle/phi/api/yaml/op_compat.yaml +++ b/paddle/phi/api/yaml/op_compat.yaml @@ -1774,7 +1774,7 @@ out : Out - op : pool2d - backward : pool2d_grad + backward : pool2d_grad, pool2d_double_grad inputs : {x : X} outputs : @@ -1789,6 +1789,7 @@ pool2d : GetPoolExpectedKernelType pool2d_grad : GetPoolGradExpectedKernelType pool2d_double_grad : GetPoolExpectedKernelType + keep_signature : [pool2d, pool2d_grad, pool2d_double_grad] extra : attrs : [bool use_mkldnn = false, bool use_quantizer = false, str mkldnn_data_type = "float32", bool is_test = false] @@ -1804,6 +1805,7 @@ get_expected_kernel_type : pool3d : GetPoolExpectedKernelType pool3d_grad : GetPoolGradExpectedKernelType + keep_signature : [pool3d, pool3d_grad] extra : attrs : [bool use_mkldnn = false] diff --git a/paddle/phi/ops/compat/pool_sig.cc b/paddle/phi/ops/compat/pool_sig.cc new file mode 100644 index 00000000000000..9d5fda52cf2e32 --- /dev/null +++ b/paddle/phi/ops/compat/pool_sig.cc @@ -0,0 +1,112 @@ +// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "paddle/phi/core/compat/op_utils.h" + +namespace phi { + +KernelSignature Pool2dOpArgumentMapping( + const ArgumentMappingContext& ctx UNUSED) { + return KernelSignature("pool2d", + {"X"}, + {"ksize", + "strides", + "paddings", + "ceil_mode", + "exclusive", + "data_format", + "pooling_type", + "global_pooling", + "adaptive", + "padding_algorithm"}, + {"Out"}); +} + +KernelSignature Pool2dGradOpArgumentMapping( + const ArgumentMappingContext& ctx UNUSED) { + return KernelSignature("pool2d_grad", + {"X", "Out", "Out@GRAD"}, + {"ksize", + "strides", + "paddings", + "ceil_mode", + "exclusive", + "data_format", + "pooling_type", + "global_pooling", + "adaptive", + "padding_algorithm"}, + {"X@GRAD"}); +} + +KernelSignature Pool2dDoubleGradOpArgumentMapping( + const ArgumentMappingContext& ctx UNUSED) { + return KernelSignature("pool2d_double_grad", + {"X"}, + {"ksize", + "strides", + "paddings", + "ceil_mode", + "exclusive", + "data_format", + "pooling_type", + "global_pooling", + "adaptive", + "padding_algorithm"}, + {"Out"}); +} + +KernelSignature Pool3dOpArgumentMapping( + const ArgumentMappingContext& ctx UNUSED) { + return KernelSignature("pool3d", + {"X"}, + {"ksize", + "strides", + "paddings", + "ceil_mode", + "exclusive", + "data_format", + "pooling_type", + "global_pooling", + "adaptive", + "padding_algorithm"}, + {"Out"}); +} + +KernelSignature Pool3dGradOpArgumentMapping( + const ArgumentMappingContext& ctx UNUSED) { + return KernelSignature("pool3d_grad", + {"X", "Out", "Out@GRAD"}, + {"ksize", + "strides", + "paddings", + "ceil_mode", + "exclusive", + "data_format", + "pooling_type", + "global_pooling", + "adaptive", + "padding_algorithm"}, + {"X@GRAD"}); +} + +} // namespace phi + +PD_REGISTER_ARG_MAPPING_FN(pool2d, phi::Pool2dOpArgumentMapping); +PD_REGISTER_ARG_MAPPING_FN(pool2d_grad, phi::Pool2dGradOpArgumentMapping); +PD_REGISTER_ARG_MAPPING_FN(pool2d_double_grad, + phi::Pool2dDoubleGradOpArgumentMapping); + +PD_REGISTER_ARG_MAPPING_FN(pool3d, phi::Pool3dOpArgumentMapping); +PD_REGISTER_ARG_MAPPING_FN(pool3d_grad, phi::Pool3dGradOpArgumentMapping); From d263253ad11853fb1a437547423df91f0d0884ac Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Mon, 29 May 2023 12:42:48 +0800 Subject: [PATCH 18/24] [phi] RollBACK output --- paddle/phi/api/yaml/static_backward.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paddle/phi/api/yaml/static_backward.yaml b/paddle/phi/api/yaml/static_backward.yaml index 78152ad76a2421..35b9c338cded38 100755 --- a/paddle/phi/api/yaml/static_backward.yaml +++ b/paddle/phi/api/yaml/static_backward.yaml @@ -46,7 +46,7 @@ - backward_op : pool2d_double_grad forward : pool2d_grad(Tensor x, Tensor out, Tensor grad_out, IntArray kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) -> Tensor(grad_x) args : (Tensor x, Tensor grad_x_grad, IntArray kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) - output : Tensor(out_grad) + output : Tensor(grad_out_grad) infer_meta : func : Pool2DInferMeta param : [grad_x_grad, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm] From 23a87007a619e88a4d3d39536b74a6aa1bde26a0 Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Mon, 29 May 2023 17:58:42 +0800 Subject: [PATCH 19/24] [phi] try fix multiple definition --- paddle/phi/ops/compat/pool_sig.cc | 112 ------------------------------ 1 file changed, 112 deletions(-) delete mode 100644 paddle/phi/ops/compat/pool_sig.cc diff --git a/paddle/phi/ops/compat/pool_sig.cc b/paddle/phi/ops/compat/pool_sig.cc deleted file mode 100644 index 9d5fda52cf2e32..00000000000000 --- a/paddle/phi/ops/compat/pool_sig.cc +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "paddle/phi/core/compat/op_utils.h" - -namespace phi { - -KernelSignature Pool2dOpArgumentMapping( - const ArgumentMappingContext& ctx UNUSED) { - return KernelSignature("pool2d", - {"X"}, - {"ksize", - "strides", - "paddings", - "ceil_mode", - "exclusive", - "data_format", - "pooling_type", - "global_pooling", - "adaptive", - "padding_algorithm"}, - {"Out"}); -} - -KernelSignature Pool2dGradOpArgumentMapping( - const ArgumentMappingContext& ctx UNUSED) { - return KernelSignature("pool2d_grad", - {"X", "Out", "Out@GRAD"}, - {"ksize", - "strides", - "paddings", - "ceil_mode", - "exclusive", - "data_format", - "pooling_type", - "global_pooling", - "adaptive", - "padding_algorithm"}, - {"X@GRAD"}); -} - -KernelSignature Pool2dDoubleGradOpArgumentMapping( - const ArgumentMappingContext& ctx UNUSED) { - return KernelSignature("pool2d_double_grad", - {"X"}, - {"ksize", - "strides", - "paddings", - "ceil_mode", - "exclusive", - "data_format", - "pooling_type", - "global_pooling", - "adaptive", - "padding_algorithm"}, - {"Out"}); -} - -KernelSignature Pool3dOpArgumentMapping( - const ArgumentMappingContext& ctx UNUSED) { - return KernelSignature("pool3d", - {"X"}, - {"ksize", - "strides", - "paddings", - "ceil_mode", - "exclusive", - "data_format", - "pooling_type", - "global_pooling", - "adaptive", - "padding_algorithm"}, - {"Out"}); -} - -KernelSignature Pool3dGradOpArgumentMapping( - const ArgumentMappingContext& ctx UNUSED) { - return KernelSignature("pool3d_grad", - {"X", "Out", "Out@GRAD"}, - {"ksize", - "strides", - "paddings", - "ceil_mode", - "exclusive", - "data_format", - "pooling_type", - "global_pooling", - "adaptive", - "padding_algorithm"}, - {"X@GRAD"}); -} - -} // namespace phi - -PD_REGISTER_ARG_MAPPING_FN(pool2d, phi::Pool2dOpArgumentMapping); -PD_REGISTER_ARG_MAPPING_FN(pool2d_grad, phi::Pool2dGradOpArgumentMapping); -PD_REGISTER_ARG_MAPPING_FN(pool2d_double_grad, - phi::Pool2dDoubleGradOpArgumentMapping); - -PD_REGISTER_ARG_MAPPING_FN(pool3d, phi::Pool3dOpArgumentMapping); -PD_REGISTER_ARG_MAPPING_FN(pool3d_grad, phi::Pool3dGradOpArgumentMapping); From 791de7e0c67b6834a5450ace55d1c952914bbd53 Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Mon, 29 May 2023 20:55:33 +0800 Subject: [PATCH 20/24] [phi] fix keep_signature; RollBACK op_compat --- paddle/phi/api/yaml/op_compat.yaml | 4 +- paddle/phi/ops/compat/pool_sig.cc | 112 +++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 paddle/phi/ops/compat/pool_sig.cc diff --git a/paddle/phi/api/yaml/op_compat.yaml b/paddle/phi/api/yaml/op_compat.yaml index 9e93d40d2ed044..a27964d6ab53e2 100755 --- a/paddle/phi/api/yaml/op_compat.yaml +++ b/paddle/phi/api/yaml/op_compat.yaml @@ -1789,7 +1789,7 @@ pool2d : GetPoolExpectedKernelType pool2d_grad : GetPoolGradExpectedKernelType pool2d_double_grad : GetPoolExpectedKernelType - keep_signature : [pool2d, pool2d_grad, pool2d_double_grad] + keep_signature : [pool2d, pool2d_grad, pool2d_double_grad] extra : attrs : [bool use_mkldnn = false, bool use_quantizer = false, str mkldnn_data_type = "float32", bool is_test = false] @@ -1805,7 +1805,7 @@ get_expected_kernel_type : pool3d : GetPoolExpectedKernelType pool3d_grad : GetPoolGradExpectedKernelType - keep_signature : [pool3d, pool3d_grad] + keep_signature : [pool3d, pool3d_grad] extra : attrs : [bool use_mkldnn = false] diff --git a/paddle/phi/ops/compat/pool_sig.cc b/paddle/phi/ops/compat/pool_sig.cc new file mode 100644 index 00000000000000..9d5fda52cf2e32 --- /dev/null +++ b/paddle/phi/ops/compat/pool_sig.cc @@ -0,0 +1,112 @@ +// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "paddle/phi/core/compat/op_utils.h" + +namespace phi { + +KernelSignature Pool2dOpArgumentMapping( + const ArgumentMappingContext& ctx UNUSED) { + return KernelSignature("pool2d", + {"X"}, + {"ksize", + "strides", + "paddings", + "ceil_mode", + "exclusive", + "data_format", + "pooling_type", + "global_pooling", + "adaptive", + "padding_algorithm"}, + {"Out"}); +} + +KernelSignature Pool2dGradOpArgumentMapping( + const ArgumentMappingContext& ctx UNUSED) { + return KernelSignature("pool2d_grad", + {"X", "Out", "Out@GRAD"}, + {"ksize", + "strides", + "paddings", + "ceil_mode", + "exclusive", + "data_format", + "pooling_type", + "global_pooling", + "adaptive", + "padding_algorithm"}, + {"X@GRAD"}); +} + +KernelSignature Pool2dDoubleGradOpArgumentMapping( + const ArgumentMappingContext& ctx UNUSED) { + return KernelSignature("pool2d_double_grad", + {"X"}, + {"ksize", + "strides", + "paddings", + "ceil_mode", + "exclusive", + "data_format", + "pooling_type", + "global_pooling", + "adaptive", + "padding_algorithm"}, + {"Out"}); +} + +KernelSignature Pool3dOpArgumentMapping( + const ArgumentMappingContext& ctx UNUSED) { + return KernelSignature("pool3d", + {"X"}, + {"ksize", + "strides", + "paddings", + "ceil_mode", + "exclusive", + "data_format", + "pooling_type", + "global_pooling", + "adaptive", + "padding_algorithm"}, + {"Out"}); +} + +KernelSignature Pool3dGradOpArgumentMapping( + const ArgumentMappingContext& ctx UNUSED) { + return KernelSignature("pool3d_grad", + {"X", "Out", "Out@GRAD"}, + {"ksize", + "strides", + "paddings", + "ceil_mode", + "exclusive", + "data_format", + "pooling_type", + "global_pooling", + "adaptive", + "padding_algorithm"}, + {"X@GRAD"}); +} + +} // namespace phi + +PD_REGISTER_ARG_MAPPING_FN(pool2d, phi::Pool2dOpArgumentMapping); +PD_REGISTER_ARG_MAPPING_FN(pool2d_grad, phi::Pool2dGradOpArgumentMapping); +PD_REGISTER_ARG_MAPPING_FN(pool2d_double_grad, + phi::Pool2dDoubleGradOpArgumentMapping); + +PD_REGISTER_ARG_MAPPING_FN(pool3d, phi::Pool3dOpArgumentMapping); +PD_REGISTER_ARG_MAPPING_FN(pool3d_grad, phi::Pool3dGradOpArgumentMapping); From 39f9ec15e35adf7efea3e5ed0423e0b8ad0df161 Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Mon, 29 May 2023 20:57:35 +0800 Subject: [PATCH 21/24] [phi] fix manual_signature --- paddle/phi/api/yaml/op_compat.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/paddle/phi/api/yaml/op_compat.yaml b/paddle/phi/api/yaml/op_compat.yaml index a27964d6ab53e2..1882ea214bddac 100755 --- a/paddle/phi/api/yaml/op_compat.yaml +++ b/paddle/phi/api/yaml/op_compat.yaml @@ -1789,7 +1789,7 @@ pool2d : GetPoolExpectedKernelType pool2d_grad : GetPoolGradExpectedKernelType pool2d_double_grad : GetPoolExpectedKernelType - keep_signature : [pool2d, pool2d_grad, pool2d_double_grad] + manual_signature : [pool2d, pool2d_grad, pool2d_double_grad] extra : attrs : [bool use_mkldnn = false, bool use_quantizer = false, str mkldnn_data_type = "float32", bool is_test = false] @@ -1805,7 +1805,7 @@ get_expected_kernel_type : pool3d : GetPoolExpectedKernelType pool3d_grad : GetPoolGradExpectedKernelType - keep_signature : [pool3d, pool3d_grad] + manual_signature : [pool3d, pool3d_grad] extra : attrs : [bool use_mkldnn = false] From b51b2aca1ff3537881bfca232756cebad8ff928d Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Wed, 31 May 2023 22:20:57 +0800 Subject: [PATCH 22/24] [phi]clean get_expected_kernel_func;[phi] rm compat; --- .../generator/get_expected_kernel_func.cc | 10 +- .../generator/get_expected_kernel_func.h | 2 +- paddle/phi/api/yaml/op_compat.yaml | 8 +- paddle/phi/api/yaml/static_backward.yaml | 3 +- paddle/phi/ops/compat/pool_sig.cc | 112 ------------------ 5 files changed, 10 insertions(+), 125 deletions(-) delete mode 100644 paddle/phi/ops/compat/pool_sig.cc diff --git a/paddle/fluid/operators/generator/get_expected_kernel_func.cc b/paddle/fluid/operators/generator/get_expected_kernel_func.cc index ecaea78d45bba4..67ef19a6e4a4f5 100644 --- a/paddle/fluid/operators/generator/get_expected_kernel_func.cc +++ b/paddle/fluid/operators/generator/get_expected_kernel_func.cc @@ -143,17 +143,17 @@ phi::KernelKey GetPoolExpectedKernelType( return phi::KernelKey(data_type, ctx.GetPlace()); } -phi::KernelKey GetPoolGradExpectedKernelType( +phi::KernelKey GetPoolDoubleGradExpectedKernelType( const framework::ExecutionContext& ctx, const framework::OperatorWithKernel* op_ptr) { - auto input_data_type = - op_ptr->OperatorWithKernel::IndicateVarDataType(ctx, "X"); + auto data_type = + op_ptr->OperatorWithKernel::IndicateVarDataType(ctx, "grad_x@GRAD"); // NOTE(jiahongyu): Below codes originally enclosed by PADDLE_WITH_MKLDNN op_ptr->SetDnnFallback(!CanMKLDNNSupportPool(ctx)); - // NOTE(jiahongyu): Above codes originally enclosed by PADDLE_WITH_MKLDNN + // NOTE(jiahongyu) END: Above codes originally enclosed by PADDLE_WITH_MKLDNN - return phi::KernelKey(input_data_type, ctx.GetPlace()); + return phi::KernelKey(data_type, ctx.GetPlace()); } phi::KernelKey GetSgdExpectedKernelType( diff --git a/paddle/fluid/operators/generator/get_expected_kernel_func.h b/paddle/fluid/operators/generator/get_expected_kernel_func.h index 7472ea57937334..7868676172d71c 100644 --- a/paddle/fluid/operators/generator/get_expected_kernel_func.h +++ b/paddle/fluid/operators/generator/get_expected_kernel_func.h @@ -36,7 +36,7 @@ phi::KernelKey GetPoolExpectedKernelType( const framework::ExecutionContext& ctx, const framework::OperatorWithKernel* op_ptr); -phi::KernelKey GetPoolGradExpectedKernelType( +phi::KernelKey GetPoolDoubleGradExpectedKernelType( const framework::ExecutionContext& ctx, const framework::OperatorWithKernel* op_ptr); diff --git a/paddle/phi/api/yaml/op_compat.yaml b/paddle/phi/api/yaml/op_compat.yaml index 456dcd72b90136..8cbb02d235abbe 100755 --- a/paddle/phi/api/yaml/op_compat.yaml +++ b/paddle/phi/api/yaml/op_compat.yaml @@ -1788,9 +1788,8 @@ support_tensor : true get_expected_kernel_type : pool2d : GetPoolExpectedKernelType - pool2d_grad : GetPoolGradExpectedKernelType - pool2d_double_grad : GetPoolExpectedKernelType - manual_signature : [pool2d, pool2d_grad, pool2d_double_grad] + pool2d_grad : GetPoolExpectedKernelType + pool2d_double_grad : GetPoolDoubleGradExpectedKernelType extra : attrs : [bool use_mkldnn = false, bool use_quantizer = false, str mkldnn_data_type = "float32", bool is_test = false] @@ -1805,8 +1804,7 @@ {kernel_size : ksize} get_expected_kernel_type : pool3d : GetPoolExpectedKernelType - pool3d_grad : GetPoolGradExpectedKernelType - manual_signature : [pool3d, pool3d_grad] + pool3d_grad : GetPoolExpectedKernelType extra : attrs : [bool use_mkldnn = false] diff --git a/paddle/phi/api/yaml/static_backward.yaml b/paddle/phi/api/yaml/static_backward.yaml index cbabe9830b7e8a..4b8790728f6780 100755 --- a/paddle/phi/api/yaml/static_backward.yaml +++ b/paddle/phi/api/yaml/static_backward.yaml @@ -57,7 +57,7 @@ - backward_op : pool2d_double_grad forward : pool2d_grad(Tensor x, Tensor out, Tensor grad_out, IntArray kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) -> Tensor(grad_x) - args : (Tensor x, Tensor grad_x_grad, IntArray kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) + args : (Tensor grad_x_grad, IntArray kernel_size, int[] strides, int[] paddings, bool ceil_mode, bool exclusive, str data_format, str pooling_type, bool global_pooling, bool adaptive, str padding_algorithm) output : Tensor(grad_out_grad) infer_meta : func : Pool2DInferMeta @@ -65,7 +65,6 @@ kernel : func : pool2d_double_grad param : [grad_x_grad, kernel_size, strides, paddings, ceil_mode, exclusive, data_format, pooling_type, global_pooling, adaptive, padding_algorithm] - no_need_buffer : x - backward_op : pool2d_grad forward : pool2d(Tensor x, IntArray kernel_size, int[] strides = {1,1}, int[] paddings = {0,0}, bool ceil_mode = false, bool exclusive = true, str data_format = "NCHW", str pooling_type = "", bool global_pooling = false, bool adaptive = false, str padding_algorithm = "EXPLICIT") -> Tensor(out) diff --git a/paddle/phi/ops/compat/pool_sig.cc b/paddle/phi/ops/compat/pool_sig.cc deleted file mode 100644 index 9d5fda52cf2e32..00000000000000 --- a/paddle/phi/ops/compat/pool_sig.cc +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "paddle/phi/core/compat/op_utils.h" - -namespace phi { - -KernelSignature Pool2dOpArgumentMapping( - const ArgumentMappingContext& ctx UNUSED) { - return KernelSignature("pool2d", - {"X"}, - {"ksize", - "strides", - "paddings", - "ceil_mode", - "exclusive", - "data_format", - "pooling_type", - "global_pooling", - "adaptive", - "padding_algorithm"}, - {"Out"}); -} - -KernelSignature Pool2dGradOpArgumentMapping( - const ArgumentMappingContext& ctx UNUSED) { - return KernelSignature("pool2d_grad", - {"X", "Out", "Out@GRAD"}, - {"ksize", - "strides", - "paddings", - "ceil_mode", - "exclusive", - "data_format", - "pooling_type", - "global_pooling", - "adaptive", - "padding_algorithm"}, - {"X@GRAD"}); -} - -KernelSignature Pool2dDoubleGradOpArgumentMapping( - const ArgumentMappingContext& ctx UNUSED) { - return KernelSignature("pool2d_double_grad", - {"X"}, - {"ksize", - "strides", - "paddings", - "ceil_mode", - "exclusive", - "data_format", - "pooling_type", - "global_pooling", - "adaptive", - "padding_algorithm"}, - {"Out"}); -} - -KernelSignature Pool3dOpArgumentMapping( - const ArgumentMappingContext& ctx UNUSED) { - return KernelSignature("pool3d", - {"X"}, - {"ksize", - "strides", - "paddings", - "ceil_mode", - "exclusive", - "data_format", - "pooling_type", - "global_pooling", - "adaptive", - "padding_algorithm"}, - {"Out"}); -} - -KernelSignature Pool3dGradOpArgumentMapping( - const ArgumentMappingContext& ctx UNUSED) { - return KernelSignature("pool3d_grad", - {"X", "Out", "Out@GRAD"}, - {"ksize", - "strides", - "paddings", - "ceil_mode", - "exclusive", - "data_format", - "pooling_type", - "global_pooling", - "adaptive", - "padding_algorithm"}, - {"X@GRAD"}); -} - -} // namespace phi - -PD_REGISTER_ARG_MAPPING_FN(pool2d, phi::Pool2dOpArgumentMapping); -PD_REGISTER_ARG_MAPPING_FN(pool2d_grad, phi::Pool2dGradOpArgumentMapping); -PD_REGISTER_ARG_MAPPING_FN(pool2d_double_grad, - phi::Pool2dDoubleGradOpArgumentMapping); - -PD_REGISTER_ARG_MAPPING_FN(pool3d, phi::Pool3dOpArgumentMapping); -PD_REGISTER_ARG_MAPPING_FN(pool3d_grad, phi::Pool3dGradOpArgumentMapping); From d4ce1148df4773606ebfd6c4139bb44375f4a5ea Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Thu, 1 Jun 2023 23:36:33 +0800 Subject: [PATCH 23/24] [phi] Fix Misdeletion --- paddle/fluid/operators/generator/get_expected_kernel_func.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/paddle/fluid/operators/generator/get_expected_kernel_func.cc b/paddle/fluid/operators/generator/get_expected_kernel_func.cc index 4c4289f1d88a25..562011fedfdd14 100644 --- a/paddle/fluid/operators/generator/get_expected_kernel_func.cc +++ b/paddle/fluid/operators/generator/get_expected_kernel_func.cc @@ -82,6 +82,7 @@ phi::KernelKey GetCheckFiniteAndUnscaleExpectedKernelType( if (ctx.MultiInputVar("X").size() >= 1) { dtype = op_ptr->IndicateVarDataType(ctx, "X"); } + return phi::KernelKey(dtype, ctx.GetPlace()); } phi::KernelKey GetReduceExpectedKernelType( From 8b81c168ced7c5a40f8353debbb8fea87ca674ed Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Fri, 2 Jun 2023 11:58:15 +0800 Subject: [PATCH 24/24] add use_cudnn --- paddle/phi/api/yaml/op_compat.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/paddle/phi/api/yaml/op_compat.yaml b/paddle/phi/api/yaml/op_compat.yaml index 439531c0f1296e..bf69143637dad0 100755 --- a/paddle/phi/api/yaml/op_compat.yaml +++ b/paddle/phi/api/yaml/op_compat.yaml @@ -1854,7 +1854,7 @@ pool2d_double_grad : GetPoolDoubleGradExpectedKernelType extra : attrs : [bool use_mkldnn = false, bool use_quantizer = false, - str mkldnn_data_type = "float32", bool is_test = false] + str mkldnn_data_type = "float32", bool is_test = false, bool use_cudnn = false] - op : pool3d backward : pool3d_grad @@ -1868,7 +1868,7 @@ pool3d : GetPoolExpectedKernelType pool3d_grad : GetPoolExpectedKernelType extra : - attrs : [bool use_mkldnn = false] + attrs : [bool use_mkldnn = false, bool use_cudnn = false] - op : pow backward : pow_grad, pow_double_grad, pow_triple_grad