Skip to content

Fix: allow DSP builds without C_PACK by falling back to the configured LAPACK provider - #8258

Merged
mohanchen merged 4 commits into
deepmodeling:developfrom
DanielZhao0432:fix-dsp-optional-cpack
Nov 4, 2026
Merged

mohanchen merged 4 commits into
deepmodeling:developfrom
DanielZhao0432:fix-dsp-optional-cpack

Conversation

@DanielZhao0432

@DanielZhao0432 DanielZhao0432 commented Nov 2, 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

Fix #8247

Unit Tests and/or Case Tests for my changes

  • Commands run:
    1. Functional test of the fallback (local, no DSP hardware): compiled
      cpack_zhegvx_fallback.cpp with -D__DSP together with a small driver that
      calls cpack_zhegvx_driver on a 2x2 generalized eigenproblem (workspace
      query + solve, same protocol as diago_lapack.cpp), linked against system
      OpenBLAS/LAPACK → correct eigenvalues, max residual 4.4e-16.
    2. CMake configure matrix with mock vendor prefixes:
      • USE_DSP=ON without MT_CPACK_DIR → configures; prints the fallback
        STATUS message; cpack_zhegvx_fallback.cpp is added to the hsolver target;
      • USE_DSP=ON with valid MT_CPACK_DIR → configures; fallback not added,
        libc_pack.a linked (behavior unchanged from [Feat] Add DSP Lapack support #8097);
      • USE_DSP=ON with a bad MT_CPACK_DIR → FATAL_ERROR with a clear message;
      • reconfiguring the same build directory with and without MT_CPACK_DIR
        switches the provider selection correctly both ways;
      • DSP PW-only build (ENABLE_LCAO=OFF, no MT_CPACK_DIR) → configures, and
        the fallback is correctly not added to any target.
    3. MODULE_HSOLVER_LCAO unit test (ENABLE_ELPA=OFF build), now with a
      registered complex ks_solver=lapack case: 5/5 pass single-rank and on 2 MPI
      ranks. The ELPA variant fails to link on this machine due to a pre-existing
      local ELPA/genelpa version mismatch, unrelated to this PR (diago_elpa.cpp
      is untouched).
    4. python3 tools/03_code_analysis/agent_governance_check.py --staged → exit 0.
  • Result summary: all checks above pass (tested revision 073b3ae606).
  • Reproducibility record:
    • Fallback driver: g++ -std=c++11 -D__DSP -I source driver.cpp source/source_hsolver/cpack_zhegvx_fallback.cpp -o test -lopenblas -lgfortran;
      the driver calls cpack_zhegvx_driver on a 2x2 generalized eigenproblem
      (workspace query + solve) and checks residuals of H z = lambda S z.
    • Configure matrix: cmake -S . -B <dir> -DUSE_DSP=ON -DENABLE_ELPA=OFF -DMTBLAS_FFT_DIR=<mock> -DMT_HOST_DIR=<mock> [+- -DMT_CPACK_DIR=<mock>] for
      the unset/valid/invalid-prefix, reconfiguration-toggle, and ENABLE_LCAO=OFF
      scenarios; provider selection verified via the generated hsolver build files.
    • Solver tests: build with ENABLE_ELPA=OFF and run
      OMP_NUM_THREADS=1 ./MODULE_HSOLVER_LCAO (1 rank) and
      mpirun -np 2 ./MODULE_HSOLVER_LCAO. Note: the new complex lapack case is
      NOT skipped on 2 ranks because nb2d=1 gives a 1x1 BLACS grid (dsize==1);
      the dsize > 1 skip guard only triggers for larger grids.
  • Checks not run, with reason: full DSP compile+run requires Tianhe hardware and
    will be verified there (both configurations: with and without MT_CPACK_DIR)
    and reported; CI has no DSP toolchain.

What's changed?

  • Since [Feat] Add DSP Lapack support #8097, every DSP build hard-required C_PACK (MT_CPACK_DIR) because
    DiagoLapack always calls cpack_zhegvx_driver under __DSP. This makes
    C_PACK optional: with MT_CPACK_DIR set, behavior is unchanged; without it,
    the new source/source_hsolver/cpack_zhegvx_fallback.cpp provides
    cpack_zhegvx_driver by forwarding to the configured LAPACK provider's
    zhegvx_.
  • Implementation selection is done by CMake source-file selection (the fallback is
    added to the hsolver objects only when USE_DSP is on and MT_CPACK_DIR is
    unset), so no new compile-time macro is introduced and the two implementations
    can never be linked together.
  • MODULE_HSOLVER_LCAO compiles diago_lapack.cpp directly, so the fallback is
    wired into that test target as well for DSP builds without C_PACK.
  • A complex ks_solver=lapack case is added to the DiagoKPointsTest
    instantiation in test_diago_lcao.cpp; the complex LAPACK path previously had
    no registered coverage there.
  • Legacy Makefile and pyabacus build surfaces need no update: neither supports
    DSP builds (no __DSP there).
  • User-visible change: DSP builds no longer require C_PACK; MT_CPACK_DIR
    remains the way to enable the DSP-offloaded eigensolver. No INPUT changes.

Governance Notes

  • INPUT/docs changes: none.
  • Core module impact: hsolver build lists and the DSP link libraries only; no
    runtime code path changes for non-DSP builds.
  • Exceptions requested: none.

Since deepmodeling#8097, USE_DSP hard-requires MT_CPACK_DIR and DiagoLapack always
calls cpack_zhegvx_driver under __DSP, coupling every DSP build to
C_PACK even though only the serial generalized eigensolver uses it.

Make MT_CPACK_DIR optional: when set, link libc_pack.a as before; when
unset, compile the new cpack_zhegvx_fallback.cpp, which provides
cpack_zhegvx_driver by forwarding to the reference zhegvx_. The two
implementations are selected by CMake source-file selection, so no new
compile-time macro is introduced and they can never be linked together.

Fixes deepmodeling#8247
…ck case

- MODULE_HSOLVER_LCAO compiles diago_lapack.cpp directly, so DSP builds
  without C_PACK need cpack_zhegvx_fallback.cpp there too.
- Add a complex ks_solver=lapack case to the DiagoKPointsTest
  instantiation; the complex LAPACK path (zhegvx_once) had no registered
  coverage.
- Wording: zhegvx_ comes from the configured LAPACK provider, not
  necessarily Netlib reference LAPACK.
@DanielZhao0432 DanielZhao0432 added Bugs Bugs that only solvable with sufficient knowledge of DFT GPU & DCU & HPC GPU and DCU and HPC related any issues Compile & CICD & Docs & Dependencies Issues related to compiling ABACUS labels Nov 2, 2026
@DanielZhao0432 DanielZhao0432 changed the title DSP: make C_PACK optional; fall back to the configured LAPACK provider Fix: allow DSP builds without C_PACK by falling back to the configured LAPACK provider Nov 2, 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.

No confirmed implementation defect found in the inspected forwarding and build-selection paths. The inline comment asks for a reproducible validation record and clearer skip counts.

Static review of 073b3ae6 against d20090cc: whitespace and governance checks completed with no blockers; the documentation warning was assessed against the stated scope. No build or runtime checks were performed. Full DSP validation remains outstanding as noted in the PR.

@DanielZhao0432

Copy link
Copy Markdown
Collaborator Author

@ABACUS-PR-BOT If you think this PR has no defect, then please approve it.

@Cstandardlib

Copy link
Copy Markdown
Collaborator

LGTM🙂 Please resolve the conflicts, and make sure it works on real DSP env

@ABACUS-PR-BOT

Copy link
Copy Markdown
Collaborator

This bot submits COMMENT reviews only; it does not issue approvals. Please ask a human reviewer for an APPROVE review.

…-cpack

Resolve conflict in source_hsolver/unittests/CMakeLists.txt: adopt the
upstream addtest() style while keeping the conditional
cpack_zhegvx_fallback.cpp source in both MODULE_HSOLVER_LCAO variants.
@mohanchen
mohanchen merged commit bcf2fe7 into deepmodeling:develop Nov 4, 2026
18 checks passed
@DanielZhao0432
DanielZhao0432 deleted the fix-dsp-optional-cpack branch November 4, 2026 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bugs Bugs that only solvable with sufficient knowledge of DFT Compile & CICD & Docs & Dependencies Issues related to compiling ABACUS GPU & DCU & HPC GPU and DCU and HPC related any issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[DSP] USE_DSP should not hard-require C_PACK; allow DSP builds with reference LAPACK

4 participants