Skip to content

Pass kernel arguments that exceed the device's limit through memory - #767

Open
michel2323 wants to merge 1 commit into
JuliaGPU:mainfrom
michel2323:spill-oversized-kernel-args
Open

michel2323 wants to merge 1 commit into
JuliaGPU:mainfrom
michel2323:spill-oversized-kernel-args

Conversation

@michel2323

@michel2323 michel2323 commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Level Zero limits the total size of a kernel's arguments to the device's maxArgumentsSize, 2048 bytes on current Intel GPUs (Arc, Data Center GPU Max), and IGC refuses to build a kernel that goes over it. Julia kernels take their arguments by value, so large isbits arguments hit this; ExaModels' expression patterns are 4–16 KB each in a process flowsheet model:

error: Total size of kernel arguments exceeds limit! Total arguments size: 4152, limit: 2048
ZeError: error occurred when building module (ZE_RESULT_ERROR_MODULE_BUILD_FAILURE)

On PVC this is a hardware limit, so IGC_OverrideOCLMaxParamSize only hides the error (#497).

With this PR, a kernel whose arguments don't fit is compiled as a wrapper that takes the largest arguments, as few as needed, as pointers to a copy in device memory and loads them before calling the kernel, so the kernel sees the same values. chipStar does the same for HIP on Level Zero. Kernels whose arguments fit are unaffected.

Each launch needs the value in device memory. On discrete GPUs NEO waits for the queue before copying a small upload, so uploading on every launch would make every such launch synchronous (as it is in AMReX's equivalent). The copies are therefore cached by content (LRU, 256 entries / 64 MiB per device) and never written again, and launches take ownership of them like of any array they use. Relaunching with the same value, which ExaModels does for every callback, copies nothing.

IGC also fails some kernels within the limit with "Kernel inputs exceed total register size", e.g. one looping over a 1 KB tuple on an A770. When the arguments are larger than half the limit and the build fails, the kernel is built again with its large arguments through memory. Arguments that don't fit even then (e.g. 256 Ints) throw an ArgumentError with the kernel name, the sizes and the limit.

Limitations: a kernel that indexes such a value dynamically keeps a copy in private memory, which counts against scratch space. A new value on every launch still waits for the queue on discrete GPUs.

Tested on an Arc A770 and on a Data Center GPU Max 1550 (Aurora, LTS stack): @oneapi and KernelAbstractions kernels with 2–32 KB arguments (64 KB on PVC) fail to build on main and give correct results here, also when launched without synchronization with more distinct values than the cache holds. On the A770, a kernel indexing a 64 KB argument dynamically needs 66 KB of scratch per work-item and loses the device. On Aurora, an ExaModels flowsheet model now builds and evaluates its objective, constraints and Jacobian.

Fixes #497

@maleadt
maleadt force-pushed the spill-oversized-kernel-args branch 2 times, most recently from c072a68 to 58eaa6c Compare December 2, 2026 17:35
@maleadt
maleadt marked this pull request as ready for review December 2, 2026 17:35
@maleadt

maleadt commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

I force-pushed a reworked version: the tests now use Float32 (CI's Iris Xe has no FP64), launches hold their own reference to a cached copy so a concurrent eviction can't free it before submission, the wrapper returns the kernel's result so GPUCompiler still validates it, and the test now forces evictions.

Level Zero limits the total size of a kernel's arguments to the device's
`maxArgumentsSize`, 2048 bytes on current Intel GPUs, and IGC refuses to
build a kernel beyond it ("Total size of kernel arguments exceeds
limit"). Large isbits arguments, like ExaModels' expression patterns,
hit that.

When the arguments of a kernel don't fit, `zefunction` now compiles it
as a wrapper, `SpilledKernel`, that takes the largest arguments (as few
as needed) as device pointers and loads their values before calling the
kernel. Launches upload those values to device memory, cached by content
so that relaunching with the same value doesn't copy it again, as a
small upload waits for the queue on discrete GPUs. Launches take
ownership of the copies like of any array the kernel uses. Kernels whose
arguments fit compile and launch as before.

IGC also fails to build some kernels whose large arguments are within
the limit ("Kernel inputs exceed total register size", e.g. a 1 KB
tuple indexed dynamically on DG2), so those are built again with the
larger arguments passed through memory. Arguments that don't fit even
when passing everything larger than a pointer through memory throw an
`ArgumentError` naming the kernel, the size and the limit.

Fixes JuliaGPU#497
@maleadt
maleadt force-pushed the spill-oversized-kernel-args branch from 58eaa6c to 449352f Compare December 3, 2026 05:40

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kernel argument parameters too large

2 participants