Repository navigation
Conversation
|
Documentation preview: https://juliagpu.github.io/KernelAbstractions.jl/previews/PR990/ |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #990 +/- ##
==========================================
- Coverage 90.79% 89.14% -1.66%
==========================================
Files 33 33
Lines 3293 3030 -263
==========================================
- Hits 2990 2701 -289
- Misses 303 329 +26 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
61dc4fa to
c4a2810
Compare
|
This looks like a good change. I left a few comments regarding repetition in the docstrings. |
c4a2810 to
1c2ba83
Compare
Benchmark resultsCompared with a585449d8, the merge base. Times are the minimum time of every benchmark. A change is unusual when it exceeds both three times the benchmark's typical change between consecutive runs on the default branch and a minimum per category (performance 3%, latency 5%, applications 3%, other 3%). A benchmark that starts or stops allocating is listed however few the allocations. A single run can still be a fluke, so rerun before drawing conclusions.
All benchmarks
|
1c2ba83 to
6cef071
Compare
KernelInterface 0.5 (JuliaGPU/KernelAbstractions.jl#990) replaces the backend-wide KI.sub_group_size with KI.sub_group_sizes, the widths a kernel can request when it is compiled. Metal can't request a SIMD-group width, which is a property of the compiled pipeline, but it is 32 for every pipeline on Apple GPUs, so offer that as the only width. Requesting it compiles the same kernel as not requesting one; other widths throw an ArgumentError.
… request one KernelInterface 0.4 promised that every kernel runs with the width `KI.sub_group_size(backend)` reports. Intel back-ends therefore force 32 on every kernel, which makes register-heavy kernels spill (JuliaGPU/oneAPI.jl#772), back-ends that can't fix the width have to report no sub-groups at all, and callers that size things from the width can't choose it. KernelInterface 0.5 splits the contract. `supports_subgroups` only promises the sub-group operations; a kernel compiled without a request runs at a width the back-end chooses per launch, which its work-items read with `get_max_sub_group_size()`. `KI.sub_group_sizes(backend)` lists the widths of at most 64 that a kernel can request, the back-end's suggestion first; `kernel_function(...; sub_group_size = W)`, also through `KI.@launch`, compiles a kernel that runs with exactly `W` and rejects other widths with an `ArgumentError`; `nothing` means no request, so that callers with an optional width need one call site. The fallback of `sub_group_sizes` is `()`, which is also right for a back-end with sub-groups that can't guarantee a width. `KI.sub_group_size(backend)` now throws an error pointing to the replacements, until it is removed in 1.0, so that code written for 0.4 fails instead of computing wrong results with a width the kernel doesn't have. The testsuite runs kernels without a request against the width they report, and the sub-group queries for every offered width, the communication functions for the first, narrowest and widest.
Implements KernelInterface 0.5 for the POCL back-end, and moves KernelAbstractions to it. `KI.sub_group_sizes` returns the widths of up to 64 that the device supports, with the one kernels were compiled for before first: 32, 64 or 16, or else the first one the device lists. Kernels without a request are still compiled for that width, and a requested width is checked against the list before it becomes PoCL's `intel_reqd_sub_group_size`.
With KernelInterface 0.5, only kernels that request a width get a fixed one, and a `@kernel` had no way to ask: the only route to compiler options is the back-end's `compiler_options` hook. Kernels whose performance depends on the width, e.g. register-heavy ones that spill at 32 on Intel GPUs, need to pick it. Kernel constructors take a `sub_group_size` keyword, `my_kernel(backend, 256; sub_group_size = 16)`. `Kernel` stores the request as a `NamedTuple` of compiler options in a new trailing type parameter, and passes it on to `KI.kernel_function` after the back-end's `compiler_options`, so that back-ends overriding that hook don't drop it. Since the option names are part of the type, a kernel without a request compiles only the launch path without one; a `Union`-typed field compiled both, which made the first launch of every kernel 12 ms slower on PoCL. `nothing`, the default, requests no width and compiles the kernel as before. The constructors become a single method taking the sizes as varargs: a kernel defined in a local scope with several keyword methods would box their keyword bodies. This is the sub-group slice of the per-kernel options proposed in #839.
6cef071 to
0ca5f1c
Compare
Points every back-end job at the back end's tb/ki-0.5 branch, and installs the tb/ki-0.5 branches of GPUArrays and AcceleratedKernels, since their released versions don't work with KernelInterface 0.5. The back ends' own [sources] point at those branches too, but Julia 1.10 ignores them. To be reverted once the back ends support KernelInterface 0.5 on main.
AcceleratedKernels sizes its sub-group reductions and scans from `KI.sub_group_size(backend)`, which KernelInterface 0.5 removes: only kernels that request a width get a fixed one (JuliaGPU/KernelAbstractions.jl#990). AcceleratedKernels reaches KernelInterface through KernelAbstractions' re-export and so had no bound on it, and would fail at run time once the back-ends move to 0.5. Depending on KernelInterface directly, with compat 0.4, keeps this release on back-ends it works with; the port to 0.5 needs a breaking release.
AcceleratedKernels sizes its sub-group reductions and scans from `KI.sub_group_size(backend)`, which KernelInterface 0.5 removes: only kernels that request a width get a fixed one (JuliaGPU/KernelAbstractions.jl#990). AcceleratedKernels reaches KernelInterface through KernelAbstractions' re-export and so had no bound on it, and would fail at run time once the back-ends move to 0.5. Depending on KernelInterface directly, with compat 0.4, keeps this release on back-ends it works with; the port to 0.5 needs a breaking release.
KernelInterface 0.5 guarantees a host-selected sub-group width only when the kernel requests it (#810, item 4).
Why
KernelInterface 0.4 promises every kernel the width
KI.sub_group_size(backend), so back-ends pin it for all kernels, including the many that never look at it:ComplexF32matmul from 82 to 15 ms (SIMD32 spills, KernelInterface kernels are always compiled for SIMD32, which makes register-heavy kernels spill oneAPI.jl#772), but slows GPUArrays' tiled matmul from 104 to 119 ms.sumof 2²⁶Float32takes 1.81 ms at width 32 vs 1.04 ms at 16 on Arc A770, but 14.4 vs 16.1 ms on Iris Xe.cl_intel_required_subgroup_size.What changes
sub_group_size = Wguarantees exactly widthW. A width not insub_group_sizesthrows anArgumentError;nothingmeans no request.get_max_sub_group_size().@groupreduceand the other KernelAbstractions collectives already do, and need no change.sub_group_sizesmeans the host can't request a width. Ifsupports_subgroups(backend)is true, kernels can still use the sub-group operations and read the width on the device.KI.sub_group_size(backend)throws, pointing to the replacement, so that 0.4 code fails instead of computing with the wrong width.Back-ends remove their
KI.sub_group_sizemethod, acceptsub_group_size = nothinginkernel_function, and reject widths they don't list with anArgumentError(also when they list none). Back-ends that offer widths implementsub_group_sizes. An offered width can still fail to compile for a particular kernel.KernelAbstractions:
Kernelgains a fifth type parameter for its compiler options. Four-parameter dispatch and theKernel{B, WS, ND, F}(backend, f)constructor still work. Encoding whether a width was requested in theKerneltype matters for latency: first-launch inference and codegen of a new kernel on PoCL takes 69 ms (70 ms on main, 82 ms with aUnion{Nothing, Int}field instead).Back-ends
This PR ports POCL. The other back-ends are ported on
tb/ki-0.5branches, and their KernelAbstractions and KernelInterface test suites pass against this one:sub_group_sizes(32, 1, 2, 4, 8, 16, 64)(32,)(32,)(32,)(32, 8, 16)(32, 8, 16)(32, 1, 2, 4, 8, 16, 64)Where several widths are offered, each was requested and read back on the device. In these tests, unrequested kernels kept their previous width. AMDGPU doesn't offer 64 on RDNA yet: in wave64 mode its shuffles only reach lanes in the same half (
shfl_xor(v, 32)gave[1, 2, 33, 34], not[33, 34, 1, 2]).Rollout
Released back-ends, GPUArrays and JLArrays require KernelInterface 0.4, so nothing picks this up early. AcceleratedKernels calls the removed API through KernelAbstractions' re-export, so it gets a cap first:
The last commit,
[TEMP], points Buildkite at thetb/ki-0.5branches; drop it before merging.