Enzyme.jl icon indicating copy to clipboard operation
Enzyme.jl copied to clipboard

Attempt to provide a better error for undef sret

Open vchuravy opened this issue 3 years ago • 5 comments

I was thinking if we can find which values weren't initalized by Enzyme for the shadow sret we could fix them up with fictious values instead of Julia throwing an error, but I haven't found a solution yet since for some values we can't take a pointer Symbol...

x-ref: #347

vchuravy avatar Aug 20 '22 02:08 vchuravy

Codecov Report

Merging #422 (88b4ce2) into main (0f3233d) will decrease coverage by 0.46%. The diff coverage is 22.22%.

@@            Coverage Diff             @@
##             main     #422      +/-   ##
==========================================
- Coverage   76.33%   75.87%   -0.47%     
==========================================
  Files          17       17              
  Lines        4226     4244      +18     
==========================================
- Hits         3226     3220       -6     
- Misses       1000     1024      +24     
Impacted Files Coverage Δ
src/compiler.jl 74.47% <22.22%> (-0.32%) :arrow_down:
src/compiler/orcv2.jl 61.90% <0.00%> (-10.48%) :arrow_down:

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

codecov-commenter avatar Aug 20 '22 02:08 codecov-commenter

I think the better soution would be to zero-initialize the sret (instead of undef as it is currently) and then define something like.

zeroof(::Symbol) = :Zero

vchuravy avatar Sep 05 '22 19:09 vchuravy

So I thought about this a bit more, and I think there's a reasonably nice solution here. Namely, this error can only occur if an active input value contains an allocatedinline value for whom bits of 0's are not legal.

Since we know the proper julia type, and this only is an issue on the outermost level where there's an ABI interface from Enzyme to Julia (already wrapped), prior to returning from the llvmcall we create, we can initialize any allocatedinline types with placeholders of choice.

wsmoses avatar Sep 05 '22 19:09 wsmoses

Zero init'ing the sret wouldn't be sufficient, you'd need to post copying the result from the Enzyme struct, or alternatively only copy the relevant parts of the LLVM struct.

wsmoses avatar Sep 05 '22 19:09 wsmoses

we can initialize any allocatedinline types with placeholders of choice.

Can you implement that?

vchuravy avatar Sep 06 '22 12:09 vchuravy