From 4098ba29ed180e5035fc90573b8eeef8224f373e Mon Sep 17 00:00:00 2001 From: luotao1 Date: Mon, 8 Apr 2019 20:06:13 +0800 Subject: [PATCH] reduce hasAttr elapsed time in RunImpl test=develop --- paddle/fluid/framework/operator.cc | 4 +++- paddle/fluid/framework/operator.h | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/paddle/fluid/framework/operator.cc b/paddle/fluid/framework/operator.cc index 040f669f2b..1723a9a78a 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 2e733badb8..489b660996 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; }; -- GitLab