SINGA-108 Add Python wrapper to singa Add interface file and script for driver.i. Add new API for py wrapper in driver.cc & driver.h.
Project: http://git-wip-us.apache.org/repos/asf/incubator-singa/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-singa/commit/9b68af11 Tree: http://git-wip-us.apache.org/repos/asf/incubator-singa/tree/9b68af11 Diff: http://git-wip-us.apache.org/repos/asf/incubator-singa/diff/9b68af11 Branch: refs/heads/master Commit: 9b68af11f64cfa553d78bdda803f423ebd433b0b Parents: 0dd2d5c Author: xiezl <[email protected]> Authored: Fri Dec 4 16:02:21 2015 +0800 Committer: xiezl <[email protected]> Committed: Tue Dec 8 12:28:56 2015 +0800 ---------------------------------------------------------------------- include/singa/driver.h | 1 + src/driver.cc | 7 +++++++ src/driver.i | 15 +++++++++++++++ src/generatepy.sh | 5 +++++ 4 files changed, 28 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/9b68af11/include/singa/driver.h ---------------------------------------------------------------------- diff --git a/include/singa/driver.h b/include/singa/driver.h index 48c2c02..c7d2606 100644 --- a/include/singa/driver.h +++ b/include/singa/driver.h @@ -56,6 +56,7 @@ class Driver { * files. * @param[in] job_conf job configuration. */ + void Train(bool resume, const std::string str); void Train(bool resume, const JobProto& job_conf); /** * Create workers and servers to conduct the training. http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/9b68af11/src/driver.cc ---------------------------------------------------------------------- diff --git a/src/driver.cc b/src/driver.cc index 336a2b5..816e0df 100644 --- a/src/driver.cc +++ b/src/driver.cc @@ -150,6 +150,13 @@ void Driver::Init(int argc, char **argv) { RegisterParamGenerator<UniformSqrtFanInOutGen>(kUniformSqrtFanInOut); } +void Driver::Train(bool resume, const std::string str){ + JobProto job_conf; + job_conf.ParseFromString(str); + Train(resume,job_conf); + +} + void Driver::Train(bool resume, const JobProto& job_conf) { Cluster::Setup(job_id_, singa_conf_, job_conf.cluster()); if (singa_conf_.has_log_dir()) http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/9b68af11/src/driver.i ---------------------------------------------------------------------- diff --git a/src/driver.i b/src/driver.i new file mode 100644 index 0000000..3dea542 --- /dev/null +++ b/src/driver.i @@ -0,0 +1,15 @@ +%module driver +%include "std_vector.i" +%include "std_string.i" +%{ +#include "../include/singa/driver.h" +%} + +namespace singa{ +using std::vector; +class Driver{ +public: +void Train(bool resume, const std::string job_conf); +}; +} + http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/9b68af11/src/generatepy.sh ---------------------------------------------------------------------- diff --git a/src/generatepy.sh b/src/generatepy.sh new file mode 100644 index 0000000..6fc4b77 --- /dev/null +++ b/src/generatepy.sh @@ -0,0 +1,5 @@ + +swig -c++ -python driver.i +g++ -fPIC driver.cc driver_wrap.cxx -shared -o _driver.so -DMSHADOW_USE_CUDA=0 \ + -DMSHADOW_USE_CBLAS=1 -DMSHADOW_USE_MKL=0 -DUSE_GPU -std=c++11 \ + -I/usr/cuda-7.5/include -I../include -I/usr/include/python2.7/
