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 convert an object of type LLVM.ConstantArray to an object of type LLVM.Instruction #2144

Closed
mhauru opened this issue Nov 29, 2024 · 2 comments

Comments

@mhauru
Copy link
Contributor

mhauru commented Nov 29, 2024

MWE:

module MWE

import Enzyme

abstract type A end

# Two copies of the same type.
struct Normal1{T<:Real} <: A
    σ::T
end

struct Normal2{T<:Real} <: A
    σ::T
end

logpdf(d, x::Real) = log(d.σ) - 0.5 * (x)^2

function func(x)
    dists = [Normal1{Float64}(1.0), Normal2{Float64}(1.0)]
    return sum(n -> logpdf(dists[n], x[n]), 1:2)
end

Enzyme.gradient(Enzyme.Forward, Enzyme.Const(func), [0.5, 0.7])

end

Out:

ERROR: MethodError: Cannot `convert` an object of type LLVM.ConstantArray to an object of type LLVM.Instruction

Closest candidates are:
  convert(::Type{T}, ::T) where T
   @ Base Base.jl:84
  convert(::Type{<:LLVM.Value}, ::LLVM.Metadata)
   @ LLVM ~/.julia/packages/LLVM/wMjUU/src/core/metadata.jl:77

Stacktrace:
  [1] push!(a::Vector{LLVM.Instruction}, item::LLVM.ConstantArray)
    @ Base ./array.jl:1118
  [2] (::Enzyme.Compiler.var"#make_replacement#55"{})(cur::LLVM.Value, prevbb::LLVM.IRBuilder)
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/g7K4e/src/errors.jl:334
  [3] julia_error(cstr::Cstring, val::Ptr{…}, errtype::Enzyme.API.ErrorType, data::Ptr{…}, data2::Ptr{…}, B::Ptr{…})
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/g7K4e/src/errors.jl:591
  [4] EnzymeCreateForwardDiff(logic::Enzyme.Logic, todiff::LLVM.Function, retType::Enzyme.API.CDIFFE_TYPE, constant_args::Vector{…}, TA::Enzyme.TypeAnalysis, returnValue::Bool, mode::Enzyme.API.CDerivativeMode, runtimeActivity::Bool, width::Int64, additionalArg::Ptr{…}, typeInfo::Enzyme.FnTypeInfo, uncacheable_args::Vector{…})
    @ Enzyme.API ~/.julia/packages/Enzyme/g7K4e/src/api.jl:319
  [5] enzyme!(job::GPUCompiler.CompilerJob{…}, 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{…})
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/g7K4e/src/compiler.jl:2275
  [6] codegen(output::Symbol, job::GPUCompiler.CompilerJob{…}; libraries::Bool, deferred_codegen::Bool, optimize::Bool, toplevel::Bool, strip::Bool, validate::Bool, only_entry::Bool, parent_job::Nothing)
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/g7K4e/src/compiler.jl:5426
  [7] codegen
    @ ~/.julia/packages/Enzyme/g7K4e/src/compiler.jl:4196 [inlined]
  [8] _thunk(job::GPUCompiler.CompilerJob{Enzyme.Compiler.EnzymeTarget, Enzyme.Compiler.EnzymeCompilerParams}, postopt::Bool)
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/g7K4e/src/compiler.jl:6298
  [9] _thunk
    @ ~/.julia/packages/Enzyme/g7K4e/src/compiler.jl:6298 [inlined]
 [10] cached_compilation
    @ ~/.julia/packages/Enzyme/g7K4e/src/compiler.jl:6339 [inlined]
 [11] 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)
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/g7K4e/src/compiler.jl:6452
 [12] thunk_generator(world::UInt64, source::LineNumberNode, 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, 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)
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/g7K4e/src/compiler.jl:6604
 [13] autodiff
    @ ~/.julia/packages/Enzyme/g7K4e/src/Enzyme.jl:640 [inlined]
 [14] macro expansion
    @ ~/.julia/packages/Enzyme/g7K4e/src/sugar.jl:673 [inlined]
 [15] gradient(::EnzymeCore.ForwardMode{…}, ::EnzymeCore.Const{…}, ::Vector{…}; chunk::Nothing, shadows::Tuple{…})
    @ Enzyme ~/.julia/packages/Enzyme/g7K4e/src/sugar.jl:575
 [16] gradient(::EnzymeCore.ForwardMode{…}, ::EnzymeCore.Const{…}, ::Vector{…})
    @ Enzyme ~/.julia/packages/Enzyme/g7K4e/src/sugar.jl:575
 [17] top-level scope
    @ REPL[2]:23
Some type information was truncated. Use `show(err)` to see complete types.

On current main.

@wsmoses
Copy link
Member

wsmoses commented Nov 29, 2024

Should be resolved by #2143 (the prev PR fixed and added a test, but wasn't in batch mode, which this hit an additional issue of).

@wsmoses wsmoses closed this as completed Nov 30, 2024
@mhauru
Copy link
Contributor Author

mhauru commented Dec 2, 2024

Confirmed fixed, thanks @wsmoses!

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