Repository: incubator-singa Updated Branches: refs/heads/dev 62c6603ff -> f026b6050
SINGA-212 Disable the compilation of libcnmem if USE_CUDA is OFF The compilation of libcnmem should be disabled if USE_CUDA is OFF. USE_CUDNN should also be OFF if USE_CUDA is OFF. Some definitions should be added into the source code to fix the problem. Project: http://git-wip-us.apache.org/repos/asf/incubator-singa/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-singa/commit/f026b605 Tree: http://git-wip-us.apache.org/repos/asf/incubator-singa/tree/f026b605 Diff: http://git-wip-us.apache.org/repos/asf/incubator-singa/diff/f026b605 Branch: refs/heads/dev Commit: f026b60502f2fd66aa971c07c87ecf451463d76a Parents: 62c6603 Author: xiezl <[email protected]> Authored: Wed Jun 29 16:33:16 2016 +0800 Committer: xiezl <[email protected]> Committed: Wed Jun 29 16:33:16 2016 +0800 ---------------------------------------------------------------------- CMakeLists.txt | 28 ++++++++++++++++++---------- examples/CMakeLists.txt | 2 ++ examples/cifar10/alexnet.cc | 1 + include/singa/core/memory.h | 6 +++++- 4 files changed, 26 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/f026b605/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/CMakeLists.txt b/CMakeLists.txt index ff94d4e..a8be759 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,13 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Thirdparty) #message(STATUS "module path: ${CMAKE_MODULE_PATH}") +OPTION(USE_CBLAS "Use CBlas libs" ON) +OPTION(USE_CUDA "Use Cuda libs" ON) +OPTION(USE_CUDNN "Use Cudnn libs" ON) +OPTION(USE_OPENCV "Use opencv" OFF) +OPTION(USE_LMDB "Use LMDB libs" OFF) +OPTION(USE_PYTHON "Generate py wrappers" OFF) + # Flags IF(UNIX OR APPLE) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall") @@ -15,16 +22,14 @@ IF(CMAKE_BUILD_TYPE=Debug) ENDIF() #message(STATUS "${CMAKE_CXX_FLAGS}") SET(SINGA_INCLUDE_DIR - "${CMAKE_SOURCE_DIR}/include;${CMAKE_SOURCE_DIR}/lib/cnmem/include;${PROJECT_BINARY_DIR}") + "${CMAKE_SOURCE_DIR}/include;${PROJECT_BINARY_DIR}") +IF(USE_CUDA) + LIST(APPEND SINGA_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/lib/cnmem/include") +ELSEIF(USE_CUDA) + OPTION(USE_CUDNN "Use Cudnn libs" OFF) +ENDIF() INCLUDE_DIRECTORIES(${SINGA_INCLUDE_DIR}) -OPTION(USE_CBLAS "Use CBlas libs" ON) -OPTION(USE_CUDA "Use Cuda libs" ON) -OPTION(USE_CUDNN "Use Cudnn libs" ON) -OPTION(USE_OPENCV "Use opencv" OFF) -OPTION(USE_LMDB "Use LMDB libs" OFF) -OPTION(USE_PYTHON "Generate py wrappers" OFF) - INCLUDE("cmake/Dependencies.cmake") INCLUDE("cmake/Utils.cmake") ADD_DEFINITIONS(-DUSE_CMAKE) @@ -39,8 +44,11 @@ CONFIGURE_FILE ( SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) -ADD_SUBDIRECTORY(lib/cnmem) -LIST(APPEND SINGA_LINKER_LIBS cnmem) +IF(USE_CUDA) + ADD_SUBDIRECTORY(lib/cnmem) + LIST(APPEND SINGA_LINKER_LIBS cnmem) +ENDIF() + ADD_SUBDIRECTORY(src) ADD_SUBDIRECTORY(test) ADD_SUBDIRECTORY(examples) http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/f026b605/examples/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index b06f434..c2ec7e9 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -3,6 +3,8 @@ INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/include) AUX_SOURCE_DIRECTORY(cifar10 cifar_source) +IF(USE_CUDNN) ADD_EXECUTABLE(alexnet ${cifar_source}) ADD_DEPENDENCIES(alexnet singa_core singa_model singa_utils) TARGET_LINK_LIBRARIES(alexnet singa_core singa_utils singa_model protobuf ${SINGA_LIBKER_LIBS}) +ENDIF(USE_CUDNN) http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/f026b605/examples/cifar10/alexnet.cc ---------------------------------------------------------------------- diff --git a/examples/cifar10/alexnet.cc b/examples/cifar10/alexnet.cc index 5175f49..6480557 100644 --- a/examples/cifar10/alexnet.cc +++ b/examples/cifar10/alexnet.cc @@ -18,6 +18,7 @@ * under the License. * *************************************************************/ + #include "./cifar10.h" #include "singa/model/feed_forward_net.h" #include "singa/model/optimizer.h" http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/f026b605/include/singa/core/memory.h ---------------------------------------------------------------------- diff --git a/include/singa/core/memory.h b/include/singa/core/memory.h index c35f5d0..7c22ea3 100644 --- a/include/singa/core/memory.h +++ b/include/singa/core/memory.h @@ -19,8 +19,12 @@ #ifndef SINGA_CORE_MEMORY_H_ #define SINGA_CORE_MEMORY_H_ -#include "cnmem.h" #include "singa/singa_config.h" + +#ifdef USE_CUDA +#include "cnmem.h" +#endif + #include <mutex> namespace singa {
