From 121fdcb740b55ae57aef65c0dd63d863f41bc336 Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Fri, 27 Nov 2026 13:34:44 +0100 Subject: [PATCH 1/2] Support KernelInterface 0.5 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. --- Project.toml | 6 +++--- README.md | 2 +- docs/src/api/algorithms.md | 6 +++--- docs/src/api/sort.md | 2 +- src/AcceleratedKernels.jl | 5 +---- src/accumulate/accumulate_1d_gpu.jl | 9 +++++---- src/accumulate/accumulate_nd.jl | 7 ++++--- src/accumulate/tuning.jl | 2 +- src/algorithms.jl | 8 +++----- src/block.jl | 31 +++++++++++++++++++---------- src/findall.jl | 8 ++++---- src/reduce/mapreduce_1d_gpu.jl | 7 ++++--- src/reduce/mapreduce_nd.jl | 29 ++++++++++++++------------- src/reduce/mapreduce_ordered.jl | 6 +++--- src/reduce/tuning.jl | 2 +- src/select.jl | 8 ++++---- test/Project.toml | 2 +- test/algorithms.jl | 2 +- test/generic/accumulate.jl | 4 +++- test/generic/reduce.jl | 4 +++- test/generic/sort.jl | 2 +- test/runtests.jl | 5 +---- 22 files changed, 83 insertions(+), 74 deletions(-) diff --git a/Project.toml b/Project.toml index b21d6f81..018db0b7 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "AcceleratedKernels" uuid = "6a4ca0a5-0e36-4168-a932-d9be78d558f1" -version = "0.5.14" +version = "0.6.0" authors = ["Andrei-Leonard Nicusan and contributors"] [deps] @@ -35,8 +35,8 @@ Atomix = "1.7" CUDA = "6.5" CUDACore = "6.5" GPUArraysCore = "0.2.1" -KernelAbstractions = "0.9.43, 0.10" -KernelInterface = "0.4" +KernelAbstractions = "0.10.10" +KernelInterface = "0.5" Metal = "1.12" OpenCL = "1" PrecompileTools = "1" diff --git a/README.md b/README.md index 4005da13..38beeb21 100644 --- a/README.md +++ b/README.md @@ -363,7 +363,7 @@ Start Julia with multiple threads to run the tests on a multithreaded CPU backen $> julia --threads=4 -e 'import Pkg; Pkg.test("AcceleratedKernels")' ``` -With KernelAbstractions 0.10, whose host backend runs kernels on PoCL, `--cpu-ka` tests +As the host backend runs kernels on PoCL, `--cpu-ka` tests AcceleratedKernels' GPU kernels on host arrays instead of the threaded CPU algorithms: ```bash $> julia -e 'import Pkg; Pkg.test("AcceleratedKernels"; test_args=["--cpu-ka"])' diff --git a/docs/src/api/algorithms.md b/docs/src/api/algorithms.md index 16a9af7a..e8a2713d 100644 --- a/docs/src/api/algorithms.md +++ b/docs/src/api/algorithms.md @@ -65,6 +65,6 @@ Base's views and reshapes have. MappedArrays.jl does not define such rules yet, #### The host backend Arrays in host memory (`Array` and views of it) are on the host backend. `Auto` processes them on -Julia threads with the `CPUThreads` algorithms. On KernelAbstractions 0.10 the host backend also -runs AcceleratedKernels' GPU kernels (on PoCL), so an explicit kernel algorithm such as -`MergeSort()` works on host arrays there; on KernelAbstractions 0.9 it is an `ArgumentError`. +Julia threads with the `CPUThreads` algorithms. The host backend also runs AcceleratedKernels' +GPU kernels (on PoCL), so an explicit kernel algorithm such as `MergeSort()` works on host arrays +too. diff --git a/docs/src/api/sort.md b/docs/src/api/sort.md index 19e76b99..eb88db17 100644 --- a/docs/src/api/sort.md +++ b/docs/src/api/sort.md @@ -41,7 +41,7 @@ never replaced: | [`BitonicSort`](@ref AcceleratedKernels.BitonicSort) | no | yes | no | no | all | kernels | | [`CPUThreads.SampleSort`](@ref AcceleratedKernels.CPUThreads.SampleSort) | yes | yes | yes | yes | all | host | -"Kernels" means GPU backends, and the host backend on KernelAbstractions 0.10, which runs +"Kernels" means GPU backends, and the host backend, which runs AcceleratedKernels' kernels on PoCL. See [Algorithms and backends](@ref) for how `Auto` chooses. ```@docs diff --git a/src/AcceleratedKernels.jl b/src/AcceleratedKernels.jl index 2115b540..d86e4b26 100644 --- a/src/AcceleratedKernels.jl +++ b/src/AcceleratedKernels.jl @@ -34,10 +34,7 @@ import Adapt using GPUArraysCore: AnyGPUArray, @allowscalar, neutral_element using KernelAbstractions using KernelAbstractions: @context -# Sub-group operations, with KernelAbstractions 0.10 -@static if isdefined(KernelAbstractions, :KernelInterface) - const KI = KernelAbstractions.KernelInterface -end +import KernelInterface as KI # Exposed functions from upstream packages diff --git a/src/accumulate/accumulate_1d_gpu.jl b/src/accumulate/accumulate_1d_gpu.jl index 00d8c58c..e83b97c4 100644 --- a/src/accumulate/accumulate_1d_gpu.jl +++ b/src/accumulate/accumulate_1d_gpu.jl @@ -144,7 +144,8 @@ function accumulate_1d_gpu!( start = scan_start(v, init, seed) subgroups = scan_subgroup_width(backend, typeof(seed), block_size) - kernel! = scan_tile_kernel!(backend, block_size) + sub_group_size = sub_group_request(subgroups) + kernel! = scan_tile_kernel!(backend, block_size; sub_group_size) if num_blocks == 1 kernel!(op, v, src, load, start, seed, inclusive, nothing, nothing, items, subgroups, ndrange=block_size) @@ -160,9 +161,9 @@ function accumulate_1d_gpu!( if tuning(scan_tuning, backend, eltype(v)).reduce_then_scan # Reduce the tiles, then scan them from their prefix: this reads the source twice and # writes the result once - tile_aggregates_kernel!(backend, block_size)(op, totals, src, load, start, seed, - items, subgroups, - ndrange=num_blocks * block_size) + tile_aggregates_kernel!(backend, block_size; sub_group_size)( + op, totals, src, load, start, seed, items, subgroups, + ndrange=num_blocks * block_size) scan_totals!() kernel!(op, v, src, load, start, seed, inclusive, nothing, totals, items, subgroups, ndrange=num_blocks * block_size) diff --git a/src/accumulate/accumulate_nd.jl b/src/accumulate/accumulate_nd.jl index 86ff72f0..06b52a21 100644 --- a/src/accumulate/accumulate_nd.jl +++ b/src/accumulate/accumulate_nd.jl @@ -169,10 +169,11 @@ function slice_pass!(kind, backend, block_size, nslices, v, src, load, op::OP, s kernel!(v, src, load, op, start, seed, carries, totals, inclusive, n_inner, len, nchunks, per_chunk, nthreads; ndrange=(block_size * cld(nthreads, block_size),)) else - kernel! = slice_tiles_kernel!(backend, block_size) + subgroups = scan_subgroup_width(backend, typeof(seed), block_size) + kernel! = slice_tiles_kernel!(backend, block_size; + sub_group_size=sub_group_request(subgroups)) kernel!(v, src, load, op, start, seed, carries, totals, inclusive, n_inner, len, - nchunks, per_chunk, Val(items), - scan_subgroup_width(backend, typeof(seed), block_size); + nchunks, per_chunk, Val(items), subgroups; ndrange=(block_size * nslices * nchunks,)) end return nothing diff --git a/src/accumulate/tuning.jl b/src/accumulate/tuning.jl index 9157d147..c77ee6bc 100644 --- a/src/accumulate/tuning.jl +++ b/src/accumulate/tuning.jl @@ -67,7 +67,7 @@ returned by [`scan_tuning`](@ref). adds their prefix, which reads and writes the result twice. GPUs are faster with the former, CPUs, whose caches hold the result, with the latter. - `subgroups`: whether the kernel algorithms scan the values of a block with sub-group - operations, where the backend has them (from KernelAbstractions 0.10), rather than in local + operations, where the backend has them, rather than in local memory. CPUs, whose sub-group operations synchronize the whole block, scan faster without. - `wide_optional_flag`: as for [`ReduceTuning`](@ref). diff --git a/src/algorithms.jl b/src/algorithms.jl index 04e47124..563a9a61 100644 --- a/src/algorithms.jl +++ b/src/algorithms.jl @@ -126,7 +126,7 @@ end # module CPUThreads # Capabilities: correctness facts about a backend, checked for `Auto` and explicit algorithms # alike. Unlike tunings, they cannot be changed per device. -# The host backend: `KernelAbstractions.CPU` on KernelAbstractions 0.9, its PoCL backend on 0.10. +# The host backend: KernelAbstractions' PoCL backend const HOST_BACKEND = get_backend(Int[]) const HostBackend = typeof(HOST_BACKEND) @@ -143,11 +143,9 @@ runs_threads(::HostBackend) = true runs_kernels(backend) Whether AK's kernels (`@kernel cpu=false`) run on `backend`: every GPU backend, and the host -backend of KernelAbstractions 0.10, which compiles kernels for PoCL. KernelAbstractions 0.9's -`CPU` backend cannot run them. +backend, which compiles kernels for PoCL. """ runs_kernels(::Backend) = true -runs_kernels(::HostBackend) = nameof(HostBackend) !== :CPU # Tunings: values chosen per device by the `*_tuning(backend, T)` hooks, to which AK's package @@ -214,7 +212,7 @@ fill_threads(a::A, t) where {A} = function require_kernels(a, backend) runs_kernels(backend) || throw(ArgumentError( "$(algname(a)) runs AcceleratedKernels' GPU kernels, which " * - "$(backend_name(backend)) cannot run (on the host, this needs KernelAbstractions 0.10); " * + "$(backend_name(backend)) cannot run; " * "use `Auto()` or a `CPUThreads` algorithm")) nothing end diff --git a/src/block.jl b/src/block.jl index e0f4bdd6..cce74b3b 100644 --- a/src/block.jl +++ b/src/block.jl @@ -19,22 +19,33 @@ end # The sub-group width `W` for a block scan or reduction of `T` in blocks of `block_size` threads, # as a `Val`, or `Val(0)` for the local-memory one. Sub-groups must be enabled by the tuning, -# linear (from KernelAbstractions 0.10), able to shuffle `T`, and `W ≤ block_size ≤ W²`, as one -# sub-group combines the sub-groups' values. -@static if isdefined(KernelAbstractions, :KernelInterface) - function subgroup_width(backend, ::Type{T}, block_size) where {T} - KI.supports_linear_subgroups(backend) && KI.supports_shuffle(backend, T) || return Val(0) - W = KI.sub_group_size(backend) - return ispow2(W) && W <= block_size <= W * W ? Val(W) : Val(0) +# linear, able to shuffle `T`, and `W ≤ block_size ≤ W²`, as one sub-group combines the +# sub-groups' values. `W` is the first such width the backend offers (its suggestion first), and +# the kernels that take it must be constructed with `sub_group_size = sub_group_request(Val(W))`, +# as a kernel is only guaranteed the width it requests. +function subgroup_width(backend, ::Type{T}, block_size) where {T} + KI.supports_linear_subgroups(backend) && KI.supports_shuffle(backend, T) || return Val(0) + for W in KI.sub_group_sizes(backend) + ispow2(W) && W <= block_size <= W * W && return Val(W) end -else - subgroup_width(backend, T, block_size) = Val(0) + return Val(0) end scan_subgroup_width(backend, ::Type{T}, block_size) where {T} = tuning(scan_tuning, backend, T).subgroups ? subgroup_width(backend, T, block_size) : Val(0) reduce_subgroup_width(backend, ::Type{T}, block_size) where {T} = tuning(reduce_tuning, backend, T).subgroups ? subgroup_width(backend, T, block_size) : Val(0) +# The sub-group width a kernel taking the sub-group widths `subgroups` requests: none for the +# local-memory path. A kernel can only request one width, so those of its block operations that +# use sub-groups must agree; widths chosen for the same block size do, as only the operations' +# types, not the widths, decide whether a backend's width suits them. +@inline sub_group_request(::Val{W}) where {W} = W == 0 ? nothing : W +function sub_group_request(::Val{A}, ::Val{B}) where {A, B} + A == 0 || B == 0 || A == B || + throw(ArgumentError("a kernel cannot use sub-groups of widths $A and $B")) + return sub_group_request(Val(max(A, B))) +end + # The local memory of a block reduction or scan of `N` values (see `block_reduce` and # `block_exclusive_scan`): a value per sub-group, or per thread without sub-groups @inline block_slots(N, ::Val{W}) where {W} = W == 0 ? N : N ÷ W @@ -51,7 +62,6 @@ reduce_subgroup_width(backend, ::Type{T}, block_size) where {T} = @inline reduce_group!(@context, op, sdata, ithread) return sdata[0x1] end -@static if isdefined(KernelAbstractions, :KernelInterface) @inline function block_reduce(@context, op, sdata, x, ithread, ::Val{W}) where {W} N = @groupsize()[1] x = KI.sub_group_reduce(op, x) @@ -65,7 +75,6 @@ end # sub-groups of a block to run the same sub-group operations; thread 0's is the result) return KI.sub_group_reduce(op, sdata[ithread % nsg + 0x1], nsg) end -end # Exclusive scan of the values `x` of the block's threads, seeded with `seed`, with `sdata` of diff --git a/src/findall.jl b/src/findall.jl index f719ae86..a3eb7675 100644 --- a/src/findall.jl +++ b/src/findall.jl @@ -137,15 +137,15 @@ function compact( scan_subgroup_width(backend, Int32, block_size), bufs, like) end -# (a function barrier on the block size: from KernelAbstractions 0.10, constructing the kernels -# then infers, which saved 0.5 µs per kernel and call on CUDA) +# (a function barrier on the block size: constructing the kernels then infers, which saved 0.5 µs per kernel and call on CUDA) function compact_tiles(bools, ::Type{I}, output_indices, backend, ::Val{B}, items::Val{N}, subgroups, bufs, like) where {I, B, N} num_blocks = cld(length(bools), B * N) block_counts = bufs.counts # Count each tile's selected elements, as the scans reduce their tiles, then scan the counts - tile_aggregates_kernel!(backend, B)( + sub_group_size = sub_group_request(subgroups) + tile_aggregates_kernel!(backend, B; sub_group_size)( +, block_counts, one_based(bools), b -> Int32(b), Int32(0), Int32(0), items, subgroups; ndrange=num_blocks * B) accumulate_nested!(+, block_counts, bufs.scan; backend, init=0) @@ -153,7 +153,7 @@ function compact_tiles(bools, ::Type{I}, output_indices, backend, ::Val{B}, item out = similar_on(backend, like, I, (n,)) if n > 0 - compact_kernel!(backend, B)( + compact_kernel!(backend, B; sub_group_size)( out, bools, block_counts, eachindex(bools), output_indices, items, subgroups; ndrange=num_blocks * B) end diff --git a/src/reduce/mapreduce_1d_gpu.jl b/src/reduce/mapreduce_1d_gpu.jl index 43a4532f..93aecf63 100644 --- a/src/reduce/mapreduce_1d_gpu.jl +++ b/src/reduce/mapreduce_1d_gpu.jl @@ -120,10 +120,11 @@ end function mapreduce_1d_pass!(commutative::Bool, backend, block_size, items_per_thread, src, dst, f::F, op::OP, seed, init, blocks; buffer=nothing) where {F, OP} if commutative - kernel! = mapreduce_1d_kernel!(backend, block_size) + subgroups = reduce_subgroup_width(backend, typeof(seed), block_size) + kernel! = mapreduce_1d_kernel!(backend, block_size; + sub_group_size=sub_group_request(subgroups)) Base.inferencebarrier(kernel!)(src, dst, f, op, seed, init, blocks, Val(block_size), - Val(items_per_thread), - reduce_subgroup_width(backend, typeof(seed), block_size); + Val(items_per_thread), subgroups; ndrange=(block_size * blocks,)) else len = length(src) diff --git a/src/reduce/mapreduce_nd.jl b/src/reduce/mapreduce_nd.jl index f5ded82c..96fb23cb 100644 --- a/src/reduce/mapreduce_nd.jl +++ b/src/reduce/mapreduce_nd.jl @@ -132,10 +132,11 @@ function launch!(shape::ByLanes, f::F, op::OP, dst, src, kind, backend, alg, buf (; base_offset, outer_strides, outer_sizes, dst_size, reduce_size) = ix block_size = alg.block_size blocks = cld(dst_size, block_size ÷ shape.lanes) - by_lanes_kernel!(backend, block_size)( + subgroups = reduce_subgroup_width(backend, typeof(seed), block_size) + by_lanes_kernel!(backend, block_size; sub_group_size=sub_group_request(subgroups))( kernel_buffer(src, kind), dst, f, op, seed, init, base_offset, outer_strides, outer_sizes, dst_size, reduce_size, Val(shape.lanes), - reduce_subgroup_width(backend, typeof(seed), block_size), + subgroups, ndrange=(block_size * blocks,), ) end @@ -149,20 +150,20 @@ function launch!(shape::ByBlock, f::F, op::OP, dst, src, kind, backend, alg, buf block_size, blocks = alg.block_size, shape.blocks W = isdense_buffer(kind) ? vector_width(buffer, base_offset, outer_strides, reduce_strides, reduce_size, block_size) : 0 + subgroups = reduce_subgroup_width(backend, typeof(seed), block_size) + sub_group_size = sub_group_request(subgroups) if W > 0 - kernel! = by_block_vector_kernel!(backend, block_size) + kernel! = by_block_vector_kernel!(backend, block_size; sub_group_size) Base.inferencebarrier(kernel!)( buffer, dst, f, op, seed, init, base_offset, outer_strides, outer_sizes, - dst_size, reduce_size, blocks, Val(W), - reduce_subgroup_width(backend, typeof(seed), block_size), + dst_size, reduce_size, blocks, Val(W), subgroups, ndrange=(block_size * blocks,), ) else - kernel! = by_block_kernel!(backend, block_size) + kernel! = by_block_kernel!(backend, block_size; sub_group_size) Base.inferencebarrier(kernel!)( buffer, dst, f, op, seed, init, base_offset, outer_strides, outer_sizes, - reduce_strides, reduce_sizes, dst_size, reduce_size, blocks, - reduce_subgroup_width(backend, typeof(seed), block_size), + reduce_strides, reduce_sizes, dst_size, reduce_size, blocks, subgroups, ndrange=(block_size * blocks,), ) end @@ -174,11 +175,11 @@ function launch!(shape::ByBlocks, f::F, op::OP, dst, src, kind, backend, alg, bu reduce_size) = ix block_size, groups = alg.block_size, shape.groups partials = bufs.partials - multigroup_kernel!(backend, block_size)( + subgroups = reduce_subgroup_width(backend, typeof(seed), block_size) + multigroup_kernel!(backend, block_size; sub_group_size=sub_group_request(subgroups))( kernel_buffer(src, kind), partials, f, op, seed, base_offset, outer_strides, outer_sizes, reduce_strides, reduce_sizes, - Val(dst_size), reduce_size, groups, - reduce_subgroup_width(backend, typeof(seed), block_size), + Val(dst_size), reduce_size, groups, subgroups, ndrange=(block_size * dst_size * groups,), ) combine_groups!(backend, partials, dst, op, seed, init, dst_size, groups, false, @@ -242,10 +243,10 @@ function combine_groups!(backend, partials, dst, op::OP, seed, init, dst_size, g ordered_pass!(backend, block_size, 1, partials, dst, PartialInputs(), op, seed, init, 0, (1,), (dst_size,), (dst_size,), (groups,), dst_size, groups, 1) else - by_block_kernel!(backend, block_size)( + subgroups = reduce_subgroup_width(backend, typeof(seed), block_size) + by_block_kernel!(backend, block_size; sub_group_size=sub_group_request(subgroups))( partials, dst, PartialInputs(), op, seed, init, 0, (1,), (dst_size,), (dst_size,), - (groups,), dst_size, groups, dst_size, - reduce_subgroup_width(backend, typeof(seed), block_size), + (groups,), dst_size, groups, dst_size, subgroups, ndrange=(block_size * dst_size,)) end end diff --git a/src/reduce/mapreduce_ordered.jl b/src/reduce/mapreduce_ordered.jl index 3e1b3c4d..5add26eb 100644 --- a/src/reduce/mapreduce_ordered.jl +++ b/src/reduce/mapreduce_ordered.jl @@ -97,12 +97,12 @@ function ordered_pass!( ) where {F, OP} W = dense_buffer ? ordered_vector_width(src, base_offset, outer_strides, reduce_strides, reduce_size, block_size, items_per_thread) : 0 - kernel! = ordered_kernel!(backend, block_size) + subgroups = reduce_subgroup_width(backend, typeof(seed), block_size) + kernel! = ordered_kernel!(backend, block_size; sub_group_size=sub_group_request(subgroups)) Base.inferencebarrier(kernel!)( src, dst, f, op, seed, init, base_offset, outer_strides, outer_sizes, reduce_strides, reduce_sizes, - output_size, reduce_size, groups, Val(items_per_thread), Val(W), - reduce_subgroup_width(backend, typeof(seed), block_size), + output_size, reduce_size, groups, Val(items_per_thread), Val(W), subgroups, ndrange=(block_size * output_size * groups,), ) return nothing diff --git a/src/reduce/tuning.jl b/src/reduce/tuning.jl index 14bcb730..c9a7703d 100644 --- a/src/reduce/tuning.jl +++ b/src/reduce/tuning.jl @@ -57,7 +57,7 @@ Values that fill unset algorithm fields for reductions on one device, as returne (so that Compute Sanitizer's initcheck doesn't see reads of unwritten bytes there), or with a `Bool`, which some compilers handle better in local memory. The results are the same. - `subgroups`: whether the kernels combine the values of a block with sub-group operations, - where the backend has them (from KernelAbstractions 0.10), keeping a value per sub-group + where the backend has them, keeping a value per sub-group rather than per thread in local memory. CPUs, whose sub-group operations synchronize the whole block, reduce faster without. diff --git a/src/select.jl b/src/select.jl index e45541a4..b8f380e7 100644 --- a/src/select.jl +++ b/src/select.jl @@ -780,8 +780,8 @@ function radix_select!(a::RadixSelect, dst, src, rk::NTuple{NS, Int}, backend, d B = len <= 2048 ? 256 : 512 items = nextpow(2, cld(len, B)) W = scan_subgroup_width(backend, UInt32, B) - select_block_kernel!(backend, B)(dst, src, rev, rk, src_layout, dst_layout, Val(items), - W; ndrange=B * nslices) + select_block_kernel!(backend, B; sub_group_size=sub_group_request(W))( + dst, src, rev, rk, src_layout, dst_layout, Val(items), W; ndrange=B * nslices) else select_global!(a, dst, src, rk, backend, src_layout, dst_layout, rev, bufs) end @@ -806,8 +806,8 @@ function select_global!(a, dst, src, ranks::NTuple{NR}, backend, src_layout, dst WS = scan_subgroup_width(backend, UInt32, 256) (; hist, kst, ust, pmin, pmax, comp) = bufs select_init_kernel!(backend, 256)(hist, kst, ust, rk, len; ndrange=256 * nslices) - hist! = select_hist_kernel!(backend, B) - resolve! = select_resolve_kernel!(backend, 256) + hist! = select_hist_kernel!(backend, B; sub_group_size=sub_group_request(W)) + resolve! = select_resolve_kernel!(backend, 256; sub_group_size=sub_group_request(WS, WR)) for pass in 0:sizeof(K) - 1 hist!(hist, comp, pmin, pmax, kst, ust, src, rev, src_layout, pass, bps, cap, Val(NS), Val(a.items_per_thread), W; ndrange=B * bps * nslices) diff --git a/test/Project.toml b/test/Project.toml index 6d2fde2e..a2c0edee 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -25,7 +25,7 @@ AcceleratedKernels = {path = ".."} AMDGPU = "2.10" Adapt = "4" CUDACore = "6.5" -KernelAbstractions = "0.9.43, 0.10.5" +KernelAbstractions = "0.10.10" MappedArrays = "0.4" Metal = "1.12" OpenCL = "1" diff --git a/test/algorithms.jl b/test/algorithms.jl index 11c4830e..091dc183 100644 --- a/test/algorithms.jl +++ b/test/algorithms.jl @@ -38,7 +38,7 @@ struct SizeOnly{T, N} <: AbstractArray{T, N} end Base.size(a::SizeOnly) = a.dims -# A backend that cannot run AK's kernels, like KernelAbstractions 0.9's `CPU` +# A backend that cannot run AK's kernels struct NoKernelsBackend <: KernelAbstractions.Backend end AK.runs_kernels(::NoKernelsBackend) = false diff --git a/test/generic/accumulate.jl b/test/generic/accumulate.jl index 212033a8..d773599e 100644 --- a/test/generic/accumulate.jl +++ b/test/generic/accumulate.jl @@ -275,7 +275,9 @@ function subgroup_scans() @eval AK.scan_tuning(::typeof(BACKEND), ::Type) = AK.ScanTuning(; subgroups=true, reduce_then_scan=$reduce_then_scan) Base.invokelatest() do - @test AK.scan_subgroup_width(BACKEND, Int32, 256) !== Val(0) + # (one of the widths the kernels can request) + @test AK.scan_subgroup_width(BACKEND, Int32, 256) in + map(Val, AK.KI.sub_group_sizes(BACKEND)) for (sz, dims) in (((100_000,), nothing), ((3, 6200), 2), ((3, 70_000), 2)) xh = rand(Int32(-9):Int32(9), sz...) alg = dims === nothing ? scan_alg() : slice_alg() diff --git a/test/generic/reduce.jl b/test/generic/reduce.jl index 948af251..ab9e47ba 100644 --- a/test/generic/reduce.jl +++ b/test/generic/reduce.jl @@ -1019,7 +1019,9 @@ end # without a neutral element (`plus` has none) plus(a, b) = a + b function subgroup_reductions() - @test AK.reduce_subgroup_width(BACKEND, Int32, 256) !== Val(0) + # (one of the widths the kernels can request) + @test AK.reduce_subgroup_width(BACKEND, Int32, 256) in + map(Val, AK.KI.sub_group_sizes(BACKEND)) for (sz, dims) in (((10^6,), :), ((64, 1000), 1), ((20_000, 300), 1), ((100_000, 4), 1)) xh = rand(Int32, sz...) x = array_from_host(xh) diff --git a/test/generic/sort.jl b/test/generic/sort.jl index 45960cb7..e0cc3fbe 100644 --- a/test/generic/sort.jl +++ b/test/generic/sort.jl @@ -119,7 +119,7 @@ end else @test_throws ArgumentError AK.sort!(v; alg=AK.CPUThreads.SampleSort()) end - # AK's kernels need a backend that runs them (on the host, KernelAbstractions 0.10) + # AK's kernels need a backend that runs them if !AK.runs_kernels(BACKEND) for alg in (AK.MergeSort(), AK.RadixSort(), AK.BitonicSort()) @test_throws ArgumentError AK.sort!(v; alg) diff --git a/test/runtests.jl b/test/runtests.jl index 8e84baa5..4cdacfa2 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -82,11 +82,8 @@ if in_test_env("OpenCL") :(OpenCL.cl.device().max_work_group_size)) end -# AK's kernels on the host backend, only with --cpu-ka: KernelAbstractions 0.10 runs them (on -# PoCL), 0.9 does not +# AK's kernels on the host backend (on PoCL), only with --cpu-ka if args.custom["cpu-ka"] !== nothing - AK.runs_kernels(AK.HOST_BACKEND) || - error("--cpu-ka needs KernelAbstractions 0.10, whose host backend runs AK's kernels") add_backend!("cpu-ka", nothing, :(get_backend([])), 1024; host_kernels=true) end From 4d2bd059bc400c42ab4430878fecf0b9e160c7cf Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Fri, 27 Nov 2026 13:35:05 +0100 Subject: [PATCH 2/2] [TEMP] Test against the KernelInterface 0.5 branch of KernelAbstractions --- Project.toml | 4 ++++ test/Project.toml | 3 +++ 2 files changed, 7 insertions(+) diff --git a/Project.toml b/Project.toml index 018db0b7..c93fe0fa 100644 --- a/Project.toml +++ b/Project.toml @@ -27,6 +27,10 @@ MetalExt = "Metal" OpenCLExt = "OpenCL" oneAPIExt = "oneAPI" +[sources] +KernelAbstractions = {url = "https://github.com/JuliaGPU/KernelAbstractions.jl", rev = "tb/sub-group-request"} +KernelInterface = {url = "https://github.com/JuliaGPU/KernelAbstractions.jl", rev = "tb/sub-group-request", subdir = "lib/KernelInterface"} + [compat] AMDGPU = "2.9" Adapt = "4" diff --git a/test/Project.toml b/test/Project.toml index a2c0edee..254ebf9b 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -4,6 +4,7 @@ Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c" +KernelInterface = "4ee993da-d684-4d17-a7dd-4e58e78d92bf" MappedArrays = "dbb5928d-eab1-5f90-85c2-b9b0edb7c900" ParallelTestRunner = "d3525ed8-44d0-4b2c-a655-542cee43accc" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" @@ -20,6 +21,8 @@ pocl_jll = "627d6b7a-bbe6-5189-83e7-98cc0a5aeadd" [sources] AcceleratedKernels = {path = ".."} +KernelAbstractions = {url = "https://github.com/JuliaGPU/KernelAbstractions.jl", rev = "tb/sub-group-request"} +KernelInterface = {url = "https://github.com/JuliaGPU/KernelAbstractions.jl", rev = "tb/sub-group-request", subdir = "lib/KernelInterface"} [compat] AMDGPU = "2.10"