Repository navigation
perf(lcao): reuse common terms across magnetic components - #8256
Stardust0831 wants to merge 3 commits into
Conversation
| { | ||
| const size_t NA1 = co4.first; | ||
| for( size_t MA1=0; MA1!=2*LA1+1; ++MA1 ) | ||
| for (const auto &co5 : co4.second) |
There was a problem hiding this comment.
I noticed several uses of auto (some of which were already present in the original code), but we generally recommend using explicit type declarations wherever possible to improve code readability and maintainability, thanks!
There was a problem hiding this comment.
I agree we should avoid using auto
There was a problem hiding this comment.
ABACUS-PR-BOT
left a comment
There was a problem hiding this comment.
No confirmed correctness regression found in the inspected paths. The inline comments suggest a matrix-level regression and one project-rule cleanup.
Static review of 06ab2be77 against d20090cc: whitespace and governance checks passed. The linked baseline comparisons were inspected as author-provided evidence; no build or runtime checks were performed.
| { | ||
| const double r = ir * dr; | ||
| radial[ir] = r; | ||
| values[ir] = std::pow(r, l) * std::pow(cutoff - r, 2) * std::exp(-(0.7 + 0.03 * index) * r); |
There was a problem hiding this comment.
Non-blocking: Please name the cutoff distance and exponential argument before passing them to std::pow and std::exp. AGENTS.md rule 14 requires named locals for computed call arguments, and this makes both fixture values directly inspectable.
There was a problem hiding this comment.
Thanks for the suggestion. I would prefer to keep these short fixture expressions as written in this revision.
| for( size_t MB=0; MB!=2*LB+1; ++MB ) | ||
| { | ||
| const Tdata overlap = co8.second.cal_overlap( tauA*lat0, tauB*lat0, MA1, MA2, MB ); | ||
| const size_t offset = (MA1 * (2 * LA2 + 1) + MA2) * (2 * LB + 1) + MB; |
There was a problem hiding this comment.
Non-blocking: Please add a small Matrix_Orbs21 regression for the caller-used layouts, using unequal basis dimensions and scalar reference values for overlap and gradient outputs. The added tests stop at Orb11/Orb21, so they do not exercise this flattened offset and tensor assignment.
There was a problem hiding this comment.
Agreed that a matrix-level test would add coverage for the layout mapping. The current tests compare batched integrals and gradients against scalar evaluation, but do not directly test tensor assignment. I would prefer to defer the additional matrix-level test in this PR.
Resolve the CMake formatting conflict while retaining the integral reuse test target and its source list.
What's changed?
RI integral assembly repeatedly evaluates the same radial interpolation and solid harmonics for different magnetic components. Compute these common terms once per orbital pair and reuse the two-center results during three-center assembly.
The scalar interfaces remain available. Vector evaluation preserves each component's angular summation order; common-factor reuse can change FP64 rounding. Temporary arrays are local to evaluation. This changes CPU integral evaluation and introduces no persistent geometry cache or device allocation.
Performance
LCAO HSE calculations on displaced Si32 and CsPbI3 (5 atoms), using one V100, one MPI rank, four physical CPU cores/OpenMP threads and serial BLAS on SAI. Both versions use cuSOLVER diagonalization and CPU LibRI contractions. The baseline is unmodified
d20090cc137f.Ranges cover two paired runs in separate allocations on shared nodes, with reversed execution order. Ratios are calculated within each pair; SCF iteration counts match. Complete time includes process startup. The RI stage is measured by
Exx_LRI::cal_exx_ions, which includes geometry-dependent integrals and derivatives; EXX force contractions are unchanged.Unit Tests and/or Case Tests for my changes
The full CUDA executable build and integral tests passed with one and four OpenMP threads. Tests compare all magnetic components against scalar evaluation, cover origin/near-origin/cutoff behavior, and check gradients by finite differences in all three directions.
The benchmark cases, a CPU execution control, and complex-tensor Si32 on a regular 2x1x1 k mesh with two MPI ranks/GPUs all converged with matching iteration counts. Maximum differences were 1.4e-11 eV/atom, 2.0e-10 eV/Angstrom and 1.4e-9 kbar. These comparisons establish agreement with the baseline. The combined changes also passed a build and regression checks with CUDA disabled.
Inputs, timings, numerical comparisons and test logs. Benchmark executables enable identical existing timer JSON output; this instrumentation is excluded from the change.
Linked Issue
Supersedes the integral-evaluation part of #8193. This change is independent of the radial-table and Libxc optimizations and does not require #8169.
Governance Notes
No documentation update required: this changes internal LCAO integral evaluation without changing INPUT parameters, dependencies or numerical settings.