Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows CUDART link #354

Closed
yhmtsai opened this issue Sep 25, 2019 · 1 comment
Closed

Windows CUDART link #354

yhmtsai opened this issue Sep 25, 2019 · 1 comment
Assignees
Labels
is:help-wanted Need ideas on how to solve this. mod:cuda This is related to the CUDA module. plat:windows This is related to the Windows Operating system

Comments

@yhmtsai
Copy link
Member

yhmtsai commented Sep 25, 2019

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

  1. Do not link the cuda library in benchmark/spmv in Windows
    if (NOT MSVC)
    target_link_libraries(spmv ginkgo ${CUDA_RUNTIME_LIBS}
    ${CUBLAS} ${CUSPARSE})
    target_include_directories(spmv SYSTEM PRIVATE ${CUDA_INCLUDE_DIRS})
    endif()
  2. Force nvcc to use -cudart=shared in Windows.
  3. 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.
    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()

    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

@yhmtsai yhmtsai added is:help-wanted Need ideas on how to solve this. mod:cuda This is related to the CUDA module. plat:windows This is related to the Windows Operating system labels Sep 25, 2019
@yhmtsai
Copy link
Member Author

yhmtsai commented Oct 17, 2019

Conclusion:
Keep the same behavior in linux/MacOS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
is:help-wanted Need ideas on how to solve this. mod:cuda This is related to the CUDA module. plat:windows This is related to the Windows Operating system
Projects
None yet
Development

No branches or pull requests

5 participants