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

Throw a runtime error if tape size mismatch is detected #508

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

vchuravy
Copy link
Member

@vchuravy vchuravy commented Oct 11, 2022

On #500 we now get a reasonable error. @wsmoses it looks we can't emit branches in the allocator? That would be required to not make this hurt performance.

ERROR: LoadError: Enzyme: Allocation failed, size mismatch between Julia 8 and Enzyme 98304 for Enzyme.Compiler.EnzymeTape{1024, NamedTuple{(Symbol("1"), Symbol("2"), Symbol("3")), Tuple{NamedTuple{(Symbol("1"), Symbol("2"), Symbol("3"), Symbol("4"), Symbol("5")), Tuple{NamedTuple{(Symbol("1"), Symbol("2"), Symbol("3"), Symbol("4"), Symbol("5"), Symbol("6"), Symbol("7")), Tuple{Core.LLVMPtr{Float32, 0}, Core.LLVMPtr{Float32, 0}, UInt64, UInt8, UInt32, Core.LLVMPtr{Float32, 0}, Core.LLVMPtr{Float32, 0}}}, Any, Any, UInt64, Bool}}, Any, Any}}}
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] check_allocation(tag::Type, size::Int64)
   @ Enzyme.Compiler ~/src/Enzyme/src/compiler.jl:3595
 [3] macro expansion
   @ ~/src/Enzyme/src/compiler.jl:6168 [inlined]
 [4] enzyme_call
   @ ~/src/Enzyme/src/compiler.jl:5899 [inlined]
 [5] CombinedAdjointThunk
   @ ~/src/Enzyme/src/compiler.jl:5876 [inlined]
 [6] autodiff
   @ ~/src/Enzyme/src/Enzyme.jl:205 [inlined]
 [7] autodiff
   @ ~/src/Enzyme/src/Enzyme.jl:236 [inlined]
 [8] main()
   @ Main ~/src/Enzyme/issue500.jl:23
 [9] top-level scope
   @ ~/src/Enzyme/issue500.jl:28

addr = @cfunction(check_allocation, Cvoid, (Any, Int))
addr = LLVM.ConstantInt(reinterpret(Int, addr); ctx)
alloc_check_fn = LLVM.const_inttoptr(addr, LLVM.PointerType(LLVM.FunctionType(LLVM.VoidType(ctx), [T_prjlvalue, T_size_t])))
call!(B, alloc_check_fn, [tag, Size])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call needs to (in appropriate order) added to the returned list of added instructions

@vchuravy
Copy link
Member Author

julia> sizeof(A{N, NT})
65568

julia> N = 684
684

julia> sizeof(A{N, NT})
8

So when we go over ~2^16 bytes we hit an internal threshold and we no longer allocate the NTuple as a chunk.

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

Successfully merging this pull request may close these issues.

2 participants