From 6e2f96841a5d3e64dc1c4eabb85b7984099b1d0e Mon Sep 17 00:00:00 2001 From: Yang Yang Date: Tue, 3 Oct 2017 17:36:29 +0000 Subject: [PATCH] simple test --- paddle/framework/executor.cc | 30 ++++++++++++++++++------ paddle/framework/executor_test.cc | 39 ++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 8 deletions(-) diff --git a/paddle/framework/executor.cc b/paddle/framework/executor.cc index ebe3259bc..9e7f6f88d 100644 --- a/paddle/framework/executor.cc +++ b/paddle/framework/executor.cc @@ -14,6 +14,7 @@ limitations under the License. */ #include "paddle/framework/executor.h" #include +#include #include "paddle/framework/op_registry.h" #include "paddle/framework/operator.h" #include "paddle/framework/scope.h" @@ -22,6 +23,8 @@ limitations under the License. */ namespace paddle { namespace framework { +// using std::unique_ptr op_ptr; + class LinearListView; class GraphView; @@ -158,14 +161,27 @@ Executor* NewLocalExecutor(const platform::Place& place, } void ExecutorImpl::Run() { - // operators running - scope_->NewVar(); - device_->cpu_device_context->Wait(); -#ifndef PADDLE_ONLY_CPU - if (device_->cuda_device_context) { - device_->cuda_device_context->Wait(); + // TODO(tonyyang-svail): only runs the first block + auto& block = program_desc_->blocks(0); + + for (auto& var : block.vars()) { + scope_->NewVar(var.name()); } -#endif + + // std::vector ops; + for (auto& op_desc : block.ops()) { + auto op = framework::OpRegistry::CreateOp(op_desc); + op->InferShape(device_->cpu_device_context); + op->Compute(); + } + + // TODO(tonyyang-svail): need to test gpu device + // device_->cpu_device_context->Wait(); + // #ifndef PADDLE_ONLY_CPU + // if (device_->cuda_device_context) { + // device_->cuda_device_context->Wait(); + // } + // #endif } void ExecutorImpl::Initialize() { diff --git a/paddle/framework/executor_test.cc b/paddle/framework/executor_test.cc index 6f8ca3876..9ab1b6580 100644 --- a/paddle/framework/executor_test.cc +++ b/paddle/framework/executor_test.cc @@ -13,6 +13,8 @@ See the License for the specific language governing permissions and limitations under the License. */ #include "paddle/framework/executor.h" +#include "paddle/framework/attribute.h" + #include "gtest/gtest.h" using namespace paddle::platform; @@ -20,8 +22,43 @@ using namespace paddle::framework; TEST(Executor, Init) { ProgramDesc pdesc; + + auto root_block = pdesc.add_blocks(); + root_block->set_idx(0); + root_block->set_parent_idx(-1); + + auto a = root_block->add_vars(); + a->set_name("a"); + auto a_lt = a->mutable_lod_tensor(); + a_lt->set_data_type(paddle::framework::DataType::FP32); + a_lt->add_dims(640); + a_lt->add_dims(640); + + auto b = root_block->add_vars(); + b->set_name("b"); + auto b_lt = b->mutable_lod_tensor(); + b_lt->set_data_type(paddle::framework::DataType::FP32); + b_lt->add_dims(640); + b_lt->add_dims(640); + + auto c = root_block->add_vars(); + c->set_name("c"); + auto c_lt = c->mutable_lod_tensor(); + c_lt->set_data_type(paddle::framework::DataType::FP32); + c_lt->add_dims(640); + c_lt->add_dims(640); + + auto op1 = root_block->add_ops(); + op1->set_type("elementwise_add"); + auto X = op1->add_inputs(); + X->set_parameter("X"); + X->add_arguments("a"); + auto Y = op1->add_inputs(); + Y->set_parameter("Y"); + Y->add_arguments("b"); + CPUPlace cpu_place; Executor* executor = NewLocalExecutor(cpu_place, pdesc, true); executor->Run(); delete executor; -} \ No newline at end of file +} -- GitLab