Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/marian-nmt/marian.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Junczys-Dowmunt <marcinjd@microsoft.com>2018-12-07 07:43:44 +0300
committerMarcin Junczys-Dowmunt <marcinjd@microsoft.com>2018-12-07 07:43:44 +0300
commitebb1cda730ef0d1a8a782dd608051f573fb9c955 (patch)
tree3d273b4f82e2e9d7e3c290f0ef78cf6c54d3ed2a
parentd7a746051c0b9cf383c1cead7410549d81db077f (diff)
allow static linking of cuda libs
-rw-r--r--CMakeLists.txt31
-rw-r--r--src/CMakeLists.txt3
-rw-r--r--src/examples/CMakeLists.txt1
-rw-r--r--src/tests/CMakeLists.txt3
4 files changed, 27 insertions, 11 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 51449338..4ef58d12 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -77,9 +77,26 @@ endif()
set(EXT_LIBS ${EXT_LIBS} ${CMAKE_DL_LIBS})
if(COMPILE_CUDA)
+
+if(USE_STATIC_LIBS)
+ set(_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
+ if(WIN32)
+ list(INSERT CMAKE_FIND_LIBRARY_SUFFIXES 0 .lib .a)
+ else()
+ set(CMAKE_FIND_LIBRARY_SUFFIXES .a _static.a)
+ endif()
+endif()
+
find_package(CUDA "8.0")
if(CUDA_FOUND)
- set(EXT_LIBS ${EXT_LIBS} ${CUDA_curand_LIBRARY} ${CUDA_cusparse_LIBRARY})
+ if(USE_STATIC_LIBS)
+ find_library(CUDA_culibos_LIBRARY NAMES culibos PATHS ${CUDA_TOOLKIT_ROOT_DIR}/lib64)
+ set(EXT_LIBS ${EXT_LIBS} ${CUDA_curand_LIBRARY} ${CUDA_cusparse_LIBRARY} ${CUDA_culibos_LIBRARY} ${CUDA_CUBLAS_LIBRARIES})
+ message("-- Found CUDA libraries: ${CUDA_curand_LIBRARY} ${CUDA_cusparse_LIBRARY} ${CUDA_culibos_LIBRARY} ${CUDA_CUBLAS_LIBRARIES}")
+ else(USE_STATIC_LIBS)
+ set(EXT_LIBS ${EXT_LIBS} ${CUDA_curand_LIBRARY} ${CUDA_cusparse_LIBRARY} ${CUDA_CUBLAS_LIBRARIES})
+ message("-- Found CUDA libraries: ${CUDA_curand_LIBRARY} ${CUDA_cusparse_LIBRARY} ${CUDA_CUBLAS_LIBRARIES}")
+endif(USE_STATIC_LIBS)
if(USE_CUDNN)
find_package(CUDNN "7.0")
@@ -106,15 +123,15 @@ if(CUDA_FOUND)
# set the path for the generated static lib
set(NCCL_STATIC "${CMAKE_CURRENT_BINARY_DIR}/nccl/lib/libnccl_static.a")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_NCCL")
-
+
LIST(APPEND CUDA_NVCC_FLAGS -DUSE_NCCL; )
# disables compilation for sm_30 to avoid ptxas warning... that's general Kepler support. But K80s are supported for instance by sm_35
set(GENCODE "-gencode=arch=compute_35,code=sm_35 -gencode=arch=compute_50,code=sm_50 -gencode=arch=compute_60,code=sm_60 -gencode=arch=compute_61,code=sm_61")
- # sets output to build, passes cuda location from FindCUDA, sets c++ compiler to the same one CMake uses.
+ # sets output to build, passes cuda location from FindCUDA, sets c++ compiler to the same one CMake uses.
add_custom_command(OUTPUT ${NCCL_STATIC}
- COMMAND make src.build
+ COMMAND make src.build
BUILDDIR=${CMAKE_CURRENT_BINARY_DIR}/nccl
CUDA_HOME=${CUDA_TOOLKIT_ROOT_DIR}
CUDA8_GENCODE=${GENCODE}
@@ -125,11 +142,15 @@ if(CUDA_FOUND)
set_target_properties(nccl PROPERTIES IMPORTED_LOCATION ${NCCL_STATIC})
add_dependencies(nccl nccl_target)
set(EXT_LIBS ${EXT_LIBS} nccl)
-
+
# adds the resulting files to be removed by `make clean`
set_directory_properties(PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_CURRENT_BINARY_DIR}/nccl)
endif(USE_NCCL)
+if(USE_STATIC_LIBS)
+ set(CMAKE_FIND_LIBRARY_SUFFIXES ${_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
+endif()
+
else(CUDA_FOUND)
message(FATAL_ERROR "CUDA has not been found, set -DCOMPILE_CUDA=off to avoid this check and to compile the CPU version only")
endif(CUDA_FOUND)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d534d7f1..3a486150 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -112,7 +112,7 @@ cuda_add_library(marian_cuda
training/gradient_dropping/gpu/dropper.cu
training/gradient_dropping/gpu/sparse_algorithm.cu
STATIC)
-
+
target_compile_options(marian_cuda PUBLIC ${ALL_WARNINGS})
endif(CUDA_FOUND)
@@ -182,7 +182,6 @@ foreach(exec ${EXECUTABLES})
target_link_libraries(${exec} marian ${EXT_LIBS} ${EXT_LIBS} ${CMAKE_THREAD_LIBS_INIT})
if(CUDA_FOUND)
target_link_libraries(${exec} marian marian_cuda ${EXT_LIBS} ${CMAKE_THREAD_LIBS_INIT})
- cuda_add_cublas_to_target(${exec})
endif(CUDA_FOUND)
set_target_properties(${exec} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
endforeach(exec)
diff --git a/src/examples/CMakeLists.txt b/src/examples/CMakeLists.txt
index bcce6083..8740fa6b 100644
--- a/src/examples/CMakeLists.txt
+++ b/src/examples/CMakeLists.txt
@@ -5,7 +5,6 @@ foreach(exec iris_example mnist_example)
target_link_libraries(${exec} marian ${EXT_LIBS})
if(CUDA_FOUND)
target_link_libraries(${exec} marian marian_cuda ${EXT_LIBS})
- cuda_add_cublas_to_target(${exec})
endif(CUDA_FOUND)
set_target_properties(${exec} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
endforeach(exec)
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
index 2ca5c75a..347a18b7 100644
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -12,7 +12,6 @@ foreach(test ${UNIT_TESTS})
if(CUDA_FOUND)
target_link_libraries("run_${test}" marian marian_cuda ${EXT_LIBS} Catch)
- cuda_add_cublas_to_target("run_${test}")
endif(CUDA_FOUND)
add_test(NAME ${test} COMMAND "run_${test}")
@@ -29,7 +28,6 @@ if(CUDA_FOUND)
add_executable(pooling_test pooling_test.cpp)
target_link_libraries(pooling_test marian ${EXT_LIBS} Catch)
target_link_libraries(pooling_test marian marian_cuda ${EXT_LIBS} Catch)
-cuda_add_cublas_to_target(pooling_test)
endif(CUDA_FOUND)
add_executable(sqlite_test sqlite_test.cpp)
@@ -44,7 +42,6 @@ foreach(exec
target_link_libraries(${exec} marian ${EXT_LIBS} Catch)
if(CUDA_FOUND)
target_link_libraries(${exec} marian marian_cuda ${EXT_LIBS} Catch)
- cuda_add_cublas_to_target(${exec})
endif(CUDA_FOUND)
set_target_properties(${exec} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")