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
Here's a @dynamo I use to trace code execution (full MWE below):
@dynamofunction (t::IRTracer)(fargs...)
ir =IR(fargs...)
ir ==nothing&&return# intrinsic functionsfor (v, st) in ir
ex = st.expr
if Meta.isexpr(ex, :call)
ir[v] =Expr(:call, record_or_recurse!, self, ex.args...)
else
ir[v] =Expr(:call, identity, ex)
endendreturn ir
end
Essentially, it does 2 things:
Replaces all calls to f with record_or_recurse!(..., f, ...), which either records f to the list of operations or recursively applies transformation to f.
Replaces all other statements (i.g. constants) with call to identity function.
When I apply this code to function f = x -> sum(x; dims=1) (or any other function with keywords), the following error is printed (although code runs fine and returns correct result):
Internal error: encountered unexpected error in runtime:
AssertionError(msg="argextype only works on argument-position values")
argextype at ./compiler/utilities.jl:166
argextype at ./compiler/utilities.jl:158 [inlined]
call_sig at ./compiler/ssair/inlining.jl:882
process_simple! at ./compiler/ssair/inlining.jl:956
assemble_inline_todo! at ./compiler/ssair/inlining.jl:999
ssa_inlining_pass! at ./compiler/ssair/inlining.jl:74 [inlined]
run_passes at ./compiler/ssair/driver.jl:138
optimize at ./compiler/optimize.jl:174
typeinf at ./compiler/typeinfer.jl:33
typeinf_edge at ./compiler/typeinfer.jl:484
...
If I comment out any of the transformations above (either function calls, or constants), error disappears.
My best guess so far is that the compiler attempts to infer the type of dims argument and makes an assertion that it is still a constant, but since I replaced it with a call to identity(:dims), the compiler pass fails.
Does this theory sound reasonable? If so, is there some metadata about :dims var that I should update to make this work?
MWE:
import IRTools: IR, @code_ir, @dynamo, self, var
const PRIMITIVES =Set([
Core.kwfunc(sum),
Core.apply_type,
])
mutable struct IRTracer
primitives::Set{Any}
ops::Vector{Any}endfunctionIRTracer(;primitives=PRIMITIVES)
returnIRTracer(primitives, [])
end
Base.show(io::IO, t::IRTracer) =print(io, "IRTracer($(length(t.ops)))")
functionrecord_or_recurse!(t::IRTracer, fargs...)
fn, args = fargs[1], fargs[2:end]
if fn in t.primitives || (fn isa Type && fn <:NamedTuple)
res =fn(args...)
push!(t.ops, fargs)
else
res =t(fn, args...)
endreturn res
end@dynamofunction (t::IRTracer)(fargs...)
ir =IR(fargs...)
ir ==nothing&&return# intrinsic functionsfor (v, st) in ir
ex = st.expr
if Meta.isexpr(ex, :call)
ir[v] =Expr(:call, record_or_recurse!, self, ex.args...)
else
ir[v] =Expr(:call, identity, ex)
endendreturn ir
end
x =rand(2, 4)
t =IRTracer()
f = x ->sum(x; dims=1)
t(f, x)
The text was updated successfully, but these errors were encountered:
Here's a
@dynamo
I use to trace code execution (full MWE below):Essentially, it does 2 things:
f
withrecord_or_recurse!(..., f, ...)
, which either recordsf
to the list of operations or recursively applies transformation tof
.identity
function.When I apply this code to function
f = x -> sum(x; dims=1)
(or any other function with keywords), the following error is printed (although code runs fine and returns correct result):Original function IR (
@code_ir f(x)
):Transformed IR (
@code_ir t(f, x)
, wheret::IRTracer
):If I comment out any of the transformations above (either function calls, or constants), error disappears.
My best guess so far is that the compiler attempts to infer the type of
dims
argument and makes an assertion that it is still a constant, but since I replaced it with a call toidentity(:dims)
, the compiler pass fails.Does this theory sound reasonable? If so, is there some metadata about
:dims
var that I should update to make this work?MWE:
The text was updated successfully, but these errors were encountered: