Skip to content

perf(pw): accelerate GPU projector and DeltaSpin workloads (by OutisLi and dyzheng) - #8461

Open
Flying-dragon-boxing wants to merge 6 commits into
deepmodeling:developfrom
Flying-dragon-boxing:split/pr8306-projector-deltaspin-gpu
Open

Flying-dragon-boxing wants to merge 6 commits into
deepmodeling:developfrom
Flying-dragon-boxing:split/pr8306-projector-deltaspin-gpu

Conversation

@Flying-dragon-boxing

Copy link
Copy Markdown
Collaborator

Summary

Split from #8306 as an independent GPU projector/DeltaSpin optimization.

  • Fold and cache eligible device projectors by k point, with the existing GEMM path as fallback.
  • Move DeltaSpin projector contractions and magnetic-moment accumulation to CUDA.
  • Reuse fixed-overlap response data and batch eligible response solves.
  • Pass solver and logging dependencies explicitly through the updated DeltaSpin interfaces.

No INPUT parameter or input-file behavior is changed.

Performance

Measured against the same pre-synchronization baseline on dual RTX 4090 GPUs. These are end-to-end SCF wall times, not kernel-only timings.

  • Original Fe32 DeltaSpin case: 3545.84 s -> 2308.01 s (1.536x). This is one complete baseline/candidate pair and should be repeated before treating the magnitude as final.
  • Original Fe16 case: 713.80 s -> 704.28 s (1.014x).
  • Si16 smoke case: 1.029x.
  • Fe32 SCF/constraint/k-point/hPsi call counts matched. The largest SCF energy difference across the tested cases was about 1.15e-8 eV.

The branch was subsequently merged with upstream/develop at 5064965; performance was not re-measured after that synchronization.

Verification

  • CUDA 12.6, RTX 4090: cmake --build build -j 16 passed at c8eb4de.
  • OMP_NUM_THREADS=1 ctest --test-dir build --output-on-failure -R '^(MODULE_LCAO_deltaspin_template_helpers|MODULE_BASE_KERNELS_Unittests)$': 2/2 passed.
  • git diff --check upstream/develop...HEAD: passed.
  • python3 tools/03_code_analysis/agent_governance_check.py --base upstream/develop --head HEAD --format text: no blocking findings.
  • ROCm was not built or tested.

Review notes

  • The projector cache is restricted to supported CUDA layouts; other types, pool-parallel layouts, and unsupported precisions retain the generic implementation.
  • Global dependency references decrease (net -5); the remaining moves are migration-neutral while rank, stream, and solver values are passed explicitly.
  • New header dependencies provide the fixed-overlap and folded-projector types used by the implementation.

dyzheng and others added 2 commits November 25, 2026 15:44
Split from deepmodeling#8306. Add grouped projector products, batched complex GEMMs, fixed-overlap response solves, and device constraint/moment kernels.
…jector-deltaspin-gpu

# Conflicts:
#	source/source_lcao/module_deltaspin/cal_mw_from_lambda.cpp
#	source/source_lcao/module_deltaspin/deltaspin_pw_mi.cpp
#	source/source_pw/module_proj/onsite_proj_tools.h
#	source/source_pw/module_pwdft/kernels/onsite_op.h
#	source/source_pw/module_pwdft/nonlocal_workspace.cpp
#	source/source_pw/module_pwdft/nonlocal_workspace.h
#	source/source_pw/module_pwdft/op_pw_nl.cpp
@mohanchen mohanchen added Refactor Refactor ABACUS codes GPU & DCU & HPC GPU and DCU and HPC related any issues labels Dec 2, 2026
@Flying-dragon-boxing Flying-dragon-boxing changed the title perf(pw): accelerate GPU projector and DeltaSpin workloads perf(pw): accelerate GPU projector and DeltaSpin workloads (by OutisLi and dyzheng) Dec 2, 2026
@Flying-dragon-boxing
Flying-dragon-boxing marked this pull request as ready for review December 2, 2026 05:54
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-02T06:02:39.433700Z e49b1ab Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e49b1ab52e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}
if (projector_fold_)
{
folded = projector_fold_->project(bands, nbasis / npol,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Add focused tests for the folded CUDA projector path

When CUDA complex-double runs with an eligible single-rank, grid-aligned cell, this branch replaces the ordinary P^H psi GEMM with ProjectorFold::project, but a repo-wide search finds no focused test for ProjectorFold or its companion add path. A phase, grouping, or scatter error would alter nonlocal Hamiltonian applications without a test comparing these operations to the reference GEMMs. Add CUDA comparisons for both operations before enabling the optimization.

AGENTS.md reference: AGENTS.md:L26-L27

Useful? React with 👍 / 👎.

release();
return;
}
host_work_.resize(host_bytes_);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Fall back when host batch workspace allocation fails

If the optional batch path is selected and host_bytes_ exceeds available host memory, host_work_.resize() throws during Batch construction; prepare_batch() does not catch it, so the DeltaSpin update exits instead of returning false and using the serial response solve. Handle this host allocation failure like the device-allocation failures so batching remains optional.

Useful? React with 👍 / 👎.

@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 optional response cache can consume memory required by later GPU scratch; please preserve the fallback for those cases. Two nonblocking notes cover focused tests and the new CUDA code style.

Static review only; no builds or runtime tests were run.

Comment on lines +271 to +272
bool batch_response = false;
if (fixed_overlap && nk > 1) { batch_response = fixed_overlap->prepare_batch(); }

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.

[P2] Reserve required response scratch before optional caches

prepare_batch() runs before becp_pointer is allocated, and the first cal_hs_subspace() plus later calculate_delta_hcc() also allocate required GPU scratch. If the optional cache fits but consumes that headroom, those resize_memory_op calls exit instead of taking the fallback. Please reserve the required peak workspace first, or release the optional caches and retry before a fatal allocation path.

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

GPU & DCU & HPC GPU and DCU and HPC related any issues Refactor Refactor ABACUS codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants