EnzymeAD / EnzymeAD/Enzyme.jl

`Illegal calling convention fixup` in Julia v1.11 when enabling code coverage

Open
#3,318 4 comments 0 reactions 0 assignees View on GitHub
Julia v1.11
Dominant language
Julia
Stars
586
Forks
108
Avg merge
1d 5h
Merged PRs (30d)
44

Description

Running
```julia
using Enzyme
using Oceananigans

arch = CPU()
FT = Float64

N = 100
topo = (Periodic, Flat, Flat)
grid = RectilinearGrid(arch, FT, topology=topo, size=N, halo=2, x=(-1, 1), y=(-1, 1), z=(-1, 1))
fwd, rev = Enzyme.autodiff_thunk(ReverseSplitWithPrimal, Const{typeof(CenterField)}, Duplicated, typeof(Const(grid)))
tape, primal, shadowp = fwd(Const(CenterField), Const(grid))

shadow = if shadowp isa Base.RefValue
shadowp[]
else
shadowp
end

@assert size(primal) == size(shadow)
```
with
```
julia +1.11 --project -O0 --code-coverage=user test_enzyme.jl
```
crashes with the following error:
```
ERROR: LoadError: AssertionError: Enzyme Internal Error: Illegal calling convention fixup
ctype = LLVM.ArrayType([1 x {} addrspace(10)*])
tape = LLVM.PointerType({} addrspace(10)* addrspace(10)*)
val = [1 x {} addrspace(10)*] %3
prev = {} addrspace(10)* addrspace(10)* undef
lidxs = UInt32[]
ridxs = UInt32[]
tape_type(tape) = @NamedTuple{1}
convert(LLVMType, tape_type(tape)) = LLVM.ArrayType([1 x {} addrspace(10)*])

Stacktrace:
[1] calling_conv_fixup(builder::LLVM.IRBuilder, val::LLVM.Value, tape::LLVM.LLVMType, prev::LLVM.UndefValue, lidxs::Vector{UInt32}, ridxs::Vector{UInt32}, emesg::Nothing)
@ Enzyme.Compiler ~/.julia/packages/Enzyme/CCx0o/src/compiler/utils.jl:619
[2] calling_conv_fixup (repeats 3 times)
@ ~/.julia/packages/Enzyme/CCx0o/src/compiler/utils.jl:508 [inlined]
[3] calling_conv_fixup(builder::LLVM.IRBuilder, val::LLVM.Value, tape::LLVM.LLVMType)
@ Enzyme.Compiler ~/.julia/packages/Enzyme/CCx0o/src/compiler/utils.jl:508
[4] create_abi_wrapper(enzyme_context::Enzyme.EnzymeContext, enzymefn::LLVM.Function, TT::Type, rettype::Type, actualRetType::Type, Mode::Enzyme.API.CDerivativeMode, augmented::Ptr{Nothing}, width::Int64, returnPrimal::Bool, shadow_init::Bool, world::UInt64, interp::Enzyme.Compiler.Interpreter.EnzymeInterpreter{Nothing}, runtime_activity::Bool)
@ Enzyme.Compiler ~/.julia/packages/Enzyme/CCx0o/src/compiler.jl:3555
[5] macro expansion
@ ~/.julia/packages/Enzyme/CCx0o/src/compiler.jl:2828 [inlined]
[6] macro expansion
@ ~/.julia/packages/LLVM/aXQtR/src/base.jl:113 [inlined]
[7] enzyme!(enzyme_context::Enzyme.EnzymeContext, job::GPUCompiler.CompilerJob{Enzyme.Compiler.EnzymeTarget{GPUCompiler.NativeCompilerTarget}, Enzyme.Compiler.EnzymeCompilerParams{Enzyme.Compiler.PrimalCompilerParams}}, interp::Enzyme.Compiler.Interpreter.EnzymeInterpreter{Nothing}, mod::LLVM.Module, primalf::LLVM.Function, TT::Type, mode::Enzyme.API.CDerivativeMode, width::Int64, parallel::Bool, actualRetType::Type, wrap::Bool, modifiedBetween::NTuple{N, Bool} where N, returnPrimal::Bool, expectedTapeType::Type, loweredArgs::Set{Int64}, boxedArgs::Set{Int64}, removedRoots::Set{Int64})
@ Enzyme.Compiler ~/.julia/packages/Enzyme/CCx0o/src/compiler.jl:2718
[8] compile_unhooked(output::Symbol, job::GPUCompiler.CompilerJob{Enzyme.Compiler.EnzymeTarget{GPUCompiler.NativeCompilerTarget}, Enzyme.Compiler.EnzymeCompilerParams{Enzyme.Compiler.PrimalCompilerParams}})
@ Enzyme.Compiler ~/.julia/packages/Enzyme/CCx0o/src/compiler.jl:6068
[9] #compile#163
@ ~/.julia/packages/GPUCompiler/Yuvf5/src/driver.jl:67 [inlined]
[10] compile
@ ~/.julia/packages/GPUCompiler/Yuvf5/src/driver.jl:55 [inlined]
[11] _thunk(job::GPUCompiler.CompilerJob{Enzyme.Compiler.EnzymeTarget{GPUCompiler.NativeCompilerTarget}, Enzyme.Compiler.EnzymeCompilerParams{Enzyme.Compiler.PrimalCompilerParams}}, postopt::Bool)
@ Enzyme.Compiler ~/.julia/packages/Enzyme/CCx0o/src/compiler.jl:7011
[12] _thunk
@ ~/.julia/packages/Enzyme/CCx0o/src/compiler.jl:7009 [inlined]
[13] cached_compilation
@ ~/.julia/packages/Enzyme/CCx0o/src/compiler.jl:7079 [inlined]
[14] thunkbase(mi::Core.MethodInstance, World::UInt64, FA::Type{<:Annotation}, A::Type{<:Annotation}, TT::Type, Mode::Enzyme.API.CDerivativeMode, width::Int64, ModifiedBetween::NTuple{N, Bool} where N, ReturnPrimal::Bool, ShadowInit::Bool, ABI::Type, ErrIfFuncWritten::Bool, RuntimeActivity::Bool, StrongZero::Bool, edges::Vector{Any})
@ Enzyme.Compiler ~/.julia/packages/Enzyme/CCx0o/src/compiler.jl:7195
[15] thunk_generator(world::UInt64, source::Union{LineNumberNode, Method}, FA::Type, A::Type, TT::Type, Mode::Enzyme.API.CDerivativeMode, Width::Int64, ModifiedBetween::NTuple{N, Bool} 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/CCx0o/src/compiler.jl:7339
[16] tape_type(::ReverseModeSplit{true, true, false, false, 0, (false, false, true, false, false), FFIABI, false, false, false}, ::Type{Const{typeof(KernelAbstractions.cpu_init_kernel)}}, ::Type{Const{Nothing}}, ::Type{Const{KernelAbstractions.CompilerMetadata{KernelAbstractions.NDIteration.DynamicSize, KernelAbstractions.NDIteration.NoDynamicCheck, CartesianIndex{1}, CartesianIndices{1, Tuple{Base.OneTo{Int64}}}, KernelAbstractions.NDIteration.NDRange{1, KernelAbstractions.NDIteration.DynamicSize, KernelAbstractions.NDIteration.DynamicSize, CartesianIndices{1, Tuple{Base.OneTo{Int64}}}, CartesianIndices{1, Tuple{Base.OneTo{Int64}}}}}}}, ::Type{Duplicated{Array{Float64, 3}}}, ::Type{Const{typeof(zero)}}, ::Type{Const{Type{Float64}}})
@ Enzyme ~/.julia/packages/Enzyme/CCx0o/src/Enzyme.jl:1231
[17] _create_tape_kernel(::KernelAbstractions.Kernel{KernelAbstractions.CPU, KernelAbstractions.NDIteration.DynamicSize, KernelAbstractions.NDIteration.DynamicSize, typeof(KernelAbstractions.cpu_init_kernel)}, ::ReverseModeSplit{true, true, false, false, 0, (false, false, true, false, false), FFIABI, false, false, false}, ::Type, ::Type, ::Tuple{Int64}, ::KernelAbstractions.NDIteration.NDRange{1, KernelAbstractions.NDIteration.DynamicSize, KernelAbstractions.NDIteration.DynamicSize, CartesianIndices{1, Tuple{Base.OneTo{Int64}}}, CartesianIndices{1, Tuple{Base.OneTo{Int64}}}}, ::Duplicated{Array{Float64, 3}}, ::Vararg{Any})
@ EnzymeExt ~/.julia/packages/KernelAbstractions/scVtc/ext/EnzymeCore08Ext.jl:67
[18] #augmented_primal#7
@ ~/.julia/packages/KernelAbstractions/scVtc/ext/EnzymeCore08Ext.jl:255
[19] macro expansion
@ ~/.julia/packages/Enzyme/CCx0o/src/compiler.jl:6938 [inlined]
[20] enzyme_call
@ ~/.julia/packages/Enzyme/CCx0o/src/compiler.jl:6408 [inlined]
[21] AugmentedForwardThunk
@ ~/.julia/packages/Enzyme/CCx0o/src/compiler.jl:6356 [inlined]
[22] macro expansion
@ ~/.julia/packages/Enzyme/CCx0o/src/rules/jitrules.jl:467 [inlined]
[23] runtime_generic_augfwd(::Type{Val{(false, false, false, true, false, false)}}, ::Val{false}, ::Val{false}, ::Val{1}, ::Val{(true, true, true, true, true, true)}, ::Val{@NamedTuple{1, 2, 3}}, ::typeof(Core.kwcall), ::Nothing, ::@NamedTuple{ndrange::Int64}, ::Nothing, ::KernelAbstractions.Kernel{KernelAbstractions.CPU, KernelAbstractions.NDIteration.DynamicSize, KernelAbstractions.NDIteration.DynamicSize, typeof(KernelAbstractions.cpu_init_kernel)}, ::Nothing, ::Array{Float64, 3}, ::Array{Float64, 3}, ::typeof(zero), ::Nothing, ::Type{Float64}, ::Nothing)
@ Enzyme.Compiler ~/.julia/packages/Enzyme/CCx0o/src/rules/jitrules.jl:600
[24] #zeros#23
@ ~/.julia/packages/KernelAbstractions/scVtc/src/cpu.jl:9 [inlined]
[25] zeros
@ ~/.julia/packages/KernelAbstractions/scVtc/src/cpu.jl:6 [inlined]
[26] zeros
@ ~/.julia/packages/KernelAbstractions/scVtc/src/KernelAbstractions.jl:564 [inlined]
[27] zeros
@ ~/.julia/dev/Oceananigans/src/Grids/zeros_and_ones.jl:8 [inlined]
[28] new_data
@ ~/.julia/dev/Oceananigans/src/Grids/new_data.jl:66 [inlined]
[29] new_data
@ ~/.julia/dev/Oceananigans/src/Grids/new_data.jl:71 [inlined]
[30] Field
@ ~/.julia/dev/Oceananigans/src/Fields/field.jl:177 [inlined]
[31] Field
@ ~/.julia/dev/Oceananigans/src/Fields/field.jl:0 [inlined]
[32] augmented_julia_Field_47842_inner_7wrap
@ ~/.julia/dev/Oceananigans/src/Fields/field.jl:0
[33] macro expansion
@ ~/.julia/packages/Enzyme/CCx0o/src/compiler.jl:6938 [inlined]
[34] enzyme_call
@ ~/.julia/packages/Enzyme/CCx0o/src/compiler.jl:6408 [inlined]
[35] AugmentedForwardThunk
@ ~/.julia/packages/Enzyme/CCx0o/src/compiler.jl:6356 [inlined]
[36] macro expansion
@ ~/.julia/packages/Enzyme/CCx0o/src/rules/jitrules.jl:467 [inlined]
[37] runtime_generic_augfwd(::Type{Val{(false, false, true, false)}}, ::Val{false}, ::Val{false}, ::Val{1}, ::Val{(true, true, true, true)}, ::Val{@NamedTuple{1, 2, 3}}, ::Type{Field}, ::Nothing, ::Tuple{Center, Center, Center}, ::Nothing, ::RectilinearGrid{Float64, Periodic, Flat, Flat, Oceananigans.Grids.StaticVerticalDiscretization{OffsetArrays.OffsetVector{Float64, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}, OffsetArrays.OffsetVector{Float64, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}, Float64, Float64}, Float64, Float64, OffsetArrays.OffsetVector{Float64, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}, OffsetArrays.OffsetVector{Float64, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}, CPU, Oceananigans.Grids.GridSize{100, 1, 1, 2, 0, 0}}, ::Base.RefValue{RectilinearGrid{Float64, Periodic, Flat, Flat, Oceananigans.Grids.StaticVerticalDiscretization{OffsetArrays.OffsetVector{Float64, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}, OffsetArrays.OffsetVector{Float64, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}, Float64, Float64}, Float64, Float64, OffsetArrays.OffsetVector{Float64, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}, OffsetArrays.OffsetVector{Float64, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}, CPU, Oceananigans.Grids.GridSize{100, 1, 1, 2, 0, 0}}}, ::Type{Float64}, ::Nothing)
@ Enzyme.Compiler ~/.julia/packages/Enzyme/CCx0o/src/rules/jitrules.jl:600
[38] CenterField (repeats 2 times)
@ ~/.julia/dev/Oceananigans/src/Fields/field.jl:198 [inlined]
[39] CenterField
@ ~/.julia/dev/Oceananigans/src/Fields/field.jl:0 [inlined]
[40] augmented_julia_CenterField_34262_inner_1wrap
@ ~/.julia/dev/Oceananigans/src/Fields/field.jl:0
[41] macro expansion
@ ~/.julia/packages/Enzyme/CCx0o/src/compiler.jl:6938 [inlined]
[42] enzyme_call
@ ~/.julia/packages/Enzyme/CCx0o/src/compiler.jl:6408 [inlined]
[43] (::Enzyme.Compiler.AugmentedForwardThunk{Ptr{Nothing}, Const{typeof(CenterField)}, Duplicated{Field{Center, Center, Center, Nothing, RectilinearGrid{Float64, Periodic, Flat, Flat, Oceananigans.Grids.StaticVerticalDiscretization{OffsetArrays.OffsetVector{Float64, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}, OffsetArrays.OffsetVector{Float64, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}, Float64, Float64}, Float64, Float64, OffsetArrays.OffsetVector{Float64, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}, OffsetArrays.OffsetVector{Float64, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}, CPU, Oceananigans.Grids.GridSize{100, 1, 1, 2, 0, 0}}, Tuple{Colon, Colon, Colon}, OffsetArrays.OffsetArray{Float64, 3, Array{Float64, 3}}, Float64, FieldBoundaryConditions{BoundaryCondition{Oceananigans.BoundaryConditions.Periodic, Nothing}, BoundaryCondition{Oceananigans.BoundaryConditions.Periodic, Nothing}, Nothing, Nothing, Nothing, Nothing, Nothing, K, O}, Nothing, Nothing} where {K<:NamedTuple, O<:NamedTuple}}, Tuple{Const{RectilinearGrid{Float64, Periodic, Flat, Flat, Oceananigans.Grids.StaticVerticalDiscretization{OffsetArrays.OffsetVector{Float64, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}, OffsetArrays.OffsetVector{Float64, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}, Float64, Float64}, Float64, Float64, OffsetArrays.OffsetVector{Float64, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}, OffsetArrays.OffsetVector{Float64, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}, CPU, Oceananigans.Grids.GridSize{100, 1, 1, 2, 0, 0}}}}, 1, true, @NamedTuple{1, 2, 3, 4}})(fn::Const{typeof(CenterField)}, args::Const{RectilinearGrid{Float64, Periodic, Flat, Flat, Oceananigans.Grids.StaticVerticalDiscretization{OffsetArrays.OffsetVector{Float64, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}, OffsetArrays.OffsetVector{Float64, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}, Float64, Float64}, Float64, Float64, OffsetArrays.OffsetVector{Float64, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}, OffsetArrays.OffsetVector{Float64, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}, CPU, Oceananigans.Grids.GridSize{100, 1, 1, 2, 0, 0}}})
@ Enzyme.Compiler ~/.julia/packages/Enzyme/CCx0o/src/compiler.jl:6356
[44] top-level scope
@ ~/.julia/dev/Oceananigans/test/test_enzyme.jl:11
in expression starting at /Users/mose/.julia/dev/Oceananigans/test/test_enzyme.jl:11
```
`--code-coverage=user` is the main culprit here, removing that flag makes the code run successfully.

I asked the bot to reduce this without Oceananigans, in the meantime this is what I've got. For the record, first observed in https://github.com/CliMA/Oceananigans.jl/pull/5786.

Version numbers:
```
(test) pkg> st Enzyme Oceananigans
Status `~/.julia/dev/Oceananigans/test/Project.toml`
[7da242da] Enzyme v0.13.181
[9e8cae18] Oceananigans v0.110.8 `..`
```

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.