Skip to content

Commit 41ca809

Browse files
Merge branch 'develop' into gpu-example-modify
2 parents 4bcc6a7 + eea0f93 commit 41ca809

607 files changed

Lines changed: 16609 additions & 6506 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/devcontainer.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ jobs:
1717
matrix:
1818
dockerfile: ["gnu","intel","cuda"]
1919
steps:
20+
- name: Force Clean Workspace
21+
run: |
22+
sudo chattr -i -R ${{ github.workspace }} 2>/dev/null || true
23+
sudo chown -R $USER:$USER ${{ github.workspace }}
24+
sudo find ${{ github.workspace }} -mindepth 1 -delete
25+
2026
- name: Checkout
2127
uses: actions/checkout@v6
2228

CMakeLists.txt

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ option(ENABLE_RAPIDJSON "Enable rapid-json usage" OFF)
5252
option(ENABLE_CNPY "Enable cnpy usage" OFF)
5353
option(ENABLE_CUSOLVERMP "Enable cusolvermp" OFF)
5454

55+
if(NOT DEFINED NVHPC_ROOT_DIR AND DEFINED ENV{NVHPC_ROOT})
56+
set(NVHPC_ROOT_DIR
57+
"$ENV{NVHPC_ROOT}"
58+
CACHE PATH "Path to NVIDIA HPC SDK root directory.")
59+
endif()
60+
5561
# enable json support
5662
if(ENABLE_RAPIDJSON)
5763
find_package(RapidJSON)
@@ -397,21 +403,9 @@ if(USE_CUDA)
397403
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler=${OpenMP_CXX_FLAGS}" CACHE STRING "CUDA flags" FORCE)
398404
endif()
399405
if (ENABLE_CUSOLVERMP)
400-
add_compile_definitions(__CUSOLVERMP)
401-
find_library(CAL_LIBRARY
402-
NAMES cal
403-
PATHS ${CAL_CUSOLVERMP_PATH}
404-
NO_DEFAULT_PATH
405-
)
406-
find_library(CUSOLVERMP_LIBRARY
407-
NAMES cusolverMp
408-
PATHS ${CAL_CUSOLVERMP_PATH}
409-
NO_DEFAULT_PATH
410-
)
411-
target_link_libraries(${ABACUS_BIN_NAME}
412-
${CAL_LIBRARY}
413-
${CUSOLVERMP_LIBRARY}
414-
)
406+
# Keep cuSolverMp discovery/linking logic in a dedicated module.
407+
include(cmake/SetupCuSolverMp.cmake)
408+
abacus_setup_cusolvermp(${ABACUS_BIN_NAME})
415409
endif()
416410
endif()
417411
endif()

cmake/SetupCuSolverMp.cmake

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# =============================================================================
2+
# Configure cuSolverMp dependencies and linking for ABACUS
3+
# =============================================================================
4+
5+
include_guard(GLOBAL)
6+
7+
function(abacus_setup_cusolvermp target_name)
8+
add_compile_definitions(__CUSOLVERMP)
9+
10+
# Find cuSolverMp first, then decide communicator backend.
11+
find_library(CUSOLVERMP_LIBRARY NAMES cusolverMp
12+
HINTS ${CAL_CUSOLVERMP_PATH} ${NVHPC_ROOT_DIR}
13+
PATH_SUFFIXES lib lib64 math_libs/lib math_libs/lib64)
14+
15+
find_path(CUSOLVERMP_INCLUDE_DIR NAMES cusolverMp.h
16+
HINTS ${CAL_CUSOLVERMP_PATH} ${NVHPC_ROOT_DIR}
17+
PATH_SUFFIXES include math_libs/include)
18+
19+
if(NOT CUSOLVERMP_LIBRARY OR NOT CUSOLVERMP_INCLUDE_DIR)
20+
message(FATAL_ERROR
21+
"cusolverMp not found. Set CUSOLVERMP_PATH or NVHPC_ROOT_DIR."
22+
)
23+
endif()
24+
25+
message(STATUS "Found cusolverMp: ${CUSOLVERMP_LIBRARY}")
26+
27+
set(CUSOLVERMP_VERSION_STR "")
28+
set(CUSOLVERMP_VERSION_HEADER "${CUSOLVERMP_INCLUDE_DIR}/cusolverMp.h")
29+
if(EXISTS "${CUSOLVERMP_VERSION_HEADER}")
30+
file(STRINGS "${CUSOLVERMP_VERSION_HEADER}" CUSOLVERMP_MAJOR_LINE
31+
REGEX "^#define[ \t]+CUSOLVERMP_VER_MAJOR[ \t]+[0-9]+")
32+
file(STRINGS "${CUSOLVERMP_VERSION_HEADER}" CUSOLVERMP_MINOR_LINE
33+
REGEX "^#define[ \t]+CUSOLVERMP_VER_MINOR[ \t]+[0-9]+")
34+
file(STRINGS "${CUSOLVERMP_VERSION_HEADER}" CUSOLVERMP_PATCH_LINE
35+
REGEX "^#define[ \t]+CUSOLVERMP_VER_PATCH[ \t]+[0-9]+")
36+
string(REGEX MATCH "([0-9]+)" CUSOLVERMP_VER_MAJOR "${CUSOLVERMP_MAJOR_LINE}")
37+
string(REGEX MATCH "([0-9]+)" CUSOLVERMP_VER_MINOR "${CUSOLVERMP_MINOR_LINE}")
38+
string(REGEX MATCH "([0-9]+)" CUSOLVERMP_VER_PATCH "${CUSOLVERMP_PATCH_LINE}")
39+
if(NOT CUSOLVERMP_VER_MAJOR STREQUAL ""
40+
AND NOT CUSOLVERMP_VER_MINOR STREQUAL ""
41+
AND NOT CUSOLVERMP_VER_PATCH STREQUAL "")
42+
set(CUSOLVERMP_VERSION_STR
43+
"${CUSOLVERMP_VER_MAJOR}.${CUSOLVERMP_VER_MINOR}.${CUSOLVERMP_VER_PATCH}")
44+
endif()
45+
endif()
46+
47+
# Check minimum version requirement (>= 0.4.0)
48+
if(CUSOLVERMP_VERSION_STR AND CUSOLVERMP_VERSION_STR VERSION_LESS "0.4.0")
49+
message(FATAL_ERROR
50+
"cuSolverMp version ${CUSOLVERMP_VERSION_STR} is too old. "
51+
"ABACUS requires cuSolverMp >= 0.4.0 (NVIDIA HPC SDK >= 23.5). "
52+
"Please upgrade your NVIDIA HPC SDK installation."
53+
)
54+
endif()
55+
56+
# Auto-select communicator backend by cuSolverMp version.
57+
# cuSolverMp < 0.7.0 -> CAL, otherwise -> NCCL.
58+
set(_use_cal OFF)
59+
if(CUSOLVERMP_VERSION_STR AND CUSOLVERMP_VERSION_STR VERSION_LESS "0.7.0")
60+
set(_use_cal ON)
61+
message(STATUS
62+
"Detected cuSolverMp ${CUSOLVERMP_VERSION_STR} (< 0.7.0). Using CAL backend.")
63+
elseif(CUSOLVERMP_VERSION_STR)
64+
message(STATUS
65+
"Detected cuSolverMp ${CUSOLVERMP_VERSION_STR} (>= 0.7.0). Using NCCL backend.")
66+
elseif(NOT CUSOLVERMP_VERSION_STR)
67+
message(WARNING
68+
"Unable to detect cuSolverMp version from header. Using NCCL backend by default.")
69+
endif()
70+
71+
# Backend selection:
72+
# - _use_cal=ON -> cal communicator backend
73+
# - _use_cal=OFF -> NCCL communicator backend
74+
if(_use_cal)
75+
add_compile_definitions(__USE_CAL)
76+
77+
find_library(CAL_LIBRARY NAMES cal
78+
HINTS ${CAL_CUSOLVERMP_PATH} ${NVHPC_ROOT_DIR}
79+
PATH_SUFFIXES lib lib64 math_libs/lib64)
80+
find_path(CAL_INCLUDE_DIR NAMES cal.h
81+
HINTS ${CAL_CUSOLVERMP_PATH} ${NVHPC_ROOT_DIR}
82+
PATH_SUFFIXES include math_libs/include)
83+
84+
if(NOT CAL_LIBRARY OR NOT CAL_INCLUDE_DIR)
85+
message(FATAL_ERROR "CAL not found. Set CAL_PATH or NVHPC_ROOT_DIR.")
86+
endif()
87+
88+
message(STATUS "Found CAL: ${CAL_LIBRARY}")
89+
if(NOT TARGET CAL::CAL)
90+
add_library(CAL::CAL IMPORTED INTERFACE)
91+
set_target_properties(CAL::CAL PROPERTIES
92+
INTERFACE_LINK_LIBRARIES "${CAL_LIBRARY}"
93+
INTERFACE_INCLUDE_DIRECTORIES "${CAL_INCLUDE_DIR}")
94+
endif()
95+
else()
96+
97+
find_library(NCCL_LIBRARY NAMES nccl
98+
HINTS ${NCCL_PATH} ${NVHPC_ROOT_DIR}
99+
PATH_SUFFIXES lib lib64 comm_libs/nccl/lib)
100+
find_path(NCCL_INCLUDE_DIR NAMES nccl.h
101+
HINTS ${NCCL_PATH} ${NVHPC_ROOT_DIR}
102+
PATHS ${CUDA_TOOLKIT_ROOT_DIR}
103+
PATH_SUFFIXES include comm_libs/nccl/include)
104+
105+
if(NOT NCCL_LIBRARY OR NOT NCCL_INCLUDE_DIR)
106+
message(FATAL_ERROR "NCCL not found. Set NCCL_PATH or NVHPC_ROOT_DIR.")
107+
endif()
108+
109+
message(STATUS "Found NCCL: ${NCCL_LIBRARY}")
110+
if(NOT TARGET NCCL::NCCL)
111+
add_library(NCCL::NCCL IMPORTED INTERFACE)
112+
set_target_properties(NCCL::NCCL PROPERTIES
113+
INTERFACE_LINK_LIBRARIES "${NCCL_LIBRARY}"
114+
INTERFACE_INCLUDE_DIRECTORIES "${NCCL_INCLUDE_DIR}")
115+
endif()
116+
endif()
117+
118+
# Create cusolverMp::cusolverMp imported target
119+
if(NOT TARGET cusolverMp::cusolverMp)
120+
add_library(cusolverMp::cusolverMp IMPORTED INTERFACE)
121+
set_target_properties(cusolverMp::cusolverMp PROPERTIES
122+
INTERFACE_LINK_LIBRARIES "${CUSOLVERMP_LIBRARY}"
123+
INTERFACE_INCLUDE_DIRECTORIES "${CUSOLVERMP_INCLUDE_DIR}")
124+
endif()
125+
126+
# === Link libraries ===
127+
if(_use_cal)
128+
target_link_libraries(${target_name}
129+
CAL::CAL
130+
cusolverMp::cusolverMp)
131+
else()
132+
target_link_libraries(${target_name}
133+
NCCL::NCCL
134+
cusolverMp::cusolverMp)
135+
endif()
136+
endfunction()

0 commit comments

Comments
 (0)