Skip to content

Commit

Permalink
keep the same cudart behaviour as the previous one
Browse files Browse the repository at this point in the history
  • Loading branch information
yhmtsai committed Oct 17, 2019
1 parent e34c181 commit d012d50
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
5 changes: 0 additions & 5 deletions benchmark/spmv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ add_executable(spmv spmv.cpp)
target_link_libraries(spmv ginkgo gflags rapidjson)
if (GINKGO_BUILD_CUDA)
target_compile_definitions(spmv PRIVATE HAS_CUDA=1)
if("${CUDA_RUNTIME_LIBS}" MATCHES "Threads::Threads")
# need to import Threads
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
endif()
target_link_libraries(spmv ginkgo ${CUDA_RUNTIME_LIBS}
${CUBLAS} ${CUSPARSE})
target_include_directories(spmv SYSTEM PRIVATE ${CUDA_INCLUDE_DIRS})
Expand Down
22 changes: 10 additions & 12 deletions cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,23 @@ set(CMAKE_CUDA_COMPILER_VERSION ${CMAKE_CUDA_COMPILER_VERSION} PARENT_SCOPE)
set(CUDA_INCLUDE_DIRS ${CUDA_INCLUDE_DIRS} PARENT_SCOPE)


# nvcc uses static cudartlibrary by default
# MSVC nvcc uses static cudartlibrary by default, and other platforms use shared cudartlibrary.
# add `-cudart shared` or `-cudart=shared` according system into CMAKE_CUDA_FLAGS/GINKGO_CUDA_COMPILER_FLAGS
# to force nvcc to use dynamic cudart library.
# to force nvcc to use dynamic cudart library in MSVC.
find_library(CUDA_RUNTIME_LIBS_DYNAMIC cudart
HINT ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})
find_library(CUDA_RUNTIME_LIBS_STATIC cudart_static
HINT ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})

if("${CMAKE_CUDA_FLAGS}" MATCHES "-cudart(=| )shared" OR "${GINKGO_CUDA_COMPILER_FLAGS}" MATCHES "-cudart(=| )shared")
set(CUDA_RUNTIME_LIBS "${CUDA_RUNTIME_LIBS_DYNAMIC}" CACHE STRING "Path to a library" FORCE)
else()
set(CUDA_RUNTIME_LIBS "${CUDA_RUNTIME_LIBS_STATIC}" CACHE STRING "Path to a library" FORCE)
if(NOT MSVC)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
# link cudart_static need rt, pthread, and dl
set(CUDA_RUNTIME_LIBS "${CUDA_RUNTIME_LIBS_STATIC};rt;Threads::Threads;-Wl,--no-as-needed;dl" CACHE STRING "Path to a library" FORCE)
if(MSVC)
if("${CMAKE_CUDA_FLAGS}" MATCHES "-cudart(=| )shared" OR "${GINKGO_CUDA_COMPILER_FLAGS}" MATCHES "-cudart(=| )shared")
set(CUDA_RUNTIME_LIBS "${CUDA_RUNTIME_LIBS_DYNAMIC}" CACHE STRING "Path to a library" FORCE)
else()
set(CUDA_RUNTIME_LIBS "${CUDA_RUNTIME_LIBS_STATIC}" CACHE STRING "Path to a library" FORCE)
endif()
else()
set(CUDA_RUNTIME_LIBS "${CUDA_RUNTIME_LIBS_DYNAMIC}" CACHE STRING "Path to a library" FORCE)
endif()

find_library(CUBLAS cublas
HINT ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})
find_library(CUSPARSE cusparse
Expand Down

0 comments on commit d012d50

Please sign in to comment.