From f1ff9872634266b12e23feb9e548fd1c7fd33f75 Mon Sep 17 00:00:00 2001 From: Levi Zhou <31941107+ZhouXY-PKU@users.noreply.github.com> Date: Fri, 12 Dec 2025 15:34:31 +0800 Subject: [PATCH 01/20] Update cuda_compat.h --- .../source_base/module_device/cuda_compat.h | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/source/source_base/module_device/cuda_compat.h b/source/source_base/module_device/cuda_compat.h index 78c0f6420c..fdfa476068 100644 --- a/source/source_base/module_device/cuda_compat.h +++ b/source/source_base/module_device/cuda_compat.h @@ -12,7 +12,12 @@ #ifndef CUDA_COMPAT_H_ #define CUDA_COMPAT_H_ +#include // For std::ostream +#include // For std::invalid_argument #include // defines CUDA_VERSION +#include +#include + // NVTX header for CUDA versions prior to 12.9 vs. 12.9+ // This block ensures the correct NVTX header path is used based on CUDA_VERSION. @@ -31,4 +36,54 @@ #endif #endif +//------------------------------------------------------------------------------------------------- +// Compatibility Layer Declarations +//------------------------------------------------------------------------------------------------- +namespace ModuleBase { +namespace cuda_compat { + +/** + * @brief Prints device information that was deprecated or removed in CUDA 13.0. + * + * This function handles properties like clockRate, memoryClockRate, memoryBusWidth, + * and concurrency flags, which are not available in newer CUDA toolkits. + * + * @param os The output stream (e.g., std::cout, std::ofstream). + * @param prop The cudaDeviceProp structure containing device properties. + */ +void printDeprecatedDeviceInfo(std::ostream& os, const cudaDeviceProp& prop); + +/** + * @brief Prints the device's compute mode using a legacy string mapping. + * + * The compute mode display logic is encapsulated here as it relies on aspects + * of the driver model that have changed. + * + * @param os The output stream (e.g., std::cout, std::ofstream). + * @param prop The cudaDeviceProp structure containing device properties. + */ +void printComputeModeInfo(std::ostream& os, const cudaDeviceProp& prop); + +/** + * @brief Provides a cross-CUDA-version string conversion for cuFFT error codes. + * + * In CUDA 13.0, several error codes were removed. This function handles + * these differences gracefully. + * + * @param error The cufftResult_t error code. + * @return const char* A descriptive string for the error. + */ +const char* cufftGetErrorStringCompat(cufftResult_t error); + +} // namespace cuda_compat +} // namespace ModuleBase + +//---------------------------------------------------------------------------- +// Macro Replacement for cuFFT Error Handling +// Any file that calls _cufftGetErrorString just needs to include this header. +//---------------------------------------------------------------------------- +#ifndef ABACUS_CUDA_COMPAT_NO_CUFFT_REDIRECT + #define _cufftGetErrorString ModuleBase::cuda_compat::cufftGetErrorStringCompat +#endif + #endif // CUDA_COMPAT_H_ From e2e013fe875c54741c7f635887df375f1c9897d3 Mon Sep 17 00:00:00 2001 From: Levi Zhou <31941107+ZhouXY-PKU@users.noreply.github.com> Date: Fri, 12 Dec 2025 15:38:57 +0800 Subject: [PATCH 02/20] Create cuda_compat.cpp --- .../source_base/module_device/cuda_compat.cpp | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 source/source_base/module_device/cuda_compat.cpp diff --git a/source/source_base/module_device/cuda_compat.cpp b/source/source_base/module_device/cuda_compat.cpp new file mode 100644 index 0000000000..8ce9e80c9c --- /dev/null +++ b/source/source_base/module_device/cuda_compat.cpp @@ -0,0 +1,117 @@ +#include "cuda_compat.h" + +namespace ModuleBase { +namespace cuda_compat { + +//--------------------------------------------------------------------------- +// Implementation of printDeprecatedDeviceInfo and printComputeModeInfo +//--------------------------------------------------------------------------- +void printDeprecatedDeviceInfo(std::ostream& os, const cudaDeviceProp& prop) +{ +#if defined(CUDA_VERSION) && CUDA_VERSION < 13000 + char msg[1024]; + sprintf(msg, + " GPU Max Clock rate: %.0f MHz (%0.2f " + "GHz)\n", + deviceProp.clockRate * 1e-3f, deviceProp.clockRate * 1e-6f); + ofs_device << msg << std::endl; + // This is supported in CUDA 5.0 (runtime API device properties) + sprintf(msg, " Memory Clock rate: %.0f Mhz\n", + deviceProp.memoryClockRate * 1e-3f); + ofs_device << msg << std::endl; + + sprintf(msg, " Memory Bus Width: %d-bit\n", + deviceProp.memoryBusWidth); + ofs_device << msg << std::endl; + + sprintf(msg, + " Concurrent copy and kernel execution: %s with %d copy " + "engine(s)\n", + (deviceProp.deviceOverlap ? "Yes" : "No"), + deviceProp.asyncEngineCount); + ofs_device << msg << std::endl; + sprintf(msg, " Run time limit on kernels: %s\n", + deviceProp.kernelExecTimeoutEnabled ? "Yes" : "No"); + ofs_device << msg << std::endl; +#endif +} + +void printComputeModeInfo(std::ostream& os, const cudaDeviceProp& prop) +{ +#if defined(CUDA_VERSION) && CUDA_VERSION < 13000 + char msg[1024]; + sprintf(msg, " Supports MultiDevice Co-op Kernel Launch: %s\n", + deviceProp.cooperativeMultiDeviceLaunch ? "Yes" : "No"); + ofs_device << msg << std::endl; + + const char *sComputeMode[] = { + "Default (multiple host threads can use ::cudaSetDevice() with device " + "simultaneously)", + "Exclusive (only one host thread in one process is able to use " + "::cudaSetDevice() with this device)", + "Prohibited (no host thread can use ::cudaSetDevice() with this " + "device)", + "Exclusive Process (many threads in one process is able to use " + "::cudaSetDevice() with this device)", + "Unknown", + NULL}; + sprintf(msg, " Compute Mode:\n"); + ofs_device << msg << std::endl; + ofs_device << " " << sComputeMode[deviceProp.computeMode] << std::endl + << std::endl; +#endif +} + +//------------------------------------------------------------------------------------------------- +// Implementation of cufftGetErrorStringCompat +//------------------------------------------------------------------------------------------------- +const char* cufftGetErrorStringCompat(cufftResult_t error) +{ + switch (error) + { + case CUFFT_SUCCESS: + return "CUFFT_SUCCESS"; + case CUFFT_INVALID_PLAN: + return "CUFFT_INVALID_PLAN"; + case CUFFT_ALLOC_FAILED: + return "CUFFT_ALLOC_FAILED"; + case CUFFT_INVALID_TYPE: + return "CUFFT_INVALID_TYPE"; + case CUFFT_INVALID_VALUE: + return "CUFFT_INVALID_VALUE"; + case CUFFT_INTERNAL_ERROR: + return "CUFFT_INTERNAL_ERROR"; + case CUFFT_EXEC_FAILED: + return "CUFFT_EXEC_FAILED"; + case CUFFT_SETUP_FAILED: + return "CUFFT_SETUP_FAILED"; + case CUFFT_INVALID_SIZE: + return "CUFFT_INVALID_SIZE"; + case CUFFT_UNALIGNED_DATA: + return "CUFFT_UNALIGNED_DATA"; + case CUFFT_INVALID_DEVICE: + return "CUFFT_INVALID_DEVICE"; + case CUFFT_NO_WORKSPACE: + return "CUFFT_NO_WORKSPACE"; + case CUFFT_NOT_IMPLEMENTED: + return "CUFFT_NOT_IMPLEMENTED"; + case CUFFT_NOT_SUPPORTED: + return "CUFFT_NOT_SUPPORTED"; + +#if defined(CUDA_VERSION) && CUDA_VERSION < 13000 + case CUFFT_INCOMPLETE_PARAMETER_LIST: + return "CUFFT_INCOMPLETE_PARAMETER_LIST"; + case CUFFT_PARSE_ERROR: + return "CUFFT_PARSE_ERROR"; + case CUFFT_LICENSE_ERROR: + return "CUFFT_LICENSE_ERROR"; +#endif + + default: + return ""; + } +} + +} // cuda_compat +} // namespace cuda_compat +} // namespace ModuleBase From fff6075e897439df709c140980977386840bc033 Mon Sep 17 00:00:00 2001 From: Levi Zhou <31941107+ZhouXY-PKU@users.noreply.github.com> Date: Fri, 12 Dec 2025 15:55:04 +0800 Subject: [PATCH 03/20] Update output_device.cpp --- .../module_device/output_device.cpp | 48 +++---------------- 1 file changed, 6 insertions(+), 42 deletions(-) diff --git a/source/source_base/module_device/output_device.cpp b/source/source_base/module_device/output_device.cpp index 41b4c6d082..24c55ef0bf 100644 --- a/source/source_base/module_device/output_device.cpp +++ b/source/source_base/module_device/output_device.cpp @@ -2,6 +2,7 @@ #include "device.h" #include "source_base/tool_quit.h" +#include "source_base/module_device/cuda_compat.h" #include "source_io/module_parameter/parameter.h" #include @@ -218,19 +219,6 @@ void print_device_info( sprintf(msg, " CUDA Capability Major/Minor version number: %d.%d\n", deviceProp.major, deviceProp.minor); ofs_device << msg << std::endl; - sprintf(msg, - " GPU Max Clock rate: %.0f MHz (%0.2f " - "GHz)\n", - deviceProp.clockRate * 1e-3f, deviceProp.clockRate * 1e-6f); - ofs_device << msg << std::endl; - // This is supported in CUDA 5.0 (runtime API device properties) - sprintf(msg, " Memory Clock rate: %.0f Mhz\n", - deviceProp.memoryClockRate * 1e-3f); - ofs_device << msg << std::endl; - - sprintf(msg, " Memory Bus Width: %d-bit\n", - deviceProp.memoryBusWidth); - ofs_device << msg << std::endl; sprintf(msg, " Maximum Texture Dimension Size (x,y,z) 1D=(%d), 2D=(%d, " "%d), 3D=(%d, %d, %d)\n", @@ -238,7 +226,6 @@ void print_device_info( deviceProp.maxTexture2D[1], deviceProp.maxTexture3D[0], deviceProp.maxTexture3D[1], deviceProp.maxTexture3D[2]); ofs_device << msg << std::endl; - sprintf( msg, " Maximum Layered 1D Texture Size, (num) layers 1D=(%d), %d layers\n", @@ -285,15 +272,6 @@ void print_device_info( sprintf(msg, " Texture alignment: %zu bytes\n", deviceProp.textureAlignment); ofs_device << msg << std::endl; - sprintf(msg, - " Concurrent copy and kernel execution: %s with %d copy " - "engine(s)\n", - (deviceProp.deviceOverlap ? "Yes" : "No"), - deviceProp.asyncEngineCount); - ofs_device << msg << std::endl; - sprintf(msg, " Run time limit on kernels: %s\n", - deviceProp.kernelExecTimeoutEnabled ? "Yes" : "No"); - ofs_device << msg << std::endl; sprintf(msg, " Integrated GPU sharing Host Memory: %s\n", deviceProp.integrated ? "Yes" : "No"); ofs_device << msg << std::endl; @@ -318,28 +296,14 @@ void print_device_info( sprintf(msg, " Supports Cooperative Kernel Launch: %s\n", deviceProp.cooperativeLaunch ? "Yes" : "No"); ofs_device << msg << std::endl; - sprintf(msg, " Supports MultiDevice Co-op Kernel Launch: %s\n", - deviceProp.cooperativeMultiDeviceLaunch ? "Yes" : "No"); - ofs_device << msg << std::endl; sprintf(msg, " Device PCI Domain ID / Bus ID / location ID: %d / %d / %d\n", deviceProp.pciDomainID, deviceProp.pciBusID, deviceProp.pciDeviceID); ofs_device << msg << std::endl; - const char *sComputeMode[] = { - "Default (multiple host threads can use ::cudaSetDevice() with device " - "simultaneously)", - "Exclusive (only one host thread in one process is able to use " - "::cudaSetDevice() with this device)", - "Prohibited (no host thread can use ::cudaSetDevice() with this " - "device)", - "Exclusive Process (many threads in one process is able to use " - "::cudaSetDevice() with this device)", - "Unknown", - NULL}; - sprintf(msg, " Compute Mode:\n"); - ofs_device << msg << std::endl; - ofs_device << " " << sComputeMode[deviceProp.computeMode] << std::endl - << std::endl; + + ModuleBase::cuda_compat::printDeprecatedDeviceInfo(ofs_device, deviceProp); + + ModuleBase::cuda_compat::printComputeModeInfo(ofs_device, deviceProp); // If there are 2 or more GPUs, query to determine whether RDMA is supported if (deviceCount >= 2) { @@ -629,4 +593,4 @@ void record_device_memory( #endif } -} \ No newline at end of file +} From 7bdaee603337d938d96cc84c67546a9be034384b Mon Sep 17 00:00:00 2001 From: Levi Zhou <31941107+ZhouXY-PKU@users.noreply.github.com> Date: Fri, 12 Dec 2025 16:52:34 +0800 Subject: [PATCH 04/20] Update global.h --- source/source_pw/module_pwdft/global.h | 1 + 1 file changed, 1 insertion(+) diff --git a/source/source_pw/module_pwdft/global.h b/source/source_pw/module_pwdft/global.h index 5080ddc24d..60bf1ca17b 100644 --- a/source/source_pw/module_pwdft/global.h +++ b/source/source_pw/module_pwdft/global.h @@ -3,6 +3,7 @@ #include "source_base/global_function.h" #include "source_base/global_variable.h" +#include "source_base/module_device/cuda_compat.h" #include "source_estate/module_charge/charge_mixing.h" #include "source_pw/module_pwdft/VNL_in_pw.h" #include "source_io/restart.h" From 7a20401b6a98975f6a2f5279b4344dff38daf2be Mon Sep 17 00:00:00 2001 From: Levi Zhou <31941107+ZhouXY-PKU@users.noreply.github.com> Date: Fri, 12 Dec 2025 16:55:06 +0800 Subject: [PATCH 05/20] Update helper_cuda.h --- source/source_hsolver/kernels/cuda/helper_cuda.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/source_hsolver/kernels/cuda/helper_cuda.h b/source/source_hsolver/kernels/cuda/helper_cuda.h index e61e4597f6..79c7926f9e 100644 --- a/source/source_hsolver/kernels/cuda/helper_cuda.h +++ b/source/source_hsolver/kernels/cuda/helper_cuda.h @@ -40,6 +40,8 @@ #include "helper_string.h" +#include "source_base/module_device/cuda_compat.h" + #ifndef EXIT_WAIVED #define EXIT_WAIVED 2 #endif @@ -965,4 +967,4 @@ inline bool checkCudaCapabilities(int major_version, int minor_version) { // end of CUDA Helper Functions -#endif // COMMON_HELPER_CUDA_H_ \ No newline at end of file +#endif // COMMON_HELPER_CUDA_H_ From c899d18b8ac513ee3ee6969a3f4ef7d57477f93d Mon Sep 17 00:00:00 2001 From: Levi Zhou <31941107+ZhouXY-PKU@users.noreply.github.com> Date: Fri, 12 Dec 2025 18:05:35 +0800 Subject: [PATCH 06/20] Update output_device.cpp --- source/source_base/module_device/output_device.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/source_base/module_device/output_device.cpp b/source/source_base/module_device/output_device.cpp index 24c55ef0bf..2d47919e23 100644 --- a/source/source_base/module_device/output_device.cpp +++ b/source/source_base/module_device/output_device.cpp @@ -2,7 +2,6 @@ #include "device.h" #include "source_base/tool_quit.h" -#include "source_base/module_device/cuda_compat.h" #include "source_io/module_parameter/parameter.h" #include @@ -15,6 +14,7 @@ #if defined(__CUDA) #include +#include "source_base/module_device/cuda_compat.h" #endif #if defined(__ROCM) From 359ce3b58675f69ca149f41edfb900ce3675e466 Mon Sep 17 00:00:00 2001 From: Levi Zhou <31941107+ZhouXY-PKU@users.noreply.github.com> Date: Fri, 12 Dec 2025 18:07:40 +0800 Subject: [PATCH 07/20] Update global.h --- source/source_pw/module_pwdft/global.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/source_pw/module_pwdft/global.h b/source/source_pw/module_pwdft/global.h index 60bf1ca17b..5d52c30436 100644 --- a/source/source_pw/module_pwdft/global.h +++ b/source/source_pw/module_pwdft/global.h @@ -3,7 +3,6 @@ #include "source_base/global_function.h" #include "source_base/global_variable.h" -#include "source_base/module_device/cuda_compat.h" #include "source_estate/module_charge/charge_mixing.h" #include "source_pw/module_pwdft/VNL_in_pw.h" #include "source_io/restart.h" @@ -17,6 +16,7 @@ #ifdef __CUDA #include "cublas_v2.h" #include "cufft.h" +#include "source_base/module_device/cuda_compat.h" static const char* _cublasGetErrorString(cublasStatus_t error) { From 67d413c4ad17508a0b399b4857548238b2962846 Mon Sep 17 00:00:00 2001 From: Levi Zhou <31941107+ZhouXY-PKU@users.noreply.github.com> Date: Sat, 13 Dec 2025 09:29:37 +0800 Subject: [PATCH 08/20] Update cuda_compat.h --- source/source_base/module_device/cuda_compat.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/source/source_base/module_device/cuda_compat.h b/source/source_base/module_device/cuda_compat.h index fdfa476068..699ce23cea 100644 --- a/source/source_base/module_device/cuda_compat.h +++ b/source/source_base/module_device/cuda_compat.h @@ -78,12 +78,4 @@ const char* cufftGetErrorStringCompat(cufftResult_t error); } // namespace cuda_compat } // namespace ModuleBase -//---------------------------------------------------------------------------- -// Macro Replacement for cuFFT Error Handling -// Any file that calls _cufftGetErrorString just needs to include this header. -//---------------------------------------------------------------------------- -#ifndef ABACUS_CUDA_COMPAT_NO_CUFFT_REDIRECT - #define _cufftGetErrorString ModuleBase::cuda_compat::cufftGetErrorStringCompat -#endif - #endif // CUDA_COMPAT_H_ From 62efb32ca73d8b56c1c6508e77fff0d91ac99595 Mon Sep 17 00:00:00 2001 From: Levi Zhou <31941107+ZhouXY-PKU@users.noreply.github.com> Date: Sat, 13 Dec 2025 10:21:25 +0800 Subject: [PATCH 09/20] Update global.h --- source/source_pw/module_pwdft/global.h | 44 +------------------------- 1 file changed, 1 insertion(+), 43 deletions(-) diff --git a/source/source_pw/module_pwdft/global.h b/source/source_pw/module_pwdft/global.h index 5d52c30436..bea93a9331 100644 --- a/source/source_pw/module_pwdft/global.h +++ b/source/source_pw/module_pwdft/global.h @@ -42,48 +42,6 @@ static const char* _cublasGetErrorString(cublasStatus_t error) return ""; } -static const char* _cufftGetErrorString(cufftResult_t error) -{ - switch (error) - { - case CUFFT_SUCCESS: - return "CUFFT_SUCCESS"; - case CUFFT_INVALID_PLAN: - return "CUFFT_INVALID_PLAN"; - case CUFFT_ALLOC_FAILED: - return "CUFFT_ALLOC_FAILED"; - case CUFFT_INVALID_TYPE: - return "CUFFT_INVALID_TYPE"; - case CUFFT_INVALID_VALUE: - return "CUFFT_INVALID_VALUE"; - case CUFFT_INTERNAL_ERROR: - return "CUFFT_INTERNAL_ERROR"; - case CUFFT_EXEC_FAILED: - return "CUFFT_EXEC_FAILED"; - case CUFFT_SETUP_FAILED: - return "CUFFT_SETUP_FAILED"; - case CUFFT_INVALID_SIZE: - return "CUFFT_INVALID_SIZE"; - case CUFFT_UNALIGNED_DATA: - return "CUFFT_UNALIGNED_DATA"; - case CUFFT_INCOMPLETE_PARAMETER_LIST: - return "CUFFT_INCOMPLETE_PARAMETER_LIST"; - case CUFFT_INVALID_DEVICE: - return "CUFFT_INVALID_DEVICE"; - case CUFFT_PARSE_ERROR: - return "CUFFT_PARSE_ERROR"; - case CUFFT_NO_WORKSPACE: - return "CUFFT_NO_WORKSPACE"; - case CUFFT_NOT_IMPLEMENTED: - return "CUFFT_NOT_IMPLEMENTED"; - case CUFFT_LICENSE_ERROR: - return "CUFFT_LICENSE_ERROR"; - case CUFFT_NOT_SUPPORTED: - return "CUFFT_NOT_SUPPORTED"; - } - return ""; -} - #define CHECK_CUDA(func) \ { \ cudaError_t status = (func); \ @@ -120,7 +78,7 @@ static const char* _cufftGetErrorString(cufftResult_t error) if (status != CUFFT_SUCCESS) \ { \ printf("In File %s : CUFFT API failed at line %d with error: %s (%d)\n", __FILE__, __LINE__, \ - _cufftGetErrorString(status), status); \ + ModuleBase::cuda_compat::cufftGetErrorStringCompat(status), status); \ } \ } #endif // __CUDA From f16f4718d17d63c906ff6b12224394fd2be33a16 Mon Sep 17 00:00:00 2001 From: Levi Zhou <31941107+ZhouXY-PKU@users.noreply.github.com> Date: Sat, 13 Dec 2025 10:51:23 +0800 Subject: [PATCH 10/20] Update helper_cuda.h --- .../source_hsolver/kernels/cuda/helper_cuda.h | 55 +------------------ 1 file changed, 1 insertion(+), 54 deletions(-) diff --git a/source/source_hsolver/kernels/cuda/helper_cuda.h b/source/source_hsolver/kernels/cuda/helper_cuda.h index 79c7926f9e..bc4f5ef85a 100644 --- a/source/source_hsolver/kernels/cuda/helper_cuda.h +++ b/source/source_hsolver/kernels/cuda/helper_cuda.h @@ -109,60 +109,7 @@ static const char *_cudaGetErrorEnum(cublasStatus_t error) { #ifdef _CUFFT_H_ // cuFFT API errors static const char *_cudaGetErrorEnum(cufftResult error) { - switch (error) { - case CUFFT_SUCCESS: - return "CUFFT_SUCCESS"; - - case CUFFT_INVALID_PLAN: - return "CUFFT_INVALID_PLAN"; - - case CUFFT_ALLOC_FAILED: - return "CUFFT_ALLOC_FAILED"; - - case CUFFT_INVALID_TYPE: - return "CUFFT_INVALID_TYPE"; - - case CUFFT_INVALID_VALUE: - return "CUFFT_INVALID_VALUE"; - - case CUFFT_INTERNAL_ERROR: - return "CUFFT_INTERNAL_ERROR"; - - case CUFFT_EXEC_FAILED: - return "CUFFT_EXEC_FAILED"; - - case CUFFT_SETUP_FAILED: - return "CUFFT_SETUP_FAILED"; - - case CUFFT_INVALID_SIZE: - return "CUFFT_INVALID_SIZE"; - - case CUFFT_UNALIGNED_DATA: - return "CUFFT_UNALIGNED_DATA"; - - case CUFFT_INCOMPLETE_PARAMETER_LIST: - return "CUFFT_INCOMPLETE_PARAMETER_LIST"; - - case CUFFT_INVALID_DEVICE: - return "CUFFT_INVALID_DEVICE"; - - case CUFFT_PARSE_ERROR: - return "CUFFT_PARSE_ERROR"; - - case CUFFT_NO_WORKSPACE: - return "CUFFT_NO_WORKSPACE"; - - case CUFFT_NOT_IMPLEMENTED: - return "CUFFT_NOT_IMPLEMENTED"; - - case CUFFT_LICENSE_ERROR: - return "CUFFT_LICENSE_ERROR"; - - case CUFFT_NOT_SUPPORTED: - return "CUFFT_NOT_SUPPORTED"; - } - - return ""; + return ModuleBase::cuda_compat::cufftGetErrorStringCompat(error) } #endif From 4caacaf93274d3e557159a8cc1e83b0f7a179ea5 Mon Sep 17 00:00:00 2001 From: Levi Zhou <31941107+ZhouXY-PKU@users.noreply.github.com> Date: Sat, 13 Dec 2025 11:03:53 +0800 Subject: [PATCH 11/20] Update helper_cuda.h --- source/source_hsolver/kernels/cuda/helper_cuda.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/source_hsolver/kernels/cuda/helper_cuda.h b/source/source_hsolver/kernels/cuda/helper_cuda.h index bc4f5ef85a..4e97a98dea 100644 --- a/source/source_hsolver/kernels/cuda/helper_cuda.h +++ b/source/source_hsolver/kernels/cuda/helper_cuda.h @@ -109,7 +109,7 @@ static const char *_cudaGetErrorEnum(cublasStatus_t error) { #ifdef _CUFFT_H_ // cuFFT API errors static const char *_cudaGetErrorEnum(cufftResult error) { - return ModuleBase::cuda_compat::cufftGetErrorStringCompat(error) + return ModuleBase::cuda_compat::cufftGetErrorStringCompat(error); } #endif From 78ddf6b97927dc8da62c95f7533f91442b12c3b0 Mon Sep 17 00:00:00 2001 From: Levi Zhou <31941107+ZhouXY-PKU@users.noreply.github.com> Date: Sat, 13 Dec 2025 11:26:18 +0800 Subject: [PATCH 12/20] Update CMakeLists.txt --- source/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index a4eaf0b197..4de8e373f5 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -81,6 +81,7 @@ if(USE_CUDA) source_pw/module_pwdft/kernels/cuda/stress_op.cu source_pw/module_pwdft/kernels/cuda/wf_op.cu source_pw/module_pwdft/kernels/cuda/vnl_op.cu + source_base/module_device/cuda_compat.cpp source_base/kernels/cuda/math_ylm_op.cu source_base/kernels/cuda/math_kernel_op.cu source_base/kernels/cuda/math_kernel_op_vec.cu From 0a2fadef121f2beffbd5a18faab7a9dfdbaa0d01 Mon Sep 17 00:00:00 2001 From: Levi Zhou <31941107+ZhouXY-PKU@users.noreply.github.com> Date: Sat, 13 Dec 2025 11:33:27 +0800 Subject: [PATCH 13/20] Update CMakeLists.txt --- source/source_io/test_serial/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/source/source_io/test_serial/CMakeLists.txt b/source/source_io/test_serial/CMakeLists.txt index 57a591d597..5f48fd9925 100644 --- a/source/source_io/test_serial/CMakeLists.txt +++ b/source/source_io/test_serial/CMakeLists.txt @@ -31,6 +31,7 @@ AddTest( ../../source_base/test/tool_quit_no_exit.cpp ../../source_base/module_device/device.cpp ../../source_base/module_device/output_device.cpp + ${CMAKE_SOURCE_DIR}/source_base/module_device/cuda_compat.cpp ) AddTest( From fc2fcd6ac669bf38d2de43b538b8af44c58fdcae Mon Sep 17 00:00:00 2001 From: Levi Zhou <31941107+ZhouXY-PKU@users.noreply.github.com> Date: Sat, 13 Dec 2025 11:40:04 +0800 Subject: [PATCH 14/20] Update CMakeLists.txt --- source/source_pw/module_pwdft/CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/source_pw/module_pwdft/CMakeLists.txt b/source/source_pw/module_pwdft/CMakeLists.txt index f958fdc75e..66b8521223 100644 --- a/source/source_pw/module_pwdft/CMakeLists.txt +++ b/source/source_pw/module_pwdft/CMakeLists.txt @@ -50,6 +50,12 @@ list(APPEND objects VSep_in_pw.cpp ) +if(USE_CUDA) + list(APPEND objects + source_base/module_device/cuda_compat.cpp + ) +endif() + add_library( module_pwdft OBJECT From 3fa8260b6263523210b8002dd70e3566b35e0552 Mon Sep 17 00:00:00 2001 From: Levi Zhou <31941107+ZhouXY-PKU@users.noreply.github.com> Date: Sat, 13 Dec 2025 12:01:49 +0800 Subject: [PATCH 15/20] Update CMakeLists.txt --- source/source_pw/module_pwdft/CMakeLists.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/source/source_pw/module_pwdft/CMakeLists.txt b/source/source_pw/module_pwdft/CMakeLists.txt index 66b8521223..f958fdc75e 100644 --- a/source/source_pw/module_pwdft/CMakeLists.txt +++ b/source/source_pw/module_pwdft/CMakeLists.txt @@ -50,12 +50,6 @@ list(APPEND objects VSep_in_pw.cpp ) -if(USE_CUDA) - list(APPEND objects - source_base/module_device/cuda_compat.cpp - ) -endif() - add_library( module_pwdft OBJECT From 0c121c1ec0c95f4c6275c8817d1b6da395f41746 Mon Sep 17 00:00:00 2001 From: Levi Zhou <31941107+ZhouXY-PKU@users.noreply.github.com> Date: Sat, 13 Dec 2025 12:07:17 +0800 Subject: [PATCH 16/20] Update CMakeLists.txt --- source/source_io/test_serial/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/source_io/test_serial/CMakeLists.txt b/source/source_io/test_serial/CMakeLists.txt index 5f48fd9925..fb52f8ab59 100644 --- a/source/source_io/test_serial/CMakeLists.txt +++ b/source/source_io/test_serial/CMakeLists.txt @@ -31,7 +31,7 @@ AddTest( ../../source_base/test/tool_quit_no_exit.cpp ../../source_base/module_device/device.cpp ../../source_base/module_device/output_device.cpp - ${CMAKE_SOURCE_DIR}/source_base/module_device/cuda_compat.cpp + ${CMAKE_SOURCE_DIR}/source/source_base/module_device/cuda_compat.cpp ) AddTest( From 01852cc3471e9fdcf8422cdd64254ce3c10a9c9a Mon Sep 17 00:00:00 2001 From: Levi Zhou <31941107+ZhouXY-PKU@users.noreply.github.com> Date: Sat, 13 Dec 2025 12:20:57 +0800 Subject: [PATCH 17/20] Update cuda_compat.cpp --- source/source_base/module_device/cuda_compat.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/source_base/module_device/cuda_compat.cpp b/source/source_base/module_device/cuda_compat.cpp index 8ce9e80c9c..f8ddbf2e86 100644 --- a/source/source_base/module_device/cuda_compat.cpp +++ b/source/source_base/module_device/cuda_compat.cpp @@ -6,7 +6,7 @@ namespace cuda_compat { //--------------------------------------------------------------------------- // Implementation of printDeprecatedDeviceInfo and printComputeModeInfo //--------------------------------------------------------------------------- -void printDeprecatedDeviceInfo(std::ostream& os, const cudaDeviceProp& prop) +void printDeprecatedDeviceInfo(std::ostream& ofs_device, const cudaDeviceProp& deviceProp) { #if defined(CUDA_VERSION) && CUDA_VERSION < 13000 char msg[1024]; @@ -36,7 +36,7 @@ void printDeprecatedDeviceInfo(std::ostream& os, const cudaDeviceProp& prop) #endif } -void printComputeModeInfo(std::ostream& os, const cudaDeviceProp& prop) +void printComputeModeInfo(std::ostream& ofs_device, const cudaDeviceProp& deviceProp) { #if defined(CUDA_VERSION) && CUDA_VERSION < 13000 char msg[1024]; From 24a363e4e1be1f117c868ace63437525bb211f3f Mon Sep 17 00:00:00 2001 From: Levi Zhou <31941107+ZhouXY-PKU@users.noreply.github.com> Date: Sat, 13 Dec 2025 14:40:24 +0800 Subject: [PATCH 18/20] Update cuda_compat.cpp --- source/source_base/module_device/cuda_compat.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/source/source_base/module_device/cuda_compat.cpp b/source/source_base/module_device/cuda_compat.cpp index f8ddbf2e86..4f84c38cfe 100644 --- a/source/source_base/module_device/cuda_compat.cpp +++ b/source/source_base/module_device/cuda_compat.cpp @@ -112,6 +112,5 @@ const char* cufftGetErrorStringCompat(cufftResult_t error) } } -} // cuda_compat } // namespace cuda_compat } // namespace ModuleBase From 154ddc2e8c803317448a440986250f574732fd11 Mon Sep 17 00:00:00 2001 From: Levi Zhou <31941107+ZhouXY-PKU@users.noreply.github.com> Date: Sat, 13 Dec 2025 16:00:37 +0800 Subject: [PATCH 19/20] Update CMakeLists.txt --- source/source_io/test_serial/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/source/source_io/test_serial/CMakeLists.txt b/source/source_io/test_serial/CMakeLists.txt index fb52f8ab59..57a591d597 100644 --- a/source/source_io/test_serial/CMakeLists.txt +++ b/source/source_io/test_serial/CMakeLists.txt @@ -31,7 +31,6 @@ AddTest( ../../source_base/test/tool_quit_no_exit.cpp ../../source_base/module_device/device.cpp ../../source_base/module_device/output_device.cpp - ${CMAKE_SOURCE_DIR}/source/source_base/module_device/cuda_compat.cpp ) AddTest( From fbd614197e6f0dde10dbc2750c930661df0bef9c Mon Sep 17 00:00:00 2001 From: Levi Zhou <31941107+ZhouXY-PKU@users.noreply.github.com> Date: Sat, 13 Dec 2025 16:12:07 +0800 Subject: [PATCH 20/20] Update CMakeLists.txt --- CMakeLists.txt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9438a1919a..37302f998f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -174,7 +174,9 @@ set(ABACUS_BIN_PATH ${CMAKE_CURRENT_BINARY_DIR}/${ABACUS_BIN_NAME}) include_directories(${ABACUS_SOURCE_DIR}) include_directories(${ABACUS_SOURCE_DIR}/source_base/module_container) -set(CMAKE_CXX_STANDARD 11) +if(NOT DEFINED CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 11) +endif() set(CMAKE_CXX_STANDARD_REQUIRED ON) add_executable(${ABACUS_BIN_NAME} source/source_main/main.cpp) @@ -330,6 +332,10 @@ endif() if(USE_CUDA) cmake_minimum_required(VERSION 3.18) # required by `CUDA_ARCHITECTURES` below set_if_higher(CMAKE_CXX_STANDARD 14) + if(CUDA_VERSION VERSION_GREATER_EQUAL "13.0") + message(STATUS "CUDA ${CUDA_VERSION} detected. Setting CMAKE_CUDA_STANDARD to 17.") + set_if_higher(CMAKE_CXX_STANDARD 17) + endif() set(CMAKE_CXX_EXTENSIONS ON) set(CMAKE_CUDA_STANDARD ${CMAKE_CXX_STANDARD}) set(CMAKE_CUDA_STANDARD_REQUIRED ON)