EnzymeAD / EnzymeAD/Enzyme.jl

error with eachslice and stack

Open
#2,909 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
586
Forks
108
Avg merge
1d 5h
Merged PRs (30d)
44

Description

I get the error below on julia 1.10. It seems that slightly modifying the example by removing either `eachslice` or `stack`, the error disappears.
```julia
julia> using Enzyme, Statistics;

julia> x = rand(Float32, 3, 2, 2);

julia> dx = Duplicated(x, Enzyme.make_zero(x));

julia> function scan(x)
y = []
for x_t in eachslice(x, dims = 2)
y = vcat(y, [x_t])
end
return mean(stack(y, dims = 2))
end
scan (generic function with 1 method)

julia> scan(x)
0.4474391f0

julia> autodiff(ReverseWithPrimal, Const(scan), Active, dx)
ERROR: EnzymeInternalError: Enzyme compilation failed due to an internal error.
Please open an issue with the code to reproduce and full error log on github.com/EnzymeAD/Enzyme.jl
To toggle more information for debugging (needed for bug reports), set Enzyme.Compiler.VERBOSE_ERRORS[] = true (default false)

Stacktrace:
[1] unitrange_last
@ ./range.jl:414
[2] UnitRange
@ ./range.jl:403
[3] UnitRange
@ ./range.jl:406
[4] UnitRange
@ ./range.jl:1306
[5] map
@ ./tuple.jl:292
[6] _stack_size_check
@ ./abstractarray.jl:2895
[7] _stack_size_check
@ ./abstractarray.jl:0

Stacktrace:
[1] julia_error(msg::String, val::Ptr{…}, errtype::Enzyme.API.ErrorType, data::Ptr{…}, data2::Ptr{…}, B::Ptr{…})
@ Enzyme.Compiler ~/.julia/packages/Enzyme/pL5zf/src/errors.jl:1215
[2] julia_error(cstr::Cstring, val::Ptr{…}, errtype::Enzyme.API.ErrorType, data::Ptr{…}, data2::Ptr{…}, B::Ptr{…})
@ Enzyme.Compiler ~/.julia/packages/Enzyme/pL5zf/src/errors.jl:986
[3] EnzymeCreateAugmentedPrimal(logic::Enzyme.Logic, todiff::LLVM.Function, retType::Enzyme.API.CDIFFE_TYPE, constant_args::Vector{…}, TA::Enzyme.TypeAnalysis, returnUsed::Bool, shadowReturnUsed::Bool, typeInfo::Enzyme.FnTypeInfo, uncacheable_args::Vector{…}, forceAnonymousTape::Bool, runtimeActivity::Bool, strongZero::Bool, width::Int64, atomicAdd::Bool)
@ Enzyme.API ~/.julia/packages/Enzyme/pL5zf/src/api.jl:418
[4] macro expansion
@ ~/.julia/packages/Enzyme/pL5zf/src/compiler.jl:2654 [inlined]
[5] macro expansion
@ ~/.julia/packages/LLVM/iza6e/src/base.jl:97 [inlined]
[6] enzyme!(job::GPUCompiler.CompilerJob{…}, interp::Enzyme.Compiler.Interpreter.EnzymeInterpreter{…}, mod::LLVM.Module, primalf::LLVM.Function, TT::Type, mode::Enzyme.API.CDerivativeMode, width::Int64, parallel::Bool, actualRetType::Type, wrap::Bool, modifiedBetween::Tuple{…} where N, returnPrimal::Bool, expectedTapeType::Type, loweredArgs::Set{…}, boxedArgs::Set{…}, removedRoots::Set{…})
@ Enzyme.Compiler ~/.julia/packages/Enzyme/pL5zf/src/compiler.jl:2622
[7] compile_unhooked(output::Symbol, job::GPUCompiler.CompilerJob{Enzyme.Compiler.EnzymeTarget{…}, Enzyme.Compiler.EnzymeCompilerParams{…}})
@ Enzyme.Compiler ~/.julia/packages/Enzyme/pL5zf/src/compiler.jl:5807
[8] compile(target::Symbol, job::GPUCompiler.CompilerJob; kwargs::@Kwargs{})
@ GPUCompiler ~/.julia/packages/GPUCompiler/j4HFa/src/driver.jl:67
[9] compile
@ ~/.julia/packages/GPUCompiler/j4HFa/src/driver.jl:55 [inlined]
[10] _thunk(job::GPUCompiler.CompilerJob{Enzyme.Compiler.EnzymeTarget{…}, Enzyme.Compiler.EnzymeCompilerParams{…}}, postopt::Bool)
@ Enzyme.Compiler ~/.julia/packages/Enzyme/pL5zf/src/compiler.jl:6720
[11] _thunk
@ ~/.julia/packages/Enzyme/pL5zf/src/compiler.jl:6718 [inlined]
[12] cached_compilation
@ ~/.julia/packages/Enzyme/pL5zf/src/compiler.jl:6776 [inlined]
[13] thunkbase(mi::Core.MethodInstance, World::UInt64, FA::Type{…}, A::Type{…}, TT::Type, Mode::Enzyme.API.CDerivativeMode, width::Int64, ModifiedBetween::Tuple{…} where N, ReturnPrimal::Bool, ShadowInit::Bool, ABI::Type, ErrIfFuncWritten::Bool, RuntimeActivity::Bool, StrongZero::Bool, edges::Vector{…})
@ Enzyme.Compiler ~/.julia/packages/Enzyme/pL5zf/src/compiler.jl:6892
[14] thunk_generator(world::UInt64, source::Union{…}, FA::Type, A::Type, TT::Type, Mode::Enzyme.API.CDerivativeMode, Width::Int64, ModifiedBetween::Tuple{…} where N, ReturnPrimal::Bool, ShadowInit::Bool, ABI::Type, ErrIfFuncWritten::Bool, RuntimeActivity::Bool, StrongZero::Bool, self::Any, fakeworld::Any, fa::Type, a::Type, tt::Type, mode::Type, width::Type, modifiedbetween::Type, returnprimal::Type, shadowinit::Type, abi::Type, erriffuncwritten::Type, runtimeactivity::Type, strongzero::Type)
@ Enzyme.Compiler ~/.julia/packages/Enzyme/pL5zf/src/compiler.jl:7036
[15] macro expansion
@ ~/.julia/packages/Enzyme/pL5zf/src/rules/jitrules.jl:464 [inlined]
[16] runtime_generic_augfwd(::Type{…}, ::Val{…}, ::Val{…}, ::Val{…}, ::Val{…}, ::Val{…}, ::typeof(Base._stack_size_check), ::Nothing, ::SubArray{…}, ::SubArray{…}, ::Tuple{…}, ::Nothing)
@ Enzyme.Compiler ~/.julia/packages/Enzyme/pL5zf/src/rules/jitrules.jl:574
[17] _dim_stack!
@ ./abstractarray.jl:2886 [inlined]
[18] _dim_stack!
@ ./abstractarray.jl:0 [inlined]
[19] augmented_julia__dim_stack__14093_inner_1wrap
@ ./abstractarray.jl:0
[20] macro expansion
@ ~/.julia/packages/Enzyme/pL5zf/src/compiler.jl:6647 [inlined]
[21] enzyme_call
@ ~/.julia/packages/Enzyme/pL5zf/src/compiler.jl:6126 [inlined]
[22] AugmentedForwardThunk
@ ~/.julia/packages/Enzyme/pL5zf/src/compiler.jl:6074 [inlined]
[23] macro expansion
@ ~/.julia/packages/Enzyme/pL5zf/src/rules/jitrules.jl:447 [inlined]
[24] runtime_generic_augfwd(::Type{…}, ::Val{…}, ::Val{…}, ::Val{…}, ::Val{…}, ::Val{…}, ::typeof(Base._dim_stack!), ::Nothing, ::Val{…}, ::Nothing, ::Array{…}, ::Array{…}, ::SubArray{…}, ::SubArray{…}, ::Base.Iterators.Rest{…}, ::Base.Iterators.Rest{…})
@ Enzyme.Compiler ~/.julia/packages/Enzyme/pL5zf/src/rules/jitrules.jl:574
[25] _dim_stack
@ ./abstractarray.jl:2871
[26] _typed_stack
@ ./abstractarray.jl:2851 [inlined]
[27] _typed_stack
@ ./abstractarray.jl:2840 [inlined]
[28] augmented_julia__typed_stack_8267wrap
@ ./abstractarray.jl:0
[29] macro expansion
@ ~/.julia/packages/Enzyme/pL5zf/src/compiler.jl:6647 [inlined]
[30] enzyme_call
@ ~/.julia/packages/Enzyme/pL5zf/src/compiler.jl:6126 [inlined]
[31] AugmentedForwardThunk
@ ~/.julia/packages/Enzyme/pL5zf/src/compiler.jl:6074 [inlined]
[32] macro expansion
@ ~/.julia/packages/Enzyme/pL5zf/src/rules/jitrules.jl:447 [inlined]
[33] runtime_generic_augfwd(::Type{…}, ::Val{…}, ::Val{…}, ::Val{…}, ::Val{…}, ::Val{…}, ::typeof(Base._typed_stack), ::Nothing, ::Int64, ::Nothing, ::Type{…}, ::Type{…}, ::Type{…}, ::Nothing, ::Vector{…}, ::Vector{…})
@ Enzyme.Compiler ~/.julia/packages/Enzyme/pL5zf/src/rules/jitrules.jl:574
[34] mapreduce
@ ./reducedim.jl:359 [inlined]
[35] _stack
@ ./abstractarray.jl:2812
[36] Array
@ ./boot.jl:477 [inlined]
[37] vect
@ ./array.jl:163 [inlined]
[38] scan
@ ./REPL[62]:4 [inlined]
[39] augmented_julia_scan_15009wrap
@ ./REPL[62]:0
[40] macro expansion
@ ~/.julia/packages/Enzyme/pL5zf/src/compiler.jl:6647 [inlined]
[41] enzyme_call
@ ~/.julia/packages/Enzyme/pL5zf/src/compiler.jl:6126 [inlined]
[42] AugmentedForwardThunk
@ ~/.julia/packages/Enzyme/pL5zf/src/compiler.jl:6074 [inlined]
[43] autodiff(mode::ReverseMode{true, false, false, FFIABI, false, false}, f::Const{typeof(scan)}, ::Type{Active}, args::Duplicated{Array{Float32, 3}})
@ Enzyme ~/.julia/packages/Enzyme/pL5zf/src/Enzyme.jl:412
[44] top-level scope
@ REPL[64]:1
Some type information was truncated. Use `show(err)` to see complete types.
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.