提交 7e9f0790 编写于 作者: T tensor-tang

fix scope in thread

上级 3206bcd9
...@@ -91,6 +91,8 @@ void ThreadRunInfer( ...@@ -91,6 +91,8 @@ void ThreadRunInfer(
const std::vector<std::vector<const paddle::framework::LoDTensor*>>& jobs) { const std::vector<std::vector<const paddle::framework::LoDTensor*>>& jobs) {
auto copy_program = std::unique_ptr<paddle::framework::ProgramDesc>( auto copy_program = std::unique_ptr<paddle::framework::ProgramDesc>(
new paddle::framework::ProgramDesc(*inference_program)); new paddle::framework::ProgramDesc(*inference_program));
auto& sub_scope = scope->NewScope();
std::string feed_holder_name = "feed_" + paddle::string::to_string(tid); std::string feed_holder_name = "feed_" + paddle::string::to_string(tid);
std::string fetch_holder_name = "fetch_" + paddle::string::to_string(tid); std::string fetch_holder_name = "fetch_" + paddle::string::to_string(tid);
copy_program->SetFeedHolderName(feed_holder_name); copy_program->SetFeedHolderName(feed_holder_name);
...@@ -113,10 +115,11 @@ void ThreadRunInfer( ...@@ -113,10 +115,11 @@ void ThreadRunInfer(
auto start_ms = GetCurrentMs(); auto start_ms = GetCurrentMs();
for (size_t i = 0; i < inputs.size(); ++i) { for (size_t i = 0; i < inputs.size(); ++i) {
feed_targets[feed_target_names[0]] = inputs[i]; feed_targets[feed_target_names[0]] = inputs[i];
executor->Run(*copy_program, scope, &feed_targets, &fetch_targets, true, executor->Run(*copy_program, &sub_scope, &feed_targets, &fetch_targets,
true, feed_holder_name, fetch_holder_name); true, true, feed_holder_name, fetch_holder_name);
} }
auto stop_ms = GetCurrentMs(); auto stop_ms = GetCurrentMs();
scope->DeleteScope(&sub_scope);
LOG(INFO) << "Tid: " << tid << ", process " << inputs.size() LOG(INFO) << "Tid: " << tid << ", process " << inputs.size()
<< " samples, avg time per sample: " << " samples, avg time per sample: "
<< (stop_ms - start_ms) / inputs.size() << " ms"; << (stop_ms - start_ms) / inputs.size() << " ms";
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册