diff --git a/paddle/fluid/framework/new_executor/interpretercore_util.cc b/paddle/fluid/framework/new_executor/interpretercore_util.cc index 273a7ee8bc48c1c6c58ecd455f1efdee4c2a06da..f41cda93bf9cca9c358c4b28f26085b99690f6b9 100644 --- a/paddle/fluid/framework/new_executor/interpretercore_util.cc +++ b/paddle/fluid/framework/new_executor/interpretercore_util.cc @@ -535,7 +535,8 @@ void BuildOpFuncList(const platform::Place& place, if (op_with_kernel->PhiKernel()->IsValid()) { run_phi_kernel = true; } else { - if (!op_with_kernel->SupportsKernelType(expected_kernel_key)) { + if (!op_with_kernel->SupportsKernelType(expected_kernel_key, + exec_ctx)) { auto phi_cpu_kernel_key = FallBackToCpu( expected_kernel_key, phi_kernel_key, *op_with_kernel); op_with_kernel->ResetPhiKernel( diff --git a/paddle/fluid/framework/operator.cc b/paddle/fluid/framework/operator.cc index f32995ae417043ef28a9e57116e3b8e9325d973e..326b3840590af1f19aaa1128d1f5c8b772c37fdb 100644 --- a/paddle/fluid/framework/operator.cc +++ b/paddle/fluid/framework/operator.cc @@ -50,6 +50,7 @@ class DenseTensor; #ifdef PADDLE_WITH_MKLDNN #include "paddle/fluid/platform/mkldnn_helper.h" +#include "paddle/fluid/platform/mkldnn_op_list.h" #endif #ifdef PADDLE_WITH_MLU @@ -1352,7 +1353,7 @@ bool OperatorWithKernel::SupportsMKLDNN( } bool OperatorWithKernel::SupportsKernelType( - const OpKernelType& kernel_type) const { + const OpKernelType& kernel_type, const ExecutionContext& exe_ctx) const { auto& all_op_kernels = AllOpKernels(); auto kernels_iter = all_op_kernels.find(type_); if (kernels_iter == all_op_kernels.end()) return false; @@ -1386,16 +1387,38 @@ bool OperatorWithKernel::SupportsKernelType( } #endif +// NOTE(jiahongyu): If MKLDNN can be used, the function SupportsKernelType needs +// to check whether current op supports MKLDNN kernel. There are three +// statements in if condition: The first statement checks whether library_type_ +// are changed by other high priority backends; the second checks whether this +// op has specific implementation; the third checks whether mkldnn kernel can be +// used. +#ifdef PADDLE_WITH_MKLDNN + if (kernel_type.library_type_ == framework::LibraryType::kPlain && + !paddle::platform::in_mkldnn_white_list(type_) && + this->CanMKLDNNBeUsed(exe_ctx, kernel_type.data_type_)) { + auto tmp_kernel_type = kernel_type; + tmp_kernel_type.library_type_ = framework::LibraryType::kMKLDNN; + tmp_kernel_type.data_layout_ = framework::DataLayout::kMKLDNN; + return kernels.find(tmp_kernel_type) != kernels.end(); + } +#endif + return kernel_iter != kernels.end(); } bool OperatorWithKernel::CanMKLDNNBeUsed(const framework::ExecutionContext& ctx, proto::VarType::Type data_type) const { + // NOTE(jiahongyu): Only mkldnn kernels need to check "use_mkldnn" attribute, + // hence we first call function SupportsMKLDNN. If we check "use_mkldnn" + // attribute first, it will cause error because some codes add "use_mkldnn" + // attribute to non-mkldnn ops. + if (!this->SupportsMKLDNN(data_type)) { + return false; + } const std::string use_mkldnn_attr = "use_mkldnn"; - bool use_mkldnn_ctx = ctx.HasAttr(use_mkldnn_attr) && - ctx.Attr(use_mkldnn_attr) && - platform::is_cpu_place(ctx.GetPlace()); - return use_mkldnn_ctx && this->SupportsMKLDNN(data_type); + return ctx.HasAttr(use_mkldnn_attr) && ctx.Attr(use_mkldnn_attr) && + platform::is_cpu_place(ctx.GetPlace()); } void OperatorWithKernel::InferShape(InferShapeContext* ctx) const { @@ -1544,6 +1567,23 @@ void OperatorWithKernel::RunImpl(const Scope& scope, } } else { phi_kernel_name = kernel_signature_->name; + +// NOTE(jiahongyu): The registered MKLDNN kernel have library_type = +// LibraryType::kMKLDNN and data_layout_ = DataLayout::kMKLDNN. But the default +// values are kPlain, so we need to modify the library_type and data_layout_ +// here. There are three statements in if condition: The first statement checks +// whether library_type_ are changed by other high priority backends; the second +// checks whether this op has specific implementation; the third checks whether +// mkldnn kernel can be used. +#ifdef PADDLE_WITH_MKLDNN + if (kernel_type_->library_type_ == framework::LibraryType::kPlain && + !paddle::platform::in_mkldnn_white_list(type_) && + this->CanMKLDNNBeUsed(exe_ctx, kernel_type_->data_type_)) { + kernel_type_->library_type_ = framework::LibraryType::kMKLDNN; + kernel_type_->data_layout_ = framework::DataLayout::kMKLDNN; + } +#endif + // NOTE(Liu-xiandong):In my ctest, this branch do not be executed, // I can't understand it, it's really confusing. // But we still need to keep this to avoid errors. @@ -1771,6 +1811,23 @@ void OperatorWithKernel::RunImpl(const Scope& scope, OpKernelType OperatorWithKernel::InnerGetExpectedKernelType( const ExecutionContext& ctx) const { auto expected_kernel_key = this->GetExpectedKernelType(ctx); + +// NOTE(jiahongyu): PADDLE_WITH_MKLDNN codes are moved outside function +// GetExpectedKernelType, so that if MKLDNN can be used, the library_type_ and +// data_layout_ of expected_kernel_key need to be adjusted. There are three +// statements in if condition: The first statement checks whether library_type_ +// are changed by other high priority backends; the second checks whether this +// op has specific implementation; the third checks whether mkldnn kernel can be +// used. +#ifdef PADDLE_WITH_MKLDNN + if (expected_kernel_key.library_type_ == framework::LibraryType::kPlain && + !paddle::platform::in_mkldnn_white_list(type_) && + this->CanMKLDNNBeUsed(ctx, expected_kernel_key.data_type_)) { + expected_kernel_key.library_type_ = framework::LibraryType::kMKLDNN; + expected_kernel_key.data_layout_ = framework::DataLayout::kMKLDNN; + } +#endif + if (HasAttr("op_device")) { if (Attr("op_device") == "cpu") { expected_kernel_key.place_ = platform::CPUPlace(); diff --git a/paddle/fluid/framework/operator.h b/paddle/fluid/framework/operator.h index e649bf2fc7e9542ce7423c4870335659b634afb9..bec9c4119fc2ba2e516b788d3d8a99c9829823c8 100644 --- a/paddle/fluid/framework/operator.h +++ b/paddle/fluid/framework/operator.h @@ -323,10 +323,16 @@ class ExecutionContext { virtual const Attribute& GetAttr(const std::string& name) const { auto iter = op_.Attrs().find(name); if (iter == op_.Attrs().end()) { - return op_.RuntimeAttrs().at(name); - } else { - return iter->second; + iter = op_.RuntimeAttrs().find(name); + PADDLE_ENFORCE_NE( + iter, + op_.RuntimeAttrs().end(), + platform::errors::NotFound("(%s) is not found in AttributeMap and " + "RuntimeAttributeMap of (%s) operator.", + name, + op_.Type())); } + return iter->second; } virtual bool HasInput(const std::string& name) const; @@ -621,7 +627,8 @@ class OperatorWithKernel : public OperatorBase { bool SupportsMKLDNN(proto::VarType::Type data_type) const; - bool SupportsKernelType(const OpKernelType& kernel_type) const; + bool SupportsKernelType(const OpKernelType& kernel_type, + const ExecutionContext& exe_ctx) const; bool CanMKLDNNBeUsed(const framework::ExecutionContext& ctx, proto::VarType::Type data_type) const; diff --git a/paddle/fluid/imperative/execution_context.h b/paddle/fluid/imperative/execution_context.h index 7ed6e93ec7c7c517d8d99ac581e6f6571cd6b729..6d4f7c347b097d4da67a93f52c4b6f2aeba3f260 100644 --- a/paddle/fluid/imperative/execution_context.h +++ b/paddle/fluid/imperative/execution_context.h @@ -102,7 +102,10 @@ class DygraphExecutionContext : public framework::ExecutionContext { } bool HasAttr(const std::string& name) const override { - return attrs_.count(name) != 0 || default_attrs_.count(name) != 0; + if (attrs_.find(name) == attrs_.end()) { + return default_attrs_.find(name) != default_attrs_.end(); + } + return true; } const framework::AttributeMap& Attrs() const override { return attrs_; } diff --git a/paddle/fluid/imperative/prepared_operator.cc b/paddle/fluid/imperative/prepared_operator.cc index 30cf0e82e9ff4153c90684446a903bde1743506b..1f70bcf4f428a5afe3b49d78e64ad3eb6454096a 100644 --- a/paddle/fluid/imperative/prepared_operator.cc +++ b/paddle/fluid/imperative/prepared_operator.cc @@ -25,6 +25,9 @@ #ifdef PADDLE_WITH_XPU #include "paddle/fluid/platform/device/xpu/xpu_op_list.h" #endif +#ifdef PADDLE_WITH_MKLDNN +#include "paddle/fluid/platform/mkldnn_op_list.h" +#endif #include "paddle/fluid/framework/library_type.h" #include "paddle/fluid/platform/device/gpu/gpu_info.h" #include "paddle/fluid/platform/profiler/event_tracing.h" @@ -185,13 +188,29 @@ PreparedOp PrepareImpl( phi::KernelSignature kernel_signature; phi::KernelKey phi_kernel_key; std::string phi_kernel_name; + +// NOTE(jiahongyu): The registered MKLDNN kernel have library_type = +// LibraryType::kMKLDNN and data_layout_ = DataLayout::kMKLDNN. But the default +// values are kPlain, so we need to modify the library_type and data_layout_ +// here. There are three statements in if condition: The first statement checks +// whether library_type_ are changed by other high priority backends; the second +// checks whether this op has specific implementation; the third checks whether +// mkldnn kernel can be used. +#ifdef PADDLE_WITH_MKLDNN + if (expected_kernel_key.library_type_ == framework::LibraryType::kPlain && + !paddle::platform::in_mkldnn_white_list(op.Type()) && + op.CanMKLDNNBeUsed(dygraph_exe_ctx, expected_kernel_key.data_type_)) { + expected_kernel_key.library_type_ = framework::LibraryType::kMKLDNN; + expected_kernel_key.data_layout_ = framework::DataLayout::kMKLDNN; + } +#endif + #if defined(PADDLE_WITH_XPU) bool is_xpu_unsupport = paddle::platform::is_xpu_place(expected_kernel_key.place_) && !paddle::platform::is_xpu_support_op(op.Type(), expected_kernel_key) || paddle::platform::is_in_xpu_black_list(op.Type()); - #endif bool has_phi_kernel = false; diff --git a/paddle/fluid/operators/abs_op.cc b/paddle/fluid/operators/abs_op.cc index d8fd433c0417c7020674d78af3e4bb2d7a9fd58f..3310bdbbe8254955bdeb1a3f4b6fdfc5c32748aa 100644 --- a/paddle/fluid/operators/abs_op.cc +++ b/paddle/fluid/operators/abs_op.cc @@ -21,9 +21,6 @@ #include "paddle/fluid/framework/op_registry.h" #include "paddle/phi/core/infermeta_utils.h" #include "paddle/phi/infermeta/unary.h" -#ifdef PADDLE_WITH_MKLDNN -#include "paddle/fluid/platform/mkldnn_helper.h" -#endif namespace paddle { namespace operators { @@ -36,15 +33,6 @@ class AbsOp : public framework::OperatorWithKernel { const framework::ExecutionContext& ctx) const override { auto input_data_type = framework::OperatorWithKernel::IndicateVarDataType(ctx, "X"); - -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, input_data_type)) { - return framework::OpKernelType(input_data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif return framework::OpKernelType(input_data_type, ctx.GetPlace()); } }; @@ -86,15 +74,6 @@ class AbsGradOp : public framework::OperatorWithKernel { const framework::ExecutionContext& ctx) const override { auto input_data_type = framework::OperatorWithKernel::IndicateVarDataType(ctx, "X"); - -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, input_data_type)) { - return framework::OpKernelType(input_data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif return framework::OpKernelType(input_data_type, ctx.GetPlace()); } }; diff --git a/paddle/fluid/operators/activation_op.cc b/paddle/fluid/operators/activation_op.cc index 51600714862443d19b6dbf978a5168c0499f7486..6f59e44d546fb7fc2a30083d97fe213e0372217a 100644 --- a/paddle/fluid/operators/activation_op.cc +++ b/paddle/fluid/operators/activation_op.cc @@ -82,27 +82,18 @@ class ActivationGradOpMaker : public framework::SingleGradOpMaker { framework::OpKernelType GetKernelType(const framework::ExecutionContext& ctx, const framework::OperatorWithKernel& oper, const std::string& name) { - framework::LibraryType library{framework::LibraryType::kPlain}; - framework::DataLayout layout = framework::DataLayout::kAnyLayout; auto data_type = oper.IndicateVarDataType(ctx, name); -// FIXME(liuwei1031) temporarily disable the code to unblock users -// TODO(liuwei1031) figure out the reason behind -// https://github.com/PaddlePaddle/Paddle/issues/16096 -// and re-enable this in the future -// #ifdef PADDLE_WITH_CUDA -// auto it1 = oper.Attrs().find("use_cudnn"); -// if (it1 != oper.Attrs().end() && platform::CanCUDNNBeUsed(ctx)) { -// library = framework::LibraryType::kCUDNN; -// } -// #endif -#ifdef PADDLE_WITH_MKLDNN - if (library == framework::LibraryType::kPlain && - oper.CanMKLDNNBeUsed(ctx, data_type)) { - library = framework::LibraryType::kMKLDNN; - layout = framework::DataLayout::kMKLDNN; - } -#endif - return framework::OpKernelType(data_type, ctx.GetPlace(), layout, library); + // FIXME(liuwei1031) temporarily disable the code to unblock users + // TODO(liuwei1031) figure out the reason behind + // https://github.com/PaddlePaddle/Paddle/issues/16096 + // and re-enable this in the future + // #ifdef PADDLE_WITH_CUDA + // auto it1 = oper.Attrs().find("use_cudnn"); + // if (it1 != oper.Attrs().end() && platform::CanCUDNNBeUsed(ctx)) { + // library = framework::LibraryType::kCUDNN; + // } + // #endif + return framework::OpKernelType(data_type, ctx.GetPlace()); } class ActivationOp : public framework::OperatorWithKernel { diff --git a/paddle/fluid/operators/batch_norm_op.cc b/paddle/fluid/operators/batch_norm_op.cc index 4979ab03452005b0b35e8b8b7aff44b308242acc..4f134ff974637b6634ff9d59d063ec0c49752575 100644 --- a/paddle/fluid/operators/batch_norm_op.cc +++ b/paddle/fluid/operators/batch_norm_op.cc @@ -197,16 +197,6 @@ framework::OpKernelType BatchNormOp::GetExpectedKernelType( platform::errors::InvalidArgument( "Variance input should be of float type")); - // TODO(pzelazko-intel): enable MKLDNN layout when it's ready -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, input_data_type)) { - return framework::OpKernelType(input_data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif - return framework::OpKernelType(input_data_type, ctx.GetPlace()); } @@ -396,18 +386,7 @@ framework::OpKernelType BatchNormGradOp::GetExpectedKernelType( platform::errors::InvalidArgument("gradient variable of Y is empty")); } - // TODO(pzelazko-intel): enable MKLDNN layout when it's ready auto data_type = OperatorWithKernel::IndicateVarDataType(ctx, "X"); - -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, data_type)) { - return framework::OpKernelType(data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif - return framework::OpKernelType(data_type, ctx.GetPlace()); } diff --git a/paddle/fluid/operators/clip_op.cc b/paddle/fluid/operators/clip_op.cc index 7994dacf08794f1d6f9c8e0d6397ee0b73b9676d..997c017d3129cc4feb948f027f5fb8b65c07a792 100644 --- a/paddle/fluid/operators/clip_op.cc +++ b/paddle/fluid/operators/clip_op.cc @@ -30,15 +30,6 @@ class ClipOp : public framework::OperatorWithKernel { const framework::ExecutionContext& ctx) const override { auto input_data_type = framework::OperatorWithKernel::IndicateVarDataType(ctx, "X"); - -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, input_data_type)) { - return framework::OpKernelType(input_data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif return framework::OpKernelType(input_data_type, ctx.GetPlace()); } }; @@ -98,15 +89,6 @@ class ClipOpGrad : public framework::OperatorWithKernel { const framework::ExecutionContext& ctx) const override { auto input_data_type = OperatorWithKernel::IndicateVarDataType( ctx, framework::GradVarName("Out")); - -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, input_data_type)) { - return framework::OpKernelType(input_data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif return framework::OpKernelType(input_data_type, ctx.GetPlace()); } }; diff --git a/paddle/fluid/operators/concat_op.cc b/paddle/fluid/operators/concat_op.cc index a875f1fc8df9efce14e0d1e1767d272eed8372e9..ae65930b86ac050e1c5544faf56ece83b2ed47bd 100644 --- a/paddle/fluid/operators/concat_op.cc +++ b/paddle/fluid/operators/concat_op.cc @@ -24,10 +24,6 @@ limitations under the License. */ #include "paddle/phi/infermeta/multiary.h" #include "paddle/phi/kernels/funcs/concat_funcs.h" -#ifdef PADDLE_WITH_MKLDNN -#include -#endif - namespace paddle { namespace operators { using Tensor = phi::DenseTensor; @@ -53,14 +49,6 @@ class ConcatOp : public framework::OperatorWithKernel { PADDLE_THROW(platform::errors::InvalidArgument( "All Inputs of Concat OP are Empty!")); } -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, input_data_type)) { - return framework::OpKernelType(input_data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif return framework::OpKernelType(input_data_type, ctx.GetPlace()); } @@ -127,19 +115,6 @@ class ConcatOpGrad : public framework::OperatorWithKernel { const framework::ExecutionContext &ctx) const override { auto input_data_type = OperatorWithKernel::IndicateVarDataType( ctx, framework::GradVarName("Out")); - -#ifdef PADDLE_WITH_MKLDNN - // extra checking if attr "use_mkldnn" exist is needed because - // test_reverse_op is calling concat_grad kernel without setting - // "use_mkldnn" to any value - if (ctx.HasAttr("use_mkldnn") && - this->CanMKLDNNBeUsed(ctx, input_data_type)) { - return framework::OpKernelType(input_data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif return framework::OpKernelType(input_data_type, ctx.GetPlace()); } diff --git a/paddle/fluid/operators/conv_transpose_op.cc b/paddle/fluid/operators/conv_transpose_op.cc index 42e5eb2a43820391daa8cc296ec92b7ea87b14b4..c80cc2dc734c66cdcab07abc1ccac3705cda114a 100644 --- a/paddle/fluid/operators/conv_transpose_op.cc +++ b/paddle/fluid/operators/conv_transpose_op.cc @@ -49,15 +49,6 @@ framework::OpKernelType ConvTransposeOp::GetExpectedKernelType( } } #endif -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, data_type)) { - return framework::OpKernelType(data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif - return framework::OpKernelType(data_type, ctx.GetPlace()); } diff --git a/paddle/fluid/operators/data_norm_op.cc b/paddle/fluid/operators/data_norm_op.cc index 6f46e5bf2f8edcdb6e8403cef7fb490ac4e9f6b5..4d620b5181ccbabd20ea737af31c6609ef29d824 100644 --- a/paddle/fluid/operators/data_norm_op.cc +++ b/paddle/fluid/operators/data_norm_op.cc @@ -18,9 +18,6 @@ limitations under the License. */ #include #include "paddle/fluid/framework/data_layout.h" -#ifdef PADDLE_WITH_MKLDNN -#include "paddle/fluid/platform/mkldnn_helper.h" -#endif #include "paddle/fluid/framework/op_version_registry.h" namespace paddle { @@ -199,15 +196,6 @@ class DataNormOp : public framework::OperatorWithKernel { platform::errors::InvalidArgument( "bias input should be of float type")); } - // TODO(pzelazko-intel): enable MKLDNN layout when it's ready -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, input_data_type)) { - return framework::OpKernelType(input_data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif return framework::OpKernelType(input_data_type, ctx.GetPlace()); } @@ -508,18 +496,7 @@ class DataNormGradOp : public framework::OperatorWithKernel { "Y@GRAD can not be found for computation")); } - // TODO(pzelazko-intel): enable MKLDNN layout when it's ready auto data_type = OperatorWithKernel::IndicateVarDataType(ctx, "X"); - -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, data_type)) { - return framework::OpKernelType(data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif - return framework::OpKernelType(data_type, ctx.GetPlace()); } }; diff --git a/paddle/fluid/operators/elementwise/elementwise_div_op.h b/paddle/fluid/operators/elementwise/elementwise_div_op.h index b1f0817539f171ac93532ca4d8111bc49ea490d8..c8289ab098a3a7051c841c5c974b10a99498c7b4 100644 --- a/paddle/fluid/operators/elementwise/elementwise_div_op.h +++ b/paddle/fluid/operators/elementwise/elementwise_div_op.h @@ -45,15 +45,6 @@ class ElementwiseDivOpDoubleGrad : public framework::OperatorWithKernel { framework::OpKernelType GetExpectedKernelType( const framework::ExecutionContext& ctx) const override { auto input_data_type = OperatorWithKernel::IndicateVarDataType(ctx, "Out"); - -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, input_data_type)) { - return framework::OpKernelType(input_data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif return framework::OpKernelType(input_data_type, ctx.GetPlace()); } diff --git a/paddle/fluid/operators/elementwise/elementwise_mul_op.h b/paddle/fluid/operators/elementwise/elementwise_mul_op.h index afc06b0d9981bf725412e2095d7155ad7aad179a..23271352f6b7c9312f51d24207e54ae47318df46 100644 --- a/paddle/fluid/operators/elementwise/elementwise_mul_op.h +++ b/paddle/fluid/operators/elementwise/elementwise_mul_op.h @@ -32,15 +32,6 @@ class ElementwiseMulOp : public ElementwiseOp { const framework::ExecutionContext& ctx) const override { auto input_data_type = OperatorWithKernel::IndicateOrPromoteVarDataTypes(ctx, "X", "Y"); - -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, input_data_type)) { - return framework::OpKernelType(input_data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif return framework::OpKernelType(input_data_type, ctx.GetPlace()); } diff --git a/paddle/fluid/operators/elementwise/elementwise_op.h b/paddle/fluid/operators/elementwise/elementwise_op.h index a8e1da9f7945d7b9504ff5ec19c8fad727f6a8bf..70bdd11977b214b472a2351e1060920be8ab9947 100644 --- a/paddle/fluid/operators/elementwise/elementwise_op.h +++ b/paddle/fluid/operators/elementwise/elementwise_op.h @@ -156,15 +156,6 @@ class ElementwiseOp : public framework::OperatorWithKernel { const framework::ExecutionContext &ctx) const override { auto input_data_type = OperatorWithKernel::IndicateOrPromoteVarDataTypes(ctx, "X", "Y"); - -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, input_data_type)) { - return framework::OpKernelType(input_data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif return framework::OpKernelType(input_data_type, ctx.GetPlace()); } @@ -317,15 +308,6 @@ class ElementwiseOpGrad : public framework::OperatorWithKernel { const framework::ExecutionContext &ctx) const override { auto input_data_type = OperatorWithKernel::IndicateVarDataType( ctx, framework::GradVarName("Out")); - -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, input_data_type)) { - return framework::OpKernelType(input_data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif return framework::OpKernelType(input_data_type, ctx.GetPlace()); } @@ -371,15 +353,6 @@ class ElementwiseOpDoubleGrad : public framework::OperatorWithKernel { framework::OpKernelType GetExpectedKernelType( const framework::ExecutionContext &ctx) const override { auto input_data_type = OperatorWithKernel::IndicateVarDataType(ctx, "DOut"); - -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, input_data_type)) { - return framework::OpKernelType(input_data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif return framework::OpKernelType(input_data_type, ctx.GetPlace()); } @@ -432,15 +405,6 @@ class ElementwiseOpDoubleGradWithoutDXDY input_data_type = OperatorWithKernel::IndicateOrPromoteVarDataTypes(ctx, "DDX", "DDY"); } - -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, input_data_type)) { - return framework::OpKernelType(input_data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif return framework::OpKernelType(input_data_type, ctx.GetPlace()); } @@ -493,15 +457,6 @@ class ElementwiseOpTripleGrad : public framework::OperatorWithKernel { const framework::ExecutionContext &ctx) const override { framework::proto::VarType::Type input_data_type; input_data_type = OperatorWithKernel::IndicateVarDataType(ctx, "D_DDOut"); - -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, input_data_type)) { - return framework::OpKernelType(input_data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif return framework::OpKernelType(input_data_type, ctx.GetPlace()); } diff --git a/paddle/fluid/operators/expand_v2_op.cc b/paddle/fluid/operators/expand_v2_op.cc index fb82f0b6524ba569682e1de34a8e35b8219ff0cc..6bf40fd3bb6b8e0603eac44405f6f4955de2febc 100644 --- a/paddle/fluid/operators/expand_v2_op.cc +++ b/paddle/fluid/operators/expand_v2_op.cc @@ -37,15 +37,6 @@ class ExpandV2Op : public framework::OperatorWithKernel { const framework::ExecutionContext& ctx) const override { auto input_data_type = framework::OperatorWithKernel::IndicateVarDataType(ctx, "X"); - -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, input_data_type)) { - return framework::OpKernelType(input_data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif return framework::OpKernelType(input_data_type, ctx.GetPlace()); } @@ -163,15 +154,6 @@ class ExpandV2GradOp : public framework::OperatorWithKernel { const framework::ExecutionContext& ctx) const override { auto input_data_type = framework::OperatorWithKernel::IndicateVarDataType( ctx, framework::GradVarName("Out")); - -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, input_data_type)) { - return framework::OpKernelType(input_data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif return framework::OpKernelType(input_data_type, ctx.GetPlace()); } diff --git a/paddle/fluid/operators/fill_constant_op.cc b/paddle/fluid/operators/fill_constant_op.cc index 85aadcb07ad32b2d1b08a21916ceb236a9fc8c00..82c6b89063bea24bfee03ba14b87725b44c544ca 100644 --- a/paddle/fluid/operators/fill_constant_op.cc +++ b/paddle/fluid/operators/fill_constant_op.cc @@ -104,15 +104,6 @@ class FillConstantOp : public framework::OperatorWithKernel { } } -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, input_data_type)) { - return framework::OpKernelType(input_data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif - return kt; } }; diff --git a/paddle/fluid/operators/fused/fusion_gru_op.cc b/paddle/fluid/operators/fused/fusion_gru_op.cc index 888e447d798f9d6e3f6ef07716ad6b6bc9d69dc6..679256b47ca002f8e691ab1dbdf1dc8a43c8ee13 100644 --- a/paddle/fluid/operators/fused/fusion_gru_op.cc +++ b/paddle/fluid/operators/fused/fusion_gru_op.cc @@ -153,14 +153,6 @@ void FusionGRUOp::InferShape(framework::InferShapeContext* ctx) const { framework::OpKernelType FusionGRUOp::GetExpectedKernelType( const framework::ExecutionContext& ctx) const { auto data_type = OperatorWithKernel::IndicateVarDataType(ctx, "X"); -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, data_type)) { - return framework::OpKernelType(data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif return framework::OpKernelType(data_type, ctx.GetPlace()); } diff --git a/paddle/fluid/operators/fused/fusion_lstm_op.cc b/paddle/fluid/operators/fused/fusion_lstm_op.cc index b09c6a2959b94f90cdfd8c5f24eeca2d79b5f3eb..93507160a50724d5d7d554e12a78814f09b32fea 100644 --- a/paddle/fluid/operators/fused/fusion_lstm_op.cc +++ b/paddle/fluid/operators/fused/fusion_lstm_op.cc @@ -176,14 +176,6 @@ void FusionLSTMOp::InferShape(framework::InferShapeContext* ctx) const { framework::OpKernelType FusionLSTMOp::GetExpectedKernelType( const framework::ExecutionContext& ctx) const { auto data_type = OperatorWithKernel::IndicateVarDataType(ctx, "X"); -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, data_type)) { - return framework::OpKernelType(data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif return framework::OpKernelType(data_type, ctx.GetPlace()); } diff --git a/paddle/fluid/operators/gaussian_random_op.cc b/paddle/fluid/operators/gaussian_random_op.cc index e2ee27f2561e188b492abcf16512e2b4d78f5567..f418e48f7d9c8674bef6054d2779f5e2b013cacc 100644 --- a/paddle/fluid/operators/gaussian_random_op.cc +++ b/paddle/fluid/operators/gaussian_random_op.cc @@ -60,16 +60,6 @@ class GaussianRandomOp : public framework::OperatorWithKernel { const framework::ExecutionContext& ctx) const override { auto data_type = static_cast(ctx.Attr("dtype")); - -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, data_type)) { - return framework::OpKernelType(data_type, - ctx.device_context(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif - return framework::OpKernelType(data_type, ctx.device_context()); } diff --git a/paddle/fluid/operators/gelu_op.cc b/paddle/fluid/operators/gelu_op.cc index 15b0a04ab2f67c3e72b504d325ef707eb636046c..eb3c55711641e753b740d153bf9265cb6d0709d0 100644 --- a/paddle/fluid/operators/gelu_op.cc +++ b/paddle/fluid/operators/gelu_op.cc @@ -36,14 +36,6 @@ class GeluOp : public framework::OperatorWithKernel { framework::OpKernelType GetExpectedKernelType( const framework::ExecutionContext &ctx) const override { auto data_type = OperatorWithKernel::IndicateVarDataType(ctx, "X"); -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, data_type)) { - return framework::OpKernelType(data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif return framework::OpKernelType(data_type, ctx.GetPlace()); } }; @@ -76,14 +68,6 @@ class GeluGradOp : public framework::OperatorWithKernel { framework::OpKernelType GetExpectedKernelType( const framework::ExecutionContext &ctx) const override { auto data_type = OperatorWithKernel::IndicateVarDataType(ctx, "X"); -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, data_type)) { - return framework::OpKernelType(data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif return framework::OpKernelType(data_type, ctx.GetPlace()); } }; diff --git a/paddle/fluid/operators/interpolate_op.cc b/paddle/fluid/operators/interpolate_op.cc index ac50da83e6b782c9d926dc36fcfb48ae675f32c0..257e513700b853d6b1104fb4f89c7b2e0d1b4e99 100644 --- a/paddle/fluid/operators/interpolate_op.cc +++ b/paddle/fluid/operators/interpolate_op.cc @@ -340,20 +340,6 @@ class InterpolateOp : public framework::OperatorWithKernel { framework::OpKernelType GetExpectedKernelType( const framework::ExecutionContext& ctx) const override { auto data_type = OperatorWithKernel::IndicateVarDataType(ctx, "X"); - -#ifdef PADDLE_WITH_MKLDNN - // TODO(danqing): support other interp_method - // (https://github.com/PaddlePaddle/Paddle/pull/30016/files) - // NOTE(jiahy0825): currently only support interp_method = nearest or - // interp_method = bilinear - if (this->CanMKLDNNBeUsed(ctx, data_type)) { - return framework::OpKernelType(data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif - return framework::OpKernelType(data_type, ctx.GetPlace()); } diff --git a/paddle/fluid/operators/interpolate_v2_op.cc b/paddle/fluid/operators/interpolate_v2_op.cc index e9d0d718b9fb792d74bb127335c90f98f85b5ef4..a3e7f46fecafed3fa168ef40a69642c2ef476bcd 100644 --- a/paddle/fluid/operators/interpolate_v2_op.cc +++ b/paddle/fluid/operators/interpolate_v2_op.cc @@ -444,20 +444,6 @@ class InterpolateV2Op : public framework::OperatorWithKernel { framework::OpKernelType GetExpectedKernelType( const framework::ExecutionContext& ctx) const override { auto data_type = OperatorWithKernel::IndicateVarDataType(ctx, "X"); - -#ifdef PADDLE_WITH_MKLDNN - // TODO(danqing): support other interp_method - // (https://github.com/PaddlePaddle/Paddle/pull/30016/files) - // NOTE(jiahy0825): currently only support interp_method = nearest or - // interp_method = bilinear - if (this->CanMKLDNNBeUsed(ctx, data_type)) { - return framework::OpKernelType(data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif - return framework::OpKernelType(data_type, ctx.GetPlace()); } diff --git a/paddle/fluid/operators/log_softmax_op.cc b/paddle/fluid/operators/log_softmax_op.cc index a4286aea0784240d6263365d7f04dcacb036b2e1..99da0b08af75b9e1012edcdf1fa70b9e6bd34d7a 100644 --- a/paddle/fluid/operators/log_softmax_op.cc +++ b/paddle/fluid/operators/log_softmax_op.cc @@ -33,15 +33,6 @@ class LogSoftmaxOp : public framework::OperatorWithKernel { const framework::ExecutionContext& ctx) const override { auto input_data_type = framework::OperatorWithKernel::IndicateVarDataType(ctx, "X"); - -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, input_data_type)) { - return framework::OpKernelType(input_data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif return framework::OpKernelType(input_data_type, ctx.GetPlace()); } }; diff --git a/paddle/fluid/operators/lrn_op.cc b/paddle/fluid/operators/lrn_op.cc index b2ef8f0370e370bf352e27b5b8ed1df11640d52f..a9cfadf3b64552ee3a0e2ca3364e45272579b159 100644 --- a/paddle/fluid/operators/lrn_op.cc +++ b/paddle/fluid/operators/lrn_op.cc @@ -225,16 +225,6 @@ class LRNOp : public framework::OperatorWithKernel { framework::OpKernelType GetExpectedKernelType( const framework::ExecutionContext& ctx) const override { auto data_type = OperatorWithKernel::IndicateVarDataType(ctx, "X"); - - // TODO(pzelazko-intel): enable MKLDNN layout when it's ready -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, data_type)) { - return framework::OpKernelType(data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif return framework::OpKernelType(data_type, ctx.GetPlace()); } @@ -359,16 +349,6 @@ class LRNOpGrad : public framework::OperatorWithKernel { framework::OpKernelType GetExpectedKernelType( const framework::ExecutionContext& ctx) const override { auto data_type = OperatorWithKernel::IndicateVarDataType(ctx, "X"); - - // TODO(pzelazko-intel): enable MKLDNN layout when it's ready -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, data_type)) { - return framework::OpKernelType(data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif return framework::OpKernelType(data_type, ctx.GetPlace()); } diff --git a/paddle/fluid/operators/matmul_op.cc b/paddle/fluid/operators/matmul_op.cc index f2900bea21c26bc44d7c27ccf454f1fcf648344e..024aa7731c9c69958964b8709b678e613c301841 100644 --- a/paddle/fluid/operators/matmul_op.cc +++ b/paddle/fluid/operators/matmul_op.cc @@ -697,15 +697,6 @@ class MatMulOp : public framework::OperatorWithKernel { const framework::ExecutionContext &ctx) const override { auto input_data_type = OperatorWithKernel::IndicateOrPromoteVarDataTypes(ctx, "X", "Y"); - -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, input_data_type)) { - return framework::OpKernelType(input_data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif return framework::OpKernelType(input_data_type, ctx.GetPlace()); } @@ -889,15 +880,6 @@ class MatMulOpGrad : public framework::OperatorWithKernel { const framework::ExecutionContext &ctx) const override { auto input_data_type = OperatorWithKernel::IndicateOrPromoteVarDataTypes(ctx, "X", "Y"); - -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, input_data_type)) { - return framework::OpKernelType(input_data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif return framework::OpKernelType(input_data_type, ctx.GetPlace()); } }; diff --git a/paddle/fluid/operators/matmul_v2_op.cc b/paddle/fluid/operators/matmul_v2_op.cc index 876a90e7b96742dabc912da6b5c5d8c85984db71..21537b70a4dc86caa42cea743703e515ae6caecf 100644 --- a/paddle/fluid/operators/matmul_v2_op.cc +++ b/paddle/fluid/operators/matmul_v2_op.cc @@ -135,15 +135,6 @@ class MatMulV2Op : public framework::OperatorWithKernel { const framework::ExecutionContext& ctx) const override { auto input_data_type = OperatorWithKernel::IndicateOrPromoteVarDataTypes(ctx, "X", "Y"); - -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, input_data_type)) { - return framework::OpKernelType(input_data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif return framework::OpKernelType(input_data_type, ctx.GetPlace()); } @@ -210,15 +201,6 @@ class MatMulV2OpGrad : public framework::OperatorWithKernel { const framework::ExecutionContext& ctx) const override { auto input_data_type = OperatorWithKernel::IndicateVarDataType( ctx, framework::GradVarName("Out")); - -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, input_data_type)) { - return framework::OpKernelType(input_data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif return framework::OpKernelType(input_data_type, ctx.GetPlace()); } diff --git a/paddle/fluid/operators/prelu_op.cc b/paddle/fluid/operators/prelu_op.cc index f998ca8a5ec0fa0c6cae370fe3d4dba015988852..ee70a441a754f8ea1737cda7672be08df89516ea 100644 --- a/paddle/fluid/operators/prelu_op.cc +++ b/paddle/fluid/operators/prelu_op.cc @@ -36,15 +36,6 @@ class PReluOp : public framework::OperatorWithKernel { const framework::ExecutionContext &ctx) const override { auto input_data_type = framework::OperatorWithKernel::IndicateVarDataType(ctx, "X"); - -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, input_data_type)) { - return framework::OpKernelType(input_data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif return framework::OpKernelType(input_data_type, ctx.GetPlace()); } @@ -127,15 +118,6 @@ class PReluGradOp : public framework::OperatorWithKernel { const framework::ExecutionContext &ctx) const override { auto input_data_type = framework::OperatorWithKernel::IndicateVarDataType(ctx, "X"); - -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, input_data_type)) { - return framework::OpKernelType(input_data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif return framework::OpKernelType(input_data_type, ctx.GetPlace()); } diff --git a/paddle/fluid/operators/scale_op.cc b/paddle/fluid/operators/scale_op.cc index cab04e43e8681f3f0d674f0d0e7633b07c3971c5..7416269e33dd2e6a43c67757cc6eff3153288010 100644 --- a/paddle/fluid/operators/scale_op.cc +++ b/paddle/fluid/operators/scale_op.cc @@ -31,15 +31,6 @@ class ScaleOp : public framework::OperatorWithKernel { const framework::ExecutionContext &ctx) const override { auto input_data_type = framework::OperatorWithKernel::IndicateVarDataType(ctx, "X"); - -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, input_data_type)) { - return framework::OpKernelType(input_data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif return framework::OpKernelType(input_data_type, ctx.GetPlace()); } }; diff --git a/paddle/fluid/operators/shape_op.cc b/paddle/fluid/operators/shape_op.cc index b191f7cfa00114778f8eb88b3c9ef1b9b50413e1..445514ab9b05010a6e4ca7ccbf808ff85f8150ba 100644 --- a/paddle/fluid/operators/shape_op.cc +++ b/paddle/fluid/operators/shape_op.cc @@ -30,15 +30,6 @@ class ShapeOp : public framework::OperatorWithKernel { const framework::ExecutionContext &ctx) const override { auto input_data_type = framework::OperatorWithKernel::IndicateVarDataType(ctx, "Input"); - -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, input_data_type)) { - return framework::OpKernelType(input_data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif return framework::OpKernelType(input_data_type, ctx.GetPlace()); } diff --git a/paddle/fluid/operators/shuffle_channel_op.cc b/paddle/fluid/operators/shuffle_channel_op.cc index ba96e92d3030b57bc9bfe24a487f5da702eba04f..7e98514cde37097845a327bd99e6e1d9c6dc3f76 100644 --- a/paddle/fluid/operators/shuffle_channel_op.cc +++ b/paddle/fluid/operators/shuffle_channel_op.cc @@ -39,15 +39,6 @@ class ShuffleChannelOp : public framework::OperatorWithKernel { const framework::ExecutionContext& ctx) const override { auto input_data_type = framework::OperatorWithKernel::IndicateVarDataType(ctx, "X"); - -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, input_data_type)) { - return framework::OpKernelType(input_data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif return framework::OpKernelType(input_data_type, ctx.GetPlace()); } }; diff --git a/paddle/fluid/operators/softmax_op.cc b/paddle/fluid/operators/softmax_op.cc index 6c63b2719f409d64ab0b9043598f9f2a0a0f3c61..7cb76dc56cb8a5f171b872f7afcba3208a677874 100644 --- a/paddle/fluid/operators/softmax_op.cc +++ b/paddle/fluid/operators/softmax_op.cc @@ -53,7 +53,6 @@ class SoftmaxOp : public framework::OperatorWithKernel { platform::errors::InvalidArgument( "float16 can only be used on GPU/NPU/XPU/MLU and custom place")); } - #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) if (platform::CanCUDNNBeUsed(ctx)) { return framework::OpKernelType(input_data_type, @@ -62,15 +61,6 @@ class SoftmaxOp : public framework::OperatorWithKernel { framework::LibraryType::kCUDNN); } #endif -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, input_data_type)) { - return framework::OpKernelType(input_data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif - return framework::OpKernelType(input_data_type, ctx.GetPlace(), layout_); } }; @@ -158,15 +148,6 @@ class SoftmaxOpGrad : public framework::OperatorWithKernel { framework::LibraryType::kCUDNN); } #endif -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, input_data_type)) { - return framework::OpKernelType(input_data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif - return framework::OpKernelType(input_data_type, ctx.GetPlace(), layout_); } }; diff --git a/paddle/fluid/operators/stack_op.cc b/paddle/fluid/operators/stack_op.cc index e9706f00ce889a2dac6eafefe07592515929cd6c..d30320f9952ee3457090b4555e947bc8b8a717a0 100644 --- a/paddle/fluid/operators/stack_op.cc +++ b/paddle/fluid/operators/stack_op.cc @@ -35,15 +35,6 @@ class StackOp : public framework::OperatorWithKernel { const framework::ExecutionContext &ctx) const override { auto input_data_type = framework::OperatorWithKernel::IndicateVarDataType(ctx, "X"); - -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, input_data_type)) { - return framework::OpKernelType(input_data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif return framework::OpKernelType(input_data_type, ctx.GetPlace()); } }; diff --git a/paddle/fluid/operators/transpose_op.cc b/paddle/fluid/operators/transpose_op.cc index df62da0b565465c42cacca0820db21953f21e8d0..48024cbb3ca171b7eaef28bae7a103d44fa5d07a 100644 --- a/paddle/fluid/operators/transpose_op.cc +++ b/paddle/fluid/operators/transpose_op.cc @@ -98,14 +98,6 @@ class TransposeOp : public framework::OperatorWithKernel { framework::OpKernelType GetExpectedKernelType( const framework::ExecutionContext &ctx) const override { auto data_type = OperatorWithKernel::IndicateVarDataType(ctx, "X"); -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, data_type)) { - return framework::OpKernelType(data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif auto &data_format = ctx.Attr("data_format"); framework::DataLayout layout_ = framework::StringToDataLayout(data_format); return framework::OpKernelType(data_type, ctx.GetPlace(), layout_); @@ -202,14 +194,6 @@ class TransposeOpGrad : public framework::OperatorWithKernel { const framework::ExecutionContext &ctx) const override { auto data_type = OperatorWithKernel::IndicateVarDataType( ctx, framework::GradVarName("Out")); -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, data_type)) { - return framework::OpKernelType(data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif std::string data_format = ctx.Attr("data_format"); framework::DataLayout layout_ = framework::StringToDataLayout(data_format); return framework::OpKernelType(data_type, ctx.GetPlace(), layout_); @@ -360,14 +344,6 @@ class Transpose2OpGrad : public framework::OperatorWithKernel { framework::proto::VarType::Type data_type = OperatorWithKernel::IndicateVarDataType(ctx, framework::GradVarName("Out")); -#ifdef PADDLE_WITH_MKLDNN - if (this->CanMKLDNNBeUsed(ctx, data_type)) { - return framework::OpKernelType(data_type, - ctx.GetPlace(), - framework::DataLayout::kMKLDNN, - framework::LibraryType::kMKLDNN); - } -#endif std::string data_format = ctx.Attr("data_format"); framework::DataLayout layout_ = framework::StringToDataLayout(data_format); return framework::OpKernelType(data_type, ctx.GetPlace(), layout_); diff --git a/paddle/fluid/platform/mkldnn_op_list.h b/paddle/fluid/platform/mkldnn_op_list.h new file mode 100644 index 0000000000000000000000000000000000000000..76f0a2affcc74208f6310953d14562ede93910a0 --- /dev/null +++ b/paddle/fluid/platform/mkldnn_op_list.h @@ -0,0 +1,90 @@ +/* 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. */ + +#pragma once + +#ifdef PADDLE_WITH_MKLDNN + +#include + +namespace paddle { +namespace platform { + +// NOTE(jiahongyu): Below ops have specific PADDLE_WITH_MKLDNN hard codes within +// the function GetExpectedKernelType, so we need to handle them through +// mkldnn_white_list and solve them one-by-one in the future. +// TODO(jiahongyu): Delete mkldnn_white_list and fully support +// PADDLE_WITH_MKLDNN of GetExpectedKernelType. +static const std::unordered_set mkldnn_white_list = { + "cast", + "transfer_dtype", + "layer_norm", + "pad2d", + "pad3d", + "pool2d", + "pool2d_grad", + "slice", + "slice_grad", + "split", + "sum", + "sgd", + // NOTE(jiahongyu): squeeze MKLDNN kernel are disabled + // (https://github.com/PaddlePaddle/Paddle/pull/35781). If these MKLDNN + // kernels and codes are deleted in the future, attributes `use_mkldnn` + // should be removed from function declaration + "squeeze", + "squeeze_grad", + "squeeze2", + "squeeze2_grad", + // NOTE(jiahongyu): reshape and flatten have attribute use_mkldnn and they + // are registered in paddle, but they didn't change the ExpectedKernelType + // of tensor. Actually, mkldnn kernel of squeeze, reshape, and flatten + // should never be called. + "reshape", + "reshape_grad", + "reshape2", + "reshape2_grad", + "flatten", + "flatten_grad", + "flatten2", + "flatten2_grad", + // NOTE(jiahongyu): After fixing GetExpectedKernelType in ReduceOp, reduce + // series hard code can be deleted together. + "reduce_max", + "reduce_mean", + "reduce_mean_grad", + "reduce_min", + "reduce_sum", + "reduce_sum_grad", + // NOTE(jiahongyu): Below ops register kernel with customized_type_value, we + // need to analysis and solve them one-by-one. + "conv2d", + "conv2d_grad", + "depthwise_conv2d", + "depthwise_conv2d_grad", + "conv3d", + "conv3d_grad", + "prior_box", + "fc", + "mul", + "mul_grad", + "transpose2"}; + +inline bool in_mkldnn_white_list(const std::string& op_name) { + return mkldnn_white_list.find(op_name) != mkldnn_white_list.end(); +} + +} // namespace platform +} // namespace paddle +#endif diff --git a/paddle/phi/api/lib/kernel_dispatch.h b/paddle/phi/api/lib/kernel_dispatch.h index 015c1be57370a2fc300cbd07be8a8dd619521aea..176713b71bbcf7b014a270c0c424ae5d1de14bea 100644 --- a/paddle/phi/api/lib/kernel_dispatch.h +++ b/paddle/phi/api/lib/kernel_dispatch.h @@ -99,7 +99,6 @@ struct KernelKeyParser : ArgsIterator { inline void AssignKernelKeySet(const phi::TensorBase& tensor) { key_set.backend_set = key_set.backend_set | detail::GetTensorBackendSet(tensor); - // TODO(chenweihang): select multi layout and dtype phi::DataLayout tensor_layout = tensor.layout(); key_set.layout = tensor_layout > key_set.layout ? tensor_layout : key_set.layout;