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 Aug 29, 2018
1 parent bb1e2eb commit bf936d6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 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
25 changes: 22 additions & 3 deletions cmake/SetupCUDA.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
# 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})
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
Expand All @@ -21,4 +25,19 @@ FUNCTION(SET_CUDA_LIBRARIES)
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 bf936d6

Please sign in to comment.