You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Metal: add_input_arguments! drops the input arguments on self-recursive calls #1090
add_input_arguments! puts value_map[f] = new_f in the clone map (src/irgen.jl:1412), so a self-recursive call is retargeted to new_f with its old argument list. rewrite_input_uses! only visits uses of the old f, so that call never gets the extra arguments.
using Metal
@noinlinerec(n) = n <=1?Int(thread_position_in_grid().x) :rec(n
-1) +rec(n -2)
functionkernel(a)
@inbounds a[1] =rec(a[1])
returnend
Metal.code_llvm(kernel, Tuple{MtlDeviceVector{Int, 1}}; kernel =true, dump_module =true)
defineinternalfastcci64@julia_rec_378(i64signext %"n::Int64",
<3 x i32> %thread_position_in_grid) {
...
%4 = callfastcci64@julia_rec_378(i64signext%3, <3 x i32>
zeroinitializer)
%6 = callfastcci64@julia_rec_378(i64signext%5, <3 x i32>
zeroinitializer)
Two outcomes, depending on the function:
Wrong value: as above, the missing argument is later padded with zero, so recursive invocations see thread_position_in_grid == 0.
Segfault: if the function also needs the kernel state, AddKernelStatePass rebuilds the call with the new function type but the short argument list ("Incorrect number of arguments passed to called function!"), and the inliner in the Metal optimize_module! crashes in CallAnalyzer::analyze. This is the LLVM crash behind Use GPUToolbox's shared throw overrides Metal.jl#1138: on Julia 1.10, Rational arithmetic pulls Base's recursive print_fullname/modulesof! into the kernel. That PR removes the trigger, not this bug; the user should have gotten an InvalidIRError.
Removing the value_map[f] = new_f line fixes both for me: self-calls keep pointing at the old f and are rewritten like any other call site.
GPUCompiler 2.22.2 (line still present on main), reproduced on Julia 1.10.13 and 1.13.3.
Activity
Pass input arguments on to self-recursive calls