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

Mutating operations in ODE-like problem encounters Illegal replace ficticious phi error for Julia 1.11 but not Julia 1.10.1 #2205

Open
xkykai opened this issue Dec 17, 2024 · 0 comments

Comments

@xkykai
Copy link

xkykai commented Dec 17, 2024

Hello, I have encountered an issue when trying to perform AD on an ODE-like problem. Below is my MWE:

using Enzyme

ps = rand(32)

function solve_equation(ps, u0)
    Δt = 1e-1
    sol = zeros(32, 3)
    sol[:, 1] .= u0
    u = u0
    for i in 2:3
        sol[:, i] .= u .+ Δt .* ps
        u .= sol[:, i]
    end

    return sol
end

truth = rand(32, 3)
u0 = truth[:, 1]

solve_equation(ps, u0)

function loss(ps, truth, u0)
    return sum(abs2, solve_equation(ps, u0) .- truth)
end

loss(ps, truth, u0)

dps = deepcopy(ps) .= 0
autodiff(Enzyme.Reverse, loss, Active, Duplicated(ps, dps), Const(truth), Duplicated(u0, deepcopy(u0)))

This gives an error of

ERROR: Enzyme compilation failed due to an internal error.
 Please open an issue with the code to reproduce and full error log on github.com/EnzymeAD/Enzyme.jl
 To toggle more information for debugging (needed for bug reports), set Enzyme.Compiler.VERBOSE_ERRORS[] = true (default false)

Illegal replace ficticious phi for:   %_replacementA732 = phi i8* , !dbg !347 of   %335 = load i8*, i8* addrspace(11)* %334, align 8, !dbg !314, !tbaa !33, !alias.scope !186, !noalias !187, !nonnull !0, !enzyme_type !61, !enzymejl_byref_BITS_VALUE !0, !enzymejl_source_type_Ptr\7BFloat64\7D !0

Stacktrace:
  [1] memoryref
    @ .\boot.jl:522
  [2] copy
    @ .\array.jl:351
  [3] unaliascopy
    @ .\abstractarray.jl:1516
  [4] unalias
    @ .\abstractarray.jl:1500
  [5] broadcast_unalias
    @ .\broadcast.jl:941
  [6] preprocess
    @ .\broadcast.jl:948
  [7] preprocess_args
    @ .\broadcast.jl:950
  [8] preprocess
    @ .\broadcast.jl:947
  [9] copyto!
    @ .\broadcast.jl:964
 [10] copyto!
    @ .\broadcast.jl:920
 [11] materialize!
    @ .\broadcast.jl:878
 [12] materialize!
    @ .\broadcast.jl:875
 [13] solve_equation
    @ .\REPL[5]:7

Stacktrace:
  [1] julia_error(msg::String, val::Ptr{…}, errtype::Enzyme.API.ErrorType, data::Ptr{…}, data2::Ptr{…}, B::Ptr{…})
    @ Enzyme.Compiler C:\Users\xinle\.julia\packages\Enzyme\ydGh2\src\errors.jl:384
  [2] julia_error(cstr::Cstring, val::Ptr{…}, errtype::Enzyme.API.ErrorType, data::Ptr{…}, data2::Ptr{…}, B::Ptr{…})
    @ Enzyme.Compiler C:\Users\xinle\.julia\packages\Enzyme\ydGh2\src\errors.jl:210
  [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 C:\Users\xinle\.julia\packages\Enzyme\ydGh2\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 C:\Users\xinle\.julia\packages\Enzyme\ydGh2\src\compiler.jl:1592
  [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::Nothing)
    @ Enzyme.Compiler C:\Users\xinle\.julia\packages\Enzyme\ydGh2\src\compiler.jl:4436
  [6] codegen
    @ C:\Users\xinle\.julia\packages\Enzyme\ydGh2\src\compiler.jl:3239 [inlined]
  [7] _thunk(job::GPUCompiler.CompilerJob{Enzyme.Compiler.EnzymeTarget, Enzyme.Compiler.EnzymeCompilerParams}, postopt::Bool)
    @ Enzyme.Compiler C:\Users\xinle\.julia\packages\Enzyme\ydGh2\src\compiler.jl:5288
  [8] _thunk
    @ C:\Users\xinle\.julia\packages\Enzyme\ydGh2\src\compiler.jl:5288 [inlined]
  [9] cached_compilation
    @ C:\Users\xinle\.julia\packages\Enzyme\ydGh2\src\compiler.jl:5340 [inlined]
 [10] 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, edges::Vector{…})
    @ Enzyme.Compiler C:\Users\xinle\.julia\packages\Enzyme\ydGh2\src\compiler.jl:5451
 [11] 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 C:\Users\xinle\.julia\packages\Enzyme\ydGh2\src\compiler.jl:5636
 [12] autodiff
    @ C:\Users\xinle\.julia\packages\Enzyme\ydGh2\src\Enzyme.jl:485 [inlined]
 [13] autodiff(::ReverseMode{…}, ::typeof(loss), ::Type{…}, ::Duplicated{…}, ::Const{…}, ::Duplicated{…})
    @ Enzyme C:\Users\xinle\.julia\packages\Enzyme\ydGh2\src\Enzyme.jl:524
 [14] top-level scope
    @ REPL[12]:1
Some type information was truncated. Use `show(err)` to see complete types.

This result was run with Enzyme v0.13.24 using Julia 1.10.2. The same error occurs on Enzyme v0.13.23 on Julia 1.11.1 as well. However, when the same code is tested on Enzyme v0.13.23 on Julia 1.10.1, the code runs successfully.

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

1 participant