Skip to content

Commit

Permalink
Validator: Permit all fieldless objects.
Browse files Browse the repository at this point in the history
Since we cannot load from these, we can tolerate passing them to a GPU.
This makes it possible to use symbols.
  • Loading branch information
maleadt committed Nov 27, 2024
1 parent 09b4708 commit 9731a2c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/validation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ function check_invocation(@nospecialize(job::CompilerJob))
This is a CPU-only object not supported by GPUCompiler."""))
end

# If an object doesn't have fields, it can only be used by identity, so we can allow
# them to be passed to the GPU (this also applies to e.g. Symbols).
if fieldcount(dt) == 0
continue
end

if !isbitstype(dt)
throw(KernelError(job, "passing non-bitstype argument",
"""Argument $arg_i to your kernel function is of type $dt, which is not a bitstype:
Expand Down
12 changes: 12 additions & 0 deletions test/native_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,18 @@ end
ir = fetch(t)
@test contains(ir, r"add i64 %\d+, 3")
end

@testset "allowed mutable types" begin
# when types have no fields, we should always allow them
mod = @eval module $(gensym())
struct Empty end
end

Native.code_execution(Returns(nothing), (mod.Empty,))

# this also applies to Symbols
Native.code_execution(Returns(nothing), (Symbol,))
end
end

############################################################################################
Expand Down

0 comments on commit 9731a2c

Please sign in to comment.