FusionRCG: Orchestrating Recursive Computation Graphs across GPU Memory Hierarchies Xinran Wei†
Yihong Zhang†
Junshi Chen
arXiv:2605.10312v1 [physics.comp-ph] 11 May 2026
University of Science and Technology of China Zhongguancun Academy University of Science and Technology of China Hefei, Anhui, China Beijing, China Hefei, Anhui, China [email protected] [email protected] [email protected]
Fusong Ju∗
Wei Hu∗
Jinlong Yang
Zhongguancun Academy Beijing, China [email protected]
University of Science and Technology of China Hefei, Anhui, China [email protected]
University of Science and Technology of China Hefei, Anhui, China [email protected]
Huanhuan Xia∗ Zhongguancun Academy Beijing, China [email protected]
Abstract—Evaluating high-dimensional integrals via deep hierarchical recurrences is a dominant cost in quantum chemistry. While CPUs manage these efficiently, GPUs suffer a critical mismatch: limited per-thread memory is quickly overwhelmed by an explosion of simultaneously live intermediate variables. As recurrence scales, this forces massive data spilling to global memory, collapsing performance into a severe memory-bound regime. We present FusionRCG, a framework that jointly optimizes computation graph structure and GPU memory mapping. Exploiting the inherent topological flexibility of recurrence graphs, using electron repulsion integrals as an example, we contribute: (1) liveness-aware graph orchestration to minimize peak live intermediates; (2) algebraic dimensionality reduction via stepwise Cartesian-to-spherical fusion, shrinking intermediate footprints by up to 7.7×; and (3) an adaptive multi-tier kernel architecture routing graphs across the memory hierarchy. Evaluated on NVIDIA A100 GPUs, FusionRCG achieves up to 3.09× end-toend SCF speedup over GPU4PySCF and maintains 75% parallel efficiency at 64 GPUs, successfully rescuing these workloads from memory-bound limits. Index Terms—GPU, memory hierarchy, recursive computation graph scheduling, register pressure, electron repulsion integrals
I. I NTRODUCTION In modern large-scale quantum chemistry simulations, evaluating high-dimensional tensor integrals via deep hierarchical recurrences constitutes a critical computational bottleneck [1]– [3]. From an algorithmic and computer architecture perspective, such workloads can be naturally modeled as Recursive Computation Graphs (RCGs), where vertices represent intermediate quantities and edges encode recurrence dependencies. As the polynomial degree or the dimensionality of the † These authors contributed equally to this work.
Corresponding authors: Fusong Ju ([email protected]), Wei Hu ([email protected]), Leo Xia ([email protected]).
problem increases, the number of intermediate variables that must be simultaneously maintained within this computation graph undergoes a combinatorial explosion. While CPUs can efficiently manage this super-polynomial growth by utilizing sophisticated out-of-order execution engines and deep, multilevel cache hierarchies to absorb the exploding intermediate state [4], [5], porting such recursive workloads to modern GPUs exposes a severe architectural mismatch. GPU performance relies on massive thread-level parallelism, which strictly constrains per-thread on-chip storage [6]. When the working set of simultaneously live intermediates breaches the hard ceiling of physical registers, the compiler is forced to spill massive amounts of data to the high-latency, off-chip global memory [7]. This pure memory-hierarchy crisis drastically collapses hardware thread occupancy, submerging the execution in memory access latency and degrading an inherently compute-bound kernel into a memory-bound bottleneck [8]. A representative and highly demanding instantiation of this memory-bound RCG is the calculation of electron repulsion integrals (ERIs). ERIs are 4-index tensor integrals that describe particle interactions, serving as a foundational operator in many high-fidelity scientific simulations and typically consuming 80% of total runtime [1]–[3], [9]. Accelerating ERI calculation has therefore been a long-standing objective within the computational chemistry community, and existing GPU engines have achieved notable success [2], [9]. Most successful GPU implementations are based on Rys quadrature or McMurchie–Davidson (MD) formulations [9]–[11]. These formulations are well aligned with SIMT execution because they expose regular batched parallelism and maintain a comparatively controlled intermediate footprint.
tightly coupled dimensions relevant to GPU execution: • Computation Graph Structure and Execution Order. The HGP recurrence does not induce a unique computation graph. Different legal reduction paths generate structurally distinct graphs, and different topological orders expose different live ranges even for the same graph. Together, these factors determine the peak number of simultaneously live intermediates. • Intermediate State Size Optimization. The cost of HGP on GPUs is governed not only by arithmetic count, but also by the physical size of the intermediate state carried between recurrence stages and contraction. The basis and representation in which these intermediates are maintained directly affect both storage demand and data movement. • Memory Mapping across GPU Hierarchy. As angular momentum increases, the working set of the recurrence inevitably outgrows the smallest on-chip storage. Performance therefore depends on how intermediate state is placed across registers, shared memory, and global memory, rather than on arithmetic optimization alone. Based on these insights, we present FusionRCG, a framework that addresses the memory wall for hierarchical recursive computation graphs by systematically orchestrating their evaluation. By co-designing the graph structure, memory mapping, and algebraic boundaries, FusionRCG preserves the exact mathematical arithmetic of HGP while eliminating its historical GPU bottlenecks. Our contributions are threefold, directly addressing the dimensions above:
Fig. 1: Recursive computation graph structure of HGP and its associated GPU bottlenecks. The first recurrence phase generates a rapidly expanding dependency graph with a large peaklive frontier, while the second recurrence phase introduces long-lived accumulators; these phases are formalized later as VRR and HRR, respectively, in Section II-A. Their overlap within the same register file creates the fundamental memory bottleneck.
The Head-Gordon-Pople (HGP) algorithm, by contrast, represents a markedly different ERI formulation. HGP and its variants remain highly influential in CPU engines due to their favorable contraction-aware arithmetic structure and their substantially lower floating-point operation count than Rys quadrature and McMurchie–Davidson formulations [1], [12], [13]. However, executing HGP efficiently on GPUs is notoriously difficult, and mainstream adoption has been severely limited. This difficulty is fundamentally driven by HGP’s mathematical formulation: it evaluates an ERI through deep, chained recurrences over Cartesian intermediates. When mapped onto SIMT hardware, a target integral expands into a massive dependency graph where many intermediates are produced early but consumed much later. This forces an enormous working set to remain simultaneously live, triggering the exact memory-hierarchy crisis described above. Because of this severe register pressure, massive data spilling, and excessive global-memory traffic, many optimization efforts for HGP on GPUs inevitably hit a performance wall. Figure 1 illustrates this recursive computation graph structure and the memory bottlenecks during two HGP phases (formalized in Section II-A). Bridging the gap between HGP’s arithmetic advantages and its limited practical viability on GPUs requires more than accelerating a fixed kernel. The key insight of this work is that a strictly defined mathematical result does not imply a unique computation graph. This reveals a previously under-exploited optimization space in which HGP can be analyzed along three
• Liveness-aware graph orchestration for registercontained execution (§III-A). By jointly optimizing the graph topology and the evaluation schedule, FusionRCG drastically minimizes the peak working set of live intermediates. This structural optimization effectively eliminates register spilling for low-to-moderate degree recurrences, keeping the dense execution entirely on-chip. • Algebraic dimensionality reduction to minimize globalmemory traffic (§III-B). We step-wise fuse the standard Cartesian-to-pure-spherical shell transformation [5], [14] directly into the final stages of the recurrence. This shrinks the contraction-bound intermediate tensors and the associated buffer writes / atomicAdd traffic by up to 7.7× without introducing any mathematical approximation. • An adaptive multi-tier execution strategy across the GPU memory hierarchy (§III-C). We demonstrate that memory pressure arises from distinct sources as the problem scales. To address this, the framework automatically routes each computation graph to the appropriate memory level—emitting fundamentally different kernel architectures (register-only or shared-memory-buffered) based on computational complexity.
2
Evaluated on NVIDIA A100 GPUs against the state-ofthe-art GPU4PySCF [9], FusionRCG achieves up to 3.09× end-to-end SCF speedup on representative molecular systems with an average of 2.4× at the cc-pVQZ level, and scales to 64 GPUs with 75% parallel efficiency, successfully rescuing the execution from the memory-bound regime. Figure 2 provides an overview of the code generation and memory mapping pipeline.
which requires maintaining the architectural state of thousands of in-flight threads simultaneously. To support this, NVIDIA GPUs provide a massive but strictly partitioned register file. Each Streaming Multiprocessor (SM) contains 65,536 32-bit registers shared among all resident threads, imposing a hard per-thread architectural ceiling of 255 registers. When a compute kernel’s working set exceeds this 255register limit, the compiler is forced to spill excess intermediate values to per-thread local memory, which is physically backed by off-chip High Bandwidth Memory (HBM). These spills are devastating to performance because the bandwidth gap across the memory hierarchy is extreme. The SM register file delivers an aggregate bandwidth of ∼19 TB/s, whereas global HBM provides only ∼2 TB/s—a disparity of nearly 10,000× at the per-SM level. Between these two extremes, the shared memory/L1 cache (19 TB/s, 164 KB/SM) and L2 cache (5 TB/s, 40 MB) offer vital intermediate capacity-bandwidth trade-offs. FusionRCG utilizes this exact hierarchy, mapping intermediates strictly to registers (Tier 1) or buffering them through shared memory and global memory (Tier 2) based on the computation’s exact spatial footprint.
II. BACKGROUND AND M OTIVATION A. The HGP Recurrence for ERIs To understand the origin of the memory bottleneck, we first examine the underlying mathematical formulation. An electron repulsion integral over four Gaussian basis functions a, b, c, d is defined as: ZZ ϕa (r1 )ϕb (r1 ) ϕc (r2 )ϕd (r2 ) (ab|cd) = dr1 dr2 (1) |r1 − r2 | where ϕa is a Cartesian Gaussian with angular momentum a = (ax , ay , az ), and total angular momentum |a| = la . In the notation below, (ab|cd) denotes the target contracted ERI, whereas the bracketed quantities [· · · | · · · ](m) denote the HGP auxiliary integral family indexed by the Boys order m. The HGP algorithm [1] evaluates Eq. (1) through a two-phase hierarchical recurrence:
C. From Recurrence to Register Wall When the HGP mathematical formulation is mapped onto the SIMT execution model, it manifests as a dense computation graph whose size grows combinatorially with the angular-momentum quartet l = (la , lb , lc , ld ). Because each node in this graph represents a double-precision intermediate occupying two 32-bit registers, even modest quantum systems generate massive register demand. P For example, at l = (1, 1, 1, 1) ( li = 4), the graph contains over 700 nodes. If all intermediates were simultaneously live, the naive register requirement would exceed the 255-register hardware limit by nearly 6×. By l = (2, 2, 2, 2) P ( li = 8), the graph grows to thousands of nodes, surpassing the limit by more than 28×. Fortunately, the hardware does not need to store the entire graph simultaneously. A register is occupied only while the corresponding intermediate remains needed by a future consumer; once all uses of that value are complete, its register is reclaimed. Therefore, the actual bottleneck within the recurrence graph is the peak simultaneously live set. Let G = (V, E) denote the computation graph, where each vertex v ∈ V is an intermediate and each edge encodes a data dependency. Given a topological ordering π of G, a vertex v is live at step t if it has been computed but at least one of its consumers has not yet been scheduled. The peak liveness is defined as:
Phase 1: Vertical Recurrence Relation (VRR). Starting from Boys-function base values Fm (T ) ≡ [0 0|0 0](m) , VRR builds up angular momentum one index component at a time: [a + 1i 0|c 0](m) = (Pi − Ai ) [a 0|c 0](m) + (Wi − Pi ) [a 0|c 0](m+1) ρ ai [a − 1i 0|c 0](m) − [· · · ](m+1) + 2ζ ζ ci + [a 0|c − 1i 0](m+1) (2) 2(ζ + η) where 1i is the unit vector along axis i, and ζ, η, ρ, P, W are Gaussian-product parameters. Each node depends on 2 to 5 parents. Crucially, the choice of which index i to increment is not strictly fixed, providing a structural degree of freedom that we will exploit. Phase 2: Horizontal Recurrence Relation (HRR). After contraction, HRR transfers angular momentum from center-pair products to individual centers via a simpler binary recurrence: (a b + 1i |c d) = (a + 1i b|c d) + (Ai − Bi ) (a b|c d) (3) Each HRR node depends on exactly 2 parents. While the operation count of this two-phase approach is highly efficient, executing its data dependencies on massively parallel hardware exposes severe physical constraints.
PeakLive(π) = max {v ∈ V | v live at step t} t
B. GPU Memory Hierarchy and the Register Wall
(4)
This PeakLive metric is highly sensitive to both the graph’s structural topology and its evaluation order—the two degrees of freedom that FusionRCG optimizes.
Modern GPUs derive their massive throughput from the Single Instruction Multiple Threads (SIMT) execution model,
3
Fig. 2: FusionRCG overview. Given an angular-momentum quartet, the generator first optimizes the Phase 1 VRR graph for low peak liveness, then selects a register-only Tier 1 backend or a buffered Tier 2 backend based on decomposed register demand, and finally fuses the standard Cartesian-to-pure-spherical shell transformation into the Phase 2 HRR stage before generating specialized CUDA kernels. Algorithm 1 Axis-priority rule (consumer-first, z → y → x). 1: for i = 0, 1, 2 do 2: if c[i] > 0 then 3: axis ← i + 3 4: else if a[i] > 0 then 5: axis ← i 6: end if 7: end for
Rtotal ≈ 2 PeakLiveVRR + Nacc
(2li + 1)
(6)
Ultimately, the register wall is not caused by isolated bottlenecks, but by the overlap of a massive short-lived VRR frontier colliding with a persistent accumulator bank within the same finite register file. Figure 1 visually summarizes this sharedpressure bottleneck and how the combined footprint dictates the feasible execution regime.
However, peak liveness captures only the transient portion of the on-chip footprint. In a full HGP kernel, these shortlived VRR intermediates must coexist with a second, longlived term: the Phase 2 accumulators. These accumulators are allocated before the primitive loops begin and must remain resident across all primitive combinations. For a shell quartet l = (l1 , l2 , l3 , l4 ), their count is: 4 Y
// then left side
superposition:
Fig. 3: Axis selection reshapes the VRR computation graph before scheduling. Starting from the same recurrence state, consumer-first (left) and producer-first (right) generate graphs with identical arithmetic but different frontier width. The consumer-first graph is narrower, so fewer intermediates must remain live simultaneously.
Nacc =
// right side first
III. F USION RCG The three components of FusionRCG operate at distinct but coupled levels. At the mathematical level, HGP exposes flexibility in recurrence path selection and intermediate representation. At the algorithmic level, FusionRCG converts this flexibility into graph construction, scheduling, and staged transformation rules during code generation. At the architectural level, these decisions reduce register pressure, shrink data movement, and determine whether execution remains registerresident or must be routed through higher memory tiers.
(5)
i=1
The total shared register demand is therefore dictated by their
4
Dependency Scheduling Algorithm (DSA). Given a fixed computation graph G = (V, E) from the axis-priority construction, we then optimize only the evaluation order on that fixed computation graph. This subproblem is closely related to classical minimum-register sequencing and register-pressureaware instruction scheduling on trees, computation graphs, and GPU scheduling regions [15]–[20]. In contrast to Figure 3, which changes the graph structure itself, DSA keeps the nodes and edges unchanged and seeks a topological ordering π minimizing PeakLive(π). DSA is therefore not a new scheduling formulation; it is a lightweight domain-specific heuristic tailored to our offline recurrence code generation. Our greedy heuristic maintains a ready set R and at each step selects: X v ∗ = arg max out(w) − in(w) (7)
FusionRCG integrates three co-designed optimizations within a single code-generation framework: liveness-aware recurrence orchestration (§III-A), algebraic dimensionality reduction of the contraction-bound intermediate space (§III-B), and adaptive multi-tier mapping across the GPU memory hierarchy (§III-C). All decisions in this section are made at code-generation time—the generated GPU kernel contains a fixed, fully unrolled instruction sequence with no runtime branching. A. Liveness-Aware Recurrence Orchestration Mathematically, HGP admits multiple equivalent recurrence paths for the same target integral. Algorithmically, we exploit this freedom through graph construction and topological scheduling at code-generation time. Architecturally, the objective is to minimize the peak live frontier so that Phase 1 remains as register-resident as possible. The HGP recurrence (Eq. 2) increments one component of the multi-index (a, c) per step. With a = (ax , ay , az ) and c = (cx , cy , cz ), there are up to six valid reduction axes at each node: three on the left side (ax , ay , az ) and three on the right side (cx , cy , cz ). Choosing different axes does not change the total node count or the total arithmetic—but it fundamentally reshapes the graph topology. A “wide” expansion (reducing high-degree axes first) creates broad wavefronts where many intermediates are simultaneously live. A “deep” expansion (reducing loworder axes first) creates narrow channels that limit concurrent liveness. Figure 3 isolates this graph-construction effect: two axis-selection strategies on the same starting node produce computation graphs with identical node count but 1.5–2× different PeakLive. Figure 2(b) then isolates the execution strategy after the computation-graph structure has been fixed. This observation is the foundation of our approach: before optimizing the evaluation order of a fixed graph (a compiler problem), we optimize the graph structure itself (a domainspecific algebraic problem).
v∈R
w∈Reach(v)
The intuition behind this scoring function is that it captures the “register release potential” of scheduling v next. Nodes reachable from v with high fan-out (out ≫ in) are distributors—scheduling them early enables their consumers to execute promptly and release registers. Nodes with high fan-in (in ≫ out) are accumulators—deferring them avoids premature liveness inflation. DSA thus prioritizes paths that lead to rapid register turnover (Figure 2(b)). The algorithm runs in O(|V |2 ) time, acceptable for offline code generation: the full schedule for l = (2, 2, 2, 2) (|V | = 3,545) completes in seconds on one CPU core. B. Algebraic Dimensionality Reduction via Spherical Fusion Mathematically, the Phase 2 result can be represented either in the Cartesian shell basis or, after an exact shell transformation, in the pure spherical basis. Algorithmically, FusionRCG fuses this basis change into the recurrence boundary instead of materializing the full Cartesian tensor first. Architecturally, this reduces the size of contraction-bound intermediates and the associated global-memory traffic. Phase 2 naturally produces contraction-bound intermediates resolved in the Cartesian Gaussian shell basis. In most electronic-structure implementations, however, the final shell representation is the pure spherical harmonic Gaussian basis, so an additional Cartesian-to-spherical transformation is required [5], [14]. For a shell of angular momentum l, this transformation has the standard form X (l) (sph) (cart) Ilm = tijk,lm Iijk , (8)
Axis-Priority Rule. FusionRCG uses a deterministic axispriority rule that selects the reduction axis at each VRR node (Algorithm 1). This ordering is motivated by two observations. First, reducing ket-side indices before bra-side indices (consumerfirst) generates subgraphs whose outputs are consumed sooner by the downstream HRR phase, thereby shortening bra-side accumulator lifetimes. Second, within each side, the z → y → x traversal order exploits the fact that z-components have the smallest fan-out per recursion step in the Cartesian basis ordering, creating narrower wavefronts that minimize simultaneously live nodes. On l = (1, 1, 1, 1), this priority reduces PeakLive by 42% versus the worst axis ordering (brafirst, x → y → z), with zero change to total arithmetic or node count.
i+j+k=l (l)
where the coefficients tijk,lm depend only on the angular momentum and can therefore be pretabulated or generated analytically [5], [14]. Accordingly, each transformed index shrinks from ncart (l) = (l + 1)(l + 2)/2 Cartesian components to nsph (l) = 2l + 1 pure spherical components.
5
The compression ratio grows rapidly with l: at l = 4, each index shrinks from 15 to 9 components, yielding 154 /94 = 7.7× fewer contraction-bound intermediates for a four-index tensor. This exact shell transformation directly reduces Phase 2 node count, atomicAdd traffic to global memory, and downstream contraction work.
Fig. 4: Cartesian-to-spherical transformation and stepwise fusion. (a) At l = 2, the standard shell transformation maps 6 Cartesian Gaussian components to 5 pure spherical components per index via the fixed coefficient matrix t(l) . (b) FusionRCG applies this transformation one index at a time under a 4-bit mask (0000 → 1000 → 1100 → 1110 → 1111), shrinking the intermediate tensor progressively instead of materializing the full Cartesian intermediate tensor first.
Stepwise Fusion into the Recurrence. A naive implementation would first materialize the full Cartesian intermediate tensor and only then apply Eq. (8). FusionRCG instead fuses this standard shell transformation into Phase 2, applying it incrementally at HRR boundaries. The transformation state is tracked by a 4-bit mask, so each step retires a Cartesian index immediately after it has been consumed and replaces it with its smaller spherical counterpart. The result is a progressively shrinking intermediate tensor rather than a materialize-thentransform pipeline. The correctness of this rearrangement follows from the fact that HRR operators are linear and act on disjoint index pairs. Let the contracted VRR output be the four-center Cartesian tensor Hαβγδ := χA,cart χB,cart χC,cart χD,cart , (9) α γ β δ
T(la ) ⊗T(lb ) acts only on (α, β), the two operations commute: Rcd T(la ) ⊗T(lb ) = T(la ) ⊗T(lb ) Rcd . (14) Advancing the bra transformation ahead of the ket HRR therefore does not change the mathematical result. Finally, the ket indices are transformed: X (l ) (l ) (3) (4) Gµνλσ := Tλγc′ Tσδd′ Gµνγ ′ δ′ . (15) γ ′ δ′
where α, β, γ, δ index Cartesian components on centers A, B, C, D. For a shell of angular momentum l, the corresponding pure spherical basis functions satisfy X (l) cart ϕsph Tµα χα . (10) µ :=
Chaining these steps gives the fused operator emitted by FusionRCG, Gfinal = T(lc ) ⊗T(ld ) Rcd T(la ) ⊗T(lb ) Rab H. (16) Using Eq. (14), this is algebraically identical to the conventional materialize-then-transform pipeline, T(la ) ⊗T(lb ) ⊗T(lc ) ⊗T(ld ) Rcd Rab H. (17)
α (la )
(lb )
(lc )
(ld )
The conventional scheme applies T ⊗T ⊗T ⊗T after both HRR sweeps. FusionRCG interleaves these transformations with the bra–ket HRR sequence. For compact notation, the following derivation groups the two bra transformations and the two ket transformations; the implementation realizes the same algebra through the per-index mask shown in Figure 4. First, the bra-side HRR operator Rab (·; Oab ), with Oab = A − B, produces (1) Gαβγδ := Rab (H; Oab ) αβγδ . (11) The bra indices can then be transformed immediately: X (2) (la ) (lb ) (1) Gµνγδ := Tµα Tνβ Gαβγδ ,
Stepwise spherical fusion is therefore an implementation rearrangement, not a numerical approximation: it preserves the HGP result while avoiding the full Cartesian footprint during Phase 2. C. Adaptive Multi-Tier Kernel Architecture Mathematically and algorithmically, the first two components reduce the transient live set and the size of Phase 2 intermediates, but they do not remove the strong dependence of total footprint on angular momentum. Architecturally, the remaining problem is therefore one of memory placement: different quartets must be mapped to different levels of the GPU hierarchy according to their decomposed register demand. While the liveness-aware orchestration (§III-A) and algebraic dimensionality reduction (§III-B) presented above significantly reduce on-chip memory pressure, the residual register footprint still varies dramatically across angularmomentum quartets. A natural design choice would be to adopt a single buffered execution pipeline for all cases, since buffering through shared memory and global memory can accommodate arbitrarily large working sets. However, such a
(12)
αβ
or compactly G(2) = T(la ) ⊗T(lb ) G(1) . This step shrinks the bra half of the tensor from ncart (la )ncart (lb ) to nsph (la )nsph (lb ) components before the ket-side sweep begins. The ket-side HRR operator Rcd (·; Ocd ), with Ocd = C−D, then acts only on the ket indices: (3) Gµνγ ′ δ′ := Rcd (G(2) ; Ocd ) µνγ ′ δ′ . (13) Because Rcd is linear and touches only (γ, δ), while
6
Algorithm 2 Tier 1 Register-Only ERI Kernel (Optimized Stepwise Spherical Fusion)
uniform strategy introduces non-negligible fixed overheads— global buffer allocation, a layout-conversion kernel, and two separate kernel launches with synchronization barriers. For low-to-moderate degree quartets where total register spill remains below ∼1 KB, these fixed costs exceed the spill penalty itself, making a lightweight register-only path consistently faster (validated in §V-B). Conversely, for high-degree quartets whose persistent Phase 2 accumulator bank alone surpasses the hardware register budget, no scheduling improvement can fit the data on chip, and buffered execution becomes structurally mandatory. This asymmetry motivates our adaptive two-tier kernel architecture. The tier decision is derived from the decomposed register pressure model in Eq. (6): the same register file is jointly occupied by the transient VRR live frontier and the persistent accumulator bank (Figure 1), so the feasible execution regime depends on their combined footprint relative to the 255-register architectural limit. Concretely, this yields two hardware regimes:
1: Input: Shell quartet (a, b, c, d) with primitives {(αi , ci )},
density D 2: H[0 . . . Nhrr − 1] ← 0
▷ contraction accumulators (registers) 3: for each primitive quartet (αa , αb , αc , αd ) do 4: ζ, η, P, Q, T ← G AUSSIAN PAIRS(αa , αb , αc , αd ) 5: F0 , . . . , Fm ← B OYS(T, m) 6: V ← VRRπ∗ (F0 . . . Fm , ζ, η, P, Q) ▷ DSA-ordered schedule π ∗ 7: H += ca cb cc cd · V 8: end for 9: Gcart ← HRR bra (H, Oab ) ▷ stepwise spherical fusion Gsph ← (T(la ) ⊗ T(lb ) ) · Gcart Gcart ← HRRket (Gsph , Ocd ) Gsph ← (T(lc ) ⊗ T(ld ) ) · Gcart 10: J, K += S CATTER(Gsph , D)
overhead-free path outperforms the two-kernel Tier 2 pipeline despite the minor spill. P 2) Tier 2: Buffered Two-Kernel Pipeline ( li ≥ 7): When Nacc alone exceeds the register budget (Regime II), accumulator variables cannot reside in registers regardless of VRR scheduling. This structural constraint—not an implementation choice—necessitates a fundamentally different architecture with two cooperating kernels (Figure 2 (a)).
P Regime I ( li ≤ 6). The combined footprint of transient VRR intermediates and persistent accumulators still fits in registers. Nacc reaches at most 225 (at l = (2, 2, 1, 1): 5 × 5 × 3 × 3); after DSA, PeakLiveVRR ≲ 50. Shared register occupancy therefore remains within the hardware budget with at most negligible spill (<1 KB), so a register-only fused kernel is emitted (§III-C1). P Regime II ( li ≥ 7). The persistent accumulator bank already dominates the shared footprint. At (2, 2, 2, 1): 5 × 5 × 5 × 3 = 375 doubles = 750 registers—3× the hardware limit before any transient VRR term is added. In this regime, keeping accumulators on chip is structurally impossible, so a buffered two-kernel pipeline is emitted (§III-C2) while VRR intermediates are still kept register-resident as much as possible. The tier boundaries are not tuned hyperparameters: they follow directly from Eq. (6) and the 255-register limit. P 1) Tier 1: Register-Only Kernels ( li ≤ 6): When the shared footprint fits in registers (Regime I), FusionRCG generates a single fused kernel that keeps all intermediates in the register file. Phase 1 (VRR) executes inside four nested primitive loops using DSA-scheduled register variables. Results accumulate into Phase 2 (HRR) input variables via +=, exploiting the well-known accumulate-then-transform restructuring [1] that avoids n4p redundant HRR evaluations. Phase 2 executes once after the loops, and the output contraction (J/K matrix update via atomicAdd) is fused inline—no intermediate writes to global memory at any point. Algorithm 2 illustrates the generated kernel structure. This path has zero fixed overhead: no global buffer allocation, no transpose, no extra kernel launch. For quartets where residual spill is below ∼1 KB (e.g., 484 B for (1, 1, 1, 1)), this
Kernel 1 (Evaluation). A warp-sized batch of 32 threads cooperatively evaluates their respective shell quartets. VRR intermediates remain in registers (bounded by DSA); HRR accumulators are written to an interleaved global buffer layout, enabling coalesced memory access across the warp. A two-pass lifetime allocator (forward dry-run for birth/death timestamps, reverse-time best-fit packing) enables slot reuse: for l = (2, 2, 2, 2), this compresses 3,545 slots to 1,865—a 1.9× reduction. Kernel 2 (Contraction). Each thread block processes one task with 64 threads. Both the density matrix tile D and the intermediate buffer are loaded into shared memory (≤ 48 KB), delivering ∼19 TB/s bandwidth—10× over HBM. The conP traction Jcd += ab Dab · I[a, b, c, d] exploits 8-fold ERI permutation symmetry via scale factors. IV. I MPLEMENTATION FusionRCG is implemented as an offline code generator rather than a hand-written collection of CUDA kernels. This design is necessary because each angular-momentum quartet induces a different recurrence graph, liveness profile, tier decision, and lowering strategy; encoding these combinations manually would be both error-prone and difficult to maintain as the optimization rules evolve. For each parameter tuple l = (l1 , l2 , l3 , l4 ), the generator therefore executes a nine-stage
7
Throughput and Speedup from DSA Scheduling