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

propp #868

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

propp #868

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Enzyme.jl
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,15 @@ result, ∂v, ∂A
AugT(primal_ptr), AdjT(adjoint_ptr)
end

@inline function batch(f::F, args...) where {F}
tt = Tuple{map(Core.Typeof, args)...}
world = codegen_world_age(Core.Typeof(f), tt)
width = 1
RABI = DefaultABI
thunk = Enzyme.Compiler.batch_thunk(Val(world), F, tt, Val(width), RABI)
thunk(f, args...)
end

# White lie, should be `Core.LLVMPtr{Cvoid, 0}` but that's not supported by ccallable
Base.@ccallable function __enzyme_float(x::Ptr{Cvoid})::Cvoid
return nothing
Expand Down
41 changes: 40 additions & 1 deletion src/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ using LLVM
using CEnum

const EnzymeLogicRef = Ptr{Cvoid}
const EnzymeTraceInterfaceRef = Ptr{Cvoid}
const EnzymeTypeAnalysisRef = Ptr{Cvoid}
const EnzymeAugmentedReturnPtr = Ptr{Cvoid}
const EnzymeTypeAnalyzerRef = Ptr{Cvoid}
Expand Down Expand Up @@ -102,7 +103,13 @@ end
DEM_ForwardMode = 0,
DEM_ReverseModePrimal = 1,
DEM_ReverseModeGradient = 2,
DEM_ReverseModeCombined = 3
DEM_ReverseModeCombined = 3,
DEM_BatchMode = 4,
)

@cenum(CProbProgMode,
DEM_Trace = 0,
DEM_Condition = 1
)

# Create the derivative function itself.
Expand Down Expand Up @@ -134,6 +141,38 @@ function EnzymeCreatePrimalAndGradient(logic, todiff, retType, constant_args, TA
augmented, atomicAdd)
end

# TODO rename abi -> CreateEnzymeStaticTraceInterface
# TODO remove contextref
# function EnzymeCreateStaticTraceInterface(fns::Vararg{T,13}) where {T}
# ccall((:CreateEnzymeStaticTraceInterface), EnzymeTraceInterfaceRef,
# (LLVMContextRef, LLVMValueRef,LLVMValueRef,LLVMValueRef,LLVMValueRef,LLVMValueRef,LLVMValueRef,LLVMValueRef,LLVMValueRef,LLVMValueRef,LLVMValueRef,LLVMValueRef,LLVMValueRef,LLVMValueRef),
# LLVM.context(fns[1]), fns...)
# end

# TODO rename abi
function EnzymeFreeTraceInterface(interface)
ccall((:FreeTraceInterface), Cvoid,
(EnzymeTraceInterfaceRef,), interface)
end

# TODO rename abi -> EnzymeCreateTrace
function EnzymeCreateTrace(logic, totrace, sample_functions, observe_functions, generative_functions, active_random_variables, mode, autodiff, interface)
ccall((:CreateTrace, libEnzyme), LLVMValueRef,
(EnzymeLogicRef, LLVMValueRef,
Ptr{LLVMValueRef}, Csize_t,
Ptr{LLVMValueRef}, Csize_t,
Ptr{LLVMValueRef}, Csize_t,
Ptr{Cstring}, Csize_t,
CProbProgMode,
UInt8, EnzymeTraceInterfaceRef),
logic, totrace,
sample_functions, length(sample_functions),
observe_functions, length(observe_functions),
generative_functions, length(generative_functions),
active_random_variables, length(active_random_variables),
mode, autodiff, interface)
end

function EnzymeCreateForwardDiff(logic, todiff, retType, constant_args, TA,
returnValue, mode, width, additionalArg, typeInfo,
uncacheable_args)
Expand Down
Loading
Loading