Skip to content

Insert call instructions (without any caching) #1276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 40 commits into
base: main
Choose a base branch
from
Open

Conversation

jumerckx
Copy link
Collaborator

No description provided.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit

JuliaFormatter

[JuliaFormatter] reported by reviewdog 🐶

Reactant.jl/src/utils.jl

Lines 1105 to 1113 in 68e7079

traced_result = push_inst!(Expr(
:call,
GlobalRef(Core, :_apply_iterate),
Base.iterate,
call_epilogue,
push_inst!(Expr(:call, GlobalRef(Core, :tuple), fn_args[1], push_inst!(Expr(:call, GlobalRef(Core, :tuple), fn_args[2:end]...)))),
push_inst!(Expr(:call, GlobalRef(Core, :tuple), traced_result)),
push_inst!(Expr(:call, GlobalRef(Reactant, :get_args_from_finalize_function), finalize_function_result)),
))


[JuliaFormatter] reported by reviewdog 🐶

Reactant.jl/src/utils.jl

Lines 1117 to 1122 in 68e7079

push_inst!(Expr(
:call,
GlobalRef(Base, :setindex!),
GlobalRef(Reactant, :TRACE_CALLS),
should_trace_call,
))


[JuliaFormatter] reported by reviewdog 🐶

Reactant.jl/src/utils.jl

Lines 1125 to 1130 in 68e7079

push_inst!(Expr(
:call,
GlobalRef(Base, :setindex!),
GlobalRef(Reactant, :TRACE_CALLS),
TRACE_CALLS[],
))

@jumerckx
Copy link
Collaborator Author

jumerckx commented May 14, 2025

Status:

Test Summary:           | Pass  Fail  Error  Broken  Total      Time
Reactant.jl Tests       | 1480     5     27       1   1513  45m55.8s

(https://github.com/EnzymeAD/Reactant.jl/actions/runs/15022467542/job/42214855196?pr=1276#step:10:6661)

@jumerckx jumerckx marked this pull request as ready for review May 21, 2025 15:00
@@ -675,14 +675,14 @@ function Base.similar(
::Broadcasted{AbstractReactantArrayStyle{N}}, ::Type{T}, dims
) where {T<:Reactant.ReactantPrimitive,N}
@assert N isa Int
return TracedRArray{T,length(dims)}((), nothing, map(length, dims))
return Ops.fill(zero(unwrapped_eltype(T)), dims)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor, but could we make a smaller PR with some of these utilities to get that in first (and confirm everything works)

Comment on lines 772 to 774
@testset "call: caching for Julia operands" begin
y = rand(3)
y_ra = Reactant.to_rarray(y)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
@testset "call: caching for Julia operands" begin
y = rand(3)
y_ra = Reactant.to_rarray(y)
@testset "call: caching for Julia operands" begin
y = rand(3)
y_ra = Reactant.to_rarray(y)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

@testset "call: basic" begin
a = rand(2, 3)
b = rand(2, 3)
a_ra = Reactant.to_rarray(a)
b_ra = Reactant.to_rarray(b)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

@test @jit(call1(a_ra, c_ra)) call1(a, c)
ir = @code_hlo optimize = false call1(a_ra, c_ra)
ops = [op for op in Reactant.MLIR.IR.OperationIterator(Reactant.MLIR.IR.body(ir))]
@test length(ops) == 3
end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

ir = @code_hlo optimize = false call3(y_ra)
ops = [op for op in Reactant.MLIR.IR.OperationIterator(Reactant.MLIR.IR.body(ir))]
@test length(ops) == 5 # call3, .+, .*, _call3 (2X)
end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

@testset "call: Caching struct arguments" begin
a = rand(10)
b = rand(10)
foo = Foo(Reactant.to_rarray(a))
foo2 = Foo(Reactant.to_rarray(b))
bar = Foo(Bar(Reactant.to_rarray(b))) # typeof(foo) == typeof(bar), but these don't match!
ir = @code_hlo optimize = false call4(foo, foo2, bar)
ops = [op for op in Reactant.MLIR.IR.OperationIterator(Reactant.MLIR.IR.body(ir))]
@test length(ops) == 3 # call4, _call4 for {foo, foo2}, and _call4 for bar
end

$(from_locals...)
Reactant.TRACE_CALLS[] = temp
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be changed because we can't depend on Reactant here. I could add a macro @notrace_calls in ReactantCore?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants