Skip to content
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

Cannot deduce type of copy call void @llvm.memcpy.p10i8.p0i8.i64 #1547

Open
vchuravy opened this issue Jun 20, 2024 · 4 comments
Open

Cannot deduce type of copy call void @llvm.memcpy.p10i8.p0i8.i64 #1547

vchuravy opened this issue Jun 20, 2024 · 4 comments

Comments

@vchuravy
Copy link
Member

Reproducer:

git clone https://github.com/vchuravy/WaterLily.jl
cd WaterLily.jl/examples
git checkout vc/enzyme
# instantiate local project
julia +1.10 --project=. TandemFoilOptim.jl
ERROR: LoadError: Enzyme execution failed.
Enzyme cannot deduce type
Current scope: 
; Function Attrs: mustprogress willreturn
define internal fastcc void @preprocess_julia__make_foils_1_2261([6 x {} addrspace(10)*]* noalias nocapture nofree noundef nonnull writeonly sret([6 x {} addrspace(10)*]) align
 8 dereferenceable(48) "enzyme_type"="{[-1]:Pointer, [-1,0]:Pointer, [-1,8]:Pointer, [-1,16]:Pointer, [-1,32]:Pointer}" %0, float "enzyme_type"="{[-1]:Float@float}" "enzymejl_p
armtype"="138083780338720" "enzymejl_parmtype_ref"="0" %1) unnamed_addr #42 !dbg !725 {
; ...

Cannot deduce type of copy   call void @llvm.memcpy.p10i8.p0i8.i64(i8 addrspace(10)* noundef align 1 dereferenceable(7) %newstruct31.sroa.3.sroa.2.0.newstruct31.sroa.3.0..sroa_
raw_idx.sroa_raw_idx, i8* noundef nonnull align 1 dereferenceable(7) %newstruct31.sroa.3.sroa.2.1.newstruct24.sroa.3.0.sroa_idx.sroa_idx, i64 noundef 7, i1 noundef false) #44, 
!dbg !85

Caused by:
Stacktrace:
 [1] Simulation
   @ ~/src/WaterLily/src/WaterLily.jl:65
 [2] #make_foils#1
   @ ~/src/WaterLily/examples/TandemFoilOptim.jl:24

Full log: https://gist.github.com/vchuravy/8e70c7ff38fd150f941fef6a7af6cc92

@wsmoses
Copy link
Member

wsmoses commented Jun 21, 2024

The problem is that this type doesn't have any ino when taking a typetree of it between bytes 16 and 24.

  %box34 = call noalias nonnull dereferenceable(240) "enzyme_type"="{[-1]:Pointer, [-1,0]:Integer, [-1,8]:Integer, [-1,9]:Integer, [-1,10]:Integer, [-1,11]:Integer, [-1,12]:Integer, [-1,13]:Integer, [-1,14]:Integer, [-1,15]:Integer, [-1,16]:Integer, [-1,24]:Integer, [-1,25]:Integer, [-1,26]:Integer, [-1,27]:Integer, [-1,28]:Integer, [-1,29]:Integer, [-1,30]:Integer, [-1,31]:Integer, [-1,32]:Float@float, [-1,40]:Float@double, [-1,48]:Integer, [-1,49]:Integer, [-1,50]:Integer, [-1,51]:Integer, [-1,52]:Integer, [-1,53]:Integer, [-1,54]:Integer, [-1,55]:Integer, [-1,56]:Float@double, [-1,64]:Integer, [-1,65]:Integer, [-1,66]:Integer, [-1,67]:Integer, [-1,68]:Integer, [-1,69]:Integer, [-1,70]:Integer, [-1,71]:Integer, [-1,72]:Integer, [-1,73]:Integer, [-1,74]:Integer, [-1,75]:Integer, [-1,76]:Integer, [-1,77]:Integer, [-1,78]:Integer, [-1,79]:Integer, [-1,80]:Integer, [-1,81]:Integer, [-1,82]:Integer, [-1,83]:Integer, [-1,84]:Integer, [-1,85]:Integer, [-1,86]:Integer, [-1,87]:Integer, [-1,88]:Integer, [-1,89]:Integer, [-1,90]:Integer, [-1,91]:Integer, [-1,92]:Integer, [-1,93]:Integer, [-1,94]:Integer, [-1,95]:Integer, [-1,96]:Integer, [-1,97]:Integer, [-1,98]:Integer, [-1,99]:Integer, [-1,100]:Integer, [-1,101]:Integer, [-1,102]:Integer, [-1,103]:Integer, [-1,104]:Integer, [-1,105]:Integer, [-1,106]:Integer, [-1,107]:Integer, [-1,108]:Integer, [-1,109]:Integer, [-1,110]:Integer, [-1,111]:Integer, [-1,112]:Integer, [-1,113]:Integer, [-1,114]:Integer, [-1,115]:Integer, [-1,116]:Integer, [-1,117]:Integer, [-1,118]:Integer, [-1,119]:Integer, [-1,120]:Integer, [-1,121]:Integer, [-1,122]:Integer, [-1,123]:Integer, [-1,124]:Integer, [-1,125]:Integer, [-1,126]:Integer, [-1,127]:Integer, [-1,128]:Integer, [-1,136]:Integer, [-1,137]:Integer, [-1,138]:Integer, [-1,139]:Integer, [-1,140]:Integer, [-1,141]:Integer, [-1,142]:Integer, [-1,143]:Integer, [-1,144]:Float@float, [-1,152]:Float@double, [-1,160]:Integer, [-1,161]:Integer, [-1,162]:Integer, [-1,163]:Integer, [-1,164]:Integer, [-1,165]:Integer, [-1,166]:Integer, [-1,167]:Integer, [-1,168]:Float@double, [-1,176]:Integer, [-1,177]:Integer, [-1,178]:Integer, [-1,179]:Integer, [-1,180]:Integer, [-1,181]:Integer, [-1,182]:Integer, [-1,183]:Integer, [-1,184]:Integer, [-1,185]:Integer, [-1,186]:Integer, [-1,187]:Integer, [-1,188]:Integer, [-1,189]:Integer, [-1,190]:Integer, [-1,191]:Integer, [-1,192]:Integer, [-1,193]:Integer, [-1,194]:Integer, [-1,195]:Integer, [-1,196]:Integer, [-1,197]:Integer, [-1,198]:Integer, [-1,199]:Integer, [-1,200]:Integer, [-1,201]:Integer, [-1,202]:Integer, [-1,203]:Integer, [-1,204]:Integer, [-1,205]:Integer, [-1,206]:Integer, [-1,207]:Integer, [-1,208]:Integer, [-1,209]:Integer, [-1,210]:Integer, [-1,211]:Integer, [-1,212]:Integer, [-1,213]:Integer, [-1,214]:Integer, [-1,215]:Integer, [-1,216]:Integer, [-1,217]:Integer, [-1,218]:Integer, [-1,219]:Integer, [-1,220]:Integer, [-1,221]:Integer, [-1,222]:Integer, [-1,223]:Integer, [-1,224]:Integer, [-1,225]:Integer, [-1,226]:Integer, [-1,227]:Integer, [-1,228]:Integer, [-1,229]:Integer, [-1,230]:Integer, [-1,231]:Integer, [-1,232]:Integer, [-1,233]:Integer, [-1,234]:Integer, [-1,235]:Integer, [-1,236]:Integer, [-1,237]:Integer, [-1,238]:Integer, [-1,239]:Integer}" {} addrspace(10)* @julia.gc_alloc_obj({}** nonnull %current_task1, i64 noundef 240, {} addrspace(10)* noundef addrspacecast ({}* inttoptr (i64 137776915697616 to {}*) to {} addrspace(10)*)) #46, !dbg !757
  %35 = bitcast {} addrspace(10)* %box34 to i8 addrspace(10)*, !dbg !757


julia> obj(137776915697616)
AutoBody{WaterLily.var"#comp#232"{Bool, var"#sdf#3"{Int64}, var"#map#2"{Bool, Int64, Float32, Float64, Int64, Float64, SVector{2, Rational{Int64}}, SVector{2, Rational{Int64}}}}, var"#map#2"{Bool, Int64, Float32, Float64, Int64, Float64, SVector{2, Rational{Int64}}, SVector{2, Rational{Int64}}}}

@wsmoses
Copy link
Member

wsmoses commented Jun 21, 2024

okay I'm deeply confused by this memcpy of 7 bytes. Why is this happening. where does it come from?

@wsmoses
Copy link
Member

wsmoses commented Jun 21, 2024

logs of relevance so we don't need to rerun:

julia> obj(x) = Base.unsafe_pointer_to_objref(Base.reinterpret(Ptr{Cvoid}, x))
obj (generic function with 1 method)

julia> obj(137776915697616)
AutoBody{WaterLily.var"#comp#232"{Bool, var"#sdf#3"{Int64}, var"#map#2"{Bool, Int64, Float32, Float64, Int64, Float64, SVector{2, Rational{Int64}}, SVector{2, Rational{Int64}}}}, var"#map#2"{Bool, Int64, Float32, Float64, Int64, Float64, SVector{2, Rational{Int64}}, SVector{2, Rational{Int64}}}}

julia> T =obj(137776915697616)
AutoBody{WaterLily.var"#comp#232"{Bool, var"#sdf#3"{Int64}, var"#map#2"{Bool, Int64, Float32, Float64, Int64, Float64, SVector{2, Rational{Int64}}, SVector{2, Rational{Int64}}}}, var"#map#2"{Bool, Int64, Float32, Float64, Int64, Float64, SVector{2, Rational{Int64}}, SVector{2, Rational{Int64}}}}

julia> fieldtypes(T)
(WaterLily.var"#comp#232"{Bool, var"#sdf#3"{Int64}, var"#map#2"{Bool, Int64, Float32, Float64, Int64, Float64, SVector{2, Rational{Int64}}, SVector{2, Rational{Int64}}}}, var"#map#2"{Bool, Int64, Float32, Float64, Int64, Float64, SVector{2, Rational{Int64}}, SVector{2, Rational{Int64}}})

julia> fieldoffsets(T)
ERROR: UndefVarError: `fieldoffsets` not defined
Stacktrace:
 [1] top-level scope
   @ REPL[10]:1

julia> fieldoffset(T, 1)
0x0000000000000000

julia> fieldoffset(T, 2)
0x0000000000000080

julia> T = fieldtypes(T)[1]
WaterLily.var"#comp#232"{Bool, var"#sdf#3"{Int64}, var"#map#2"{Bool, Int64, Float32, Float64, Int64, Float64, SVector{2, Rational{Int64}}, SVector{2, Rational{Int64}}}}

julia> fieldtypes(T)
(Bool, var"#sdf#3"{Int64}, var"#map#2"{Bool, Int64, Float32, Float64, Int64, Float64, SVector{2, Rational{Int64}}, SVector{2, Rational{Int64}}})

julia> fieldtypes(T, 1)
ERROR: MethodError: no method matching fieldtypes(::Type{WaterLily.var"#comp#232"{Bool, var"#sdf#3"{Int64}, var"#map#2"{Bool, Int64, Float32, Float64, Int64, Float64, SVector{2, Rational{Int64}}, SVector{2, Rational{Int64}}}}}, ::Int64)

Closest candidates are:
  fieldtypes(::Type)
   @ Base reflection.jl:919

Stacktrace:
 [1] top-level scope
   @ REPL[15]:1

julia> fieldoffset(T, 1)
0x0000000000000000

julia> fieldoffset(T, 2)
0x0000000000000008

julia> fieldoffset(T, 3)
0x0000000000000010

julia> fieldoffset(T, 4)
ERROR: BoundsError: attempt to access DataType at index [4]
Stacktrace:
 [1] fieldoffset(x::DataType, idx::Int64)
   @ Base ./reflection.jl:779
 [2] top-level scope
   @ REPL[19]:1

julia> S = fieldtype(T, 3)
var"#map#2"{Bool, Int64, Float32, Float64, Int64, Float64, SVector{2, Rational{Int64}}, SVector{2, Rational{Int64}}}

julia> size(S)
ERROR: MethodError: no method matching size(::Type{var"#map#2"{Bool, Int64, Float32, Float64, Int64, Float64, SVector{2, Rational{Int64}}, SVector{2, Rational{Int64}}}})

Closest candidates are:
  size(::LLVM.FunctionBlockSet)
   @ LLVM ~/.julia/packages/LLVM/6cDbl/src/core/function.jl:129
  size(::BitVector)
   @ Base bitarray.jl:104
  size(::BitVector, ::Integer)
   @ Base bitarray.jl:107
  ...

Stacktrace:
 [1] top-level scope
   @ REPL[21]:1

julia> sizeof(S)
112

julia> using LLVM
 │ Package LLVM not found, but a package named LLVM is available from a registry. 
 │ Install package?
 │   (examples) pkg> add LLVM 
 └ (y/n/o) [y]: y
   Resolving package versions...
    Updating `~/git/Enzyme.jl/WaterLily.jl/examples/Project.toml`
  [929cbde3] + LLVM v7.2.1
  No Changes to `~/git/Enzyme.jl/WaterLily.jl/examples/Manifest.toml`
Precompiling project...
  ✗ GLMakie
  74 dependencies successfully precompiled in 59 seconds. 296 already precompiled.
  3 dependencies had output during precompilation:
┌ WaterLily → WaterLilyWriteVTKExt
│  ┌ Warning: 
│  │ Using WaterLily in serial (ie. JULIA_NUM_THREADS=1) is not recommended because it disables the GPU backend and defaults to serial CPU.
│  │ Use JULIA_NUM_THREADS=auto, or any number of threads greater than 1, to allow multi-threading in CPU or GPU backends.
│  └ @ WaterLily ~/git/Enzyme.jl/WaterLily.jl/src/WaterLily.jl:142
└  
┌ WaterLily → WaterLilyCUDAExt
│  ┌ Warning: 
│  │ Using WaterLily in serial (ie. JULIA_NUM_THREADS=1) is not recommended because it disables the GPU backend and defaults to serial CPU.
│  │ Use JULIA_NUM_THREADS=auto, or any number of threads greater than 1, to allow multi-threading in CPU or GPU backends.
│  └ @ WaterLily ~/git/Enzyme.jl/WaterLily.jl/src/WaterLily.jl:142
└  
┌ WaterLily → WaterLilyReadVTKExt
│  ┌ Warning: 
│  │ Using WaterLily in serial (ie. JULIA_NUM_THREADS=1) is not recommended because it disables the GPU backend and defaults to serial CPU.
│  │ Use JULIA_NUM_THREADS=auto, or any number of threads greater than 1, to allow multi-threading in CPU or GPU backends.
│  └ @ WaterLily ~/git/Enzyme.jl/WaterLily.jl/src/WaterLily.jl:142
└  
  1 dependency errored.
  For a report of the errors see `julia> err`. To retry use `pkg> precompile`

julia> ctx = LLVM.Context()
LLVM.Context(0x0000000005bc7470, typed ptrs)

julia> tt(T) = string(Enzyme.typetree(T, ctx, ""))
tt (generic function with 1 method)

julia> tt(S)
"{[0]:Integer, [8]:Integer, [9]:Integer, [10]:Integer, [11]:Integer, [12]:Integer, [13]:Integer, [14]:Integer, [15]:Integer, [16]:Float@float, [24]:Float@double, [32]:Integer, [33]:Integer, [34]:Integer, [35]:Integer, [36]:Integer, [37]:Integer, [38]:Integer, [39]:Integer, [40]:Float@double, [48]:Integer, [49]:Integer, [50]:Integer, [51]:Integer, [52]:Integer, [53]:Integer, [54]:Integer, [55]:Integer, [56]:Integer, [57]:Integer, [58]:Integer, [59]:Integer, [60]:Integer, [61]:Integer, [62]:Integer, [63]:Integer, [64]:Integer, [65]:Integer, [66]:Integer, [67]:Integer, [68]:Integer, [69]:Integer, [70]:Integer, [71]:Integer, [72]:Integer, [73]:Integer, [74]:Integer, [75]:Integer, [76]:Integer, [77]:Integer, [78]:Integer, [79]:Integer, [80]:Integer, [81]:Integer, [82]:Integer, [83]:Integer, [84]:Integer, [85]:Integer, [86]:Integer, [87]:Integer, [88]:Integer, [89]:Integer, [90]:Integer, [91]:Integer, [92]:Integer, [93]:Integer, [94]:Integer, [95]:Integer, [96]:Integer, [97]:Integer, [98]:Integer, [99]:Integer, [100]:Integer, [101]:Integer, [102]:Integer, [103]:Integer, [104]:Integer, [105]:Integer, [106]:Integer, [107]:Integer, [108]:Integer, [109]:Integer, [110]:Integer, [111]:Integer}"

julia> fieldtypes(S)
(Bool, Int64, Float32, Float64, Int64, Float64, SVector{2, Rational{Int64}}, SVector{2, Rational{Int64}})

julia> fieldoffset(S, 1)
0x0000000000000000

julia> fieldoffset(S, 2)
0x0000000000000008

julia> fieldoffset(S, 3)
0x0000000000000010

julia> fieldoffset(S, 4)
0x0000000000000018

julia> Int(fieldoffset(S, 4))
24

julia> Int(fieldoffset(S, 3))
16

julia> fieldtypes(S)[3]
Float32

@vchuravy
Copy link
Member Author

Why is this happening. where does it come from?

This is likely LLVM optimizing a copy loop? But why 7 and not 9 I do not know.

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

No branches or pull requests

2 participants