diff --git a/paddle/fluid/framework/operator.cc b/paddle/fluid/framework/operator.cc index b4714407686d85d0ffd0d5986ce780bcea818415..d8312c698b70fe28e2311a7e467feea2b181b7c3 100644 --- a/paddle/fluid/framework/operator.cc +++ b/paddle/fluid/framework/operator.cc @@ -1414,16 +1414,10 @@ bool OperatorWithKernel::SupportsKernelType( 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"; return ctx.HasAttr(use_mkldnn_attr) && ctx.Attr(use_mkldnn_attr) && - platform::is_cpu_place(ctx.GetPlace()); + platform::is_cpu_place(ctx.GetPlace()) && + this->SupportsMKLDNN(data_type); } void OperatorWithKernel::InferShape(InferShapeContext* ctx) const { diff --git a/paddle/fluid/imperative/dygraph_grad_maker.h b/paddle/fluid/imperative/dygraph_grad_maker.h index aaa7f9fa4121d92c5adb04071f157ef16e6fd051..e0c943f18ce20a7a41c0de02d4308771e3bca36f 100644 --- a/paddle/fluid/imperative/dygraph_grad_maker.h +++ b/paddle/fluid/imperative/dygraph_grad_maker.h @@ -209,7 +209,7 @@ class GradOpBaseMakerBase { const NameVarBaseMap& var_base_map_in_; const NameVarBaseMap& var_base_map_out_; const framework::AttributeMap& attrs_; - const framework::AttributeMap* default_attrs_; + const framework::AttributeMap* default_attrs_ = nullptr; const std::map& inplace_map_; }; diff --git a/paddle/fluid/imperative/execution_context.h b/paddle/fluid/imperative/execution_context.h index 6d4f7c347b097d4da67a93f52c4b6f2aeba3f260..4ac885dbe3f9739f78f6fbf66b3b5e57859918d2 100644 --- a/paddle/fluid/imperative/execution_context.h +++ b/paddle/fluid/imperative/execution_context.h @@ -103,7 +103,8 @@ class DygraphExecutionContext : public framework::ExecutionContext { bool HasAttr(const std::string& name) const override { if (attrs_.find(name) == attrs_.end()) { - return default_attrs_.find(name) != default_attrs_.end(); + return &default_attrs_ != nullptr && + default_attrs_.find(name) != default_attrs_.end(); } return true; } diff --git a/paddle/fluid/imperative/op_base.h b/paddle/fluid/imperative/op_base.h index 3faa9a0cfb6297f93c131b929fd6941946bcf7a6..cee0ad250730ec65c270c449617f13b919177ace 100644 --- a/paddle/fluid/imperative/op_base.h +++ b/paddle/fluid/imperative/op_base.h @@ -221,7 +221,7 @@ class OpBase { NameVarMap ins_; NameVarMap outs_; framework::AttributeMap attrs_; - const framework::AttributeMap* default_attrs_; + const framework::AttributeMap* default_attrs_ = nullptr; std::unique_ptr op_; platform::Place place_; size_t id_{-1UL};