JuliaGPU / JuliaGPU/GPUCompiler.jl

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

Open
#597 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
187
Forks
68
Avg merge
1d 12h
Merged PRs (30d)
28

Description

Before https://github.com/JuliaGPU/GPUCompiler.jl/commit/eec85d5096370dd4e518e99519e6bd55bd2bf053 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:
```julia
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))
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the check_invocation entry point and trace how verification now occurs before emit_llvm, since the issue identifies the missing LLVM.Function access as the constraint. Use the minimal Julia/GPU example to reproduce abstract dispatch-type arguments and compare them with concrete types. Done means non-isbits values unused by the kernel are accepted while used values remain rejected.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.