未验证 提交 aca60e9a 编写于 作者: T Tao Luo 提交者: GitHub

remove unnecessary prepare_data (#17080)

test=develop
上级 55ce36e9
...@@ -1023,6 +1023,7 @@ Scope* OperatorWithKernel::PrepareData( ...@@ -1023,6 +1023,7 @@ Scope* OperatorWithKernel::PrepareData(
std::vector<std::string>* transfered_inplace_vars, std::vector<std::string>* transfered_inplace_vars,
RuntimeContext* ctx) const { RuntimeContext* ctx) const {
Scope* new_scope = nullptr; Scope* new_scope = nullptr;
if (!need_prepare_data_) return new_scope;
std::unordered_set<std::string> no_buffer_ins; std::unordered_set<std::string> no_buffer_ins;
if (info_) { if (info_) {
...@@ -1115,6 +1116,10 @@ Scope* OperatorWithKernel::PrepareData( ...@@ -1115,6 +1116,10 @@ Scope* OperatorWithKernel::PrepareData(
SetTensorToVariable(*var, out, trans_var); SetTensorToVariable(*var, out, trans_var);
} }
} }
// If new_scope = nullptr, it means that for each input of this Op, there is
// no TransformData. Thus, PrepareData could be skipped at the rest iterations
// of this Op's execution to save the elapsed time.
if (!new_scope) need_prepare_data_ = false;
return new_scope; return new_scope;
} }
......
...@@ -506,6 +506,7 @@ class OperatorWithKernel : public OperatorBase { ...@@ -506,6 +506,7 @@ class OperatorWithKernel : public OperatorBase {
mutable std::unique_ptr<OpKernelFunc> kernel_func_; mutable std::unique_ptr<OpKernelFunc> kernel_func_;
mutable std::unique_ptr<RuntimeContext> runtime_ctx_; mutable std::unique_ptr<RuntimeContext> runtime_ctx_;
mutable const Scope* pre_scope_ = nullptr; mutable const Scope* pre_scope_ = nullptr;
mutable bool need_prepare_data_ = true;
mutable bool enable_cache_runtime_context = false; mutable bool enable_cache_runtime_context = false;
mutable bool enable_cache_expected_kernel = false; mutable bool enable_cache_expected_kernel = false;
mutable bool all_kernels_must_compute_runtime_shape = false; mutable bool all_kernels_must_compute_runtime_shape = false;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册