Repository: incubator-singa Updated Branches: refs/heads/master efdf6d711 -> 5f67e578b
SINGA-157 Change the priority of cudnn library and install libsingagpu.so Now the compiler looks up cudnn libs before cuda libs. libsingagpu.so will be copied into .libs after compilation. Add some macros to enable cudnn_v4. Project: http://git-wip-us.apache.org/repos/asf/incubator-singa/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-singa/commit/e5f111ca Tree: http://git-wip-us.apache.org/repos/asf/incubator-singa/tree/e5f111ca Diff: http://git-wip-us.apache.org/repos/asf/incubator-singa/diff/e5f111ca Branch: refs/heads/master Commit: e5f111cacc2c1ad8922e7b4bfad7693dd0605c99 Parents: efdf6d7 Author: xiezl <[email protected]> Authored: Thu Apr 7 13:04:11 2016 +0800 Committer: xiezl <[email protected]> Committed: Thu Apr 7 13:04:11 2016 +0800 ---------------------------------------------------------------------- Makefile.am | 49 +++++++++++--------- configure.ac | 70 ++++++++++++++--------------- include/singa/neuralnet/neuron_layer.h | 2 + src/driver.cc | 2 + src/neuralnet/neuron_layer/cudnn_bm.cc | 3 +- 5 files changed, 68 insertions(+), 58 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/e5f111ca/Makefile.am ---------------------------------------------------------------------- diff --git a/Makefile.am b/Makefile.am index 2513d36..e76d952 100644 --- a/Makefile.am +++ b/Makefile.am @@ -177,6 +177,8 @@ lib_LTLIBRARIES = libsinga.la $(LTLIBS) bin_PROGRAMS = singa singatool $(PROGS) pydir = $(CURDIR)/tool/python/singa/ py_LTLIBRARIES = $(PY_PROGS) +#gpudir = $(CURDIR)/.libs +#gpu_LTLIBRARIES = libsingagpu.so #lib_LTLIBRARIES = libsinga.la libsinga_la_SOURCES = $(PROTO_SRCS) $(SINGA_SRCS) @@ -185,6 +187,13 @@ libsinga_la_LDFLAGS = if LMDB libsinga_la_CXXFLAGS += -DUSE_LMDB endif + +if DCUDNN +libsinga_la_SOURCES += $(CUDNN_SRCS) +libsinga_la_CXXFLAGS += $(CUDNN_CFLAGS) +libsinga_la_LDFLAGS += $(CUDNN_LDFLAGS) $(CUDNN_LIBS) +endif + if DCUDA libsinga_la_SOURCES += $(CUDA_SRCS) $(CUDA_HDRS) libsinga_la_CXXFLAGS += $(CUDA_CFLAGS) @@ -192,11 +201,6 @@ libsinga_la_LDFLAGS += $(CUDA_LDFLAGS) $(CUDA_LIBS) -L./ -lsingagpu -Wl,-rpath=. libsinga_la_LIBADD = libsingagpu.so endif -if DCUDNN -libsinga_la_SOURCES += $(CUDNN_SRCS) -libsinga_la_CXXFLAGS += $(CUDNN_CFLAGS) -libsinga_la_LDFLAGS += $(CUDNN_LDFLAGS) $(CUDNN_LIBS) -endif if DDIST libsinga_la_SOURCES += $(ZOOKEEPER_SRCS) libsinga_la_CXXFLAGS += $(DIST_CFLAGS) @@ -221,6 +225,12 @@ if LMDB singa_LDFLAGS += -llmdb endif +if DCUDNN +singa_SOURCES += $(CUDNN_SRCS) +singa_CXXFLAGS += $(CUDNN_CFLAGS) +singa_LDFLAGS += $(CUDNN_LDFLAGS) $(CUDNN_LIBS) +endif + if DCUDA singa_SOURCES += $(CUDA_SRCS) $(CUDA_HDRS) singa_CXXFLAGS += $(CUDA_CFLAGS) @@ -233,12 +243,6 @@ singa_CXXFLAGS += $(DIST_CFLAGS) singa_LDFLAGS += $(DIST_LDFLAGS) $(DIST_LIBS) endif -if DCUDNN -singa_SOURCES += $(CUDNN_SRCS) -singa_CXXFLAGS += $(CUDNN_CFLAGS) -singa_LDFLAGS += $(CUDNN_LDFLAGS) $(CUDNN_LIBS) -endif - if DHDFS singa_SOURCES += $(HDFS_SRCS) singa_CXXFLAGS += $(HDFS_CFLAGS) @@ -281,18 +285,18 @@ if LMDB singatest_LDFLAGS += -llmdb endif -if DCUDA -singatest_SOURCES += $(CUDA_SRCS) $(CUDA_HDRS) -singatest_CXXFLAGS += $(CUDA_CFLAGS) -singatest_LDFLAGS += $(CUDA_LDFLAGS) $(CUDA_LIBS) -endif - if DCUDNN singatest_SOURCES += $(CUDNN_SRCS) singatest_CXXFLAGS += $(CUDNN_CFLAGS) singatest_LDFLAGS += $(CUDNN_LDFLAGS) $(CUDNN_LIBS) endif +if DCUDA +singatest_SOURCES += $(CUDA_SRCS) $(CUDA_HDRS) +singatest_CXXFLAGS += $(CUDA_CFLAGS) +singatest_LDFLAGS += $(CUDA_LDFLAGS) $(CUDA_LIBS) +endif + if DDIST singatest_SOURCES += $(ZOOKEEPER_SRCS) singatest_CXXFLAGS += $(DIST_CFLAGS) @@ -303,16 +307,16 @@ _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 - if DCUDNN _driver_la_CXXFLAGS += $(CUDNN_CFLAGS) _driver_la_LDFLAGS += $(CUDNN_LDFLAGS) $(CUDNN_LIBS) endif +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) @@ -329,6 +333,7 @@ all-local: cp -f .libs/_driver.so tool/python/singa/; \ touch tool/python/singa/__init__.py; \ fi + cp libsingagpu.so .libs/ # For rat check rat: http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/e5f111ca/configure.ac ---------------------------------------------------------------------- diff --git a/configure.ac b/configure.ac index 2de8720..c54d6a9 100644 --- a/configure.ac +++ b/configure.ac @@ -53,6 +53,39 @@ AC_CHECK_LIB([protobuf], [main], [], [ PROGS='' LTLIBS='' +# Setup custom CUDNN paths +AC_ARG_ENABLE([cudnn], + [AS_HELP_STRING(--enable-cudnn,enable CUDNN support)], + [enable_cudnn="yes"], [enable_cudnn="no"]) +AM_CONDITIONAL(DCUDNN, [test "$enable_cudnn" = "yes"]) +AC_ARG_WITH([cudnn], + [AS_HELP_STRING([--with-cudnn=PATH], [prefix where CUDNN is installed])], + [cudnn_prefix=$withval], [cudnn_prefix="/usr/local/cudnn"]) +if test "$cudnn_prefix" == "yes"; then + if test "$withval" == "yes"; then + cudnn_prefix="/usr/local/cudnn" + fi +fi +if test x"$enable_cudnn" == x"yes"; then + CUDNN_CFLAGS="-I$cudnn_prefix/include" + CUDNN_LDFLAGS="-L$cudnn_prefix/lib64 -L$cudnn_prefix/lib" + CUDNN_LIBS="-lcudnn" + LIBS="$LIBS $CUDNN_LIBS" + LDFLAGS="$LDFLAGS $CUDNN_LDFLAGS" + DEBUG="-DUSE_CUDNN" + AC_DEFINE(DCUDNN,[1],[Defined if CUDNN should be used]) + AC_CHECK_LIB([cudnn], [main], [], [ + AC_MSG_ERROR([unable to find cudnn library]) + ]) +else + CUDNN_CFLAGS="" + CUDNN_LDFLAGS="" + CUDNN_LIBS="" +fi +AC_SUBST(CUDNN_CFLAGS) +AC_SUBST(CUDNN_LDFLAGS) +AC_SUBST(CUDNN_LIBS) + # Setup custom CUDA paths AC_ARG_ENABLE(cuda, [AS_HELP_STRING(--enable-cuda,enable CUDA support)], @@ -86,7 +119,7 @@ if test x"$cudaval" = x"yes"; then LDFLAGS="$LDFLAGS $CUDA_LDFLAGS -L./" LIBTOOL='LD_LIBRARY_PATH=$(PWD) $(SHELL) $(top_builddir)/libtool' NVCC="nvcc" - DEBUG="-DUSE_GPU" + DEBUG+=" -DUSE_GPU" AC_DEFINE(DCUDA,[1],[Defined if CUDA should be used]) AC_CHECK_LIB([cublas], [main], [], [ AC_MSG_ERROR([unable to find cuda library]) @@ -110,40 +143,7 @@ AC_SUBST(CUDA_LDFLAGS) AC_SUBST(CUDA_LIBS) AC_SUBST(CUDA_CFLAGS) -# Setup custom CUDNN paths -AC_ARG_ENABLE([cudnn], - [AS_HELP_STRING(--enable-cudnn,enable CUDNN support)], - [enable_cudnn="yes"], [enable_cudnn="no"]) -AM_CONDITIONAL(DCUDNN, [test "$enable_cudnn" = "yes"]) -AC_ARG_WITH([cudnn], - [AS_HELP_STRING([--with-cudnn=PATH], [prefix where CUDNN is installed])], - [cudnn_prefix=$withval], [cudnn_prefix="/usr/local/cuda"]) -if test "$cudnn_prefix" == "yes"; then - if test "$withval" == "yes"; then - cudnn_prefix="/usr/local/cuda" - fi -fi -if test x"$enable_cudnn" == x"yes"; then - CUDNN_CFLAGS="-I$cudnn_prefix/include" - CUDNN_LDFLAGS="-L$cudnn_prefix/lib64 -L$cudnn_prefix/lib" - CUDNN_LIBS="-lcudnn" - LIBS="$LIBS $CUDNN_LIBS" - LDFLAGS="$LDFLAGS $CUDNN_LDFLAGS" - DEBUG+=" -DUSE_CUDNN" - AC_DEFINE(DCUDNN,[1],[Defined if CUDNN should be used]) - AC_CHECK_LIB([cudnn], [main], [], [ - AC_MSG_ERROR([unable to find cudnn library]) - ]) -else - CUDNN_CFLAGS="" - CUDNN_LDFLAGS="" - CUDNN_LIBS="" -fi -AC_SUBST(CUDNN_CFLAGS) -AC_SUBST(CUDNN_LDFLAGS) -AC_SUBST(CUDNN_LIBS) - -# Setup custom zookeeper paths +# Setup custom zookeeper and zmq paths AC_ARG_ENABLE(dist, AS_HELP_STRING([--enable-dist],[enable dist support]), [enable_dist="yes"],[enable_dist="no"]) http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/e5f111ca/include/singa/neuralnet/neuron_layer.h ---------------------------------------------------------------------- diff --git a/include/singa/neuralnet/neuron_layer.h b/include/singa/neuralnet/neuron_layer.h index 34eee62..c9a30da 100644 --- a/include/singa/neuralnet/neuron_layer.h +++ b/include/singa/neuralnet/neuron_layer.h @@ -478,7 +478,9 @@ class CudnnBMLayer : public BMLayer, public CudnnBase { void ComputeFeature(int flag, const vector<Layer*>& srclayers) override; void ComputeGradient(int flag, const vector<Layer*>& srclayers) override; protected: +#if CUDNN_MAJOR == 4 cudnnBatchNormMode_t mode_; +#endif cudnnTensorDescriptor_t bnScaleBiasMeanVar_desc_; cudnnTensorDescriptor_t bnScaleBiasDiff_desc_; Blob<float> resultSaveMean_; http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/e5f111ca/src/driver.cc ---------------------------------------------------------------------- diff --git a/src/driver.cc b/src/driver.cc index c3924c2..5016c07 100644 --- a/src/driver.cc +++ b/src/driver.cc @@ -103,8 +103,10 @@ void Driver::Init(int argc, char **argv) { RegisterLayer<CudnnLRNLayer, int>(kCudnnLRN); RegisterLayer<CudnnSoftmaxLayer, int>(kCudnnSoftmax); RegisterLayer<CudnnSoftmaxLossLayer, int>(kCudnnSoftmaxLoss); +#if CUDNN_MAJOR == 4 RegisterLayer<CudnnBMLayer, int>(kCudnnBM); #endif +#endif RegisterLayer<DropoutLayer, int>(kDropout); RegisterLayer<DummyLayer, int>(kDummy); http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/e5f111ca/src/neuralnet/neuron_layer/cudnn_bm.cc ---------------------------------------------------------------------- diff --git a/src/neuralnet/neuron_layer/cudnn_bm.cc b/src/neuralnet/neuron_layer/cudnn_bm.cc index 32a4f57..c27232f 100644 --- a/src/neuralnet/neuron_layer/cudnn_bm.cc +++ b/src/neuralnet/neuron_layer/cudnn_bm.cc @@ -18,7 +18,7 @@ * under the License. * *************************************************************/ - +#if CUDNN_MAJOR == 4 #include "singa/neuralnet/neuron_layer.h" namespace singa { @@ -148,3 +148,4 @@ void CudnnBMLayer::ComputeGradient(int flag, resultSaveInvVariance_.gpu_data())); } } // namespace singa +#endif
