You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Refactor: Device module modernization and GPU initialization consolidation (Useful information for GPU coding) (deepmodeling#6936)
* Refactor: introduce DeviceContext singleton for unified GPU initialization
- Add DeviceContext singleton class (device_context.h/cpp) to manage GPU
device binding with thread-safe initialization using std::mutex
- Move GPU initialization from get_device_kpar() side-effect to explicit
DeviceContext::init() call in read_input.cpp after INPUT parsing
- Use MPI_COMM_TYPE_SHARED for modern node-local rank detection
- Update callers to use DeviceContext::instance().get_device_id():
- hsolver_lcao.cpp: parakSolve_cusolver()
- diag_cusolvermp.cu: constructor
- gint_gpu_vars.cpp: constructor
- td_nonlocal_lcao.cpp: remove redundant set_device_by_rank() call
This is Phase 1 of GPU resource initialization refactoring, establishing
a single entry point for GPU device binding instead of scattered calls.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Refactor: cleanup device.cpp and merge DeviceContext
Phase 2 of GPU device module refactoring:
- Remove deprecated functions: stringCmp, get_node_rank(), set_device_by_rank()
- Merge device_context.h/cpp into device.h/cpp
- Update include statements in dependent files
- Remove device_context.cpp from CMakeLists.txt
This reduces ~70 lines of dead code and consolidates the device
module into fewer files with a unified interface.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Refactor: modularize device module with single responsibility per file
- Create kernel_compat.h: move atomicAdd polyfill for pre-Pascal GPUs
- Create device_helpers.h/cpp: extract get_device_type and get_current_precision templates
- Create gpu_runtime.h: unified CUDA/ROCm API macros for portable GPU code
- Refactor output_device.cpp: unify duplicated CUDA/ROCm implementations (~150 lines reduced)
- Update device.h: clean interface with only DeviceContext and information namespace
- Update CMakeLists.txt: add device_helpers.cpp to build
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Refactor: simplify parakSolve_cusolver using DeviceContext
- Utilize DeviceContext for node-local rank and device count
- Remove redundant MPI_Comm_split_type and manual CUDA calls
- Cleanup unused variables and communicator management
* Refactor: remove redundant cudaGetDeviceCount in snap_psibeta_gpu
- Remove manual device count check in initialize_gpu_resources
- Rely on DeviceContext to handle device availability and binding
- Simplify GPU initialization logic in module_rt
* Refactor: rename initialize_gpu_resources to init_snap_psibeta_gpu
- Rename function to reflect its module-specific scope
- Update comments to clarify that general GPU setup is handled by DeviceContext
- Remove unused finalize_gpu_resources declaration
- Update caller in td_nonlocal_lcao.cpp
* Refactor: separate kernel_compat.h from device.h
Remove unconditional include of kernel_compat.h from device.h to
properly separate Host/Device code. The kernel_compat.h header
contains CUDA-specific code (__device__ keyword) and should only
be included by .cu files that actually use atomicAdd.
Add explicit includes to the 4 CUDA files that need it:
- stress_op.cu
- force_op.cu
- exx_cal_energy_op.cu
- phi_operator_kernel.cu
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Refactor: move get_device_kpar logic to read_input_item_system
Move GPU kpar validation from device module to kpar's reset_value
in read_input_item_system.cpp. This keeps parameter validation logic
with its related input item rather than in the device module.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Refactor: consolidate CUDA error checking macros into device_check.h
- Update device_check.h with proper error handling (exit on error, stderr output)
- Add cuSOLVER error string function with full IRS status codes
- Add CHECK_LAST_CUDA_ERROR, CHECK_CUDA_SYNC, CHECK_CAL macros
- Add ROCm CHECK_CUSOLVER support with hipsolver
- Remove error checking code from module_container/base/macros/cuda.h
- Remove error checking macros from helper_cuda.h
- Delete helper_cusolver.h (functionality merged into device_check.h)
- Update diag_cusolver.cu and diag_cusolvermp.cu to use new macros
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Refactor: replace old CUDA error macros with CHECK_* macros
- Replace cudaErrcheck -> CHECK_CUDA
- Replace cublasErrcheck -> CHECK_CUBLAS
- Replace cusolverErrcheck -> CHECK_CUSOLVER
- Replace checkCudaErrors -> CHECK_CUDA
- Replace CUSOLVER_CHECK -> CHECK_CUSOLVER
- Replace CAL_CHECK -> CHECK_CAL
- Replace cudaCheckOnDebug -> CHECK_CUDA_SYNC
- Replace getLastCudaError -> CHECK_LAST_CUDA_ERROR
- Update gpuErrcheck alias in gpu_runtime.h
- Remove deprecated compatibility aliases from device_check.h
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Refactor: remove CAL_CHECK compatibility alias from device_check.h
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Refactor: unify cufftGetErrorString into device_check.h
- Add _cufftGetErrorString static function to device_check.h
- Remove dependency on cuda_compat.h for cufft error strings
- Update CHECK_CUFFT macro to use the local function
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Refactor: remove cufftGetErrorStringCompat from cuda_compat
The function is now unified into device_check.h as _cufftGetErrorString.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Refactor: remove helper_cuda.h and helper_string.h
- Replaced helper_cuda.h with device_check.h in hegvd_op.cu and diag_cusolvermp.cu
- Removed helper_cuda.h and helper_string.h as they are no longer used
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Refactor: unify DeviceContext::init() interface for MPI and non-MPI builds
Remove conditional compilation from DeviceContext::init() signature.
Now both MPI and non-MPI builds use the same void init() interface,
with MPI_COMM_WORLD used internally in MPI builds.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Build: Fix CI failures for PyTest and CUDA test
1. PyTest: Add device_helpers.cpp to pyabacus ModuleBase build
- Fixes undefined symbol: get_device_type<DEVICE_CPU>
2. CUDA test: Add __CUDA definition for cusolver test target
- The test includes diag_cusolver.cu which needs CHECK_CUDA macros
- remove_definitions(-D__CUDA) at top of file removed the macro
- Re-add it specifically for this CUDA test target
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Test: Fix DiagoCusolver test to match new diag() interface
Update the test to use the new 4-parameter diag() interface:
- Old: diag(&hmtest, psi, eigenvalue)
- New: diag(h_mat, s_mat, psi, eigenvalue)
The test now properly extracts MatrixBlock from HamiltTEST before
calling diag().
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Refactor: replace custom CUDA error checks with unified device_check.h macros in module_gint
Replace checkCuda/checkCudaLastError with CHECK_CUDA/CHECK_LAST_CUDA_ERROR from device_check.h
to unify CUDA error handling across the codebase.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Refactor: replace remaining checkCuda with CHECK_CUDA in module_gint GPU files
Continue refactoring to use unified device_check.h macros in all module_gint GPU implementation files.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Refactor: replace CUDA_CHECK with CHECK_CUDA in module_rt/kernels/cuda
Remove custom CUDA_CHECK macro from snap_psibeta_kernel.cuh and use unified
CHECK_CUDA from device_check.h for consistent CUDA error handling.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Fix CUDA pre-6.0 atomicAdd compat in vbatched GEMM
* Add device_helpers to Makefile objects
---------
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
0 commit comments