Commit 078df41
perf(gint): shape-exact bucketing + tile ladder + wide-LDS vbatched GEMM (#7395)
* perf(gint): shape-exact bucketing + tile ladder + wide-LDS vbatched GEMM
Optimize the GPU gint batched-GEMM path (gemm_{nn,tn}_vbatch, driven from
phi_mul_phi / phi_mul_dm) for FP64 on V100/A100-class GPUs.
- phi_operator_gpu: replace the single max-shape vbatch launch with
shape-exact bucketing. Atom pairs are grouped by (nw1, nw2) via a dense
NW_MAX*NW_MAX counting-sort table, pre-enumerated once per batch in
set_bgrid_batch, so each bucket hands the kernel a scalar (m, n, k) and the
tile ladder picks the tightest tile per shape -- no cross-species tile
waste, no over-launched blocks. A guard aborts if any atom nw >= NW_MAX.
- dgemm_vbatch: scalar (m, n, k) dispatch (drops the per-batchid M/N/K device
arrays) feeding a 4x2 (NN) / 4x4 (TN) BLK_{M,N} ladder over {8,16,32,48}.
- gemm_{nn,tn}_vbatch: K-inner shared-memory layout + wide (double2/float4)
LDS inner loop -- one 16-byte LDS feeds VK FMAs per (m,n); PAD keeps the
shmem stride 16-byte aligned and warp access bank-conflict-free.
C accumulators stay double regardless of input type T, preserving the
mixed-precision fp64-accumulator fix (#7368); the phi_operator kernel
optimizations from #7366 (WantPhi dispatch, single-warp reduce) are retained.
FP64 15-case GPU benchmark: end-to-end ~1.05x (A800) / ~1.04x (V100), with
cal_gint_vl up to ~1.5x and cal_gint_rho up to ~1.65x; energies and pressures
match develop to ~1e-10 on every case.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* refactor(gint): derive shape-bucket stride from ucell.nwmax, drop hardcoded NW_MAX
The (nw1, nw2) shape-bucketing in phi_mul_phi / phi_mul_dm flattened pairs
into a dense table key via `nw1 * NW_MAX + nw2`, with NW_MAX a hardcoded 64.
That was both a magic number and an artificial ceiling: a basis with nw > 64
would abort(), and 64 was only a guess at the real max.
The true upper bound is already known to the code as ucell.nwmax (max orbital
count over all atom types), exposed via gint_gpu_vars_->nwmax. Use it: set
nw_stride_ = nwmax + 1 once in the ctor so the bucket table is sized exactly to
the basis -- no cap to maintain.
A runtime stride can't index std::array<int, NW_MAX*NW_MAX>, so the three
counting-sort tables (counts / base / cursor) move to mutable std::vector
members allocated once and re-zeroed per call. For typical nwmax~25 that's ~676
ints vs the old fixed 4096, so the hot path zeroes less and never reallocates.
The set_bgrid_batch() abort guard becomes a structurally-unreachable assert,
since nwmax is by definition the largest nw. Drop now-unused includes
(<array>, <cstdio>, <cstdlib>); add <cassert>.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* refactor(gint): clarify GEMM kernel comments, hoist shape-bucket struct
Follow-up cleanup on the shape-exact vbatched GEMM path. No behavior change.
- gemm_{nn,tn}_vbatch, dgemm_vbatch, gint_helper: rewrite the kernel comments
to describe the actual mechanism (K-inner shared-memory layout, wide vector
loads feeding VK FMAs per load, the tile ladder, fp64 cross-item
accumulation) and drop the internal "V1/V3/Phase" development shorthand that
carried no meaning outside the original work log.
- phi_operator_gpu: the local `Bucket` struct was declared identically inside
both phi_mul_phi and phi_mul_dm. Hoist it to a named GemmShapeBucket type and
reuse a single buckets_ member vector (cleared, not reallocated) across both,
reserved once in the ctor -- one less per-call heap allocation on the hot
path.
- phi_operator_gpu: pair_scratch_offset_ is fully overwritten in Pass 1 before
Pass 2 reads it, so resize() it instead of assign(..., -1); the -1 sentinel
was never observed.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 69a663f commit 078df41
7 files changed
Lines changed: 665 additions & 323 deletions
File tree
- source/source_lcao/module_gint/kernel
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
6 | 21 | | |
7 | 22 | | |
8 | | - | |
9 | | - | |
| 23 | + | |
10 | 24 | | |
11 | 25 | | |
12 | 26 | | |
13 | 27 | | |
14 | 28 | | |
15 | 29 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
22 | 72 | | |
| 73 | + | |
23 | 74 | | |
24 | 75 | | |
25 | 76 | | |
26 | 77 | | |
27 | | - | |
28 | | - | |
| 78 | + | |
29 | 79 | | |
30 | 80 | | |
31 | 81 | | |
32 | 82 | | |
33 | 83 | | |
34 | 84 | | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
41 | 129 | | |
42 | 130 | | |
43 | 131 | | |
44 | 132 | | |
45 | | - | |
| 133 | + | |
46 | 134 | | |
47 | 135 | | |
48 | 136 | | |
49 | 137 | | |
50 | | - | |
| 138 | + | |
51 | 139 | | |
52 | 140 | | |
53 | 141 | | |
54 | 142 | | |
55 | | - | |
| 143 | + | |
56 | 144 | | |
57 | 145 | | |
58 | 146 | | |
59 | 147 | | |
60 | | - | |
| 148 | + | |
61 | 149 | | |
62 | 150 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
7 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
8 | 21 | | |
9 | 22 | | |
10 | | - | |
11 | | - | |
| 23 | + | |
12 | 24 | | |
13 | 25 | | |
14 | 26 | | |
15 | 27 | | |
16 | 28 | | |
17 | 29 | | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
| 30 | + | |
23 | 31 | | |
24 | 32 | | |
25 | | - | |
26 | | - | |
| 33 | + | |
27 | 34 | | |
28 | 35 | | |
29 | 36 | | |
30 | 37 | | |
31 | 38 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
0 commit comments