Skip to content

Opaque pointer handling #2705

@vchuravy

Description

@vchuravy

On #2675 we see many errors like

ERROR: Taking the type of an opaque pointer is illegal
│ │ Stacktrace:
│ │   [1] error(s::String)
│ │     @ Base ./error.jl:44
│ │   [2] eltype
│ │     @ ~/.julia/packages/LLVM/iza6e/src/core/type.jl:293 [inlined]
│ │   [3] propagate_returned!(mod::LLVM.Module)
│ │     @ Enzyme.Compiler ~/work/Enzyme.jl/Enzyme.jl/src/llvm/transforms.jl:1688
│ │   [4] removeDeadArgs!(mod::LLVM.Module, tm::LLVM.TargetMachine)
│ │     @ Enzyme.Compiler ~/work/Enzyme.jl/Enzyme.jl/src/llvm/transforms.jl:2563
│ │   [5] macro expansion
│ │     @ ~/work/Enzyme.jl/Enzyme.jl/src/compiler/optimize.jl:138 [inlined]
│ │   [6] macro expansion
│ │     @ ~/.julia/packages/LLVM/iza6e/src/base.jl:97 [inlined]
│ │   [7] optimize!(mod::LLVM.Module, tm::LLVM.TargetMachine)
│ │     @ Enzyme.Compiler ~/work/Enzyme.jl/Enzyme.jl/src/compiler/optimize.jl:29
│ │   [8] compile_unhooked(output::Symbol, job::GPUCompiler.CompilerJob{Enzyme.Compiler.EnzymeTarget{GPUCompiler.NativeCompilerTarget}, Enzyme.Compiler.EnzymeCompilerParams{Enzyme.Compiler.PrimalCompilerParams}})
│ │     @ Enzyme.Compiler ~/work/Enzyme.jl/Enzyme.jl/src/compiler.jl:4774
│ │   [9] compile(target::Symbol, job::GPUCompiler.CompilerJob; kwargs::@Kwargs{})
│ │     @ GPUCompiler ~/.julia/packages/GPUCompiler/Gp8bZ/src/driver.jl:67
│ │  [10] compile
│ │     @ ~/.julia/packages/GPUCompiler/Gp8bZ/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 ~/work/Enzyme.jl/Enzyme.jl/src/compiler.jl:5960
│ │  [12] _thunk
│ │     @ ~/work/Enzyme.jl/Enzyme.jl/src/compiler.jl:5958 [inlined]
│ │  [13] cached_compilation
│ │     @ ~/work/Enzyme.jl/Enzyme.jl/src/compiler.jl:6015 [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 ~/work/Enzyme.jl/Enzyme.jl/src/compiler.jl:6131
│ │  [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 ~/work/Enzyme.jl/Enzyme.jl/src/compiler.jl:6275
│ │  [16] autodiff
│ │     @ ~/work/Enzyme.jl/Enzyme.jl/src/Enzyme.jl:658 [inlined]
│ │  [17] autodiff
│ │     @ ~/work/Enzyme.jl/Enzyme.jl/src/Enzyme.jl:562 [inlined]
│ │  [18] autodiff
│ │     @ ~/work/Enzyme.jl/Enzyme.jl/src/Enzyme.jl:534 [inlined]
│ │  [19] hvp!(res::Vector{Float64}, f::typeof(f), x::Vector{Float64}, v::Vector{Float64})
│ │     @ Enzyme ~/work/Enzyme.jl/Enzyme.jl/src/sugar.jl:1312

argeltype = if LLVM.version().major >= 12
# TODO try to get sret element type if possible
# note currently opaque pointers has this break [and we need to doa check if opaque
# and if so get inner piece]
eltype(value_type(arg))
else

Metadata

Metadata

Assignees

No one assigned

    Labels

    Julia v1.12Related to compatibility with Julia v1.12

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions