Repository navigation
GPU JIT: cap fused kernels at the CUDA parameter limit - #38
AdvaitTahilyani wants to merge 11 commits into
Conversation
ptxas rejects kernels with more than 4352 bytes of parameters below PTX ISA 8.1 (we target 8.0 on sm_80), and a long unsynchronized elementwise chain fused into one loop passed every array (a (3 + 2 * rank) * 8 byte memref descriptor each) and scalar as a parameter of a single launch. The loop fuser now stops merging when the fused loop would capture more than the limit less 128 bytes (32764 for PTX >= 8.1 on sm_70+; CNUM_JIT_MAX_PARAM_BYTES overrides it); temporaries used only inside the merged loop are free. Copies of temporaries into outputs move up next to their producer first, so a split kernel keeps the outputs thread-local instead of materializing every intermediate. The budget is part of the kernel cache key. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit fafda827f1fbf3712558dd217252653e9873bb52)
A PTX image that did not assemble used to be embedded as PTX, and loading it at engine initialization hit report_fatal_error (LLVM ERROR, server abort). generateNVIDIAHost now returns nullptr with the ptxas log, and compileKernel retries the AST as one kernel per op. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 7a2a5be0c2717153c532f45bf27ad204dfc10518)
Long unsynchronized chains (lat.py's batch loop, also with no fused-op cap), 120 live outputs in 1-D/2-D/3-D, 110 distinct inputs of mixed dtypes and 150 views of one array, vs NumPy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 180f30ec741b9f07748899be3e6f61c6ea3dc77c)
adityapb
left a comment
There was a problem hiding this comment.
Verdict: approve with nits.
This is a static review. Line numbers are at this PR's head.
These hold up:
paramBytes: it matches the lowering. Each memref costs(3+2·rank)·8bytes with the default kernel ABI, scalars count as at most 8 bytes, and sunk values are free.- The budget is really exercised: on A100/H100 it is effectively 4224 bytes, because PTX is capped at 8.0, so
test_jit_paramsdoes exercise splitting. hoistOutputCopies: safe, because outputs are fresh arrays.- Cache key: the budget is part of it.
- [minor] The ptxas fallback can itself abort.
- The fallback recompiles the whole node unfused (
jit.cpp:2771-2781), and the temporaries are freed only at the end of the host function (:283-285), so it needs device memory for all the intermediates at once. - On a long chain over a large tile (e.g. 200 ops on a 400 MB tile),
cn_mgpuMemAllochitsreport_fatal_error("JIT temporary allocation failed"). - This is rare: it only happens when the budgeted kernel still fails ptxas.
- Fix: split at the rejected kernel, or free temporaries after their last use.
- The fallback recompiles the whole node unfused (
Temporaries were freed at the end of the host function, so the unfused fallback (and any split kernel chain) needed device memory for every intermediate at once. The dealloc now follows the temporary's last user; launches and frees are ordered on the chare's stream. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Validated: GPU build compiles; CPU regress +p1/+p2 (orig 15/15, ports 25/25, ops 33/33, |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Correction to my earlier comment: the GPU job did include the JIT long-chain check, and it failed ( |
fuseElementwiseLoops() hoists every allocation above the first loop so that loops become adjacent, so 7ea597f's early frees did not lower the peak: an unfused chain (the ptxas fallback, or a kernel split at the parameter budget) still allocated all of its temporaries before the first launch and ran out of device memory. Each remaining alloc now moves to just before its first user, so the chain holds only its live temporaries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The ptxas fallback could still run out of device memory. This is now fixed in 664bde9.
Validated on 1 A100-40GB: one 1-D float64 tile, 1 PE,
The GPU build of the #38 head compiles. The merged-up heads are validated on #42 and #44. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A long unsynced elementwise chain could produce a fused kernel with more than 4 KB of parameters. ptxas rejected it and the server aborted. Now:
No change in stencil or black_scholes timings. Adds
test_jit_params.🤖 Generated with Claude Code