Skip to content

KernelInterface kernels are always compiled for SIMD32, which makes register-heavy kernels spill #772

Open

Description

@maleadt

KI.kernel_function compiles every KernelInterface kernel with sub_group_size = KI.sub_group_size(backend), which is 32 where the device supports it (src/oneAPIKernels.jl, kernel_function and device_limits). That holds whether or not the kernel uses sub-group operations. For register-heavy kernels, SIMD32 makes IGC spill heavily, while its own choice (or SIMD16) doesn't spill at all.

I found this with the register-blocked matmul kernel from JuliaGPU/GPUArrays.jl#856, where each work-item keeps a 4x4 block of accumulators. On an Iris Xe (0x9a49, oneAPI.jl 2.10.0, NEO_jll 26.35.39758, libigc_jll 2.41.5), zeKernelGetProperties reports these spills in bytes:

kernel SIMD32 SIMD16 IGC default
blocked, Float32 / Int32 1856 0 0
blocked, ComplexF32 5312 992 0

Timings at 1024^3, launched through @oneapi with each sub_group_size:

eltype SIMD32 (what KI uses) SIMD16 default
Float32 9.7 ms 5.2 ms 8.0 ms
Int32 11.0 ms 6.4 ms
ComplexF32 95 ms 16.9 ms

So the KernelAbstractions path runs this kernel 1.9x (Float32) to 5.6x (ComplexF32) slower than it could. For ComplexF32 it ends up about 2.6x slower than GPUArrays' simple tiled kernel, which doesn't spill at either width.

Reproducer, with GPUArrays at the ksh/gemm-register-blocking branch:

using oneAPI, GPUArrays, LinearAlgebra
using LinearAlgebra: MulAddMul

M = N = K = 1024
for T in (Float32, ComplexF32), sg in (32, 16, nothing)
    A = oneArray(rand(T, M, K)); B = oneArray(rand(T, K, N)); C = oneArray(zeros(T, M, N))
    args = (C, A, B, MulAddMul(true, false), M, N, K, Val('N'), Val('N'),
            Val(16), Val(16), Val(4), Val(4), Val(8))
    f = GPUArrays.blocked_matmul_kernel!
    k = sg === nothing ? (@oneapi launch=false f(args...)) :
                         (@oneapi launch=false sub_group_size=sg f(args...))
    println("$T sub_group_size=$sg: spill=$(oneL0.properties(k.fun).spillMemSize) bytes")
end

The same forced width is behind the Float64 miscompile in #750.

Requiring a sub-group size only matters for kernels whose results depend on it, i.e. ones that use sub-group operations, or that assume KI.sub_group_size lanes per sub-group. One option would be to compile other kernels without intel_reqd_sub_group_size and leave the choice to IGC. That needs a way to tell which kernels depend on the width: a flag on kernel_function, or detecting sub-group intrinsics in the compiled IR. Another option is to promise 16 instead of 32 on devices that support both, which fixes the spills here but not the general issue.

Activity

  1. christiangnrd commented on Nov 19, 2026

    @christiangnrd
    Member

    I think promising 16 instead of 32 is a fine interim fix. When I initially selected 32 I did so because that's the most common one amongst backends, but if 16 is better on oneAPI then we should go with that

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions