Skip to content

Commit c61614c

Browse files
authored
Validator: Permit all fieldless objects. (#650)
Since we cannot load from these, we can tolerate passing them to a GPU. This makes it possible to use symbols and some other mutable objects.
1 parent 77700d0 commit c61614c

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/validation.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ function check_invocation(@nospecialize(job::CompilerJob))
8888
This is a CPU-only object not supported by GPUCompiler."""))
8989
end
9090

91+
# If an object doesn't have fields, it can only be used by identity, so we can allow
92+
# them to be passed to the GPU (this also applies to e.g. Symbols).
93+
if fieldcount(dt) == 0
94+
continue
95+
end
96+
9197
if !isbitstype(dt)
9298
throw(KernelError(job, "passing non-bitstype argument",
9399
"""Argument $arg_i to your kernel function is of type $dt, which is not a bitstype:

test/native_tests.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,18 @@ end
162162
ir = fetch(t)
163163
@test contains(ir, r"add i64 %\d+, 3")
164164
end
165+
166+
@testset "allowed mutable types" begin
167+
# when types have no fields, we should always allow them
168+
mod = @eval module $(gensym())
169+
struct Empty end
170+
end
171+
172+
Native.code_execution(Returns(nothing), (mod.Empty,))
173+
174+
# this also applies to Symbols
175+
Native.code_execution(Returns(nothing), (Symbol,))
176+
end
165177
end
166178

167179
############################################################################################

0 commit comments

Comments
 (0)