Skip to content

feat(xc): offload Libxc grid potentials to CUDA - #8364

Open
Stardust0831 wants to merge 9 commits into
deepmodeling:developfrom
Stardust0831:feat/libxc-cuda-grid-7-1
Open

Stardust0831 wants to merge 9 commits into
deepmodeling:developfrom
Stardust0831:feat/libxc-cuda-grid-7-1

Conversation

@Stardust0831

@Stardust0831 Stardust0831 commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Reminder

  • I have read AGENTS.md and docs/developers_guide/agent_governance.md.
  • I have linked an issue or explained why this PR does not need one.
  • I have added adequate unit tests and/or case tests, or explained why not.
  • I have listed the exact verification commands run and their results.
  • I have described user-visible behavior changes, including INPUT parameter changes.
  • I have explained core-module impact for ESolver, HSolver, ElecState, Hamilt, Operator, Psi, or other source/ changes.
  • I have requested any needed governance exception below.

Linked Issue

Related to deepmodeling/abacus-develop#3344: Support the GPU version of libxc.

Unit Tests and/or Case Tests for my changes

  • Commands run:
compute-sanitizer --tool memcheck --report-api-errors no --leak-check full --error-exitcode 99 \
  "$build/source/source_hamilt/module_xc/test/MODULE_HAMILT_XCTest_VXC" --gtest_filter='*LibxcCudaPotential*'
GTEST_FILTER='LibxcDeviceInput.DefaultAndAllowedDevices' ctest --test-dir "$build" -V --no-tests=error -R '^MODULE_IO_read_item_serial$'
abacus_std_gpu --version
abacus_std_gpu -h device_xc
abacus_std_gpu --check-input
OMP_NUM_THREADS=4 mpirun -np 1 --bind-to core --map-by slot:PE=4 abacus_std_gpu
  • Result summary: All 24 LDA, GGA and HSE grid tests passed with CUDA Libxc 7.1.2. Memcheck reported zero errors and zero leaked bytes. Both builds passed the INPUT test and accepted the default and explicit CPU settings. Only the opt-in build accepted device_xc gpu. Si32 HSE06 converged with the default build and with both runtime choices in the opt-in build. The three final energies agreed within 6 × 10⁻⁹ eV.
  • CMake accepted Libxc 7.0.0 and CPU-only 7.1.2 with the option off and rejected both when it was on. Reconfiguring the same build directory ON/OFF/ON selected the expected backend each time.
  • Checks not run, with reason: The full integration suite was not run locally. The Si32 case exercises the build and runtime choices in an HSE06 calculation.

Si32 HSE06 benchmark, official Libxc 7.1.2. Both Libxc modes used the same executable, one Tesla V100, one MPI rank and four physical CPU cores. cuSOLVER used the GPU and exact exchange used the CPU throughout. The table reports medians from the original three runs per mode.

Calculation Libxc grid, CPU → GPU Total time, CPU → GPU
Single point 45.62 → 5.71 s (7.99x) 99.65 → 61.05 s (1.63x)
Forces and stress 46.12 → 6.41 s (7.20x) 141.78 → 102.26 s (1.39x)

Download the Si32 case · Per-run timings

What's changed?

ABACUS can evaluate Libxc LDA/GGA potentials on CUDA, including the semilocal part of HSE. The CMake option ENABLE_LIBXC_CUDA defaults to OFF. To enable it, install Libxc 7.1.0 or later built with -DENABLE_CUDA=ON and configure ABACUS with -DUSE_CUDA=ON -DENABLE_LIBXC=ON -DENABLE_LIBXC_CUDA=ON. This uses the public Libxc host/device API. Libxc 7.1.2 release

At runtime, device_xc defaults to cpu. These INPUT settings select GPU evaluation.

device     gpu
device_xc  gpu

Governance Notes

  • INPUT/docs changes: device_xc accepts cpu or gpu. Its registration provides CLI help and the generated parameter reference. The installation guide describes the CUDA build requirements.
  • Core module impact: The ElecState potential factory passes the device choice to the Hamiltonian XC evaluator, which batches each rank's grid. The existing global reads supply magnetism and RDMFT settings. The host initialization helper includes xc.h for the Libxc types and flags it uses.
  • Exceptions requested: None.

@Stardust0831
Stardust0831 marked this pull request as ready for review November 22, 2026 16:34
@Stardust0831
Stardust0831 force-pushed the feat/libxc-cuda-grid-7-1 branch from 23464e9 to 3332ebf Compare November 22, 2026 16:41
Comment thread source/CMakeLists.txt Resolved
@Growl1234

Copy link
Copy Markdown
Collaborator

@susilehtola Sorry to bother you here, but would you like to have a look?

@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 source review at 3332ebfd; no build or runtime tests were run.

@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 the small-gradient test update at 222c9fcea225; no tests were run.

@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 finiteness checks are addressed in source at 95e2bd2b7. Three non-blocking follow-ups cover coordinated input rejection, the integrated noncollinear GPU test, and test-handle cleanup.

Static review only; no builds or tests were run, and CI was not verified.

item.check_value = [](const Input_Item&, const Parameter& para) {
if (para.input.device_xc == "gpu")
{
ModuleBase::WARNING_QUIT("ReadInput", "device_xc gpu requires ABACUS built with -DENABLE_LIBXC_CUDA=ON.");

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 route the unsupported-build rejection through the synchronized input-error path. check_value runs only on rank 0; with a CUDA build where ENABLE_LIBXC_CUDA=OFF, device gpu plus device_xc gpu makes rank 0 exit while the other ranks can enter DeviceContext::init's collective, leaving termination dependent on the MPI launcher. A multi-rank rejection test would cover this path.

xc_gga_exc_vxc(&host[0], points, rho_data, sigma_data, exc_host_data, vrho_host_data, vsigma_host_data);
}
XC_Functional_Libxc::xc_cuda_exc_vxc(device[0], points, rho_data, sigma_data,
exc_device_data, vrho_device_data, vsigma_device_data);

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 host/device comparison through v_xc_libxc, including an nspin=4, gga_grad=2 case and the returned energy, vtxc, and four potential channels. This test currently calls the raw CUDA helper, while the existing noncollinear finite-difference test uses the CPU overload, so neither protects the new backend choice through the full mapped-density path.

}
}
XC_Functional_Libxc::finish_func(host);
XC_Functional_Libxc::finish_func(device);

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 make both Libxc handle vectors clean up through a scoped owner or fixture TearDown. Any fatal assertion above returns before these finish_func calls, so a numerical mismatch also leaves the Libxc allocations live and can add misleading leak reports to the sanitizer run.

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.

3 participants