From 0dccdee0d9a2c4358f2d82b87cb9321533870820 Mon Sep 17 00:00:00 2001 From: Chen Weihang Date: Fri, 4 Feb 2022 19:08:48 +0800 Subject: [PATCH] remove unchanged infermeta new (#39343) --- paddle/fluid/operators/conj_op.cc | 19 ++++---- paddle/fluid/operators/sign_op.cc | 3 +- paddle/fluid/operators/sign_op.h | 47 -------------------- paddle/pten/infermeta/unary.cc | 12 +---- paddle/pten/infermeta/unary.h | 5 --- paddle/pten/tests/core/test_meta_fn_utils.cc | 2 +- 6 files changed, 12 insertions(+), 76 deletions(-) delete mode 100644 paddle/fluid/operators/sign_op.h diff --git a/paddle/fluid/operators/conj_op.cc b/paddle/fluid/operators/conj_op.cc index 4d801bc003e..c2211f9ab05 100644 --- a/paddle/fluid/operators/conj_op.cc +++ b/paddle/fluid/operators/conj_op.cc @@ -22,22 +22,16 @@ #include "paddle/fluid/platform/mkldnn_helper.h" #endif +#include "paddle/fluid/framework/infershape_utils.h" +#include "paddle/pten/core/infermeta_utils.h" +#include "paddle/pten/infermeta/unary.h" + namespace paddle { namespace operators { class ConjOp : public framework::OperatorWithKernel { public: using framework::OperatorWithKernel::OperatorWithKernel; - - void InferShape(framework::InferShapeContext *ctx) const override { - OP_INOUT_CHECK(ctx->HasInput("X"), "Input", "X", "conj"); - OP_INOUT_CHECK(ctx->HasOutput("Out"), "Output", "Out", "conj"); - - auto in_dims = ctx->GetInputDim("X"); - - ctx->SetOutputDim("Out", in_dims); - ctx->ShareLoD("X", /*->*/ "Out"); - } }; class ConjOpMaker : public framework::OpProtoAndCheckerMaker { @@ -72,9 +66,12 @@ class ConjGradMaker : public framework::SingleGradOpMaker { namespace ops = paddle::operators; +DELCARE_INFER_SHAPE_FUNCTOR(conj, ConjInferShapeFunctor, + PT_INFER_META(pten::UnchangedInferMeta)); REGISTER_OPERATOR(conj, ops::ConjOp, ops::ConjOpMaker, ops::ConjGradMaker, - ops::ConjGradMaker); + ops::ConjGradMaker, + ConjInferShapeFunctor); REGISTER_OP_CPU_KERNEL( conj, ops::ConjKernel + #include "paddle/fluid/framework/infershape_utils.h" #include "paddle/fluid/framework/op_registry.h" #include "paddle/fluid/platform/float16.h" @@ -60,7 +61,7 @@ class SignGradMaker : public framework::SingleGradOpMaker { namespace ops = paddle::operators; DELCARE_INFER_SHAPE_FUNCTOR(sign, SignInferShapeFunctor, - PT_INFER_META(pten::UnchangedInferMetaNew)); + PT_INFER_META(pten::UnchangedInferMeta)); REGISTER_OPERATOR(sign, ops::SignOp, ops::SignOpMaker, ops::SignGradMaker, ops::SignGradMaker, diff --git a/paddle/fluid/operators/sign_op.h b/paddle/fluid/operators/sign_op.h deleted file mode 100644 index 41bcf9e8ae1..00000000000 --- a/paddle/fluid/operators/sign_op.h +++ /dev/null @@ -1,47 +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/eigen.h" -#include "paddle/fluid/framework/op_registry.h" -#include "paddle/fluid/framework/pten_utils.h" -#include "paddle/fluid/operators/eigen/eigen_function.h" - -#include "paddle/pten/kernels/sign_kernel.h" - -namespace paddle { -namespace operators { - -// See Note [ Why still keep the original kernel implementation? ] -template -class SignKernel : public framework::OpKernel { - public: - virtual void Compute(const framework::ExecutionContext& context) const { - auto* x = context.Input("X"); - auto* out = context.Output("Out"); - auto& dev_ctx = context.device_context(); - out->mutable_data(x->place()); - - // call new kernel - pten::SignKernel::TYPE>( - static_cast::TYPE&>(dev_ctx), - *x, out); - } -}; - -} // namespace operators -} // namespace paddle diff --git a/paddle/pten/infermeta/unary.cc b/paddle/pten/infermeta/unary.cc index 57bac52cef5..e7079516994 100644 --- a/paddle/pten/infermeta/unary.cc +++ b/paddle/pten/infermeta/unary.cc @@ -21,16 +21,6 @@ limitations under the License. */ namespace pten { -void UnchangedInferMetaNew(MetaConfig config, - const MetaTensor& x, - MetaTensor* out) { - out->share_meta(x); -} - -DenseTensorMeta UnchangedInferMeta(const DenseTensorMeta& x_meta) { - return x_meta; -} - void UnchangedInferMeta(const MetaTensor& x, MetaTensor* out) { out->share_meta(x); } @@ -319,4 +309,4 @@ void ReduceInferMeta(const MetaTensor& x, } // namespace pten -PT_REGISTER_INFER_META_FN(sign, pten::UnchangedInferMetaNew); +PT_REGISTER_INFER_META_FN(sign, pten::UnchangedInferMeta); diff --git a/paddle/pten/infermeta/unary.h b/paddle/pten/infermeta/unary.h index c1a939c2dec..d13d93ad184 100644 --- a/paddle/pten/infermeta/unary.h +++ b/paddle/pten/infermeta/unary.h @@ -31,11 +31,6 @@ class MetaConfig; // Because functions in this file not only can infer shape, but also need // infer lod or other useful data. -// TODO(chenweihang): to avoid conflit, remove this function in next PR -void UnchangedInferMetaNew(MetaConfig config, - const MetaTensor& x, - MetaTensor* out); - void UnchangedInferMeta(const MetaTensor& x, MetaTensor* out); void FlattenInferMeta(const MetaTensor& x, diff --git a/paddle/pten/tests/core/test_meta_fn_utils.cc b/paddle/pten/tests/core/test_meta_fn_utils.cc index e25fdd3a204..c7d092c468f 100644 --- a/paddle/pten/tests/core/test_meta_fn_utils.cc +++ b/paddle/pten/tests/core/test_meta_fn_utils.cc @@ -29,7 +29,7 @@ TEST(MetaFunctionMap, InferMetaFnExists) { pten::MetaTensor meta_x(&dense_x); pten::DenseTensor dense_out1; pten::MetaTensor meta_out(&dense_out1); - pten::UnchangedInferMetaNew(/*is_runtime=*/true, meta_x, &meta_out); + pten::UnchangedInferMeta(meta_x, &meta_out); auto shared_meat_x = std::make_shared(&dense_x); pten::DenseTensor dense_out2; -- GitLab