diff --git a/source/Makefile.Objects b/source/Makefile.Objects index 4b8288b5f5..6d310cf975 100644 --- a/source/Makefile.Objects +++ b/source/Makefile.Objects @@ -510,6 +510,7 @@ OBJS_XC=xc_functional.o\ xc_funct_exch_gga.o\ xc_funct_corr_gga.o\ xc_funct_hcth.o\ + exx_info.o\ OBJS_IO=input_conv.o\ berryphase.o\ diff --git a/source/source_base/module_device/device_check.h b/source/source_base/module_device/device_check.h new file mode 100644 index 0000000000..a708cc1d7f --- /dev/null +++ b/source/source_base/module_device/device_check.h @@ -0,0 +1,182 @@ +#ifndef DEVICE_CHECK_H +#define DEVICE_CHECK_H + +#include + +#ifdef __CUDA +#include "cublas_v2.h" +#include "cufft.h" +#include "source_base/module_device/cuda_compat.h" + +static const char* _cublasGetErrorString(cublasStatus_t error) +{ + switch (error) + { + case CUBLAS_STATUS_SUCCESS: + return "CUBLAS_STATUS_SUCCESS"; + case CUBLAS_STATUS_NOT_INITIALIZED: + return "CUBLAS_STATUS_NOT_INITIALIZED"; + case CUBLAS_STATUS_ALLOC_FAILED: + return "CUBLAS_STATUS_ALLOC_FAILED"; + case CUBLAS_STATUS_INVALID_VALUE: + return "CUBLAS_STATUS_INVALID_VALUE"; + case CUBLAS_STATUS_ARCH_MISMATCH: + return "CUBLAS_STATUS_ARCH_MISMATCH"; + case CUBLAS_STATUS_MAPPING_ERROR: + return "CUBLAS_STATUS_MAPPING_ERROR"; + case CUBLAS_STATUS_EXECUTION_FAILED: + return "CUBLAS_STATUS_EXECUTION_FAILED"; + case CUBLAS_STATUS_INTERNAL_ERROR: + return "CUBLAS_STATUS_INTERNAL_ERROR"; + } + return ""; +} + +#define CHECK_CUDA(func) \ + { \ + cudaError_t status = (func); \ + if (status != cudaSuccess) \ + { \ + printf("In File %s : CUDA API failed at line %d with error: %s (%d)\n", __FILE__, __LINE__, \ + cudaGetErrorString(status), status); \ + } \ + } + +#define CHECK_CUBLAS(func) \ + { \ + cublasStatus_t status = (func); \ + if (status != CUBLAS_STATUS_SUCCESS) \ + { \ + printf("In File %s : CUBLAS API failed at line %d with error: %s (%d)\n", __FILE__, __LINE__, \ + _cublasGetErrorString(status), status); \ + } \ + } + +#define CHECK_CUSOLVER(func) \ + { \ + cusolverStatus_t status = (func); \ + if (status != CUSOLVER_STATUS_SUCCESS) \ + { \ + printf("In File %s : CUSOLVER API failed at line %d with error: %s (%d)\n", __FILE__, __LINE__, \ + _cusolverGetErrorString(status), status); \ + } \ + } + +#define CHECK_CUFFT(func) \ + { \ + cufftResult_t status = (func); \ + if (status != CUFFT_SUCCESS) \ + { \ + printf("In File %s : CUFFT API failed at line %d with error: %s (%d)\n", __FILE__, __LINE__, \ + ModuleBase::cuda_compat::cufftGetErrorStringCompat(status), status); \ + } \ + } +#endif // __CUDA + +#ifdef __ROCM +#include +#include +#include + +static const char* _hipblasGetErrorString(hipblasStatus_t error) +{ + switch (error) + { + case HIPBLAS_STATUS_SUCCESS: + return "HIPBLAS_STATUS_SUCCESS"; + case HIPBLAS_STATUS_NOT_INITIALIZED: + return "HIPBLAS_STATUS_NOT_INITIALIZED"; + case HIPBLAS_STATUS_ALLOC_FAILED: + return "HIPBLAS_STATUS_ALLOC_FAILED"; + case HIPBLAS_STATUS_INVALID_VALUE: + return "HIPBLAS_STATUS_INVALID_VALUE"; + case HIPBLAS_STATUS_ARCH_MISMATCH: + return "HIPBLAS_STATUS_ARCH_MISMATCH"; + case HIPBLAS_STATUS_MAPPING_ERROR: + return "HIPBLAS_STATUS_MAPPING_ERROR"; + case HIPBLAS_STATUS_EXECUTION_FAILED: + return "HIPBLAS_STATUS_EXECUTION_FAILED"; + case HIPBLAS_STATUS_INTERNAL_ERROR: + return "HIPBLAS_STATUS_INTERNAL_ERROR"; + case HIPBLAS_STATUS_NOT_SUPPORTED: + return "HIPBLAS_STATUS_NOT_SUPPORTED"; + case HIPBLAS_STATUS_HANDLE_IS_NULLPTR: + return "HIPBLAS_STATUS_HANDLE_IS_NULLPTR"; + default: + return ""; + } + return ""; +} + +static const char* _hipfftGetErrorString(hipfftResult_t error) +{ + switch (error) + { + case HIPFFT_SUCCESS: + return "HIPFFT_SUCCESS"; + case HIPFFT_INVALID_PLAN: + return "HIPFFT_INVALID_PLAN"; + case HIPFFT_ALLOC_FAILED: + return "HIPFFT_ALLOC_FAILED"; + case HIPFFT_INVALID_TYPE: + return "HIPFFT_INVALID_TYPE"; + case HIPFFT_INVALID_VALUE: + return "HIPFFT_INVALID_VALUE"; + case HIPFFT_INTERNAL_ERROR: + return "HIPFFT_INTERNAL_ERROR"; + case HIPFFT_EXEC_FAILED: + return "HIPFFT_EXEC_FAILED"; + case HIPFFT_SETUP_FAILED: + return "HIPFFT_SETUP_FAILED"; + case HIPFFT_INVALID_SIZE: + return "HIPFFT_INVALID_SIZE"; + case HIPFFT_UNALIGNED_DATA: + return "HIPFFT_UNALIGNED_DATA"; + case HIPFFT_INCOMPLETE_PARAMETER_LIST: + return "HIPFFT_INCOMPLETE_PARAMETER_LIST"; + case HIPFFT_INVALID_DEVICE: + return "HIPFFT_INVALID_DEVICE"; + case HIPFFT_PARSE_ERROR: + return "HIPFFT_PARSE_ERROR"; + case HIPFFT_NO_WORKSPACE: + return "HIPFFT_NO_WORKSPACE"; + case HIPFFT_NOT_IMPLEMENTED: + return "HIPFFT_NOT_IMPLEMENTED"; + case HIPFFT_NOT_SUPPORTED: + return "HIPFFT_NOT_SUPPORTED"; + } + return ""; +} + +#define CHECK_CUDA(func) \ + { \ + hipError_t status = (func); \ + if (status != hipSuccess) \ + { \ + printf("In File %s : HIP API failed at line %d with error: %s (%d)\n", __FILE__, __LINE__, \ + hipGetErrorString(status), status); \ + } \ + } + +#define CHECK_CUBLAS(func) \ + { \ + hipblasStatus_t status = (func); \ + if (status != HIPBLAS_STATUS_SUCCESS) \ + { \ + printf("In File %s : HIPBLAS API failed at line %d with error: %s (%d)\n", __FILE__, __LINE__, \ + _hipblasGetErrorString(status), status); \ + } \ + } + +#define CHECK_CUFFT(func) \ + { \ + hipfftResult_t status = (func); \ + if (status != HIPFFT_SUCCESS) \ + { \ + printf("In File %s : HIPFFT API failed at line %d with error: %s (%d)\n", __FILE__, __LINE__, \ + _hipfftGetErrorString(status), status); \ + } \ + } +#endif // __ROCM + +#endif // DEVICE_CHECK_H \ No newline at end of file diff --git a/source/source_hamilt/module_xc/CMakeLists.txt b/source/source_hamilt/module_xc/CMakeLists.txt index 4db1ef083d..9d38b59fa2 100644 --- a/source/source_hamilt/module_xc/CMakeLists.txt +++ b/source/source_hamilt/module_xc/CMakeLists.txt @@ -17,6 +17,7 @@ add_library( xc_functional_libxc_wrapper_xc.cpp xc_functional_libxc_wrapper_gcxc.cpp xc_functional_libxc_wrapper_tauxc.cpp + exx_info.cpp ) if(ENABLE_COVERAGE) diff --git a/source/source_hamilt/module_xc/exx_info.cpp b/source/source_hamilt/module_xc/exx_info.cpp new file mode 100644 index 0000000000..8416891052 --- /dev/null +++ b/source/source_hamilt/module_xc/exx_info.cpp @@ -0,0 +1,9 @@ +#include "exx_info.h" + +//---------------------------------------------------------- +// init "GLOBAL CLASS" object +//---------------------------------------------------------- +namespace GlobalC +{ + Exx_Info exx_info; +} \ No newline at end of file diff --git a/source/source_hamilt/module_xc/exx_info.h b/source/source_hamilt/module_xc/exx_info.h index 5cca433b94..55ae60668f 100644 --- a/source/source_hamilt/module_xc/exx_info.h +++ b/source/source_hamilt/module_xc/exx_info.h @@ -95,4 +95,12 @@ struct Exx_Info } }; +//========================================================== +// EXPLAIN : define "GLOBAL CLASS" +//========================================================== +namespace GlobalC +{ + extern Exx_Info exx_info; +} // namespace GlobalC + #endif diff --git a/source/source_pw/module_pwdft/global.cpp b/source/source_pw/module_pwdft/global.cpp index f483101fe2..fd2195162d 100644 --- a/source/source_pw/module_pwdft/global.cpp +++ b/source/source_pw/module_pwdft/global.cpp @@ -4,9 +4,6 @@ //---------------------------------------------------------- namespace GlobalC { -#ifdef __EXX - Exx_Info exx_info; -#endif Restart restart; // Peize Lin add 2020.04.04 } diff --git a/source/source_pw/module_pwdft/global.h b/source/source_pw/module_pwdft/global.h index bea93a9331..d25b26ef9f 100644 --- a/source/source_pw/module_pwdft/global.h +++ b/source/source_pw/module_pwdft/global.h @@ -13,211 +13,11 @@ #endif #include "source_estate/magnetism.h" #include "source_hamilt/module_xc/xc_functional.h" -#ifdef __CUDA -#include "cublas_v2.h" -#include "cufft.h" -#include "source_base/module_device/cuda_compat.h" - -static const char* _cublasGetErrorString(cublasStatus_t error) -{ - switch (error) - { - case CUBLAS_STATUS_SUCCESS: - return "CUBLAS_STATUS_SUCCESS"; - case CUBLAS_STATUS_NOT_INITIALIZED: - return "CUBLAS_STATUS_NOT_INITIALIZED"; - case CUBLAS_STATUS_ALLOC_FAILED: - return "CUBLAS_STATUS_ALLOC_FAILED"; - case CUBLAS_STATUS_INVALID_VALUE: - return "CUBLAS_STATUS_INVALID_VALUE"; - case CUBLAS_STATUS_ARCH_MISMATCH: - return "CUBLAS_STATUS_ARCH_MISMATCH"; - case CUBLAS_STATUS_MAPPING_ERROR: - return "CUBLAS_STATUS_MAPPING_ERROR"; - case CUBLAS_STATUS_EXECUTION_FAILED: - return "CUBLAS_STATUS_EXECUTION_FAILED"; - case CUBLAS_STATUS_INTERNAL_ERROR: - return "CUBLAS_STATUS_INTERNAL_ERROR"; - } - return ""; -} - -#define CHECK_CUDA(func) \ - { \ - cudaError_t status = (func); \ - if (status != cudaSuccess) \ - { \ - printf("In File %s : CUDA API failed at line %d with error: %s (%d)\n", __FILE__, __LINE__, \ - cudaGetErrorString(status), status); \ - } \ - } - -#define CHECK_CUBLAS(func) \ - { \ - cublasStatus_t status = (func); \ - if (status != CUBLAS_STATUS_SUCCESS) \ - { \ - printf("In File %s : CUBLAS API failed at line %d with error: %s (%d)\n", __FILE__, __LINE__, \ - _cublasGetErrorString(status), status); \ - } \ - } - -#define CHECK_CUSOLVER(func) \ - { \ - cusolverStatus_t status = (func); \ - if (status != CUSOLVER_STATUS_SUCCESS) \ - { \ - printf("In File %s : CUSOLVER API failed at line %d with error: %s (%d)\n", __FILE__, __LINE__, \ - _cusolverGetErrorString(status), status); \ - } \ - } - -#define CHECK_CUFFT(func) \ - { \ - cufftResult_t status = (func); \ - if (status != CUFFT_SUCCESS) \ - { \ - printf("In File %s : CUFFT API failed at line %d with error: %s (%d)\n", __FILE__, __LINE__, \ - ModuleBase::cuda_compat::cufftGetErrorStringCompat(status), status); \ - } \ - } -#endif // __CUDA - -#ifdef __ROCM -#include -#include -#include - -static const char* _hipblasGetErrorString(hipblasStatus_t error) -{ - switch (error) - { - case HIPBLAS_STATUS_SUCCESS: - return "HIPBLAS_STATUS_SUCCESS"; - case HIPBLAS_STATUS_NOT_INITIALIZED: - return "HIPBLAS_STATUS_NOT_INITIALIZED"; - case HIPBLAS_STATUS_ALLOC_FAILED: - return "HIPBLAS_STATUS_ALLOC_FAILED"; - case HIPBLAS_STATUS_INVALID_VALUE: - return "HIPBLAS_STATUS_INVALID_VALUE"; - case HIPBLAS_STATUS_ARCH_MISMATCH: - return "HIPBLAS_STATUS_ARCH_MISMATCH"; - case HIPBLAS_STATUS_MAPPING_ERROR: - return "HIPBLAS_STATUS_MAPPING_ERROR"; - case HIPBLAS_STATUS_EXECUTION_FAILED: - return "HIPBLAS_STATUS_EXECUTION_FAILED"; - case HIPBLAS_STATUS_INTERNAL_ERROR: - return "HIPBLAS_STATUS_INTERNAL_ERROR"; - case HIPBLAS_STATUS_NOT_SUPPORTED: - return "HIPBLAS_STATUS_NOT_SUPPORTED"; - case HIPBLAS_STATUS_HANDLE_IS_NULLPTR: - return "HIPBLAS_STATUS_HANDLE_IS_NULLPTR"; - default: - return ""; - } - return ""; -} - -// static const char *_rocsolverGetErrorString(rocsolver_status error) -// { -// switch (error) -// { -// // case ROCSOLVER_STATUS_SUCCESS: -// // return "CUSOLVER_STATUS_SUCCESS"; -// } -// return ""; -// } - -static const char* _hipfftGetErrorString(hipfftResult_t error) -{ - switch (error) - { - case HIPFFT_SUCCESS: - return "HIPFFT_SUCCESS"; - case HIPFFT_INVALID_PLAN: - return "HIPFFT_INVALID_PLAN"; - case HIPFFT_ALLOC_FAILED: - return "HIPFFT_ALLOC_FAILED"; - case HIPFFT_INVALID_TYPE: - return "HIPFFT_INVALID_TYPE"; - case HIPFFT_INVALID_VALUE: - return "HIPFFT_INVALID_VALUE"; - case HIPFFT_INTERNAL_ERROR: - return "HIPFFT_INTERNAL_ERROR"; - case HIPFFT_EXEC_FAILED: - return "HIPFFT_EXEC_FAILED"; - case HIPFFT_SETUP_FAILED: - return "HIPFFT_SETUP_FAILED"; - case HIPFFT_INVALID_SIZE: - return "HIPFFT_INVALID_SIZE"; - case HIPFFT_UNALIGNED_DATA: - return "HIPFFT_UNALIGNED_DATA"; - case HIPFFT_INCOMPLETE_PARAMETER_LIST: - return "HIPFFT_INCOMPLETE_PARAMETER_LIST"; - case HIPFFT_INVALID_DEVICE: - return "HIPFFT_INVALID_DEVICE"; - case HIPFFT_PARSE_ERROR: - return "HIPFFT_PARSE_ERROR"; - case HIPFFT_NO_WORKSPACE: - return "HIPFFT_NO_WORKSPACE"; - case HIPFFT_NOT_IMPLEMENTED: - return "HIPFFT_NOT_IMPLEMENTED"; - case HIPFFT_NOT_SUPPORTED: - return "HIPFFT_NOT_SUPPORTED"; - } - return ""; -} - -#define CHECK_CUDA(func) \ - { \ - hipError_t status = (func); \ - if (status != hipSuccess) \ - { \ - printf("In File %s : HIP API failed at line %d with error: %s (%d)\n", __FILE__, __LINE__, \ - hipGetErrorString(status), status); \ - } \ - } - -#define CHECK_CUBLAS(func) \ - { \ - hipblasStatus_t status = (func); \ - if (status != HIPBLAS_STATUS_SUCCESS) \ - { \ - printf("In File %s : HIPBLAS API failed at line %d with error: %s (%d)\n", __FILE__, __LINE__, \ - _hipblasGetErrorString(status), status); \ - } \ - } - -// #define CHECK_CUSOLVER(func)\ -// {\ -// rocsolver_status status = (func);\ -// if(status != CUSOLVER_STATUS_SUCCESS)\ -// {\ -// printf("In File %s : CUSOLVER API failed at line %d with error: %s (%d)\n",\ -// __FILE__, __LINE__, _rocsolverGetErrorString(status), status);\ -// }\ -// } - -#define CHECK_CUFFT(func) \ - { \ - hipfftResult_t status = (func); \ - if (status != HIPFFT_SUCCESS) \ - { \ - printf("In File %s : HIPFFT API failed at line %d with error: %s (%d)\n", __FILE__, __LINE__, \ - _hipfftGetErrorString(status), status); \ - } \ - } -#endif // __ROCM +#include "source_base/module_device/device_check.h" //========================================================== // EXPLAIN : define "GLOBAL CLASS" //========================================================== -namespace GlobalC -{ -//#ifdef __EXX - extern Exx_Info exx_info; -//#endif -} // namespace GlobalC #include "source_cell/parallel_kpoints.h" #include "source_cell/unitcell.h" diff --git a/source/source_pw/module_pwdft/module_exx_helper/exx_helper.cpp b/source/source_pw/module_pwdft/module_exx_helper/exx_helper.cpp index 1b41163967..db0a2aa49a 100644 --- a/source/source_pw/module_pwdft/module_exx_helper/exx_helper.cpp +++ b/source/source_pw/module_pwdft/module_exx_helper/exx_helper.cpp @@ -57,10 +57,3 @@ template class Exx_Helper, base_device::DEVICE_GPU>; template class Exx_Helper, base_device::DEVICE_GPU>; #endif -#ifndef __EXX -#include "source_hamilt/module_xc/exx_info.h" -namespace GlobalC -{ - Exx_Info exx_info; -} -#endif \ No newline at end of file