diff --git a/paddle/fluid/framework/operator.cc b/paddle/fluid/framework/operator.cc index 040f669f2b4da50d005dd52ee7cc49f9424eff20..1723a9a78a0da6e3eac7f823f79fe802a916e5b3 100644 --- a/paddle/fluid/framework/operator.cc +++ b/paddle/fluid/framework/operator.cc @@ -884,6 +884,8 @@ void OperatorWithKernel::RunImpl(const Scope& scope, // result of HasAttr. if (!enable_cache_runtime_context && HasAttr(kEnableCacheRuntimeContext)) enable_cache_runtime_context = true; + if (!enable_cache_expected_kernel && HasAttr(kEnableCacheExpectedKernel)) + enable_cache_expected_kernel = true; if (!all_kernels_must_compute_runtime_shape && HasAttr(kAllKernelsMustComputeRuntimeShape)) all_kernels_must_compute_runtime_shape = true; @@ -906,7 +908,7 @@ void OperatorWithKernel::RunImpl(const Scope& scope, platform::DeviceContextPool& pool = platform::DeviceContextPool::Instance(); auto* dev_ctx = pool.Get(place); - if (!HasAttr(kEnableCacheExpectedKernel) || !kernel_type_) { + if (!enable_cache_expected_kernel || !kernel_type_) { ChooseKernel(*runtime_ctx, scope, place); } diff --git a/paddle/fluid/framework/operator.h b/paddle/fluid/framework/operator.h index 2e733badb8ab17826f7a12e9e17771f3b8dd3fb8..489b66099658d522fe1f1adaad763b66bdd22c91 100644 --- a/paddle/fluid/framework/operator.h +++ b/paddle/fluid/framework/operator.h @@ -507,6 +507,7 @@ class OperatorWithKernel : public OperatorBase { mutable std::unique_ptr runtime_ctx_; mutable const Scope* pre_scope_ = nullptr; mutable bool enable_cache_runtime_context = false; + mutable bool enable_cache_expected_kernel = false; mutable bool all_kernels_must_compute_runtime_shape = false; };