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

Make alpaka follow CMAKE_CUDA_RUNTIME_LIBRARY #2342

Conversation

fwyzard
Copy link
Contributor

@fwyzard fwyzard commented Aug 3, 2024

CMake uses CMAKE_CUDA_RUNTIME_LIBRARY to link the static (libcudart_static.a) or shared (libcudart.so) CUDA runtime library.

This PR makes alpaka follow the same variable, and applies it also to the cuRAND libraries.

@psychocoderHPC psychocoderHPC added this to the 1.2.0 milestone Aug 5, 2024
@psychocoderHPC psychocoderHPC merged commit 2c386dc into alpaka-group:develop Aug 5, 2024
22 checks passed
@@ -543,11 +543,19 @@ if(alpaka_ACC_GPU_CUDA_ENABLE)
endif()

# Link the CUDA Runtime library
target_link_libraries(alpaka INTERFACE CUDA::cudart)
if(CMAKE_CUDA_RUNTIME_LIBRARY STREQUAL "Shared")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default CMAKE_CUDA_RUNTIME_LIBRARY is not set so this if condation will be false and we link static.
In all old alpaka versions we linked always against cudart.
@fwyzard was the change of the default behavior of alpaka intended?

I run into issue with our main code PIConGPU when compiling with clang as CUDA compiler.

If there is no strong reason for the change of the default behaviour I could open a PR with

if(NOT DEFINED CMAKE_CUDA_RUNTIME_LIBRARY) 
     set(CMAKE_CUDA_RUNTIME_LIBRARY "Shared") 
 endif() 

Which will keep the default behaviour of alpaka but still provide the possibility of static linking.

Copy link
Contributor Author

@fwyzard fwyzard Aug 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I did not mean to change the default behaviour.

However, the default behaviour before #2329 and this PR was kind of tricky.

If configured with alpaka_DISABLE_VENDOR_RNG=OFF:

  • the CUDA binaries (e.g. axpyTest) are linked with both libcudart.so and -lcudart_static; I think the shared library took precedence because it was coming first on the command line;
  • the CUDA host-only applications (e.g. hostOnlyAPITest) were linked with libcudart.so.

If configured with alpaka_DISABLE_VENDOR_RNG=ON:

  • the CUDA binaries (e.g. axpyTest) were linked with cudart_static;
  • the CUDA host-only applications (e.g. hostOnlyAPITest) were not linked with either library, and in fact failed to link.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the default should be "shared" (I agree it should be), let me invert the logic of the checks:

        if(CMAKE_CUDA_RUNTIME_LIBRARY STREQUAL "Static")
            target_link_libraries(alpaka INTERFACE CUDA::cudart_static)
        else()
            target_link_libraries(alpaka INTERFACE CUDA::cudart)
        endif()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #2348 .

@fwyzard fwyzard deleted the follow_CMAKE_CUDA_RUNTIME_LIBRARY branch August 22, 2024 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants