2016-05-07 23:56:23 +03:00
|
|
|
cmake_minimum_required(VERSION 3.5.1)
|
|
|
|
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
2017-03-30 01:51:50 +03:00
|
|
|
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} /usr/local/cuda-8.0/lib64)
|
2016-05-07 23:56:23 +03:00
|
|
|
|
2017-07-04 16:06:26 +03:00
|
|
|
|
2018-01-24 05:35:55 +03:00
|
|
|
project(marian CXX C)
|
2017-06-14 15:06:20 +03:00
|
|
|
|
2017-07-04 16:06:26 +03:00
|
|
|
# Custom CMake options
|
2017-06-14 15:06:20 +03:00
|
|
|
option(COMPILE_EXAMPLES "Compile examples" OFF)
|
|
|
|
option(COMPILE_TESTS "Compile tests" OFF)
|
2018-01-09 17:18:57 +03:00
|
|
|
option(COMPILE_SERVER "Compile marian-server" ON)
|
2018-03-01 15:36:27 +03:00
|
|
|
option(COMPILE_CPU "Compile CPU version" ON)
|
2018-03-03 05:06:26 +03:00
|
|
|
option(COMPILE_CUDA "Compile GPU version" ON)
|
2017-06-27 17:20:32 +03:00
|
|
|
option(USE_CUDNN "Use CUDNN library" OFF)
|
2018-02-26 09:08:25 +03:00
|
|
|
option(USE_MPI "Use MPI library" OFF)
|
2017-06-27 17:20:32 +03:00
|
|
|
|
2017-07-04 16:06:26 +03:00
|
|
|
# Project versioning
|
|
|
|
find_package(Git QUIET)
|
2017-07-13 15:02:43 +03:00
|
|
|
include(GetVersionFromFile)
|
2017-07-04 16:06:26 +03:00
|
|
|
|
|
|
|
message(STATUS "Project name: ${PROJECT_NAME}")
|
2017-08-30 16:35:47 +03:00
|
|
|
message(STATUS "Project version: ${PROJECT_VERSION_STRING_FULL}")
|
2017-01-21 18:11:40 +03:00
|
|
|
|
2017-07-04 16:06:26 +03:00
|
|
|
# Set compilation flags
|
2018-03-03 05:06:26 +03:00
|
|
|
set(CMAKE_CXX_FLAGS_RELEASE " -std=c++11 -O3 -Ofast -m64 -pthread -march=native -Wl,--no-as-needed -funroll-loops -ffinite-math-only -fPIC -Wno-unused-result -Wno-deprecated -Wno-deprecated-gpu-targets")
|
|
|
|
set(CMAKE_CXX_FLAGS_DEBUG " -std=c++11 -g -O0 -pthread -fPIC -Wno-unused-result -Wno-deprecated -Wno-deprecated-gpu-targets")
|
2017-06-02 13:43:36 +03:00
|
|
|
set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE} -g -pg")
|
2017-06-01 01:03:55 +03:00
|
|
|
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_RELEASE})
|
|
|
|
|
2017-07-04 16:06:26 +03:00
|
|
|
# Find packages
|
2018-03-03 05:06:26 +03:00
|
|
|
|
|
|
|
set(EXT_LIBS ${EXT_LIBS} ${CMAKE_DL_LIBS})
|
|
|
|
|
|
|
|
if(COMPILE_CUDA)
|
2017-07-04 16:06:26 +03:00
|
|
|
find_package(CUDA "8.0" REQUIRED)
|
|
|
|
if(CUDA_FOUND)
|
2017-11-24 19:06:25 +03:00
|
|
|
set(EXT_LIBS ${EXT_LIBS} ${CUDA_curand_LIBRARY} ${CUDA_cusparse_LIBRARY})
|
2018-02-25 07:11:02 +03:00
|
|
|
|
|
|
|
if(USE_CUDNN)
|
|
|
|
find_package(CUDNN "7.0")
|
|
|
|
if(CUDNN_FOUND)
|
|
|
|
include_directories(${CUDNN_INCLUDE_DIRS})
|
|
|
|
set(EXT_LIBS ${EXT_LIBS} ${CUDNN_LIBRARIES})
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCUDNN")
|
|
|
|
LIST(APPEND CUDA_NVCC_FLAGS -DCUDNN; )
|
2018-03-01 15:36:27 +03:00
|
|
|
endif(CUDNN_FOUND)
|
|
|
|
endif(USE_CUDNN)
|
2018-03-03 05:06:26 +03:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCUDA_FOUND")
|
|
|
|
else(CUDA_FOUND)
|
|
|
|
message(WARNING "Cannot find CUDA compiling CPU version only")
|
2017-07-04 16:06:26 +03:00
|
|
|
endif(CUDA_FOUND)
|
|
|
|
|
2018-03-03 05:06:26 +03:00
|
|
|
else(COMPILE_CUDA)
|
|
|
|
message(WARNING "COMPILE_CUDA=off : Building only CPU version")
|
|
|
|
endif(COMPILE_CUDA)
|
|
|
|
|
2017-06-17 22:22:27 +03:00
|
|
|
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
2017-11-24 20:13:19 +03:00
|
|
|
list(APPEND CUDA_NVCC_FLAGS -std=c++11; --default-stream per-thread; -O0; -g; -Xcompiler '-fPIC'; -arch=sm_30; -gencode=arch=compute_30,code=sm_30; -gencode=arch=compute_50,code=sm_50; -gencode=arch=compute_52,code=sm_52; -gencode=arch=compute_60,code=sm_60; -gencode=arch=compute_61,code=sm_61; -gencode=arch=compute_61,code=compute_61 ;)
|
2017-06-17 22:22:27 +03:00
|
|
|
else(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
2017-11-24 20:13:19 +03:00
|
|
|
list(APPEND CUDA_NVCC_FLAGS -std=c++11; --default-stream per-thread; -O3; --use_fast_math; -Xcompiler '-fPIC'; -arch=sm_30; -gencode=arch=compute_30,code=sm_30; -gencode=arch=compute_50,code=sm_50; -gencode=arch=compute_52,code=sm_52; -gencode=arch=compute_60,code=sm_60; -gencode=arch=compute_61,code=sm_61; -gencode=arch=compute_61,code=compute_61 ;)
|
2017-06-17 22:22:27 +03:00
|
|
|
endif(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
|
|
|
|
2017-07-04 16:06:26 +03:00
|
|
|
list(REMOVE_DUPLICATES CUDA_NVCC_FLAGS)
|
|
|
|
set(CUDA_PROPAGATE_HOST_FLAGS OFF)
|
2017-06-27 17:20:32 +03:00
|
|
|
|
2017-11-02 13:33:47 +03:00
|
|
|
find_package(Tcmalloc)
|
|
|
|
if(Tcmalloc_FOUND)
|
|
|
|
include_directories(${Tcmalloc_INCLUDE_DIR})
|
|
|
|
set(EXT_LIBS ${EXT_LIBS} ${Tcmalloc_LIBRARIES})
|
|
|
|
else(Tcmalloc_FOUND)
|
|
|
|
message(WARNING "Cannot find TCMalloc library. Continuing.")
|
|
|
|
endif(Tcmalloc_FOUND)
|
|
|
|
|
2018-02-26 09:08:25 +03:00
|
|
|
if(USE_MPI)
|
2018-03-01 15:36:27 +03:00
|
|
|
find_package(MPI 2.0)
|
|
|
|
if(MPI_FOUND)
|
|
|
|
include_directories(${MPI_INCLUDE_PATH})
|
|
|
|
set(EXT_LIBS ${EXT_LIBS} ${MPI_LIBRARIES})
|
|
|
|
add_definitions(-DMPI_FOUND=1)
|
|
|
|
endif(MPI_FOUND)
|
2018-02-26 09:08:25 +03:00
|
|
|
endif(USE_MPI)
|
2018-01-21 10:06:51 +03:00
|
|
|
|
2018-03-01 15:36:27 +03:00
|
|
|
if(COMPILE_CPU)
|
|
|
|
find_package(MKL)
|
|
|
|
if(MKL_FOUND)
|
|
|
|
include_directories(${MKL_INCLUDE_DIR})
|
|
|
|
set(EXT_LIBS ${EXT_LIBS} ${MKL_LIBRARIES})
|
|
|
|
add_definitions(-DBLAS_FOUND=1 -DMKL_FOUND=1)
|
|
|
|
else(MKL_FOUND)
|
|
|
|
set(BLA_VENDOR "OpenBLAS")
|
|
|
|
find_package(BLAS)
|
|
|
|
if(BLAS_FOUND)
|
|
|
|
include_directories(${BLAS_INCLUDE_DIR})
|
|
|
|
set(EXT_LIBS ${EXT_LIBS} ${BLAS_LIBRARIES})
|
|
|
|
add_definitions(-DBLAS_FOUND=1)
|
|
|
|
endif(BLAS_FOUND)
|
|
|
|
endif(MKL_FOUND)
|
|
|
|
endif(COMPILE_CPU)
|
2018-02-22 04:44:04 +03:00
|
|
|
|
2017-01-05 01:14:44 +03:00
|
|
|
find_package(ZLIB)
|
|
|
|
if(ZLIB_FOUND)
|
2017-07-13 15:02:43 +03:00
|
|
|
include_directories(${ZLIB_INCLUDE_DIRS})
|
|
|
|
set(EXT_LIBS ${EXT_LIBS} ${ZLIB_LIBRARIES})
|
2017-01-05 01:14:44 +03:00
|
|
|
else(ZLIB_FOUND)
|
2017-11-02 13:33:47 +03:00
|
|
|
message(SEND_ERROR "Cannot find zlib.")
|
2017-01-05 01:14:44 +03:00
|
|
|
endif(ZLIB_FOUND)
|
|
|
|
|
2018-02-26 21:38:27 +03:00
|
|
|
set(BOOST_COMPONENTS system timer iostreams filesystem chrono program_options thread regex)
|
2016-05-07 23:56:23 +03:00
|
|
|
|
2017-08-07 12:39:57 +03:00
|
|
|
find_package(PythonLibs 2.7)
|
|
|
|
if(PYTHONLIBS_FOUND)
|
2017-08-19 15:49:55 +03:00
|
|
|
set(BOOST_COMPONENTS ${BOOST_COMPONENTS} python)
|
2017-08-07 12:39:57 +03:00
|
|
|
message(STATUS "Found Python")
|
|
|
|
include_directories(${PYTHON_INCLUDE_DIRS})
|
|
|
|
set(EXT_LIBS ${EXT_LIBS} ${PYTHON_LIBRARIES})
|
|
|
|
else(PYTHONLIBS_FOUND)
|
2017-11-02 13:33:47 +03:00
|
|
|
message(WARNING "Cannot find python libraries. Building without bindings.")
|
2017-08-07 12:39:57 +03:00
|
|
|
endif(PYTHONLIBS_FOUND)
|
|
|
|
|
2018-01-09 17:18:57 +03:00
|
|
|
if(COMPILE_SERVER)
|
|
|
|
find_package(OpenSSL)
|
|
|
|
if(OpenSSL_FOUND)
|
|
|
|
message(STATUS "Found OpenSSL")
|
|
|
|
include_directories(${OPENSSL_INCLUDE_DIR})
|
|
|
|
set(EXT_LIBS ${EXT_LIBS} ${OPENSSL_CRYPTO_LIBRARY})
|
|
|
|
else(OpenSSL_FOUND)
|
|
|
|
message(WARNING "Cannot find OpenSSL library. Not compiling server.")
|
2018-01-13 22:24:03 +03:00
|
|
|
set(COMPILE_SERVER "off")
|
2018-01-09 17:18:57 +03:00
|
|
|
endif(OpenSSL_FOUND)
|
|
|
|
endif(COMPILE_SERVER)
|
2017-08-19 10:01:31 +03:00
|
|
|
|
2017-08-19 15:49:55 +03:00
|
|
|
find_package(Boost COMPONENTS ${BOOST_COMPONENTS})
|
|
|
|
if(Boost_FOUND)
|
|
|
|
include_directories(${Boost_INCLUDE_DIRS})
|
|
|
|
set(EXT_LIBS ${EXT_LIBS} ${Boost_LIBRARIES})
|
|
|
|
else(Boost_FOUND)
|
2017-11-02 13:33:47 +03:00
|
|
|
message(SEND_ERROR "Cannot find Boost libraries. Terminating.")
|
2017-08-19 15:49:55 +03:00
|
|
|
endif(Boost_FOUND)
|
|
|
|
|
2017-06-14 15:06:20 +03:00
|
|
|
if(COMPILE_TESTS)
|
2017-07-13 15:02:43 +03:00
|
|
|
enable_testing()
|
2017-06-14 15:06:20 +03:00
|
|
|
endif(COMPILE_TESTS)
|
|
|
|
|
2018-02-25 04:56:33 +03:00
|
|
|
if(COMPILE_EXAMPLES)
|
|
|
|
add_definitions(-DCOMPILE_EXAMPLES=1)
|
|
|
|
endif(COMPILE_EXAMPLES)
|
2017-07-04 16:06:26 +03:00
|
|
|
|
|
|
|
# Compile source files
|
|
|
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/common/version.h.in
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src/common/version.h @ONLY)
|
|
|
|
|
2016-05-07 23:56:23 +03:00
|
|
|
include_directories(${marian_SOURCE_DIR}/src)
|
|
|
|
add_subdirectory(src)
|
2016-09-16 19:28:00 +03:00
|
|
|
|
2017-07-04 16:06:26 +03:00
|
|
|
|
2017-06-14 15:06:20 +03:00
|
|
|
# Add a target to generate API documentation with Doxygen
|
2016-09-16 19:28:00 +03:00
|
|
|
find_package(Doxygen)
|
|
|
|
if(DOXYGEN_FOUND)
|
2017-07-13 15:02:43 +03:00
|
|
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
|
|
|
|
add_custom_target(doc
|
|
|
|
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
COMMENT "Generating API documentation with Doxygen" VERBATIM
|
|
|
|
)
|
2016-09-16 19:28:00 +03:00
|
|
|
endif(DOXYGEN_FOUND)
|