Open ptiede opened 4 months ago
Calling Enzyme.API.inlineall!(true)
at the top of the program can reduce the allocations significantly in my experience
That is good to know, and I can definitely add that! Are these allocations something I should expect with this kind of code?
Ok so I also sporadically get a segfault from code very similar to this. If I change apply instrument to
@inline function apply_instrument(vis, J::ObservedInstrumentModel, x)
vout = similar(vis, SMatrix{2,2,eltype(vis[1]), 4})
xint = x.instrument
vout .= apply_jones.(vis, eachindex(vis), Ref(J), Ref(xint))
return vout
end
I get a gc corruption error when calling Ref, which sometime spits out a ton of info. An example is below.
err_gccorruption_enzyme_sep2.txt
The code to reproduce this is quite long, but the segfault always occurs in this part of the code. I am going to see if I can get a more reliable MWE.
@ptiede can you open that as an issue with a MWE and also confirm you’re on 1.10.5?
Ya for sure! And ya I am on 1.10.5.
This is a fun one. I am finding that for certain code patterns Enzyme is inserting a large number of allocations into the reverse pass even if the forward pass only does a small number or zero allocations. The MWE is
which gives output
The problem isn't so much the performance as it is the allocations. Profiling the code I see the following
So a large portion of the time is spent allocating when calling getindex. Interestingly if I inline
apply_instrument
the problem goes away and I get the dramatically improved performanceI am on Julia 1.10.4 and Enzyme 0.12.25