Skip to content

POCL backend: KernelAbstractions.zeros of a bits-union element type throws #791

Description

@maleadt

On the POCL backend (KernelAbstractions main), zeros and ones of a bits-union element type such as Union{Missing, Bool} fail while compiling the fill kernel. Allocating such an array works, and so do kernels that read or write it.

using KernelAbstractions
b = KernelAbstractions.POCLBackend()

KernelAbstractions.allocate(b, Union{Missing, Bool}, 3)   # works

@kernel function f!(y, x)
    i = @index(Global)
    @inbounds y[i] = ismissing(x[i])
end
x = copyto!(KernelAbstractions.allocate(b, Union{Missing, Bool}, 3), [missing, true, false])
y = KernelAbstractions.allocate(b, Bool, 3)
f!(b)(y, x; ndrange=3)                                     # works: Bool[1, 0, 0]

KernelAbstractions.zeros(b, Union{Missing, Bool}, 3)
# ERROR: ArgumentError: type does not have a definite number of fields
Stacktrace:
  [1] fieldcount(t::Any)                          @ Base runtime_internals.jl:1323
  [2] check_invocation(job::GPUCompiler.CompilerJob)  @ GPUCompiler src/validation.jl:99
  [3] compile_unhooked(...)                       @ GPUCompiler src/driver.jl:72
  ...
  [6] (::KernelAbstractions.POCL.var"#compile_to_obj##0#compile_to_obj##1")(ctx)  @ src/pocl/compiler/compilation.jl:230
  ...
 [13] clfunction(f::typeof(KernelAbstractions.POCL.POCLKernels.gpu_init_kernel), tt::...)  @ src/pocl/compiler/execution.jl:197
 ...
 [18] #zeros#2

KernelAbstractions main at d15c1df (0.10.0-dev), Julia 1.13.0, pocl_jll 7.2, x86_64 (AMD Ryzen 9 9950X). ones fails the same way, and so does Union{Missing, Int32}.

The POCL backend's zeros and ones launch init_kernel(arr, f, ::Type{T}) (src/pocl/backend.jl), which takes the element type as an argument. GPUCompiler's check_invocation calls fieldcount on that argument's type, which throws for Type{Union{Missing, Bool}}. Computing the fill value on the host and passing it (init_kernel(arr, zero(T))), or passing f alone, would avoid the type argument; check_invocation could also skip Type arguments, which are singletons.

AcceleratedKernels' test suite builds its test arrays with zeros, so on this backend it skips its bits-union tests (JuliaGPU/AcceleratedKernels.jl#133); that skip goes once this is fixed.

Activity

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