Skip to content

Support KernelInterface 0.5 - #218

Draft
maleadt wants to merge 2 commits into
mainfrom
tb/ki-0.5
Draft

maleadt wants to merge 2 commits into
mainfrom
tb/ki-0.5

Conversation

@maleadt

@maleadt maleadt commented Nov 27, 2026

Copy link
Copy Markdown
Member

Ports AcceleratedKernels to KernelInterface 0.5 (JuliaGPU/KernelAbstractions.jl#990), as AcceleratedKernels 0.6.0. The 0.5.x series stays on KernelInterface 0.4 (#217, released as 0.5.14).

What changes

KernelInterface 0.5 removes KI.sub_group_size(backend), the one width at which every kernel ran. Instead a backend lists the widths a kernel can request (KI.sub_group_sizes(backend), its suggestion first), and only a kernel constructed with sub_group_size = W is guaranteed to run at width W. Without a request, the backend may choose any width.

AcceleratedKernels' block reductions and scans (src/block.jl) depend on knowing the width on the host. It sizes their local memory (a slot per sub-group), and it selects the ByLanes reductions that reduce a whole output within one sub-group. So:

  • subgroup_width now picks the first width in KI.sub_group_sizes that meets the existing conditions (sub-groups enabled by the tuning, linear sub-groups, shuffles of the element type, a power of two, W ≤ block_size ≤ W²). It falls back to Val(0), the local-memory path, when no width fits.
  • Every kernel that receives Val(W) is now constructed with sub_group_size = W, using KernelAbstractions 0.10.10's new constructor keyword. These are the scan, tile-aggregate and compaction kernels, the 1-D, ordered, by-block, by-block-vector, by-lanes and multigroup reductions, the second pass that combines groups, and RadixSelect's block, histogram and resolve kernels. Kernels on the local-memory path request nothing, so they compile as before.
  • RadixSelect's resolve kernel takes both a scan width and a reduction width. A kernel can request only one width, so sub_group_request(WS, WR) checks that the two agree. They always do: both are chosen for the same block size, and the element type decides only whether a width is usable at all, never which one is picked.
  • KernelInterface is imported directly (import KernelInterface as KI). The compat entries are now KernelInterface = "0.5" and KernelAbstractions = "0.10.10".
  • KernelAbstractions 0.9 is no longer supported, because the width request needs 0.10.10. The isdefined(KernelAbstractions, :KernelInterface) guards are gone, as is the 0.9 special case of runs_kernels for the host backend. The docs and comments that mentioned 0.9 are updated to match.
  • The sub-group tests now also check that the chosen width is one the backend offers.

The back-end extensions (ext/) needed no changes, since none of them uses the sub-group width.

Behaviour per device

  • PoCL (the host backend): it offers (32, 1, 2, 4, 8, 16, 64), so blocks of 256 threads use width 32, as before. Its CPU tunings keep sub-groups off by default.
  • oneAPI (Arc A770, oneAPI.jl tb/ki-0.5): it offers (32, 8, 16), so blocks of 256 threads request 32, the width they used before.
  • Other GPU backends: these use the first offered width that fits the block, which is normally the width they reported before. The difference is that the kernels now request that width explicitly instead of relying on a backend-wide default.

Testing

On Julia 1.12, against tb/sub-group-request, on a Ryzen 9 5950X:

  • The full test suite with --cpu --cpu-ka, which covers the threaded algorithms and AK's kernels on PoCL, including the sub-group reductions and scans that the tests force on: Overall | 104449 104449, SUCCESS.
  • The full test suite on oneAPI, on an Intel Arc A770, against oneAPI.jl and GPUArrays.jl tb/ki-0.5: Overall | 52891 52891, SUCCESS.
  • A script that forces each offered width through the sub-group paths, on PoCL and on oneAPI, covering whole-array, ByLanes, ByBlock, ByBlocks and ordered reductions, 1-D and sliced scans, and findall:
    • A kernel that requests a width sees exactly that width on the device: 1, 2, 4, 8, 16, 32 and 64 each on PoCL, and 8, 16 and 32 each on oneAPI. Without a request it sees 32 on both.
    • With the request, every width that fits blocks of 256 gave 19/19 correct results: 32, 16 and 64 on PoCL, and 32 and 16 on oneAPI (reductions, scans, findall, and RadixSelect for slices of one block and for the global passes). The other widths do not fit blocks of 256.
    • Red-green check: with the request disabled (sub_group_request returning nothing), the kernels compile at the default width of 32. Width 32 still gave 19/19 correct, but 16 gave only 4/19 on both PoCL and oneAPI. On PoCL, width 64 gave 2/15 on the reductions, scans and findall, and then hung in RadixSelect. So the request is what makes a non-default width correct.

Not tested here: the CUDA, AMDGPU, Metal and OpenCL back-ends. Each has a KernelInterface 0.5 branch (tb/ki-0.5) whose [TEMP] commit points at this branch, and KernelAbstractions.jl#990's Buildkite jobs test them together.

Before merging

Drop the [TEMP] commit, which points [sources] at the KernelInterface 0.5 branch of KernelAbstractions, once KernelInterface 0.5 and KernelAbstractions 0.10.10 are registered.

KernelInterface 0.5 drops `KI.sub_group_size`, the width every kernel ran at: a kernel is
now only guaranteed a sub-group width it requests when it is constructed. The block
reductions and scans size their local memory and pick their code paths by that width, so
choose it from `KI.sub_group_sizes` (the first width that fits the block, which is the
backend's suggestion where it fits) and construct every kernel that takes it with
`sub_group_size = W`. Kernels on the local-memory path request nothing.

This needs KernelAbstractions 0.10.10, whose kernel constructors take the request, so
support for KernelAbstractions 0.9 goes, together with the guards for it. KernelInterface
is imported directly.

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.

1 participant