diff --git a/CMakeLists.txt b/CMakeLists.txt index 64aa9dc..e790a5b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,6 +56,10 @@ if (USE_OMP) endif() if (USE_ACC) find_package(OpenACC REQUIRED) + # Provides CUDA::cublas / CUDA::cusolver imported targets (headers + libs), + # so the GPU build does not depend on CPATH from the developer's shell + # reaching the compiler (see issue #98) + find_package(CUDAToolkit REQUIRED) endif() set(CMAKE_CXX_STANDARD 14) diff --git a/SlaterGPUConfig.cmake.in b/SlaterGPUConfig.cmake.in index 9ed9cc8..991b47f 100644 --- a/SlaterGPUConfig.cmake.in +++ b/SlaterGPUConfig.cmake.in @@ -8,10 +8,10 @@ find_dependency(MPI REQUIRED) find_dependency(BLAS REQUIRED) find_dependency(LAPACK REQUIRED) -# Find CUDA if available -find_package(CUDA QUIET) -if(CUDA_FOUND) - enable_language(CUDA) +# The GPU build links CUDA::cublas / CUDA::cusolver, which consumers need +# to resolve from the exported SlaterGPU target +if(@USE_ACC@) + find_dependency(CUDAToolkit REQUIRED) endif() # Include the targets file diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 82b0f85..807b72d 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -12,24 +12,16 @@ set(TEST_COMP_FLAGS ${CMAKE_CXX_FLAGS}) # CUDA/GPU dependencies - only when USE_ACC is enabled if(USE_ACC) - enable_language(CUDA) - find_package(CUDA REQUIRED) - find_library(CUDART_LIBRARY cudart ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES}) - - target_link_options(sgpu.exe PRIVATE + target_link_options(sgpu.exe PRIVATE -acc=gpu ) - set(TEST_COMP_FLAGS ${TEST_COMP_FLAGS} + set(TEST_COMP_FLAGS ${TEST_COMP_FLAGS} -DUSE_ACC=1 -acc=gpu ) - - # GPU-specific link libraries - set(GPU_LIBRARIES - "${CUDART_LIBRARY}" - "${CUDA_LIBRARIES}" - "${CUDA_TOOLKIT_ROOT_DIR}/../../math_libs/lib64/libcublas.so" - "${CUDA_TOOLKIT_ROOT_DIR}/../../math_libs/lib64/libcusolver.so" - ) + + # GPU-specific link libraries; cuBLAS/cuSolver come transitively from + # the SlaterGPU target (CUDA::cublas / CUDA::cusolver) + set(GPU_LIBRARIES CUDA::cudart) else() # CPU-only mode set(GPU_LIBRARIES "") diff --git a/pixi.toml b/pixi.toml index a954a6f..ba755f9 100644 --- a/pixi.toml +++ b/pixi.toml @@ -10,7 +10,7 @@ version = "0.1.14" [package.build.backend] name = "pixi-build-cmake" -version = ">=0.3.6,<=0.4.2" +version = ">=0.3.6,<=0.4.5" [package.build.config] compilers = [] diff --git a/src/integrals/CMakeLists.txt b/src/integrals/CMakeLists.txt index 7569011..ee1bd3d 100644 --- a/src/integrals/CMakeLists.txt +++ b/src/integrals/CMakeLists.txt @@ -60,6 +60,9 @@ if(USE_ACC) target_compile_options(SlaterGPU PRIVATE ${SLATER_COMP_FLAGS} -DUSE_ACC=1 -acc=gpu ) + # PUBLIC: cuda_util.h includes cublas_v2.h/cusolverDn.h when USE_ACC, + # so dependents (io, sgpu.exe, consumers) need the headers and libraries too + target_link_libraries(SlaterGPU PUBLIC CUDA::cublas CUDA::cusolver) else() target_compile_options(SlaterGPU PRIVATE ${SLATER_COMP_FLAGS} -DUSE_ACC=0