diff --git a/paddle/fluid/operators/conj_op.cc b/paddle/fluid/operators/conj_op.cc index 4d801bc003ea9ac417ff66deda8359f2921e01f6..c2211f9ab0567f24225d0bf6a04e660b84d7e583 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 41bcf9e8ae133e189ed0c1ab8f6265b7c800f4d4..0000000000000000000000000000000000000000 --- 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 57bac52cef59199cfd4e21ab18ecd99bb3c4a7e3..e707951699487133de8509fa73dd9a10b2954257 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 c1a939c2dec503246a7f8acec512578a4b9b225f..d13d93ad1846048951d04775e35a62f85c4108be 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 e25fdd3a204dce31f730182928552e760958e181..c7d092c468fae3a28eb6de90e020a31e98a293d1 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;