Skip to content

Commit 65519ec

Browse files
maleadtclaude
andcommitted
Fix @device_code_tiled for kernels with Constant arguments
The compile_hook in emit_ir passed unwrapped types to code_tiled because launch does MI lookup with Constant stripped to its element type. This caused @device_code_tiled to fail with "Unsupported Julia type for Tile IR" for any kernel using Constant args (including the tiled broadcast kernels). Reconstruct Constant{T,V} types from const_argtypes in the hook so code_tiled can recover const-seeded arguments. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3b1300a commit 65519ec

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/compiler/interface.jl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,11 +376,23 @@ IR where constant values are folded in.
376376
function emit_ir(cache::CacheView, mi::Core.MethodInstance;
377377
const_argtypes::Union{Vector{Any}, Nothing}=nothing)
378378
# Invoke compile hook if set (for @device_code_* reflection)
379-
# Pass (f, tt) tuple to enable direct use with reflection utilities
379+
# Pass (f, tt) tuple to enable direct use with reflection utilities.
380+
# Reconstruct Constant{T,V} types from const_argtypes so that code_tiled
381+
# can recover const-seeded arguments (MI specTypes have them unwrapped).
380382
if compile_hook[] !== nothing
381383
ftype = mi.specTypes.parameters[1]
382384
f = isdefined(ftype, :instance) ? ftype.instance : ftype
383-
tt = Tuple{mi.specTypes.parameters[2:end]...}
385+
arg_types = collect(Any, mi.specTypes.parameters[2:end])
386+
if const_argtypes !== nothing
387+
for i in eachindex(arg_types)
388+
ca_idx = i + 1 # const_argtypes is 1-indexed: [Const(f), arg2, ...]
389+
if ca_idx <= length(const_argtypes) && const_argtypes[ca_idx] isa CC.Const
390+
val = const_argtypes[ca_idx].val
391+
arg_types[i] = Constant{typeof(val), val}
392+
end
393+
end
394+
end
395+
tt = Tuple{arg_types...}
384396
compile_hook[](f, tt)
385397
end
386398

0 commit comments

Comments
 (0)