singa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wang...@apache.org
Subject [07/12] incubator-singa git commit: SINGA-108 Add Python wrapper to singa
Date Thu, 10 Dec 2015 14:05:08 GMT
SINGA-108 Add Python wrapper to singa

Add autotool supports for wrapper compilation.


Project: http://git-wip-us.apache.org/repos/asf/incubator-singa/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-singa/commit/ef5b6556
Tree: http://git-wip-us.apache.org/repos/asf/incubator-singa/tree/ef5b6556
Diff: http://git-wip-us.apache.org/repos/asf/incubator-singa/diff/ef5b6556

Branch: refs/heads/master
Commit: ef5b655677ccd1aa8566efec26a3f9c1f6b5eb5f
Parents: b8104ef
Author: xiezl <xiezhongle@comp.nus.edu.sg>
Authored: Sat Dec 5 02:38:35 2015 +0800
Committer: xiezl <xiezhongle@comp.nus.edu.sg>
Committed: Tue Dec 8 12:45:52 2015 +0800

----------------------------------------------------------------------
 Makefile.am                   | 39 +++++++++++++++++++++-------
 configure.ac                  | 53 +++++++++++++++++++++++++++++++++++---
 tool/python/singa/__init__.py |  0
 3 files changed, 79 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/ef5b6556/Makefile.am
----------------------------------------------------------------------
diff --git a/Makefile.am b/Makefile.am
index 2d1dfc6..a09a12f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -22,12 +22,15 @@ PROTO_SRCS := src/proto/singa.pb.cc \
 PROTO_HDRS := include/proto/singa.pb.h \
               include/proto/job.pb.h \
               include/proto/common.pb.h
-PROTO_PYS := tool/pb2/singa_pb2.py \
-             tool/pb2/job_pb2.py \
-             tool/pb2/common_pb2.py
+PROTO_PYS := tool/python/pb2/singa_pb2.py \
+             tool/python/pb2/job_pb2.py \
+             tool/python/pb2/common_pb2.py
 
 CUDA_SRCS := src/utils/math_kernel.cu
 
+PY_SRCS := tool/python/singa/driver_wrap.cxx
+		   src/driver.cc 	
+
 SINGA_SRCS := src/driver.cc \
               src/server.cc \
               src/worker.cc \
@@ -127,12 +130,15 @@ TEST_SRCS := include/gtest/gtest_main.cc \
 						 src/test/test_csv_input_layer.cc
 
 #EXTRA_PROGRAMS = $(PROGS)
-EXTRA_PROGRAMS = singatest test
+EXTRA_PROGRAMS = singatest test 
 #EXTRA_LTLIBRARIES = $(LTLIBS)
-EXTRA_LTLIBRARIES = libgtest.la
+EXTRA_LTLIBRARIES = libgtest.la _driver.la
 
-lib_LTLIBRARIES = libsinga.la $(LTLIBS)
+lib_LTLIBRARIES = libsinga.la $(LTLIBS) 
 bin_PROGRAMS = singa singatool $(PROGS)
+pydir = $(CURDIR)/tool/python/singa/
+py_LTLIBRARIES = $(PY_PROGS)
+#py_LTLIBRARIES = $(PY_PROGS)
 
 #lib_LTLIBRARIES = libsinga.la
 libsinga_la_SOURCES = $(PROTO_SRCS) $(SINGA_SRCS)
@@ -209,6 +215,15 @@ singatest_CXXFLAGS += $(CUDA_CFLAGS)
 singatest_LDFLAGS += $(CUDA_LDFLAGS) $(CUDA_LIBS)
 endif
 
+_driver_la_SOURCES = $(PY_SRCS)
+_driver_la_CXXFLAGS = $(DEFAULT_FLAGS) $(MSHADOW_FLAGS) -I$(top_srcdir)/include $(PYFLAGS)

+_driver_la_LDFLAGS = -lsinga -module -shared $(PYLIBS) -avoid-version -rpath $(pydir) 
+
+if DCUDA
+_driver_la_CXXFLAGS += $(CUDA_CFLAGS)
+_driver_la_LDFLAGS += $(CUDA_LDFLAGS) $(CUDA_LIBS)
+endif
+
 clean-local:
 	rm -rf $(PROTO_SRCS) $(PROTO_HDRS)
 	rm -rf $(PROTO_PYS)
@@ -230,14 +245,20 @@ rat:
 .cu.o: .cu
 	$(NVCC) $(MSHADOW_FLAGS) $(CUDA_CFLAGS) $(CUDA_LDFLAGS) $(CUDA_LIBS) -I$(top_srcdir)/include
-std=c++11 -G -c -o $@ $<
 
+install-pyLTLIBRARIES: $(py_LTLIBRARIES)
+	cp -f .libs/_driver.so tool/python/singa/
+
+uninstall-pyLTLIBRARIES: 
+	rm -f tool/python/singa/_driver.so
+
 test: singatest
 	@./singatest
 
 $(PROTO_HDRS) $(PROTO_SRCS): $(PROTOS)
 	protoc --proto_path=$(top_srcdir)/src/proto --cpp_out=$(top_srcdir)/src/proto $(PROTOS)
-	mkdir -p $(top_srcdir)/tool/pb2/
-	touch $(top_srcdir)/tool/pb2/__init__.py
-	protoc --proto_path=$(top_srcdir)/src/proto --python_out=$(top_srcdir)/tool/pb2 $(PROTOS)
+	mkdir -p $(top_srcdir)/tool/python/pb2/
+	touch $(top_srcdir)/tool/python/pb2/__init__.py
+	protoc --proto_path=$(top_srcdir)/src/proto --python_out=$(top_srcdir)/tool/python/pb2 $(PROTOS)
 	mkdir -p $(top_srcdir)/include/singa/proto/
 	cp $(top_srcdir)/src/proto/*.pb.h $(top_srcdir)/include/singa/proto/
 	@echo

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/ef5b6556/configure.ac
----------------------------------------------------------------------
diff --git a/configure.ac b/configure.ac
index 7262837..1c4d3aa 100644
--- a/configure.ac
+++ b/configure.ac
@@ -33,6 +33,7 @@ ACLOCAL_AMFLAGS = -I m4 --install
 # Checks for programs.
 AC_PROG_CXX([g++])
 AC_PROG_CC
+AC_DISABLE_STATIC
 AC_PROG_LIBTOOL
 
 # Setup custom CUDA paths
@@ -123,14 +124,12 @@ AC_ARG_ENABLE(test,
 	[enable_test=yes],[enable_test=no])
 AM_CONDITIONAL(SINGATEST, test "$enable_test" = yes)
 if test x"$enable_test" != x"no"; then
-	PROGS='singatest test'
-	LTLIBS='libgtest.la'
+	PROGS='singatest test '
+	LTLIBS='libgtest.la '
 else
 	PROGS=''
 	LTLIBS=''
 fi
-AC_SUBST([PROGS])
-AC_SUBST([LTLIBS])
 
 AC_ARG_ENABLE(debug,
 	AS_HELP_STRING([--enable-debug],[enable debug mode]),
@@ -141,7 +140,53 @@ if test x"$enable_debug" != x"no"; then
 else
 	DEBUG+='-O2'
 fi
+
+AC_ARG_ENABLE(python,
+    [AS_HELP_STRING([--enable-python],[enable python binding])],
+    [enable_python=yes],[enable_python=no])
+AM_CONDITIONAL([PY], [test "enable_python" = "yes"])
+if test x"$enable_python" != x"no"; then
+    AC_CHECK_PROG(PY_CHECK,python,yes)
+    if test x"$PY_CHECK" != x"yes"; then
+        AC_MSG_ERROR([Cannot find command "python". Please intall before make.])
+    else    
+        PYLIBS="-lpython`python -V 2>&1 | awk '{print substr($2,1,3)}'`"
+    fi
+fi        
+AC_SUBST(PYLIBS)
+
+AC_ARG_WITH([python],
+    [AS_HELP_STRING([--with-python=PATH],[prefix where python is installed])],
+    [python_prefix=$withval],[python_prefix="/usr/local"])
+if test "$python_prefix" == "yes"; then
+    if test "$withval" == "yes"; then
+        python_prefix="/usr/local"
+    fi
+fi
+
+AC_MSG_CHECKING([Python.h in $python_prefix])
+if test -f "$python_prefix/Python.h"; then
+    AC_MSG_RESULT([python found])
+    AC_DEFINE_UNQUOTED([PYTHON_PATH], ["$python_prefix"], [Path to python binary])
+else
+    AC_MSG_RESULT([python not found!])
+    AC_MSG_FAILURE([Python.h was not found in $py_prefix])
+fi
+
+if test x"$enable_python" != x"no"; then
+    #AC_DEFINE(PY,[1],[Defined if PY should be used])
+    PY_PROGS='_driver.la '
+    PYFLAGS="-I$python_prefix "
+else
+    PY_PROGS=''
+    PYFLAGS=''
+fi
+
+AC_SUBST([PROGS])
+AC_SUBST([LTLIBS])
 AC_SUBST([DEBUG])
+AC_SUBST([PYFLAGS])
+AC_SUBST([PY_PROGS])
 
 #AC_CHECK_LIB([opencv_imgproc], [main], [], [
 #  AC_MSG_ERROR([unable to find opencv_imgproc lib])

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/ef5b6556/tool/python/singa/__init__.py
----------------------------------------------------------------------
diff --git a/tool/python/singa/__init__.py b/tool/python/singa/__init__.py
deleted file mode 100644
index e69de29..0000000


Mime
View raw message