Commit 592e7d1
abacus_fixer
Refactor DeltaSpin, step 4: encapsulate PW subspace cache in SubspaceCache
Move the three ad-hoc public SpinConstrain members sub_h_save / sub_s_save /
becp_save (raw TK* pointers) plus the lambda_in_sub_ snapshot into a new
spinconstrain::pw::SubspaceCache (deltaspin_pw_cache.h), owned by value as
SpinConstrain::pw_cache_.
The class encapsulates the CPU vs GPU allocation/free difference:
- allocate_cpu()/release_cpu() use new[]/delete[] on the host;
- allocate_gpu()/release_gpu() use base_device resize/delete_memory_op on
DEVICE_GPU, guarded by #if __CUDA/__ROCM.
It still exposes raw per-k pointers h_k()/s_k()/becp_k() because the hsolver
subspace routines and GPU memcpy ops require raw pointers, so std::vector is
not applicable for the device buffers. The buffer element type is fixed to
std::complex<double> (the PW path is always complex; the TK=double stub never
allocates the cache).
This also fixes a latent bug: the old SpinConstrain destructor called
delete[] on sub_h_save/sub_s_save/becp_save unconditionally. In GPU runs those
pointers are device memory allocated with resize_memory_op<DEVICE_GPU>, so
delete[] on them is undefined behavior (and on some setups an invalid free).
The destructor is now trivial (= default); device buffers are correctly freed
via release_gpu() -> delete_memory_op<DEVICE_GPU>() in
update_psi_charge_pw_gpu(), and host buffers via release_cpu() in
update_psi_charge_pw_cpu(). The singleton lives for the whole program so no
leak is introduced.
Call sites updated: cal_mw_from_lambda.cpp (CPU+GPU allocation points and
per-k views) and deltaspin_pw_impl.cpp (asserts, per-k views, CPU/GPU release,
lambda_in_sub_ access). Buffer layout and reuse semantics are unchanged.
No INPUT parameter behavior changes; docs update not required.
Verification:
- cmake --build build -j 16 (CPU, __LCAO): success
- cmake --build build_pw_gpu --target module_pwdft (CUDA, nvcc 12.9): success
(covers the __CUDA allocation/free branch)
- OMP_NUM_THREADS=1 ctest --test-dir build -R deltaspin: 5/5 passed
- python3 tools/03_code_analysis/agent_governance_check.py --staged:
no findings1 parent c49c67b commit 592e7d1
4 files changed
Lines changed: 172 additions & 54 deletions
File tree
- source
- source_lcao/module_deltaspin
- source_pw/module_pwdft
Lines changed: 12 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
167 | | - | |
| 167 | + | |
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
| 171 | + | |
| 172 | + | |
175 | 173 | | |
176 | 174 | | |
177 | 175 | | |
178 | 176 | | |
179 | 177 | | |
180 | 178 | | |
181 | | - | |
182 | | - | |
183 | | - | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
184 | 182 | | |
185 | 183 | | |
186 | 184 | | |
| |||
224 | 222 | | |
225 | 223 | | |
226 | 224 | | |
227 | | - | |
| 225 | + | |
228 | 226 | | |
229 | 227 | | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
| 228 | + | |
| 229 | + | |
234 | 230 | | |
235 | 231 | | |
236 | 232 | | |
237 | 233 | | |
238 | 234 | | |
239 | 235 | | |
240 | 236 | | |
241 | | - | |
242 | | - | |
243 | | - | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
244 | 240 | | |
245 | 241 | | |
246 | 242 | | |
| |||
Lines changed: 141 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| 63 | + | |
63 | 64 | | |
64 | 65 | | |
65 | 66 | | |
| |||
456 | 457 | | |
457 | 458 | | |
458 | 459 | | |
459 | | - | |
460 | | - | |
461 | | - | |
462 | | - | |
463 | | - | |
464 | | - | |
465 | | - | |
466 | | - | |
467 | | - | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
468 | 464 | | |
469 | 465 | | |
470 | 466 | | |
| |||
509 | 505 | | |
510 | 506 | | |
511 | 507 | | |
512 | | - | |
513 | | - | |
514 | | - | |
515 | | - | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
516 | 511 | | |
517 | 512 | | |
518 | 513 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
128 | | - | |
| 128 | + | |
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
| |||
315 | 315 | | |
316 | 316 | | |
317 | 317 | | |
318 | | - | |
319 | | - | |
320 | | - | |
| 318 | + | |
321 | 319 | | |
322 | 320 | | |
323 | 321 | | |
| |||
332 | 330 | | |
333 | 331 | | |
334 | 332 | | |
335 | | - | |
336 | | - | |
337 | | - | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
338 | 336 | | |
339 | 337 | | |
340 | 338 | | |
| |||
354 | 352 | | |
355 | 353 | | |
356 | 354 | | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
| 355 | + | |
363 | 356 | | |
364 | 357 | | |
365 | 358 | | |
| |||
435 | 428 | | |
436 | 429 | | |
437 | 430 | | |
438 | | - | |
439 | | - | |
440 | | - | |
| 431 | + | |
441 | 432 | | |
442 | 433 | | |
443 | 434 | | |
| |||
449 | 440 | | |
450 | 441 | | |
451 | 442 | | |
452 | | - | |
453 | | - | |
454 | | - | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
455 | 446 | | |
456 | 447 | | |
457 | 448 | | |
| |||
471 | 462 | | |
472 | 463 | | |
473 | 464 | | |
474 | | - | |
475 | | - | |
476 | | - | |
477 | | - | |
478 | | - | |
479 | | - | |
| 465 | + | |
480 | 466 | | |
481 | 467 | | |
482 | 468 | | |
| |||
0 commit comments