Skip to content

(Re-)Allow to passing non-isbits when not used in kernel #597

@hexaeder

Description

@hexaeder

Before eec85d5 the check_invocation function allowed to pass arbitrary objects as long as they were not used by the kernel. This is helpful for passing pure dispatch types f(::Type{something). Currently that's only possible if those types are Core.Compiler.isconstType.

I tried to add it back, however since then check_invocation does not have access to the entry::LLVM.Function anymore, which was used to check if the argument is used. I think this is only generated in the emit_llvm call, which happens after the verification step.

I think this would be a nice feature but there are certainly always ways around it, so feel free to close if out of scope :)

Minimal example / testcase:

using Pkg
pkg"activate --temp"
pkg"add KernelAbstractions, CUDA"
using KernelAbstractions
using CUDA

abstract type AbstractAction end
struct Addition{M} <: AbstractAction
    meta::M
end
struct Multiplication{M} <: AbstractAction
    meta::M
end

@kernel function kernel!(::Type{T}, z, x, y) where {T<:AbstractAction}
    i = @index(Global)
    z[i] = apply(T, x[i], y[i])
end

@inline apply(::Type{<:Addition}, x, y) = x + y
@inline apply(::Type{<:Multiplication}, x, y) = x * y

x = CuArray(1:10)
y = CuArray(1:10)
z = CuArray(zeros(10))
kernel = kernel!(get_backend(x))

# works on concrete type
kernel(Addition{:foo}, z, x, y; ndrange=length(z))
kernel(Multiplication{:foo}, z, x, y; ndrange=length(z))

# does not work on abstract type
kernel(Addition, z, x, y; ndrange=length(z))
kernel(Multiplication, z, x, y; ndrange=length(z))

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