Skip to content

feat(lcao): add optional LibRI GPU contractions through DDLA - #8169

Open
Stardust0831 wants to merge 33 commits into
deepmodeling:developfrom
Stardust0831:experiment/lcao-hse-gpu
Open

Stardust0831 wants to merge 33 commits into
deepmodeling:developfrom
Stardust0831:experiment/lcao-hse-gpu

Conversation

@Stardust0831

@Stardust0831 Stardust0831 commented Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator

What's changed?

Enable optional GPU acceleration of LCAO Kohn–Sham exact-exchange tensor contractions through LibRI's DDLA CUDA backend. ENABLE_LIBRI_GPU defaults to OFF; INPUT device_exx defaults to cpu. Build with USE_CUDA=ON, ENABLE_LIBRI_GPU=ON, an explicit compatible LIBRI_DIR and a CUDA DDLA installation, then select:

device                 gpu
device_exx             gpu
symmetry               1
exx_symmetry_realspace  1

GPU RI supports spatial symmetry and real-space EXX reduction. Use the official LibRI v0.3.0.0 release at 589f6f8c6df3916575a1ba41e840de919d40d345 and a CUDA build of DDLA v0.0.7 (0a65e570d3d3bc70e4d53a7e992b2de60abc884c), or newer compatible releases. CMake consumes LibDDLAConfig.cmake / ddla::ddla, uses the public DDLA_HAS_GPU capability, and checks real/complex GPU API compilation and linkage. Both CPU and GPU RI require C++14 in ABACUS; building DDLA itself requires C++17. CPU RI retains its existing dependency selection.

The selector applies to LCAO Kohn–Sham exchange. LR/RDMFT engines retain CPU contractions, including when LR reuses Kohn–Sham exchange geometry. All ranks on a node must see the same allocated GPU list, with at least as many visible GPUs as local ranks; per-rank single-GPU masking is unsupported. Build/install instructions and INPUT help describe the supported setup.

Unit Tests and/or Case Tests for my changes

The validated source matches ABACUS e47e26947e6620fee11a44de3fdb520b49fae76e, with the official LibRI and DDLA releases above, on one V100 / one MPI rank with OMP=1 and BLAS=1. Full report · raw inputs, outputs and build logs, 2.23 MiB · independent numerical audit.

  • Full Release ABACUS builds as C++14. The official DDLA installed consumer passes as strict C++11, and both standalone ABACUS/LibRI consumers pass as C++14. GoogleTest-based unit targets use C++17 as required by GoogleTest.
  • GPU INPUT/workspace tests: 52/52, plus 2/2 Debug workspace tests; no skips. Unmodified released LibRI numerical regression source compiled as C++14 passes 456 CHECK / 38 PASS.
  • 20/20 HSE calculations, including real/complex multi-k Si2 with symmetry 1, real-space reduction off/on, displaced Si2 with nonzero forces, and water Gamma with nspin=1/2.
  • 18/18 comparisons pass: 10 CPU/GPU pairs and 8 real-space reduction off/on pairs. Maximum CPU/GPU differences are 1.7053e-12 eV, 2e-10 eV/Å and 1e-10 kbar; limits remain 1e-7 eV, 1e-6 eV/Å and 1e-5 kbar per component. Original Autotest references and tolerances are unchanged.
  • 20/20 comparisons against the previous DDLA/C++17 configuration pass, with byte-identical inputs. CLI --check-input passes 8/8 direct single-process cases; --version passes.
  • Governance, pre-commit CI and git diff --check pass. The report preserves the expected old-probe configuration failure and an initial audit error that incorrectly required GoogleTest targets to use C++14, followed by the corrected production-object audit.

Commands and configure options are in dependency validation, application validation and runtime validation. Focused checks:

ctest --test-dir build/abacus -V --timeout 120 \
  -R '^(MODULE_IO_read_(input|item)_serial|MODULE_RI_exx_workspace)$'
ctest --test-dir build/debug -V --timeout 120 -R '^MODULE_RI_exx_workspace$'
ctest --test-dir build/ddla-consumer -V
ctest --test-dir build/consumer-cpu -V
ctest --test-dir build/consumer-gpu -V
mpirun -np 1 build/libri14/test_lri_gpu_symmetry -1 all all
python3 run-e2e.py
python3 check-cli.py

Benchmark results

The Si64 timings below use the recorded earlier dependency revisions; performance was not remeasured for DDLA v0.0.7.

HSE06 Si64 on SAI 16V100: one V100, one MPI rank/four bound physical CPU cores, OMP=4, BLAS=1; APNS efficiency LCAO, Γ-only, 128 bands, 100 Ry, SCF=1e-8, RI thresholds=1e-4. Fresh atomic starts; symmetry -1, forces enabled, stress disabled. The existing exx_symmetry_realspace parameter automatically becomes 0 here.

Download original inputs and small outputs — 2.57 MiB tar.gz, 490 files · full report · individual timings CSV · numerical comparisons CSV · file/checksum manifest.

The archive contains original INPUT/STRU/KPT files, Si pseudopotential/orbitals, outputs ≤10 MiB/file, scripts and validation logs; larger omissions are listed in the manifest. Downloaded archive SHA256 verified: 4ca994d552094f9e3180751b6572653798d1463ccec9c893c3308f5143fe5587.

“beta13 baseline” denotes a baseline built from ABACUS v3.11.0-beta13, with the versions below. Commit IDs distinguish dependency revisions that share a header version string.

Build ABACUS LibRI LibXC
beta13 baseline 4e9f1636b7ca b0eff7ad70ab, CPU; header version 2.1.1 7.0.0, CPU
beta13 + GPU libraries same beta13 revision + recorded adapter patch 0e8afc393, GPU 3c7794c5047d, GPU
PR, CPU/GPU LibRI f2667c6ee, same executable pre-release a385ac9, CPU/GPU 7.0.0, CPU

Before/after timing composition. Ideal Si64, two starts per variant, paired within two allocations with reversed execution order. Means in seconds; wall time includes initialization, the initial GGA SCF, HSE SCF and complete atomic forces. Three decimals preserve means of timers printed to 0.01 s.

Component / s beta13 baseline beta13 + GPU libraries PR, CPU LibRI PR, GPU LibRI
Electronic EXX 359.895 26.295 104.265 24.980
EXX forces 398.015 29.105 115.645 28.020
Remaining wall time 84.920 30.265 32.680 32.600
Complete calculation 842.830 85.665 252.590 85.600
Comparison Overall speedup Electronic EXX saved / s EXX forces saved / s Remainder saved / s
beta13 baseline → beta13 + GPU libraries 9.84× 333.600 368.910 54.655
beta13 baseline → PR CPU LibRI 3.34× 255.630 282.370 52.240
PR CPU → GPU LibRI 2.95× 79.285 87.625 0.080

The 9.84× beta13 comparison saves 757.165 s: electronic EXX contributes 44.06%, EXX forces 48.72%, and remaining work 7.22%. It includes dependency/build changes. Baseline → PR CPU LibRI already gives 3.34×, combining ABACUS/dependency/build changes; this is not an isolated LibRI-version comparison. Selecting GPU in that same PR executable then gives 2.95×, with LibXC fixed on CPU and 99.95% of the saving in the two EXX scopes. Baseline → PR GPU LibRI is 9.85× overall.

The paired gains are 10.69×/9.11× for beta13 → experimental and 3.05×/2.85× for PR CPU → GPU; only two repetitions are available. Remainder = wall − electronic EXX − EXX forces. The following nested timers overlap these scopes and must not be added again; effective potential includes LibXC potential.

Nested timer / s beta13 baseline beta13 + GPU libraries PR, CPU LibRI PR, GPU LibRI
Effective potential 30.355 10.160 13.695 13.700
LibXC potential 20.250 4.025 8.165 8.185
LCAO solver 31.090 7.990 6.555 6.590

Calculation consistency. All 10/10 scientific runs finish normally, converge below 1e-8 and output 64 force vectors; 9/9 numerical comparisons pass. Ideal runs retain 12 GGA + 8 HSE iterations. The displaced CPU/GPU pair both use 12 + 12 iterations, with final residual 9.742e-9. The table reports maximum differences across paired runs.

Comparison max ΔE / eV max ΔE / eV/atom max atom-wise ‖ΔF‖ / eV/Å Result
beta13 baseline → GPU libraries 1.388e-07 2.169e-09 1.273e-09 PASS
beta13 baseline → PR CPU LibRI 1.455e-11 2.274e-13 2.236e-10 PASS
beta13 baseline → PR GPU LibRI 4.729e-11 7.390e-13 4.583e-10 PASS
PR CPU → GPU, ideal Si64 6.185e-11 9.663e-13 3.162e-10 PASS
PR CPU → GPU, displaced Si64 3.638e-12 5.684e-14 1.414e-10 PASS

Cross-build limits are 1e-6 eV/atom and 1e-5 eV/Å; same-PR CPU/GPU limits are 1e-8 eV/atom and 1e-6 eV/Å. Force differences are per-atom Euclidean vector norms. The extra pair moves the first Si atom by (+0.01,+0.02,−0.015) Å and has maximum force 0.398013 eV/Å, verifying nontrivial forces; it is not pooled into the ideal-structure timings. Original references and tolerances are unchanged.

Earlier beta13/CP2K and LibRI PR #17 comparisons remain separately documented with their original inputs and outputs.

Linked Issue

Reproduction data and timing composition.

Governance Notes

  • INPUT metadata, help, validation and MPI broadcast cover device_exx. The existing symmetry and exx_symmetry_realspace settings work with CPU and GPU RI; no additional INPUT parameter is introduced. Generated INPUT documentation is not committed.
  • INPUT tests use the existing serial targets and public registry accessor. They cover accepted symmetry settings, retained values, CPU selection and MD's normal symmetry reset.
  • Core impact: select the backend before LCAO EXX initialization and encapsulate dependencies in LibRI::LibRI and ddla::ddla. The RI workspace test links to LibRI::LibRI so its optional DDLA dependency reaches Debug builds too.
  • The standalone CMake consumer checks dependency propagation without launching ABACUS. Numerical contraction regressions remain in LibRI; application comparisons use ABACUS Autotest cases and a displaced-geometry supplement.
  • Governance, pre-commit CI and git diff --check pass. No new direct MPI calls, test access macros, dependency implementation patches or custom DDLA finder are introduced.
  • Follow-up: add DDLA installation to the existing toolchain workflow.

@userchba

Copy link
Copy Markdown

the LibDDLA version which is compatible with LibRI GPU is https://github.com/userchba/LibDDLA/releases/tag/v0.0.4, current LibRI GPU can't correctly compute symmetry situation which LibRI CPU can compute correctly

@mohanchen mohanchen added the GPU & DCU & HPC GPU and DCU and HPC related any issues label Oct 18, 2026

@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.

Static review of f07d8d14f39d26782490cc4bc15d0a58c5700e62 with independent source review and adjudication. No build/runtime/MPI/GPU tests were run; CI diagnostics were unavailable.

Comment thread docs/advanced/install.md Resolved
Comment thread source/source_lcao/setup_exx.cpp Resolved
@Stardust0831
Stardust0831 marked this pull request as ready for review October 19, 2026 14:30
@mohanchen mohanchen added the Compile & CICD & Docs & Dependencies Issues related to compiling ABACUS label Oct 20, 2026
@mohanchen

Copy link
Copy Markdown
Collaborator

To be consistent, I think device_exx maybe better than exx_device

@mohanchen mohanchen added Input&Output Suitable for coders without knowing too many DFT details EXX/lr-TDDFT/RPA/BSE/GW Related to beyond DFT methods labels Oct 20, 2026
@Stardust0831

Copy link
Copy Markdown
Collaborator Author

To be consistent, I think device_exx maybe better than exx_device

Thank you for the review and suggestions; I’ve renamed exx_device to device_exx.

@QuantumMisaka

QuantumMisaka commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

@PeizeLin @maki49 May you have a look? Thanks !

@mohanchen

Copy link
Copy Markdown
Collaborator

@Growl1234 Could you check the cmake changes for this PR?

@Stardust0831
Stardust0831 marked this pull request as ready for review November 21, 2026 04:39

@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.

The GPU-enabled main test target MODULE_RI_exx_workspace needs its DDLA link dependency; the inline comments also cover two nonblocking follow-ups. This review is source-only: no build or test was run, author-reported results remain attributed, and CI was not independently checked.

Comment thread source/CMakeLists.txt Resolved
@Stardust0831
Stardust0831 marked this pull request as draft November 22, 2026 09:39
Keep the upstream restart-test source and the serial reader registrations.
Remove the temporary symmetry rejection and update input coverage and installation guidance for LibRI v0.3.0.0.
@Stardust0831
Stardust0831 marked this pull request as ready for review November 23, 2026 05:14
@userchba

Copy link
Copy Markdown

What's changed?

Enable optional GPU acceleration of LCAO Kohn–Sham exact-exchange tensor contractions through LibRI's DDLA CUDA backend. ENABLE_LIBRI_GPU defaults to OFF; INPUT device_exx defaults to cpu. Build with USE_CUDA=ON, ENABLE_LIBRI_GPU=ON, an explicit compatible LIBRI_DIR and a CUDA DDLA installation, then select:

device                 gpu
device_exx             gpu
symmetry               1
exx_symmetry_realspace  1

GPU RI supports spatial symmetry and real-space EXX reduction. Use the official LibRI v0.3.0.0 release at 589f6f8c6df3916575a1ba41e840de919d40d345, or a newer compatible release. The validated DDLA revision is 7c0ca08b4349a527cec2a0c0af7d1a1082bd38c7, exposing the handle-selected batched GEMM API; the original DDLA v0.0.6 release has an incompatible interface. CMake consumes LibDDLAConfig.cmake / ddla::ddla and checks real/complex GPU API compilation and linkage. GPU RI requires C++17; CPU RI retains its existing dependency selection and C++14 requirement.

The selector applies to LCAO Kohn–Sham exchange. LR/RDMFT engines retain CPU contractions, including when LR reuses Kohn–Sham exchange geometry. All ranks on a node must see the same allocated GPU list, with at least as many visible GPUs as local ranks; per-rank single-GPU masking is unsupported. Build/install instructions and INPUT help describe the supported setup.

Unit Tests and/or Case Tests for my changes

Fresh validation of ABACUS fa1c75dcce0df12fe37267aed5ed2deef3fcaef0 with the official LibRI release above, on one V100 / one MPI rank with OMP=1 and BLAS=1. Full report · raw inputs, outputs and build logs, 2.33 MiB · independent numerical audit.

  • CPU/GPU INPUT and RI workspace tests: 50/50 CPU + 52/52 GPU, no skips. Debug standalone CMake consumers pass for both backends.
  • LibRI symmetry regressions: 456 CHECK / 38 PASS and 31,104 callback combinations, using unmodified released headers.
  • 20/20 HSE calculations, including real/complex multi-k Si2 with symmetry 1, real-space reduction off/on, a displaced Si2 structure with nonzero forces, and water Gamma with nspin=1/2.
  • 18/18 comparisons pass: 10 CPU/GPU pairs and 8 real-space reduction off/on pairs. Maximum CPU/GPU differences are 7.958e-13 eV, 1.1e-9 eV/Å and 3e-10 kbar; limits remain 1e-7 eV, 1e-6 eV/Å and 1e-5 kbar per component. Original Autotest references and tolerances are unchanged.
  • CLI --check-input passes 8/8 direct single-process cases; --version and both parameter help commands pass. The initial MPI-launched CLI attempts hit the existing check-mode exit without MPI finalization; their failed launcher statuses and successful direct rechecks are retained in the report.
  • Governance, changed-line clang-format and git diff --check pass.

Commands and complete configure options are in build.sbatch and run.sbatch. Focused checks:

ctest --test-dir build/abacus -V --timeout 120 \
  -R '^(MODULE_IO_read_(input|item)_serial|MODULE_RI_exx_workspace)$'
ctest --test-dir build/cpu -V --timeout 120 \
  -R '^(MODULE_IO_read_(input|item)_serial|MODULE_RI_exx_workspace)$'
ctest --test-dir build/consumer-cpu -V
ctest --test-dir build/consumer-gpu -V
mpirun -np 1 build/libri/test_lri_gpu_symmetry -1 all all
build/libri/test_gpu_symmetry_filters
python3 run-e2e.py
python3 check-cli-singleton.py

Benchmark results

HSE06 Si64 on SAI 16V100: one V100, one MPI rank/four bound physical CPU cores, OMP=4, BLAS=1; APNS efficiency LCAO, Γ-only, 128 bands, 100 Ry, SCF=1e-8, RI thresholds=1e-4. Fresh atomic starts; symmetry -1, forces enabled, stress disabled. The existing exx_symmetry_realspace parameter automatically becomes 0 here.

Download original inputs and small outputs — 2.57 MiB tar.gz, 490 files · full report · individual timings CSV · numerical comparisons CSV · file/checksum manifest.

The archive contains original INPUT/STRU/KPT files, Si pseudopotential/orbitals, outputs ≤10 MiB/file, scripts and validation logs; larger omissions are listed in the manifest. Downloaded archive SHA256 verified: 4ca994d552094f9e3180751b6572653798d1463ccec9c893c3308f5143fe5587.

“beta13 baseline” denotes a baseline built from ABACUS v3.11.0-beta13, with the versions below. Commit IDs distinguish dependency revisions that share a header version string.

Build ABACUS LibRI LibXC
beta13 baseline 4e9f1636b7ca b0eff7ad70ab, CPU; header version 2.1.1 7.0.0, CPU
beta13 + GPU libraries same beta13 revision + recorded adapter patch 0e8afc393, GPU 3c7794c5047d, GPU
PR, CPU/GPU LibRI f2667c6ee, same executable pre-release a385ac9, CPU/GPU 7.0.0, CPU
Before/after timing composition. Ideal Si64, two starts per variant, paired within two allocations with reversed execution order. Means in seconds; wall time includes initialization, the initial GGA SCF, HSE SCF and complete atomic forces. Three decimals preserve means of timers printed to 0.01 s.

Component / s beta13 baseline beta13 + GPU libraries PR, CPU LibRI PR, GPU LibRI
Electronic EXX 359.895 26.295 104.265 24.980
EXX forces 398.015 29.105 115.645 28.020
Remaining wall time 84.920 30.265 32.680 32.600
Complete calculation 842.830 85.665 252.590 85.600
Comparison Overall speedup Electronic EXX saved / s EXX forces saved / s Remainder saved / s
beta13 baseline → beta13 + GPU libraries 9.84× 333.600 368.910 54.655
beta13 baseline → PR CPU LibRI 3.34× 255.630 282.370 52.240
PR CPU → GPU LibRI 2.95× 79.285 87.625 0.080
The 9.84× beta13 comparison saves 757.165 s: electronic EXX contributes 44.06%, EXX forces 48.72%, and remaining work 7.22%. It includes dependency/build changes. Baseline → PR CPU LibRI already gives 3.34×, combining ABACUS/dependency/build changes; this is not an isolated LibRI-version comparison. Selecting GPU in that same PR executable then gives 2.95×, with LibXC fixed on CPU and 99.95% of the saving in the two EXX scopes. Baseline → PR GPU LibRI is 9.85× overall.

The paired gains are 10.69×/9.11× for beta13 → experimental and 3.05×/2.85× for PR CPU → GPU; only two repetitions are available. Remainder = wall − electronic EXX − EXX forces. The following nested timers overlap these scopes and must not be added again; effective potential includes LibXC potential.

Nested timer / s beta13 baseline beta13 + GPU libraries PR, CPU LibRI PR, GPU LibRI
Effective potential 30.355 10.160 13.695 13.700
LibXC potential 20.250 4.025 8.165 8.185
LCAO solver 31.090 7.990 6.555 6.590
Calculation consistency. All 10/10 scientific runs finish normally, converge below 1e-8 and output 64 force vectors; 9/9 numerical comparisons pass. Ideal runs retain 12 GGA + 8 HSE iterations. The displaced CPU/GPU pair both use 12 + 12 iterations, with final residual 9.742e-9. The table reports maximum differences across paired runs.

Comparison max ΔE / eV max ΔE / eV/atom max atom-wise ‖ΔF‖ / eV/Å Result
beta13 baseline → GPU libraries 1.388e-07 2.169e-09 1.273e-09 PASS
beta13 baseline → PR CPU LibRI 1.455e-11 2.274e-13 2.236e-10 PASS
beta13 baseline → PR GPU LibRI 4.729e-11 7.390e-13 4.583e-10 PASS
PR CPU → GPU, ideal Si64 6.185e-11 9.663e-13 3.162e-10 PASS
PR CPU → GPU, displaced Si64 3.638e-12 5.684e-14 1.414e-10 PASS
Cross-build limits are 1e-6 eV/atom and 1e-5 eV/Å; same-PR CPU/GPU limits are 1e-8 eV/atom and 1e-6 eV/Å. Force differences are per-atom Euclidean vector norms. The extra pair moves the first Si atom by (+0.01,+0.02,−0.015) Å and has maximum force 0.398013 eV/Å, verifying nontrivial forces; it is not pooled into the ideal-structure timings. Original references and tolerances are unchanged.

Earlier beta13/CP2K and LibRI PR #17 comparisons remain separately documented with their original inputs and outputs.

Linked Issue

Reproduction data and timing composition.

Governance Notes

  • INPUT metadata, help, validation and MPI broadcast cover device_exx. The existing symmetry and exx_symmetry_realspace settings work with CPU and GPU RI; no additional INPUT parameter is introduced. Generated INPUT documentation is not committed.
  • INPUT tests use the existing serial targets and public registry accessor. They cover accepted symmetry settings, retained values, CPU selection and MD's normal symmetry reset.
  • Core impact: select the backend before LCAO EXX initialization and encapsulate dependencies in LibRI::LibRI and ddla::ddla. The RI workspace test links to LibRI::LibRI so its optional DDLA dependency reaches Debug builds too.
  • The standalone CMake consumer checks dependency propagation without launching ABACUS. Numerical contraction regressions remain in LibRI; application comparisons use ABACUS Autotest cases and a displaced-geometry supplement.
  • Governance and changed-line formatting checks pass. No new direct MPI calls, test access macros, dependency implementation patches or custom DDLA finder are introduced.
  • Follow-up: add DDLA installation to the existing toolchain workflow.

I suggest the ddla release 0.0.7 https://github.com/userchba/LibDDLA/releases/tag/v0.0.7 which support no C++ 17 command when compile abacus, but compiling LibDDLA also need C++17 standard, and also this version will be more cleaner for some definition in LibRI

Consume DDLA's public GPU capability without relying on its private backend
definitions. Remove the C++17 requirement from ABACUS and update the
installation guidance and standalone consumer check.
@Stardust0831

Copy link
Copy Markdown
Collaborator Author

Thanks for the suggestion, @userchba. Updated to DDLA v0.0.7 with ABACUS remaining at C++14 and using the public DDLA_HAS_GPU check; all 20 HSE cases and 18 CPU/GPU and symmetry comparisons pass.

@userchba

Copy link
Copy Markdown

Thanks for the updates and the detailed validation, performance benchmarks, and memory analysis. I have no further concerns from my side and consider this PR ready to merge.

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

Compile & CICD & Docs & Dependencies Issues related to compiling ABACUS EXX/lr-TDDFT/RPA/BSE/GW Related to beyond DFT methods GPU & DCU & HPC GPU and DCU and HPC related any issues Input&Output Suitable for coders without knowing too many DFT details

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants