Skip to content

Commit

Permalink
Update build system to allow shared library when using CUDA
Browse files Browse the repository at this point in the history
  • Loading branch information
Rombur committed Oct 19, 2018
1 parent 8cb33f9 commit 1e5ad13
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 27 deletions.
8 changes: 1 addition & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,10 @@ INCLUDE(SetupTPLs)
INCLUDE(SetupMFMG)
INCLUDE(SetupCache)

# By default build a static library because CUDA does not work with a shared
# library
OPTION(BUILD_SHARED_LIBS "Build a shared library" OFF)

INITIALIZE_CACHE()

IF(${MFMG_ENABLE_CUDA})
IF (${BUILD_SHARED_LIBS})
MESSAGE(SEND_ERROR "CUDA build does not support shared library")
ENDIF()
# ENABLE_LANGUAGE cannot be in a function and it has to be called in the
# highest directory so we cannot encapsulate it
ENABLE_LANGUAGE(CUDA)
Expand Down Expand Up @@ -74,7 +68,7 @@ TARGET_INCLUDE_DIRECTORIES(mfmg SYSTEM PUBLIC ${DEAL_II_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(mfmg PUBLIC ${DEAL_II_LIBRARIES})
TARGET_LINK_LIBRARIES(mfmg PUBLIC ${MFMG_CUDA_LIBRARIES})
TARGET_INCLUDE_DIRECTORIES(mfmg PUBLIC ${AMGX_INCLUDE_DIR})
TARGET_LINK_LIBRARIES(mfmg PUBLIC ${AMGX_LIBRARY})
TARGET_LINK_LIBRARIES(mfmg PUBLIC ${AMGX_LIBRARIES})
TARGET_COMPILE_DEFINITIONS(mfmg PRIVATE ${CLANG_TIDY_DEFINITIONS})

IF(${Backtrace_FOUND})
Expand Down
11 changes: 11 additions & 0 deletions ci/compile_and_run.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
#!/bin/bash
# In Docker containers and for some installations, stub libraries are installed.
# The CUDA libraries are installed with the driver but to allow compilation on
# system without the correct drivers stub libraries are installed when the CUDA
# toolkit is installed. The stub libraries allow you to compile the code but not
# to run it because the symbol are missing. The idea is that at run time, we will
# pick the correct libraries instead of the stub ones. This doesn't work when
# using an `rpath` (see https://github.com/NVIDIA/nvidia-docker/issues/775). For
# some reason the problem only appears with CUSolver having missing symbol to
# OpenMP. Removing the stubs fixes the problem.
rm -r /usr/local/cuda/lib64/stubs
cd $1
rm -rf build
export LD_LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/5.4.0:${LD_LIBRARY_PATH}
mkdir build && cd build
ARGS=(
-D CMAKE_BUILD_TYPE=Debug
Expand Down
30 changes: 23 additions & 7 deletions cmake/SetupCUDA.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,39 @@
# the list of CUDA libraries that we are using
FUNCTION(SET_CUDA_LIBRARIES)
ADD_DEFINITIONS(-DMFMG_WITH_CUDA)
FIND_LIBRARY(CUSPARSE cusparse HINT ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})
FIND_LIBRARY(CUSOLVER cusolver HINT ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})
MESSAGE("implicit ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES}")
SET(MFMG_CUDA_LIBRARIES
"cusparse"
"cusolver"
${CUSPARSE}
${CUSOLVER}
PARENT_SCOPE
)
# cuSolver needs OpenMP

#### OPENMP ##################################################################
# cuSOLVER needs OpenMP
FIND_PACKAGE(OpenMP)
IF(OPENMP_FOUND)
SET(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}"
PARENT_SCOPE
)
SET(CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}"
PARENT_SCOPE
)
ELSE()
MESSAGE(SEND_ERROR "Could not find OpenMP required by cuSolver")
ENDIF()

#### AMGX ####################################################################
IF(${MFMG_ENABLE_CUDA})
IF (${MFMG_ENABLE_AMGX})
FIND_LIBRARY(AMGX_LIBRARY amgx amgxsh PATH "${AMGX_DIR}/lib")
FIND_LIBRARY(CUBLAS cublas HINT ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})
SET(AMGX_LIBRARIES
${AMGX_LIBRARY}
${CUBLAS}
PARENT_SCOPE
)
SET(AMGX_INCLUDE_DIR "${AMGX_DIR}/include" PARENT_SCOPE)
ADD_DEFINITIONS(-DMFMG_WITH_AMGX)
ENDIF()
ENDIF()
ENDFUNCTION()
13 changes: 0 additions & 13 deletions cmake/SetupTPLs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,3 @@ ELSE()
ADD_DEFINITIONS(-DDEBUG)
ENDIF()
ENDIF()

#### AMGX ####################################################################
IF(${MFMG_ENABLE_CUDA})
IF (${MFMG_ENABLE_AMGX})
ADD_LIBRARY(amgx STATIC IMPORTED)
SET_TARGET_PROPERTIES(amgx PROPERTIES IMPORTED_LOCATION
"${AMGX_DIR}/lib/libamgx.a"
IMPORTED_LINK_INTERFACE_LIBRARIES "cublas")
ADD_DEFINITIONS(-DMFMG_WITH_AMGX)
SET(AMGX_INCLUDE_DIR "${AMGX_DIR}/include")
SET(AMGX_LIBRARY amgx)
ENDIF()
ENDIF()

0 comments on commit 1e5ad13

Please sign in to comment.