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

Enzyme compilation failed for HVP with broadcast #2170

Open
gdalle opened this issue Dec 5, 2024 · 2 comments
Open

Enzyme compilation failed for HVP with broadcast #2170

gdalle opened this issue Dec 5, 2024 · 2 comments

Comments

@gdalle
Copy link
Contributor

gdalle commented Dec 5, 2024

Here's the MWE (tested on Enzyme v0.13.19):

import Enzyme

mydiff(x) = x[2:end] .- x[1:end-1];
sumdiff(x) = sum(mydiff(x));

Enzyme.hvp(sumdiff, float.(1:5), float.(1:5))

Here's the shortened error:

julia> Enzyme.hvp(sumdiff, float.(1:5), float.(1:5))
ERROR: Enzyme compilation failed.
Current scope: 
; Function Attrs: mustprogress willreturn

...

Stacktrace:
  [1] copy
    @ ./array.jl:350
  [2] unaliascopy
    @ ./abstractarray.jl:1516
  [3] unalias
    @ ./abstractarray.jl:1500
  [4] broadcast_unalias
    @ ./broadcast.jl:941
  [5] preprocess
    @ ./broadcast.jl:948
  [6] preprocess_args
    @ ./broadcast.jl:950
  [7] preprocess
    @ ./broadcast.jl:947
  [8] override_bc_copyto!
    @ ~/.julia/packages/Enzyme/ottqJ/src/compiler/interpreter.jl:663
  [9] copyto!
    @ ./broadcast.jl:920
 [10] override_bc_materialize
    @ ~/.julia/packages/Enzyme/ottqJ/src/compiler/interpreter.jl:719
 [11] mydiff
    @ ~/Work/GitHub/Julia/DifferentiationInterface.jl/DifferentiationInterface/test/playground.jl:3

Stacktrace:
  [1] julia_error(msg::String, val::Ptr{…}, errtype::Enzyme.API.ErrorType, data::Ptr{…}, data2::Ptr{…}, B::Ptr{…})
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/ottqJ/src/errors.jl:350
  [2] julia_error(cstr::Cstring, val::Ptr{…}, errtype::Enzyme.API.ErrorType, data::Ptr{…}, data2::Ptr{…}, B::Ptr{…})
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/ottqJ/src/errors.jl:176
  [3] EnzymeCreatePrimalAndGradient(logic::Enzyme.Logic, todiff::LLVM.Function, retType::Enzyme.API.CDIFFE_TYPE, constant_args::Vector{…}, TA::Enzyme.TypeAnalysis, returnValue::Bool, dretUsed::Bool, mode::Enzyme.API.CDerivativeMode, runtimeActivity::Bool, width::Int64, additionalArg::Ptr{…}, forceAnonymousTape::Bool, typeInfo::Enzyme.FnTypeInfo, uncacheable_args::Vector{…}, augmented::Ptr{…}, atomicAdd::Bool)
    @ Enzyme.API ~/.julia/packages/Enzyme/ottqJ/src/api.jl:268
  [4] 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::NTuple{…} where N, returnPrimal::Bool, expectedTapeType::Type, loweredArgs::Set{…}, boxedArgs::Set{…})
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/ottqJ/src/compiler.jl:1571
  [5] codegen(output::Symbol, job::GPUCompiler.CompilerJob{…}; libraries::Bool, deferred_codegen::Bool, optimize::Bool, toplevel::Bool, strip::Bool, validate::Bool, only_entry::Bool, parent_job::GPUCompiler.CompilerJob{…})
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/ottqJ/src/compiler.jl:4417
  [6] codegen
    @ ~/.julia/packages/Enzyme/ottqJ/src/compiler.jl:3218 [inlined]
  [7] (::GPUCompiler.var"#187#198"{GPUCompiler.CompilerJob{}, GPUCompiler.CompilerJob{}})()
    @ GPUCompiler ~/.julia/packages/GPUCompiler/2CW9L/src/driver.jl:224
  [8] get!(default::GPUCompiler.var"#187#198"{}, h::Dict{…}, key::GPUCompiler.CompilerJob{…})
    @ Base ./dict.jl:458
  [9] macro expansion
    @ ~/.julia/packages/GPUCompiler/2CW9L/src/driver.jl:223 [inlined]
 [10] 
    @ GPUCompiler ~/.julia/packages/GPUCompiler/2CW9L/src/utils.jl:108
 [11] emit_llvm
    @ ~/.julia/packages/GPUCompiler/2CW9L/src/utils.jl:106 [inlined]
 [12] 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/ottqJ/src/compiler.jl:3274
 [13] codegen
    @ ~/.julia/packages/Enzyme/ottqJ/src/compiler.jl:3218 [inlined]
 [14] _thunk(job::GPUCompiler.CompilerJob{Enzyme.Compiler.EnzymeTarget, Enzyme.Compiler.EnzymeCompilerParams}, postopt::Bool)
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/ottqJ/src/compiler.jl:5265
 [15] cached_compilation(job::GPUCompiler.CompilerJob)
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/ottqJ/src/compiler.jl:5306
 [16] thunkbase(mi::Core.MethodInstance, World::UInt64, FA::Type{…}, A::Type{…}, TT::Type, Mode::Enzyme.API.CDerivativeMode, width::Int64, ModifiedBetween::NTuple{…} where N, ReturnPrimal::Bool, ShadowInit::Bool, ABI::Type, ErrIfFuncWritten::Bool, RuntimeActivity::Bool)
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/ottqJ/src/compiler.jl:5410
 [17] thunk_generator(world::UInt64, source::LineNumberNode, FA::Type, A::Type, TT::Type, Mode::Enzyme.API.CDerivativeMode, Width::Int64, ModifiedBetween::NTuple{…} 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/ottqJ/src/compiler.jl:5562
 [18] autodiff
    @ ~/.julia/packages/Enzyme/ottqJ/src/Enzyme.jl:640 [inlined]
 [19] autodiff
    @ ~/.julia/packages/Enzyme/ottqJ/src/Enzyme.jl:544 [inlined]
 [20] autodiff
    @ ~/.julia/packages/Enzyme/ottqJ/src/Enzyme.jl:516 [inlined]
 [21] hvp!
    @ ~/.julia/packages/Enzyme/ottqJ/src/sugar.jl:1105 [inlined]
 [22] hvp(f::typeof(sumdiff), x::Vector{Float64}, v::Vector{Float64})
    @ Enzyme ~/.julia/packages/Enzyme/ottqJ/src/sugar.jl:1072
 [23] top-level scope
    @ ~/Work/GitHub/Julia/DifferentiationInterface.jl/DifferentiationInterface/test/playground.jl:6
Some type information was truncated. Use `show(err)` to see complete types.

And here's the complete log:

log.txt

@wsmoses
Copy link
Member

wsmoses commented Dec 5, 2024

hm same "does this err on the latest version of enzyme" question. On main it runs for me

julia> import Enzyme

julia> mydiff(x) = x[2:end] .- x[1:end-1];

julia> sumdiff(x) = sum(mydiff(x));

julia> Enzyme.hvp(sumdiff, float.(1:5), float.(1:5))
5-element Vector{Float64}:
 0.0
 0.0
 0.0
 0.0
 0.0

@gdalle
Copy link
Contributor Author

gdalle commented Dec 5, 2024

If I'm not mistaken, Enzyme v0.13.19 is the latest version, and currently coincides with main?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants