-
Notifications
You must be signed in to change notification settings - Fork 229
Feature: DeltaSpin for LCAO and PW base and DFTU for PW, both collinear and noncollinear spin (code change and UTs) #7384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
c582c1a
1ebccc9
694f6fb
f0a892a
ac27932
4ef2f30
cfc3141
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,8 @@ | |
| namespace container { | ||
| namespace cuSolverConnector { | ||
|
|
||
| #if CUDA_VERSION >= 11000 | ||
| // Generic API (CUDA 11.0+) | ||
| template <typename T> | ||
| static inline | ||
| void trtri (cusolverDnHandle_t& cusolver_handle, const char& uplo, const char& diag, const int& n, T* A, const int& lda) | ||
|
|
@@ -47,6 +49,57 @@ void trtri (cusolverDnHandle_t& cusolver_handle, const char& uplo, const char& d | |
| CHECK_CUDA(cudaFree(d_work)); | ||
| CHECK_CUDA(cudaFree(d_info)); | ||
| } | ||
| #else | ||
| // Legacy API fallback (CUDA < 11.0) | ||
| static inline void trtri(cusolverDnHandle_t& cusolver_handle, const char& uplo, const char& diag, const int& n, float* A, const int& lda) | ||
| { | ||
| int lwork = 0; | ||
| CHECK_CUSOLVER(cusolverDnStrtri_bufferSize(cusolver_handle, cublas_fill_mode(uplo), cublas_diag_type(diag), n, A, lda, &lwork)); | ||
| float* d_work = nullptr; | ||
| CHECK_CUDA(cudaMalloc((void**)&d_work, lwork * sizeof(float))); | ||
| int* d_info = nullptr; | ||
| CHECK_CUDA(cudaMalloc((void**)&d_info, sizeof(int))); | ||
| CHECK_CUSOLVER(cusolverDnStrtri(cusolver_handle, cublas_fill_mode(uplo), cublas_diag_type(diag), n, A, lda, d_work, lwork, d_info)); | ||
| CHECK_CUDA(cudaFree(d_work)); | ||
| CHECK_CUDA(cudaFree(d_info)); | ||
| } | ||
| static inline void trtri(cusolverDnHandle_t& cusolver_handle, const char& uplo, const char& diag, const int& n, double* A, const int& lda) | ||
| { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Should-fix] Even after fixing the non-existent symbols flagged above, the new functions allocate |
||
| int lwork = 0; | ||
| CHECK_CUSOLVER(cusolverDnDtrtri_bufferSize(cusolver_handle, cublas_fill_mode(uplo), cublas_diag_type(diag), n, A, lda, &lwork)); | ||
| double* d_work = nullptr; | ||
| CHECK_CUDA(cudaMalloc((void**)&d_work, lwork * sizeof(double))); | ||
| int* d_info = nullptr; | ||
| CHECK_CUDA(cudaMalloc((void**)&d_info, sizeof(int))); | ||
| CHECK_CUSOLVER(cusolverDnDtrtri(cusolver_handle, cublas_fill_mode(uplo), cublas_diag_type(diag), n, A, lda, d_work, lwork, d_info)); | ||
| CHECK_CUDA(cudaFree(d_work)); | ||
| CHECK_CUDA(cudaFree(d_info)); | ||
| } | ||
| static inline void trtri(cusolverDnHandle_t& cusolver_handle, const char& uplo, const char& diag, const int& n, std::complex<float>* A, const int& lda) | ||
| { | ||
| int lwork = 0; | ||
| CHECK_CUSOLVER(cusolverDnCtrtri_bufferSize(cusolver_handle, cublas_fill_mode(uplo), cublas_diag_type(diag), n, reinterpret_cast<cuComplex*>(A), lda, &lwork)); | ||
| cuComplex* d_work = nullptr; | ||
| CHECK_CUDA(cudaMalloc((void**)&d_work, lwork * sizeof(cuComplex))); | ||
| int* d_info = nullptr; | ||
| CHECK_CUDA(cudaMalloc((void**)&d_info, sizeof(int))); | ||
| CHECK_CUSOLVER(cusolverDnCtrtri(cusolver_handle, cublas_fill_mode(uplo), cublas_diag_type(diag), n, reinterpret_cast<cuComplex*>(A), lda, d_work, lwork, d_info)); | ||
| CHECK_CUDA(cudaFree(d_work)); | ||
| CHECK_CUDA(cudaFree(d_info)); | ||
| } | ||
| static inline void trtri(cusolverDnHandle_t& cusolver_handle, const char& uplo, const char& diag, const int& n, std::complex<double>* A, const int& lda) | ||
| { | ||
| int lwork = 0; | ||
| CHECK_CUSOLVER(cusolverDnZtrtri_bufferSize(cusolver_handle, cublas_fill_mode(uplo), cublas_diag_type(diag), n, reinterpret_cast<cuDoubleComplex*>(A), lda, &lwork)); | ||
| cuDoubleComplex* d_work = nullptr; | ||
| CHECK_CUDA(cudaMalloc((void**)&d_work, lwork * sizeof(cuDoubleComplex))); | ||
| int* d_info = nullptr; | ||
| CHECK_CUDA(cudaMalloc((void**)&d_info, sizeof(int))); | ||
| CHECK_CUSOLVER(cusolverDnZtrtri(cusolver_handle, cublas_fill_mode(uplo), cublas_diag_type(diag), n, reinterpret_cast<cuDoubleComplex*>(A), lda, d_work, lwork, d_info)); | ||
| CHECK_CUDA(cudaFree(d_work)); | ||
| CHECK_CUDA(cudaFree(d_info)); | ||
| } | ||
| #endif | ||
|
|
||
| static inline | ||
| void potri (cusolverDnHandle_t& cusolver_handle, const char& uplo, const char& diag, const int& n, float * A, const int& lda) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -453,6 +453,9 @@ bool parse_atom_properties(std::ifstream& ifpos, | |
| atom.lambda[ia].x /= ModuleBase::Ry_to_eV; | ||
| atom.lambda[ia].y /= ModuleBase::Ry_to_eV; | ||
| atom.lambda[ia].z /= ModuleBase::Ry_to_eV; | ||
| std::cout << "[DS-DIAG] STRU parse: lambda[" << ia << "]=(" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Blocker] Stray diagnostic |
||
| << atom.lambda[ia].x << ", " << atom.lambda[ia].y << ", " | ||
| << atom.lambda[ia].z << ") Ry/uB (converted from eV/uB)" << std::endl; | ||
| } | ||
| else if ( tmpid == "sc") | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,8 @@ | |
|
|
||
| #include "elecstate.h" | ||
| #include "source_estate/module_dm/density_matrix.h" | ||
| #include "source_basis/module_ao/parallel_orbitals.h" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Should-fix] Two new includes here ( |
||
| #include "source_cell/klist.h" | ||
|
|
||
| #include <vector> | ||
|
|
||
|
|
@@ -24,12 +26,7 @@ class ElecStateLCAO : public ElecState | |
| this->classname = "ElecStateLCAO"; | ||
| } | ||
|
|
||
| virtual ~ElecStateLCAO() | ||
| { | ||
| } | ||
|
|
||
| // update charge density for next scf step | ||
| // void getNewRho() override; | ||
| virtual ~ElecStateLCAO() = default; | ||
|
|
||
| static int out_wfc_lcao; | ||
| static bool need_psi_grid; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -257,3 +257,34 @@ bool Charge_Mixing::if_scf_oscillate(const int iteration, const double drho, con | |
|
|
||
| return false; | ||
| } | ||
|
|
||
| void Charge_Mixing::allocate_mixing_uom(int uom_size) | ||
| { | ||
| ModuleBase::TITLE("Charge_Mixing", "allocate_mixing_uom"); | ||
| ModuleBase::timer::start("Charge_Mixing", "allocate_mixing_uom"); | ||
| ModuleBase::timer::end("Charge_Mixing", "allocate_mixing_uom"); | ||
| // For nspin=2, uom_size already includes both spin channels | ||
| // (eff_pot_pw.size() = pot_index * 2 for nspin=2) | ||
| // So uom_fold should always be 1 | ||
| this->mixing->init_mixing_data(this->uom_mdata, uom_size, sizeof(double)); | ||
| this->uom_mdata.reset(); | ||
| ModuleBase::timer::start("Charge_Mixing", "allocate_mixing_uom"); | ||
| ModuleBase::timer::end("Charge_Mixing", "allocate_mixing_uom"); | ||
| return; | ||
| } | ||
|
|
||
| void Charge_Mixing::mix_uom(std::vector<double>& uom_in, std::vector<double>& uom_save_in) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Blocker] Two problems with
|
||
| { | ||
| ModuleBase::TITLE("Charge_Mixing", "mix_uom"); | ||
| ModuleBase::timer::start("Charge_Mixing", "mix_uom"); | ||
| ModuleBase::timer::end("Charge_Mixing", "mix_uom"); | ||
| double* uom_value_out = uom_in.data(); | ||
| double* uom_value_in = uom_save_in.data(); | ||
| // For all nspin cases, uom_array layout is already fully sized | ||
| // and mixing operates on the entire array | ||
| this->mixing->push_data(this->uom_mdata, uom_value_in, uom_value_out, nullptr, false); | ||
| this->mixing->mix_data(this->uom_mdata, uom_value_out); | ||
| ModuleBase::timer::start("Charge_Mixing", "mix_uom"); | ||
| ModuleBase::timer::end("Charge_Mixing", "mix_uom"); | ||
| return; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Blocker] The
#if CUDA_VERSION < 11000fallback callscusolverDnStrtri_bufferSize/cusolverDnStrtri(andD/C/Zvariants below). These symbols do not exist in any cuSOLVER release — only the genericcusolverDnXtrtri(CUDA 11.0+, used by the#if … >= 11000branch above) and the batchedcublas{S,D,C,Z}trtri_batchedexist. Any build with CUDA < 11 will fail to link with undefined references tocusolverDn{S,D,C,Z}trtri.Options:
module_container/base/macros/cuda.h:25-31which already guardsGetTypeCuda<int64_t>onCUDA_VERSION >= 11000.cublas{S,D,C,Z}trtri_batched(withbatchCount=1).