Skip to main content

Dynamic count of local loads per loop: plan

A plan, on main ac7c3b4, for review by 6 and release by the lead. It changes no core, frontend, profile or rule, and collects nothing. Each step below that measures gets its own registration before it runs.

ROADMAP item: "Dynamic count of local loads per iteration, so the two causal attention loops are not summed into one spill figure".

What the core uses today​

  • Count. The spill charge per iteration is the assembler's static spill_loads_bytes (and spill_stores_bytes), per thread. For causal attention (spill_scope per iteration and spill_loop_count = 2), it is divided evenly between the main and the diagonal loop (from_ir.rs). The reload count is these bytes over 4 B.

  • What it misses. The RTX 3070 post-hoc capture (spill-counters-rtx3070-posthoc.md, not a reference GPU) shows three faults:

    1. The even split still overcounts: 1.4 and 4.1 times the measured reloads.
    2. The two loops hold different spill code. In m128n128-w8-s2 the main loop has none.
    3. 21% to 57% of local loads are outside both loops.

    Static bytes over 4 B also cannot see wider reloads.

  • How much of the suite. In the v0.2 formal KernelIR of the four causal attention holdout shapes (IR resources only, no label), 37 of 108 configs spill on GB10 and 36 of 108 on the RTX 4070. Those IR files predate spill_loop_count. The development cases' count is step 1's first output.

What data the item needs​

For every spilling config of the four causal development cases of validation/attention-suite.json (108 configs; holdout cases are not touched), on each device:

ItemUnitWhy
D1. Executed local loads per looppredicated-on thread LDL per thread per iteration, main and diagonal loop separatelythe quantity the core should charge
D2. Their widthscount per LDL, LDL.64, LDL.128bytes per reload; the reload latency curve counts 4 B reloads
D3. Local loads outside both loopsshare of the launch totalwhat spill_scope charges per iteration but runs once
D4. The same for STLas D1 to D3stores enter the local port share
S1. Static LDL/STL per loop body, by widthinstructions in each loop's SASS basic blocksa candidate model input that needs no counters

D1 to D4 are dynamic and need GPU performance counters. S1 is static and needs only the compiled cubin.

How each is obtained​

  • D1 to D4: Nsight Compute. microbench/spill_counters.py already does this for three configs of one case. It reads the per-PC thread_inst_executed_true with the SASS opcode, attributes PCs to the main and diagonal helper by their source locations, and divides by the CTA trip counts. The extension is to all spilling development causal configs, plus the width split from the opcode suffix. It stays a post-hoc collector whose output is never a model input, as the ROADMAP requires.
  • S1: offline SASS. Compile each config for its target (sm_89, sm_121a) with line info, disassemble the cubin, find each loop's basic blocks from the helper's source locations, and count the local instructions in them by width. This needs no GPU and runs on Bifrost. It is a frontend change if adopted.

What each device can give​

RTX 4070 (sm_89)GB10 (sm_121a)
D1 to D4 (counters)Likely. The driver's RmProfilingAdminOnly was set to 0 for the RTX 4070. It needs a driver reload to take effect, and has not been confirmed since. The collector's permission probe decides: ERR_NVGPUCTRPERM means no data.Not available now. Spark 1 has RmProfilingAdminOnly=1 and the project account has no root. Enabling it needs root: the nvidia module option NVreg_RestrictProfilingToAdminUsers=0 and a module reload or reboot, or ncu run as root. That is an administrator's decision, not assumed here.
S1 (static SASS)Yes, offlineYes, offline
Same SASS on both?No. The sm_86 and sm_89 spill bytes agreed in the RTX 3070 study, but SASS for sm_121a is generated separately (the IR records ptxas-blackwell) and can place spill code differently.

Plan​

  1. S1 on both targets, offline. Report S1 per loop beside the static figure and the even split, for every spilling development config. No registration needed: it reads compiler output only.
  2. D1 to D4 on the RTX 4070, registered first. One capture under the GPU lock, gated by the quiet desktop check.
  3. Check S1 against D1 on the RTX 4070. Registered with step 2, before its data. A draft of the readings:
    • S1 per loop agrees with D1 when the ratio is within 0.8 to 1.25. Wider bounds would be needed for loops whose spill code sits on branches taken only on some iterations; those are reported separately.
    • S1 is adopted as the frontend's per-loop count if it agrees on at least 80% of (config, loop) pairs, and its median |log(S1 / D1)| is below that of the even split.
    • Otherwise the item needs a dynamic count as input. No static substitute exists, and a known limit is written.
  4. GB10.
    • Without counters: S1 can be computed but not checked on GB10. If adopted on the RTX 4070, it applies to GB10 as unchecked, and the IR says so.
    • With counters, if root is ever granted: step 2 repeats on GB10, and step 3's readings apply unchanged.
  5. Core. Not before the spill decision of ad1d505 is scored. A per-loop count changes the spill charge of those configs, so it must not land in between. The core change itself is small. Spill would carry one load count per loop instead of spill_loads_bytes / spill_loop_count, and the tile's iterations would charge the loop they belong to. That needs its own registration against microbenchmarks and the development set.

Limits​

  • Only the causal attention kernel has two loops in the suite. GEMM has one loop and stays on the static figure, though fault 3 (local loads outside the loop) applies to it too.
  • D1 counts executed instructions, not latency. Whether a reload is on the critical path is the reload latency curve's question, not this item's.
  • The RTX 3070 numbers above are for orientation only. They are not used in any reading.