Skip to content

perf(lcao): reuse common terms across magnetic components - #8256

Open
Stardust0831 wants to merge 3 commits into
deepmodeling:developfrom
Stardust0831:perf/ri-integral-reuse
Open

Stardust0831 wants to merge 3 commits into
deepmodeling:developfrom
Stardust0831:perf/ri-integral-reuse

Conversation

@Stardust0831

Copy link
Copy Markdown
Collaborator

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

System Stage Baseline (s) This PR (s) Paired speedup
Si32 RI integrals and derivatives 6.64–7.59 1.97–2.19 3.36–3.47x
Si32 Complete SCF + forces + stress 182.22–203.71 174.42–186.09 1.04–1.09x
CsPbI3 RI integrals and derivatives 16.21–16.28 2.48–2.54 6.38–6.57x
CsPbI3 Complete SCF + forces + stress 424.48–426.14 407.10–414.09 1.03–1.04x

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.

cmake --build build --target abacus_std_gpu MODULE_LCAO_integral_reuse --parallel 24
OMP_NUM_THREADS=1 ctest --test-dir build -V -R '^(MODULE_LCAO_integral_reuse)$'
OMP_NUM_THREADS=4 ctest --test-dir build -V -R '^(MODULE_LCAO_integral_reuse)$'

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.

@AsTonyshment AsTonyshment left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall.

{
const size_t NA1 = co4.first;
for( size_t MA1=0; MA1!=2*LA1+1; ++MA1 )
for (const auto &co5 : co4.second)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree we should avoid using auto

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, both. Replaced the relevant auto declarations with explicit types in 1550aaf, preserving the existing reference and value semantics. Also resolved the CMake formatting conflict with develop in e613e1a; the integral regression tests pass with one and four OpenMP threads.

@ABACUS-PR-BOT ABACUS-PR-BOT left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants