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

LLVM error: function failed verification (4) #840

Closed
tpapp opened this issue May 13, 2023 · 2 comments
Closed

LLVM error: function failed verification (4) #840

tpapp opened this issue May 13, 2023 · 2 comments

Comments

@tpapp
Copy link

tpapp commented May 13, 2023

stacktrace

ERROR: LoadError: LLVM error: function failed verification (4)
Stacktrace:
  [1] handle_error(reason::Cstring)
    @ LLVM ~/.julia/packages/LLVM/bsdku/src/core/context.jl:118
  [2] EnzymeCreatePrimalAndGradient(logic::Enzyme.Logic, todiff::LLVM.Function, retType::Enzyme.API.CDIFFE_TYPE, constant_args::Vector{Enzyme.API.CDIFFE_TYPE}, TA::Enzyme.TypeAnalysis, returnValue::Bool, dretUsed::Bool, mode::Enzyme.API.CDerivativeMode, width::Int64, additionalArg::Ptr{Nothing}, forceAnonymousTape::Bool, typeInfo::Enzyme.FnTypeInfo, uncacheable_args::Vector{Bool}, augmented::Ptr{Nothing}, atomicAdd::Bool)
    @ Enzyme.API ~/.julia/packages/Enzyme/ojlwS/src/api.jl:128
  [3] enzyme!(job::GPUCompiler.CompilerJob{Enzyme.Compiler.EnzymeTarget, Enzyme.Compiler.EnzymeCompilerParams}, mod::LLVM.Module, primalf::LLVM.Function, TT::Type, mode::Enzyme.API.CDerivativeMode, width::Int64, parallel::Bool, actualRetType::Type, wrap::Bool, modifiedBetween::Tuple{Bool, Bool}, returnPrimal::Bool, jlrules::Vector{String}, expectedTapeType::Type)
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/ojlwS/src/compiler.jl:7590
  [4] codegen(output::Symbol, job::GPUCompiler.CompilerJob{Enzyme.Compiler.EnzymeTarget, Enzyme.Compiler.EnzymeCompilerParams}; libraries::Bool, deferred_codegen::Bool, optimize::Bool, ctx::LLVM.ThreadSafeContext, strip::Bool, validate::Bool, only_entry::Bool, parent_job::Nothing)
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/ojlwS/src/compiler.jl:8938
  [5] codegen
    @ ~/.julia/packages/Enzyme/ojlwS/src/compiler.jl:8549 [inlined]
  [6] _thunk(job::GPUCompiler.CompilerJob{Enzyme.Compiler.EnzymeTarget, Enzyme.Compiler.EnzymeCompilerParams}, ctx::Nothing, postopt::Bool)
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/ojlwS/src/compiler.jl:9450
  [7] _thunk
    @ ~/.julia/packages/Enzyme/ojlwS/src/compiler.jl:9447 [inlined]
  [8] cached_compilation
    @ ~/.julia/packages/Enzyme/ojlwS/src/compiler.jl:9485 [inlined]
  [9] #s287#220
    @ ~/.julia/packages/Enzyme/ojlwS/src/compiler.jl:9543 [inlined]
 [10] var"#s287#220"(FA::Any, A::Any, TT::Any, Mode::Any, ModifiedBetween::Any, width::Any, ReturnPrimal::Any, ShadowInit::Any, World::Any, ::Any, ::Any, ::Any, ::Any, tt::Any, ::Any, ::Any, ::Any, ::Any, ::Any)
    @ Enzyme.Compiler ./none:0
 [11] (::Core.GeneratedFunctionStub)(::Any, ::Vararg{Any})
    @ Core ./boot.jl:602
 [12] thunk
    @ ~/.julia/packages/Enzyme/ojlwS/src/compiler.jl:9502 [inlined]
 [13] autodiff(#unused#::EnzymeCore.ReverseMode{true}, f::EnzymeCore.Const{typeof(ℓ)}, #unused#::Type{EnzymeCore.Active}, args::EnzymeCore.Duplicated{Vector{Float64}})
    @ Enzyme ~/.julia/packages/Enzyme/ojlwS/src/Enzyme.jl:199
 [14] autodiff(::EnzymeCore.ReverseMode{true}, ::typeof(ℓ), ::Type, ::EnzymeCore.Duplicated{Vector{Float64}})
    @ Enzyme ~/.julia/packages/Enzyme/ojlwS/src/Enzyme.jl:214
 [15] top-level scope
    @ ~/code/julia/misc/EnzymeBugMWE.jl/failed_verif.jl:40
 [16] include(fname::String)
    @ Base.MainInclude ./client.jl:478
 [17] top-level scope
    @ REPL[3]:1

versions

(EnzymeBugMWE) pkg> st Enzyme
Status `~/code/julia/misc/EnzymeBugMWE.jl/Project.toml`
  [7da242da] Enzyme v0.11.1 `https://github.com/EnzymeAD/Enzyme.jl.git#main`

(EnzymeBugMWE) pkg> st StaticArrays
Status `~/code/julia/misc/EnzymeBugMWE.jl/Project.toml`
  [90137ffa] StaticArrays v1.5.24

julia> VERSION
v"1.9.0"

MWE

using StaticArrays
import Enzyme

const ω_DIMENSION = 7

_uni_prior(z::Real) = -log(5) - abs2(z / 5)/2

_uni_prior(z::AbstractVector) = sum(_uni_prior, z)

function log_posterior((; ω_intercept, ω_std))
    ℓ_prior = _uni_prior(ω_intercept) + _uni_prior(ω_std)
    ℓ_prior
end

function transform_and_logjac(x)
    S = eltype(x)
    logjac::S = 0.0
    i::Int = 0
    function _pick(d::Int)
        v = @view x[(i+1):(i+d)]
        i += d
        v
    end
    ω_intercept = SVector{ω_DIMENSION}(_pick(ω_DIMENSION))
    pre_ω_std = SVector{ω_DIMENSION}(_pick(ω_DIMENSION))
    ω_std = exp.(pre_ω_std)
    logjac += sum(pre_ω_std)
    (;  ω_intercept, ω_std), logjac
end

function (x)
    θ, logjac = transform_and_logjac(x)
    log_posterior(θ) + logjac
end

x = ones(2 * ω_DIMENSION)

Enzyme.API.runtimeActivity!(true)
∂ℓ_∂x = zero(x)
_, y = Enzyme.autodiff(Enzyme.ReverseWithPrimal, ℓ, Enzyme.Active, Enzyme.Duplicated(x, ∂ℓ_∂x))

(this is an off-shoot from debugging #817)

@wsmoses
Copy link
Member

wsmoses commented May 13, 2023

Reduced:

using StaticArrays
import Enzyme
Enzyme.API.instname!(true)

@noinline _uni_prior(z::AbstractVector) = first(z)

@noinline function transform_and_logjac(x)
    intercept = SVector{7}(x)
    intercept, intercept, @inbounds x[1]
end

function (x)
    t, q, logjac = transform_and_logjac(x)
	( _uni_prior(t) + _uni_prior(q) ) + logjac
end

x = ones(7)

# Enzyme.API.runtimeActivity!(true)
∂ℓ_∂x = zero(x)
_, y = Enzyme.autodiff(Enzyme.ReverseWithPrimal, ℓ, Enzyme.Active, Enzyme.Duplicated(x, ∂ℓ_∂x))

@wsmoses
Copy link
Member

wsmoses commented May 14, 2023

This will be fixed by the next jll (which has been tagged on Enzyme proper, and presumably will be in registries for us to merge tomorrow).

@wsmoses wsmoses closed this as completed May 14, 2023
This was referenced May 16, 2023
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