提交 6e2f9684 编写于 作者: Y Yang Yang

simple test

上级 f29a6b02
...@@ -14,6 +14,7 @@ limitations under the License. */ ...@@ -14,6 +14,7 @@ limitations under the License. */
#include "paddle/framework/executor.h" #include "paddle/framework/executor.h"
#include <memory> #include <memory>
#include <vector>
#include "paddle/framework/op_registry.h" #include "paddle/framework/op_registry.h"
#include "paddle/framework/operator.h" #include "paddle/framework/operator.h"
#include "paddle/framework/scope.h" #include "paddle/framework/scope.h"
...@@ -22,6 +23,8 @@ limitations under the License. */ ...@@ -22,6 +23,8 @@ limitations under the License. */
namespace paddle { namespace paddle {
namespace framework { namespace framework {
// using std::unique_ptr<OperatorBase> op_ptr;
class LinearListView; class LinearListView;
class GraphView; class GraphView;
...@@ -158,14 +161,27 @@ Executor* NewLocalExecutor(const platform::Place& place, ...@@ -158,14 +161,27 @@ Executor* NewLocalExecutor(const platform::Place& place,
} }
void ExecutorImpl::Run() { void ExecutorImpl::Run() {
// operators running // TODO(tonyyang-svail): only runs the first block
scope_->NewVar(); auto& block = program_desc_->blocks(0);
device_->cpu_device_context->Wait();
#ifndef PADDLE_ONLY_CPU for (auto& var : block.vars()) {
if (device_->cuda_device_context) { scope_->NewVar(var.name());
device_->cuda_device_context->Wait();
} }
#endif
// std::vector<op_ptr> 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() { void ExecutorImpl::Initialize() {
......
...@@ -13,6 +13,8 @@ See the License for the specific language governing permissions and ...@@ -13,6 +13,8 @@ See the License for the specific language governing permissions and
limitations under the License. */ limitations under the License. */
#include "paddle/framework/executor.h" #include "paddle/framework/executor.h"
#include "paddle/framework/attribute.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
using namespace paddle::platform; using namespace paddle::platform;
...@@ -20,8 +22,43 @@ using namespace paddle::framework; ...@@ -20,8 +22,43 @@ using namespace paddle::framework;
TEST(Executor, Init) { TEST(Executor, Init) {
ProgramDesc pdesc; 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; CPUPlace cpu_place;
Executor* executor = NewLocalExecutor(cpu_place, pdesc, true); Executor* executor = NewLocalExecutor(cpu_place, pdesc, true);
executor->Run(); executor->Run();
delete executor; delete executor;
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册