-
Notifications
You must be signed in to change notification settings - Fork 97
Description
In #351 , how do we link cudart in Windows?
We set CUDA_RUNTIME_LIBS
as the cudart shared libraries, but nvcc will use -cudart=static as its default.
It works fine in Linux, but it can not be resolved in Windows.
The problem is in benchmark/spmv
which links to static and shared library.
The following are workaround solutions
- Do not link the cuda library in
benchmark/spmv
in Windowsginkgo/benchmark/spmv/CMakeLists.txt
Lines 5 to 9 in a983181
if (NOT MSVC) target_link_libraries(spmv ginkgo ${CUDA_RUNTIME_LIBS} ${CUBLAS} ${CUSPARSE}) target_include_directories(spmv SYSTEM PRIVATE ${CUDA_INCLUDE_DIRS}) endif() - Force nvcc to use
-cudart=shared
in Windows. - Use cudart shared library when giving -cudart=shared, otherwise use cudart static library.
cudart_static needs rt, dl, and pthread, so it needs to add them into the libraries.
Lines 45 to 55 in 01ee57c
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) endif() endif()
ginkgo/benchmark/spmv/CMakeLists.txt
Lines 5 to 9 in 01ee57c
if("${CUDA_RUNTIME_LIBS}" MATCHES "Threads::Threads") # need to import Threads set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) endif()
it seems to be failed with Threads::Threads
but successful with -pthread
.
I prefer to choose 2 or 3
I think option 1
is weird.
option 2 does not change too many things in CMake, but it maybe reduces usability in Windows.
option 3 works fine but benchmark/spmv
needs to include threads to use Threads::threads
correctly.
Which option do you think better way? Alternatively, is there any idea to solve this problem?
edit:
delete the fail with Threads::Threads