From 6729f32c74a80559b83a1f60a20b36cc3583dead Mon Sep 17 00:00:00 2001 From: fengjiayi Date: Sun, 15 Oct 2017 10:53:21 -0700 Subject: [PATCH] Expose Executor to Python (#4804) * Expose Executor to Python * Follow comments --- paddle/pybind/CMakeLists.txt | 2 +- paddle/pybind/pybind.cc | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/paddle/pybind/CMakeLists.txt b/paddle/pybind/CMakeLists.txt index b8fc934724..46c24e2cd5 100644 --- a/paddle/pybind/CMakeLists.txt +++ b/paddle/pybind/CMakeLists.txt @@ -1,6 +1,6 @@ if(WITH_PYTHON) cc_library(paddle_pybind SHARED SRCS pybind.cc exception.cc protobuf.cc - DEPS pybind python backward proto_desc tensor_array paddle_memory + DEPS pybind python backward proto_desc tensor_array paddle_memory executor ${GLOB_OP_LIB}) endif(WITH_PYTHON) diff --git a/paddle/pybind/pybind.cc b/paddle/pybind/pybind.cc index b143cb9f59..afc80b25b1 100644 --- a/paddle/pybind/pybind.cc +++ b/paddle/pybind/pybind.cc @@ -15,6 +15,7 @@ limitations under the License. */ #include "paddle/pybind/protobuf.h" #include "paddle/framework/backward.h" +#include "paddle/framework/executor.h" #include "paddle/framework/lod_tensor.h" #include "paddle/framework/tensor_array.h" #include "paddle/operators/cond_op.h" @@ -391,6 +392,14 @@ All parameter, weight, gradient are variables in Paddle. self.set_falsenet(net.Clone()); }); + py::class_(m, "Executor") + .def(py::init &>()) + .def("run", + [](Executor &self, const ProgramDesc &program_desc, int block_id) { + framework::Scope &global_scope = GetGlobalScope(); + self.Run(program_desc, &global_scope, block_id); + }); + m.def("unique_integer", UniqueIntegerGenerator); m.def("is_compile_gpu", IsCompileGPU); -- GitLab