Skip to content

Commit d89800f

Browse files
committed
DeltaP cleanup: remove unused subspace code + GPU stub comments
- Remove saved subspace data (s_sub_h/s/s_becp) that was never consumed. The subspace save code is preserved in git history (ad25e6b) for Phase D.2 implementation. - Remove unused includes (diago_iter_assist, hamilt.h). - Add explanatory comments to GPU float stubs. - Clean up dead nh_iat variable. BN LCAO + PW regression pass.
1 parent 00ce1e2 commit d89800f

2 files changed

Lines changed: 11 additions & 41 deletions

File tree

source/source_pw/module_pwdft/deltap_pw.cpp

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
#include "source_cell/klist.h"
77
#include "source_cell/unitcell.h"
88
#include "source_pw/module_pwdft/onsite_proj.h"
9-
#include "source_hsolver/diago_iter_assist.h"
10-
#include "source_hamilt/hamilt.h"
119
#include "source_base/constants.h"
1210
#include <iomanip>
1311
#include <iostream>
@@ -22,14 +20,7 @@ namespace {
2220
std::vector<int> s_constrain; // per-atom constrain flags
2321
double s_gamma_total = 0.0; // cached total gamma from last computation
2422
double s_dp_escon = 0.0; // cached dp_escon from last computation
25-
void* s_hamilt = nullptr; // stored HamiltPW pointer for inner loop
26-
27-
// Subspace data for inner lambda loop (saved once per SCF, reused across inner steps)
28-
bool s_sub_saved = false;
29-
std::vector<std::complex<double>> s_sub_h; // H_sub per k-point [nk*nbands*nbands]
30-
std::vector<std::complex<double>> s_sub_s; // S_sub per k-point
31-
std::vector<std::complex<double>> s_becp; // becp per k-point [nk*nproj*nbands*npol]
32-
int s_nk = 0, s_nbands = 0, s_nproj = 0, s_npol = 0;
23+
void* s_hamilt = nullptr; // stored HamiltPW pointer for inner loop (Phase D.2)
3324
}
3425

3526
void set_deltap_pw_lambda(const std::vector<double>& lambda,
@@ -73,7 +64,6 @@ bool is_deltap_pw_active()
7364
void set_deltap_pw_hamilt(void* hamilt)
7465
{
7566
s_hamilt = hamilt;
76-
s_sub_saved = false;
7767
s_lambda_set = false; // re-enable lambda update for new SCF cycle
7868
}
7969

@@ -183,37 +173,12 @@ void deltap_iter_finish(
183173
if (nk > 0 && nbands > 0 && nproj > 0)
184174
{
185175
inner_loop_ok = true;
186-
const int* nh_iat = &onsite_p->get_nh(0);
187-
auto* hamilt_t = static_cast<hamilt::Hamilt<std::complex<double>, base_device::DEVICE_CPU>*>(s_hamilt);
188-
189-
// Save subspace data (once per SCF)
190-
if (!s_sub_saved)
191-
{
192-
s_nk = nk; s_nbands = nbands; s_nproj = nproj; s_npol = npol;
193-
s_sub_h.resize(nk * nbands * nbands);
194-
s_sub_s.resize(nk * nbands * nbands);
195-
int size_becp = nbands * nproj * npol;
196-
s_becp.resize(nk * size_becp);
197-
198-
auto* psi_nc = const_cast<psi::Psi<std::complex<double>>*>(psi_cpu);
199-
for (int ik = 0; ik < nk; ik++)
200-
{
201-
psi_nc->fix_k(ik);
202-
auto* h_k = s_sub_h.data() + ik * nbands * nbands;
203-
auto* s_k = s_sub_s.data() + ik * nbands * nbands;
204-
auto* becp_k = s_becp.data() + ik * size_becp;
205-
hamilt_t->updateHk(ik);
206-
hsolver::DiagoIterAssist<std::complex<double>>::cal_hs_subspace(
207-
hamilt_t, *psi_nc, h_k, s_k);
208-
memcpy(becp_k, onsite_p->get_becp(),
209-
sizeof(std::complex<double>) * size_becp);
210-
}
211-
s_sub_saved = true;
212-
}
213176

214177
// Inner loop: re-compute gamma via becp re-weighting
215-
// Phase D.1: simple gradient descent, no subspace diagonalization
178+
// Phase D.1: simple gradient descent (no subspace diag)
216179
// Phase D.2 (TODO): subspace diag with GEMM + diag_responce
180+
// Requires: save H_sub/S_sub/becp (see git history ad25e6be8)
181+
// then H_sub(λ) = H_sub(0) + becp†·ps via GEMM
217182
for (int inner = 0; inner < inner_nmax; inner++)
218183
{
219184
std::vector<double> gamma_trial(nat, 0.0);

source/source_pw/module_pwdft/op_pw_proj.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,10 @@ template<>
434434
void OnsiteProj<OperatorPW<std::complex<float>, base_device::DEVICE_CPU>>::cal_ps_deltap(
435435
const int npol,
436436
const int m) const
437-
{}
437+
{
438+
// DeltaP not supported in single precision — silently skip.
439+
// The double-precision implementation is at line 199-277.
440+
}
438441

439442
#if ((defined __CUDA) || (defined __ROCM))
440443
template<>
@@ -469,7 +472,9 @@ template<>
469472
void OnsiteProj<OperatorPW<std::complex<float>, base_device::DEVICE_GPU>>::cal_ps_deltap(
470473
const int npol,
471474
const int m) const
472-
{}
475+
{
476+
// DeltaP not supported in single precision — silently skip.
477+
}
473478
#endif
474479

475480
// OnsiteProj::act — apply DFT+U and/or DeltaSpin Hamiltonian correction

0 commit comments

Comments
 (0)