Repository navigation
Conversation
Support the local memory whose size is chosen at launch: the `localmem` launch keyword, `KI.dynamic_localmemory` and `KI.dynamic_localmemory_size` on the device, and `KI.max_dynamic_localmemory`. A kernel that uses the block gets a local memory argument for it, added after those of the RNG so that it is always the last one. Every launch of such a kernel sizes the argument, also launches that ask for none, and the requested size travels in the kernel state for the bounds checks. OpenCL neither allows empty local memory arguments nor specifies their alignment, so launches allocate 16 bytes more than they were asked for, and the kernel starts the block at the first address that is aligned to 16 bytes. Kernels still see the size they asked for. The limit is the local memory of the device, less those 16 bytes, the static local memory that the driver reports for the kernel, and what the RNG of the kernel takes for the largest work-group. It is determined when the kernel is linked, because the driver counts the local memory arguments once they are set. The two local memory arguments of the RNG were four times as large as the `UInt32` per slot that the kernel uses, which would have left kernels that use `rand` without any dynamic local memory on Intel's CPU runtime. Allocate what is used. Assisted-by: Claude Code (Fable 5.2)
…cal memory branch The dynamic local memory of KernelInterface isn't released yet, so get both packages from the branch that has it. Julia 1.10 doesn't read `[sources]`, so CI adds them there explicitly. Assisted-by: Claude Code (Fable 5.2)
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements KernelInterface's dynamic local memory for
OpenCLBackend. The KernelInterface side is theccr-c54f0813-yayzyebranch of JuliaGPU/KernelAbstractions.jl; the CUDA counterpart is JuliaGPU/CUDA.jl#3620.Changes
OpenCL.dynamic_localmemory()is an intrinsic that becomes a local memory kernel argument through a secondadd_input_arguments!call, so it is always the last argument, after the RNG's. Only kernels that use the block get it; a kernel that only reads the size gets none.KernelState.dynamic_localmemory_size::UInt32field in the existing padding after the seed.localmemis therefore limited totypemax(UInt32), checked with anArgumentError.HostKernelcalls takelocalmem::Int, whichKI.launchforwards. The allocation islocalmem + 16bytes, and 16 bytes withoutlocalmem:clSetKernelArgrejects an empty local argument, and OpenCL doesn't specify the alignment of a local pointer argument, so the kernel rounds the pointer up to 16 bytes itself. The kernel sees exactly the requested size.KI.max_dynamic_localmemoryisCL_DEVICE_LOCAL_MEM_SIZE, lessCL_KERNEL_LOCAL_MEM_SIZE, the 16 bytes of padding and, for kernels using the RNG, its worst-case local memory. It is computed at link time, before any local argument is set, because drivers count those inCL_KERNEL_LOCAL_MEM_SIZEafterwards.@opencldoes not acceptlocalmem; only calling the kernel object does.One change beyond the feature
The two RNG local memory arguments were allocated with
LocalMem(UInt32, sizeof(UInt32) * num_slots), i.e. 16 bytes per slot, while the device code uses oneUInt32per slot. They are now 4 bytes per slot. With the old size, the worst-case RNG deduction on Intel's CPU runtime (32 × 8192 bytes) equalled the device's whole local memory, so every kernel usingrandgot a limit of 0. It is a separate hunk inlib/cl/kernel.jland can be split out.Testing
Julia 1.13, with KernelAbstractions and KernelInterface from the branch:
kernelinterfaceon Intel's CPU runtimekernelinterface,execution,device/randomon NVIDIA (OpenCL C path)main.pocl_nextdriver, thekhronostranslator, and thebuffer/svmmemory back-ends.Before merging
[sources]at the KernelAbstractions branch, and makes CI add both packages from it on Julia < 1.11, which ignores[sources]. The CI edits have not been executed.🤖 Generated with Claude Code