Skip to content

Commit 2332ce6

Browse files
authored
[Fix][LTS]Change CMAKE_CXX_STANDARD to 17 for CUDA 13 (#6772)
* Update device.cpp * Update helper_cuda.h * Update CMakeLists.txt * Update global.h
1 parent 027657d commit 2332ce6

File tree

4 files changed

+45
-23
lines changed

4 files changed

+45
-23
lines changed

CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ set(ABACUS_BIN_PATH ${CMAKE_CURRENT_BINARY_DIR}/${ABACUS_BIN_NAME})
153153
include_directories(${ABACUS_SOURCE_DIR})
154154
include_directories(${ABACUS_SOURCE_DIR}/module_base/module_container)
155155

156-
set(CMAKE_CXX_STANDARD 11)
156+
if(NOT DEFINED CMAKE_CXX_STANDARD)
157+
set(CMAKE_CXX_STANDARD 11)
158+
endif()
157159
set(CMAKE_CXX_STANDARD_REQUIRED ON)
158160

159161
add_executable(${ABACUS_BIN_NAME} source/main.cpp)
@@ -294,6 +296,10 @@ endif()
294296
if(USE_CUDA)
295297
cmake_minimum_required(VERSION 3.18) # required by `CUDA_ARCHITECTURES` below
296298
set_if_higher(CMAKE_CXX_STANDARD 14)
299+
if(CUDA_VERSION VERSION_GREATER_EQUAL "13.0")
300+
message(STATUS "CUDA ${CUDA_VERSION} detected. Setting CMAKE_CUDA_STANDARD to 17.")
301+
set_if_higher(CMAKE_CXX_STANDARD 17)
302+
endif()
297303
set(CMAKE_CXX_EXTENSIONS ON)
298304
set(CMAKE_CUDA_STANDARD ${CMAKE_CXX_STANDARD})
299305
set(CMAKE_CUDA_STANDARD_REQUIRED ON)

source/module_base/module_device/device.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#if defined(__CUDA)
1414
#include <cuda_runtime.h>
15+
#include <cuda.h>
1516
#endif
1617

1718
#if defined(__ROCM)
@@ -299,6 +300,7 @@ void print_device_info<base_device::DEVICE_GPU>(
299300
sprintf(msg, " CUDA Capability Major/Minor version number: %d.%d\n",
300301
deviceProp.major, deviceProp.minor);
301302
ofs_device << msg << std::endl;
303+
#if defined(CUDA_VERSION) && CUDA_VERSION < 13000
302304
sprintf(msg,
303305
" GPU Max Clock rate: %.0f MHz (%0.2f "
304306
"GHz)\n",
@@ -312,6 +314,7 @@ void print_device_info<base_device::DEVICE_GPU>(
312314
sprintf(msg, " Memory Bus Width: %d-bit\n",
313315
deviceProp.memoryBusWidth);
314316
ofs_device << msg << std::endl;
317+
#endif
315318
sprintf(msg,
316319
" Maximum Texture Dimension Size (x,y,z) 1D=(%d), 2D=(%d, "
317320
"%d), 3D=(%d, %d, %d)\n",
@@ -366,6 +369,7 @@ void print_device_info<base_device::DEVICE_GPU>(
366369
sprintf(msg, " Texture alignment: %zu bytes\n",
367370
deviceProp.textureAlignment);
368371
ofs_device << msg << std::endl;
372+
#if defined(CUDA_VERSION) && CUDA_VERSION < 13000
369373
sprintf(msg,
370374
" Concurrent copy and kernel execution: %s with %d copy "
371375
"engine(s)\n",
@@ -375,6 +379,7 @@ void print_device_info<base_device::DEVICE_GPU>(
375379
sprintf(msg, " Run time limit on kernels: %s\n",
376380
deviceProp.kernelExecTimeoutEnabled ? "Yes" : "No");
377381
ofs_device << msg << std::endl;
382+
#endif
378383
sprintf(msg, " Integrated GPU sharing Host Memory: %s\n",
379384
deviceProp.integrated ? "Yes" : "No");
380385
ofs_device << msg << std::endl;
@@ -399,13 +404,15 @@ void print_device_info<base_device::DEVICE_GPU>(
399404
sprintf(msg, " Supports Cooperative Kernel Launch: %s\n",
400405
deviceProp.cooperativeLaunch ? "Yes" : "No");
401406
ofs_device << msg << std::endl;
402-
sprintf(msg, " Supports MultiDevice Co-op Kernel Launch: %s\n",
403-
deviceProp.cooperativeMultiDeviceLaunch ? "Yes" : "No");
404-
ofs_device << msg << std::endl;
405407
sprintf(msg,
406408
" Device PCI Domain ID / Bus ID / location ID: %d / %d / %d\n",
407409
deviceProp.pciDomainID, deviceProp.pciBusID, deviceProp.pciDeviceID);
408410
ofs_device << msg << std::endl;
411+
#if defined(CUDA_VERSION) && CUDA_VERSION < 13000
412+
sprintf(msg, " Supports MultiDevice Co-op Kernel Launch: %s\n",
413+
deviceProp.cooperativeMultiDeviceLaunch ? "Yes" : "No");
414+
ofs_device << msg << std::endl;
415+
409416
const char *sComputeMode[] = {
410417
"Default (multiple host threads can use ::cudaSetDevice() with device "
411418
"simultaneously)",
@@ -421,7 +428,7 @@ void print_device_info<base_device::DEVICE_GPU>(
421428
ofs_device << msg << std::endl;
422429
ofs_device << " " << sComputeMode[deviceProp.computeMode] << std::endl
423430
<< std::endl;
424-
431+
#endif
425432
// If there are 2 or more GPUs, query to determine whether RDMA is supported
426433
if (deviceCount >= 2) {
427434
cudaDeviceProp prop[64];
@@ -711,4 +718,4 @@ void record_device_memory<base_device::DEVICE_GPU>(
711718
#endif
712719

713720
} // end of namespace information
714-
} // end of namespace base_device
721+
} // end of namespace base_device

source/module_hamilt_pw/hamilt_pwdft/global.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "module_hamilt_general/module_xc/xc_functional.h"
1616
#ifdef __CUDA
1717
#include "cublas_v2.h"
18+
#include <cuda.h> // for CUDA_VERSION
1819
#include "cufft.h"
1920

2021
static const char* _cublasGetErrorString(cublasStatus_t error)
@@ -65,22 +66,27 @@ static const char* _cufftGetErrorString(cufftResult_t error)
6566
return "CUFFT_INVALID_SIZE";
6667
case CUFFT_UNALIGNED_DATA:
6768
return "CUFFT_UNALIGNED_DATA";
68-
case CUFFT_INCOMPLETE_PARAMETER_LIST:
69-
return "CUFFT_INCOMPLETE_PARAMETER_LIST";
7069
case CUFFT_INVALID_DEVICE:
7170
return "CUFFT_INVALID_DEVICE";
72-
case CUFFT_PARSE_ERROR:
73-
return "CUFFT_PARSE_ERROR";
7471
case CUFFT_NO_WORKSPACE:
7572
return "CUFFT_NO_WORKSPACE";
7673
case CUFFT_NOT_IMPLEMENTED:
7774
return "CUFFT_NOT_IMPLEMENTED";
78-
case CUFFT_LICENSE_ERROR:
79-
return "CUFFT_LICENSE_ERROR";
8075
case CUFFT_NOT_SUPPORTED:
8176
return "CUFFT_NOT_SUPPORTED";
77+
78+
#if defined(CUDA_VERSION) && CUDA_VERSION < 13000
79+
case CUFFT_INCOMPLETE_PARAMETER_LIST:
80+
return "CUFFT_INCOMPLETE_PARAMETER_LIST";
81+
case CUFFT_PARSE_ERROR:
82+
return "CUFFT_PARSE_ERROR";
83+
case CUFFT_LICENSE_ERROR:
84+
return "CUFFT_LICENSE_ERROR";
85+
#endif
86+
87+
default:
88+
return "<unknown>";
8289
}
83-
return "<unknown>";
8490
}
8591

8692
#define CHECK_CUDA(func) \

source/module_hsolver/kernels/cuda/helper_cuda.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -137,30 +137,33 @@ static const char *_cudaGetErrorEnum(cufftResult error) {
137137

138138
case CUFFT_UNALIGNED_DATA:
139139
return "CUFFT_UNALIGNED_DATA";
140-
141-
case CUFFT_INCOMPLETE_PARAMETER_LIST:
142-
return "CUFFT_INCOMPLETE_PARAMETER_LIST";
143-
140+
144141
case CUFFT_INVALID_DEVICE:
145142
return "CUFFT_INVALID_DEVICE";
146143

147-
case CUFFT_PARSE_ERROR:
148-
return "CUFFT_PARSE_ERROR";
149-
150144
case CUFFT_NO_WORKSPACE:
151145
return "CUFFT_NO_WORKSPACE";
152146

153147
case CUFFT_NOT_IMPLEMENTED:
154148
return "CUFFT_NOT_IMPLEMENTED";
155149

150+
#if defined(CUDA_VERSION) && CUDA_VERSION < 13000
151+
case CUFFT_INCOMPLETE_PARAMETER_LIST:
152+
return "CUFFT_INCOMPLETE_PARAMETER_LIST";
153+
154+
case CUFFT_PARSE_ERROR:
155+
return "CUFFT_PARSE_ERROR";
156+
156157
case CUFFT_LICENSE_ERROR:
157158
return "CUFFT_LICENSE_ERROR";
159+
#endif
158160

159161
case CUFFT_NOT_SUPPORTED:
160162
return "CUFFT_NOT_SUPPORTED";
163+
164+
default:
165+
return "<unknown>";
161166
}
162-
163-
return "<unknown>";
164167
}
165168
#endif
166169

@@ -965,4 +968,4 @@ inline bool checkCudaCapabilities(int major_version, int minor_version) {
965968

966969
// end of CUDA Helper Functions
967970

968-
#endif // COMMON_HELPER_CUDA_H_
971+
#endif // COMMON_HELPER_CUDA_H_

0 commit comments

Comments
 (0)