diff --git a/source/source_pw/module_pwdft/hamilt_pw.cpp b/source/source_pw/module_pwdft/hamilt_pw.cpp index 27a56cbe11b..152e3451428 100644 --- a/source/source_pw/module_pwdft/hamilt_pw.cpp +++ b/source/source_pw/module_pwdft/hamilt_pw.cpp @@ -272,7 +272,7 @@ void HamiltPW::sPsi(const T* psi_in, // psi this->ppcell->nkb, &one, this->vkb, - this->ppcell->vkb.nc, + this->ppcell->vkbnc, psi_in, inc, &zero, @@ -288,7 +288,7 @@ void HamiltPW::sPsi(const T* psi_in, // psi npw, &one, this->vkb, - this->ppcell->vkb.nc, + this->ppcell->vkbnc, psi_in, nrow, &zero, @@ -360,7 +360,7 @@ void HamiltPW::sPsi(const T* psi_in, // psi this->ppcell->nkb, &one, this->vkb, - this->ppcell->vkb.nc, + this->ppcell->vkbnc, ps, inc, &one, @@ -376,7 +376,7 @@ void HamiltPW::sPsi(const T* psi_in, // psi this->ppcell->nkb, &one, this->vkb, - this->ppcell->vkb.nc, + this->ppcell->vkbnc, ps, this->ppcell->nkb, &one, diff --git a/source/source_pw/module_pwdft/op_pw_nl.cpp b/source/source_pw/module_pwdft/op_pw_nl.cpp index 0e5de357b1d..d3551808ea7 100644 --- a/source/source_pw/module_pwdft/op_pw_nl.cpp +++ b/source/source_pw/module_pwdft/op_pw_nl.cpp @@ -172,7 +172,7 @@ void Nonlocal>::add_nonlocal_pp(T *hpsi_in, const T *becp, this->ppcell->nkb, &this->one, this->vkb, - this->ppcell->vkb.nc, + this->ppcell->vkbnc, this->ps, inc, &this->one, @@ -197,7 +197,7 @@ void Nonlocal>::add_nonlocal_pp(T *hpsi_in, const T *becp, this->ppcell->nkb, &this->one, this->vkb, - this->ppcell->vkb.nc, + this->ppcell->vkbnc, this->ps, npm, &this->one, @@ -251,7 +251,7 @@ void Nonlocal>::act( nkb, &this->one, this->vkb, - this->ppcell->vkb.nc, + this->ppcell->vkbnc, tmpsi_in, inc, &this->zero, @@ -276,7 +276,7 @@ void Nonlocal>::act( this->npw, &this->one, this->vkb, - this->ppcell->vkb.nc, + this->ppcell->vkbnc, tmpsi_in, max_npw, &this->zero, diff --git a/source/source_pw/module_pwdft/vnl_pw.cpp b/source/source_pw/module_pwdft/vnl_pw.cpp index d6b5274d51f..83c42adac89 100644 --- a/source/source_pw/module_pwdft/vnl_pw.cpp +++ b/source/source_pw/module_pwdft/vnl_pw.cpp @@ -214,10 +214,17 @@ void pseudopot_cell_vnl::init(const UnitCell& ucell, // dq+4)*cell_factor; this->lmaxq = 2 * this->lmaxkb + 1; int npwx = this->wfcpw->npwk_max; + this->vkbnc = npwx; if (nkb > 0 && allocate_vkb) { - vkb.create(nkb, npwx); - ModuleBase::Memory::record("VNL::vkb", nkb * npwx * sizeof(std::complex)); + if (!this->use_gpu_) + { + vkb.create(nkb, npwx); + ModuleBase::Memory::record("VNL::vkb", nkb * npwx * sizeof(std::complex)); + } + // GPU path: vkb ComplexMatrix is not allocated. + // Column dimension is stored in vkbnc for gemm/gemv leading dimension. + // Actual GPU buffers (c_vkb/z_vkb) are allocated below. } // this->nqx = 10000; // calculted in allocate_nlpot.f90 diff --git a/source/source_pw/module_pwdft/vnl_pw.h b/source/source_pw/module_pwdft/vnl_pw.h index 93a593e9257..6282b138657 100644 --- a/source/source_pw/module_pwdft/vnl_pw.h +++ b/source/source_pw/module_pwdft/vnl_pw.h @@ -108,6 +108,10 @@ class pseudopot_cell_vnl std::complex*** vkb_alpha; Structure_Factor* psf = nullptr; + // Column dimension of vkb matrix (= npwx), used as leading dimension in gemm/gemv. + // On GPU path vkb ComplexMatrix is not allocated to save CPU memory; this stores the dimension. + int vkbnc = 0; + // other variables std::complex Cal_C(int alpha, int lu, int mu, int L, int M); diff --git a/source/source_pw/module_pwdft/vnl_pw_grad.cpp b/source/source_pw/module_pwdft/vnl_pw_grad.cpp index 135fe475944..65984cf581a 100644 --- a/source/source_pw/module_pwdft/vnl_pw_grad.cpp +++ b/source/source_pw/module_pwdft/vnl_pw_grad.cpp @@ -91,6 +91,11 @@ void pseudopot_cell_vnl::getgradq_vnl(const UnitCell& ucell, ModuleBase::YlmReal::grad_Ylm_Real(x1, npw, gk, ylm, dylm[0], dylm[1], dylm[2]); + // GPU path skips vkb allocation in init(); allocate now if needed + if (this->vkb.nc == 0 && this->nkb > 0 && this->vkbnc > 0) { + this->vkb.create(this->nkb, this->vkbnc); + } + int jkb = 0; for(int it = 0;it < ucell.ntype;it++) {