Store the two-electron integrals packed (8- or 4-fold), not dense — 4-8x on the largest replicated array

Open
#8 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp, python

Research direction

Start with src/qops/bindings_qops.cpp, include/common/fcidump.hpp, and python/gpu_dmrg_scf.py to trace how packed PySCF integrals become the resident FCIDUMP array. Compare 4-fold or 8-fold storage and lookup costs, then benchmark µ-term assembly and complementary-operator forming. Done means lower resident memory with no measured forming or assembly regression and the CPU block-sparse path remains bit-identical to the dense 4^m oracle.

Written by the indexing model from the issue text.

Description

performance request

The two-electron integrals are stored fully dense — K⁴ doubles — on every rank, and are materialized densely twice on the way in. Real permutational symmetry is 8-fold for the restricted case, so the resident array is ~8× larger than it needs to be.

This is the largest single replicated array in a multi-rank run, and replicated memory is the per-rank floor that decides how large a system fits no matter how many GPUs are added. It is plausibly implicated in the n16 BD=6000 OOM recorded at grow_gpu.cpp:620-623 ("33 GB captive + 14 GB free < the ML=6000 forming ctx") — not as the sole cause, but as a term that is pure duplication.

Where it comes from — our side of the boundary, not PySCF's
// src/qops/bindings_qops.cpp:48-64
using Arr4 = nb::ndarray<const double, nb::ndim<4>, nb::c_contig>;
...
fd.h2e.assign(g2e.data(), g2e.data() + n2 * n2);
// include/common/fcidump.hpp:52-54
std::size_t index2(int p, int q, int r, int s) const {
    return ((static_cast<std::size_t>(p) * norb + q) * norb + r) * norb + s;
}

The binding takes a dense rank-4 array and flat-assigns K⁴ doubles; FCIDUMP then indexes it as a fully dense ((p·K+q)·K+r)·K+s.

PySCF hands over a 4-fold-packed (npair, npair) ERI from get_h2eff() and is perfectly happy to. The ao2mo.restore(1, ...) call in _normalize_integrals (python/gpu_dmrg_scf.py) exists purely to satisfy that signature — it is not a PySCF requirement and not a physics requirement.

So per rank, at session construction, three copies coexist:

  1. PySCF's packed (npair, npair) array — ~K⁴/4
  2. the dense numpy expansion from restore(1) — K⁴
  3. the C++ fd.h2e copy — K⁴

At K = 100: ~800 MB apiece for (2) and (3), so ~1.6 GB per rank of duplication, on every rank, before a single renormalized block is allocated.

Proposed work, in ascending order
change payoff risk
a Consume the numpy buffer without the extra fd.h2e copy, or free the numpy array once copied halves the transient peak low — no algorithmic change
b Store 4-fold packed (npair, npair), expand indices inside FCIDUMP::h2() 4× on the resident array medium
c Store 8-fold packed (restricted case) 8× medium

(a) is worth doing on its own and is close to free.

The catch, and why this is not a half-day job

FCIDUMP::h2() is on the hot path of µ-term assembly and complementary-operator forming. Replacing a flat multiply-add index with a packed lookup (ij = p >= q ? p*(p+1)/2 + q : q*(q+1)/2 + p) puts branches where there is currently arithmetic. This wants measuring, not assuming.

An honest version of (b)/(c) is therefore:

  • the storage change, plus
  • a forming/assembly benchmark showing no regression, plus
  • possibly a one-off unpack into the dense form for the phases that genuinely stream it, keeping the packed array as the resident copy.

It is a dmrg_common change and touches both engines (dmrg_qops and dmrg_mpo), so the layered-oracle gates apply: the CPU block-sparse path must stay bit-identical, and the dense 4^m Fock-space oracle is the reference.

Secondary benefit

The MPI integral broadcast added in feat/pyscf_interface (_bcast_integrals) shrinks by the same factor. That is the smaller prize — the broadcast is O(K⁴) once per solver call against a solve that is O(K³M²) per sweep — while this memory is resident for the whole run. It already broadcasts the packed form rather than the expansion, so the wire cost is 4× lower today; only the resident cost remains.

Notes
  • Recorded as B1 in multigpu.md.
  • Flagged there as the one Part II item that does not need the profiling work done first: the win is a memory ratio computable from K before writing a line, so it can proceed in parallel.
  • The UHF path stores three dense K⁴ blocks (h2e, h2ab, h2bb) and has its own packing structure — aa/bb are 8-fold symmetric, ab only 4-fold. Worth scoping separately.

Effort: ~1-2 days including the benchmark. Payoff: 4-8× on the single largest replicated array.

Dominant language
C++
Stars
3
Forks
0
Avg merge
2d 8h
Merged PRs (30d)
31

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Algorithmiq/exa-dmrg

All issues in Algorithmiq/exa-dmrg

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.