Enzyme main
Loading...
Searching...
No Matches
CApi.h File Reference
#include "llvm-c/Core.h"
#include "llvm-c/DataTypes.h"
#include "llvm-c/Target.h"
#include <stddef.h>
Include dependency graph for CApi.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  IntList
 
struct  CDataPair
 
struct  CFnTypeInfo
 

Typedefs

typedef struct EnzymeOpaqueTypeAnalysis * EnzymeTypeAnalysisRef
 
typedef struct EnzymeOpaqueLogic * EnzymeLogicRef
 
typedef struct EnzymeOpaqueAugmentedReturn * EnzymeAugmentedReturnPtr
 
typedef struct EnzymeOpaqueTraceInterface * EnzymeTraceInterfaceRef
 
typedef struct EnzymeTypeTree * CTypeTreeRef
 
typedef uint8_t(* CustomRuleType) (int, CTypeTreeRef, CTypeTreeRef *, struct IntList *, size_t, LLVMValueRef, void *)
 
typedef LLVMValueRef(* CustomShadowAlloc) (LLVMBuilderRef, LLVMValueRef, size_t, LLVMValueRef *, GradientUtils *)
 
typedef LLVMValueRef(* CustomShadowFree) (LLVMBuilderRef, LLVMValueRef)
 
typedef uint8_t(* CustomFunctionForward) (LLVMBuilderRef, LLVMValueRef, GradientUtils *, LLVMValueRef *, LLVMValueRef *)
 
typedef uint8_t(* CustomFunctionDiffUse) (LLVMValueRef, const GradientUtils *, LLVMValueRef, uint8_t, CDerivativeMode, uint8_t *)
 
typedef uint8_t(* CustomAugmentedFunctionForward) (LLVMBuilderRef, LLVMValueRef, GradientUtils *, LLVMValueRef *, LLVMValueRef *, LLVMValueRef *)
 
typedef void(* CustomFunctionReverse) (LLVMBuilderRef, LLVMValueRef, DiffeGradientUtils *, LLVMValueRef)
 

Enumerations

enum  CConcreteType {
  DT_Anything = 0 , DT_Integer = 1 , DT_Pointer = 2 , DT_Half = 3 ,
  DT_Float = 4 , DT_Double = 5 , DT_Unknown = 6 , DT_X86_FP80 = 7 ,
  DT_BFloat16 = 8 , DT_FP128 = 9
}
 
enum  CValueType { VT_None = 0 , VT_Primal = 1 , VT_Shadow = 2 , VT_Both = VT_Primal | VT_Shadow }
 
enum  CDIFFE_TYPE { DFT_OUT_DIFF = 0 , DFT_DUP_ARG = 1 , DFT_CONSTANT = 2 , DFT_DUP_NONEED = 3 }
 
enum  CBATCH_TYPE { BT_SCALAR = 0 , BT_VECTOR = 1 }
 
enum  CDerivativeMode {
  DEM_ForwardMode = 0 , DEM_ReverseModePrimal = 1 , DEM_ReverseModeGradient = 2 , DEM_ReverseModeCombined = 3 ,
  DEM_ForwardModeSplit = 4 , DEM_ForwardModeError = 5
}
 
enum  CProbProgMode { DEM_Trace = 0 , DEM_Condition = 1 }
 

Functions

CTypeTreeRef EnzymeNewTypeTree ()
 
CTypeTreeRef EnzymeNewTypeTreeCT (CConcreteType, LLVMContextRef ctx)
 
CTypeTreeRef EnzymeNewTypeTreeTR (CTypeTreeRef)
 
void EnzymeFreeTypeTree (CTypeTreeRef CTT)
 
uint8_t EnzymeSetTypeTree (CTypeTreeRef dst, CTypeTreeRef src)
 
uint8_t EnzymeMergeTypeTree (CTypeTreeRef dst, CTypeTreeRef src)
 
void EnzymeTypeTreeOnlyEq (CTypeTreeRef dst, int64_t x)
 
void EnzymeTypeTreeData0Eq (CTypeTreeRef dst)
 
void EnzymeTypeTreeShiftIndiciesEq (CTypeTreeRef dst, const char *datalayout, int64_t offset, int64_t maxSize, uint64_t addOffset)
 
void EnzymeTypeTreeInsertEq (CTypeTreeRef dst, const int64_t *indices, size_t len, CConcreteType ct, LLVMContextRef ctx)
 
const char * EnzymeTypeTreeToString (CTypeTreeRef src)
 
void EnzymeTypeTreeToStringFree (const char *cstr)
 
void EnzymeSetCLBool (void *, uint8_t)
 
void EnzymeSetCLInteger (void *, int64_t)
 
void EnzymeSetCLString (void *, const char *)
 
EnzymeTypeAnalysisRef CreateTypeAnalysis (EnzymeLogicRef Log, char **customRuleNames, CustomRuleType *customRules, size_t numRules)
 
void ClearTypeAnalysis (EnzymeTypeAnalysisRef)
 
void FreeTypeAnalysis (EnzymeTypeAnalysisRef)
 
EnzymeLogicRef EnzymeTypeAnalysisGetLogic (EnzymeTypeAnalysisRef TAR)
 
EnzymeTypeAnalysisRef EnzymeGetTypeAnalysisFromTypeAnalyzer (void *TAR)
 
EnzymeTraceInterfaceRef FindEnzymeStaticTraceInterface (LLVMModuleRef M)
 
EnzymeTraceInterfaceRef CreateEnzymeStaticTraceInterface (LLVMContextRef C, LLVMValueRef getTraceFunction, LLVMValueRef getChoiceFunction, LLVMValueRef insertCallFunction, LLVMValueRef insertChoiceFunction, LLVMValueRef insertArgumentFunction, LLVMValueRef insertReturnFunction, LLVMValueRef insertFunctionFunction, LLVMValueRef insertChoiceGradientFunction, LLVMValueRef insertArgumentGradientFunction, LLVMValueRef newTraceFunction, LLVMValueRef freeTraceFunction, LLVMValueRef hasCallFunction, LLVMValueRef hasChoiceFunction)
 
EnzymeTraceInterfaceRef CreateEnzymeDynamicTraceInterface (LLVMValueRef interface, LLVMValueRef F)
 
EnzymeLogicRef CreateEnzymeLogic (uint8_t PostOpt)
 
void ClearEnzymeLogic (EnzymeLogicRef)
 
void FreeEnzymeLogic (EnzymeLogicRef)
 
void EnzymeLogicSetExternalContext (EnzymeLogicRef, void *ExternalContext)
 
void * EnzymeLogicGetExternalContext (EnzymeLogicRef)
 
void EnzymeExtractReturnInfo (EnzymeAugmentedReturnPtr ret, int64_t *data, uint8_t *existed, size_t len)
 
LLVMValueRef EnzymeExtractFunctionFromAugmentation (EnzymeAugmentedReturnPtr ret)
 
LLVMTypeRef EnzymeExtractTapeTypeFromAugmentation (EnzymeAugmentedReturnPtr ret)
 
void EnzymeRegisterAllocationHandler (char *Name, CustomShadowAlloc AHandle, CustomShadowFree FHandle)
 
LLVMValueRef EnzymeCreateForwardDiff (EnzymeLogicRef Logic, LLVMValueRef request_req, LLVMBuilderRef request_ip, LLVMValueRef todiff, CDIFFE_TYPE retType, CDIFFE_TYPE *constant_args, size_t constant_args_size, EnzymeTypeAnalysisRef TA, uint8_t returnValue, CDerivativeMode mode, uint8_t freeMemory, uint8_t runtimeActivity, uint8_t strongZero, unsigned width, LLVMTypeRef additionalArg, CFnTypeInfo typeInfo, uint8_t subsequent_calls_may_write, uint8_t *_overwritten_args, size_t overwritten_args_size, EnzymeAugmentedReturnPtr augmented)
 
LLVMValueRef EnzymeCreatePrimalAndGradient (EnzymeLogicRef Logic, LLVMValueRef request_req, LLVMBuilderRef request_ip, LLVMValueRef todiff, CDIFFE_TYPE retType, CDIFFE_TYPE *constant_args, size_t constant_args_size, EnzymeTypeAnalysisRef TA, uint8_t returnValue, uint8_t dretUsed, CDerivativeMode mode, uint8_t runtimeActivity, uint8_t strongZero, unsigned width, uint8_t freeMemory, LLVMTypeRef additionalArg, uint8_t forceAnonymousTape, CFnTypeInfo typeInfo, uint8_t subsequent_calls_may_write, uint8_t *_overwritten_args, size_t overwritten_args_size, EnzymeAugmentedReturnPtr augmented, uint8_t AtomicAdd)
 
void EnzymeRegisterCallHandler (const char *Name, CustomAugmentedFunctionForward FwdHandle, CustomFunctionReverse RevHandle)
 
LLVMValueRef EnzymeGradientUtilsNewFromOriginal (GradientUtils *gutils, LLVMValueRef val)
 
void * EnzymeGradientUtilsGetExternalContext (GradientUtils *gutils)
 
uint8_t EnzymeGradientUtilsGetAtomicAdd (GradientUtils *gutils)
 

Typedef Documentation

◆ CTypeTreeRef

typedef struct EnzymeTypeTree* CTypeTreeRef

Definition at line 87 of file CApi.h.

◆ CustomAugmentedFunctionForward

typedef uint8_t(* CustomAugmentedFunctionForward) (LLVMBuilderRef, LLVMValueRef, GradientUtils *, LLVMValueRef *, LLVMValueRef *, LLVMValueRef *)

Definition at line 206 of file CApi.h.

◆ CustomFunctionDiffUse

typedef uint8_t(* CustomFunctionDiffUse) (LLVMValueRef, const GradientUtils *, LLVMValueRef, uint8_t, CDerivativeMode, uint8_t *)

Definition at line 202 of file CApi.h.

◆ CustomFunctionForward

typedef uint8_t(* CustomFunctionForward) (LLVMBuilderRef, LLVMValueRef, GradientUtils *, LLVMValueRef *, LLVMValueRef *)

Definition at line 198 of file CApi.h.

◆ CustomFunctionReverse

typedef void(* CustomFunctionReverse) (LLVMBuilderRef, LLVMValueRef, DiffeGradientUtils *, LLVMValueRef)

Definition at line 212 of file CApi.h.

◆ CustomRuleType

typedef uint8_t(* CustomRuleType) (int, CTypeTreeRef, CTypeTreeRef *, struct IntList *, size_t, LLVMValueRef, void *)

Definition at line 147 of file CApi.h.

◆ CustomShadowAlloc

typedef LLVMValueRef(* CustomShadowAlloc) (LLVMBuilderRef, LLVMValueRef, size_t, LLVMValueRef *, GradientUtils *)

Definition at line 190 of file CApi.h.

◆ CustomShadowFree

typedef LLVMValueRef(* CustomShadowFree) (LLVMBuilderRef, LLVMValueRef)

Definition at line 193 of file CApi.h.

◆ EnzymeAugmentedReturnPtr

typedef struct EnzymeOpaqueAugmentedReturn* EnzymeAugmentedReturnPtr

Definition at line 44 of file CApi.h.

◆ EnzymeLogicRef

typedef struct EnzymeOpaqueLogic* EnzymeLogicRef

Definition at line 41 of file CApi.h.

◆ EnzymeTraceInterfaceRef

typedef struct EnzymeOpaqueTraceInterface* EnzymeTraceInterfaceRef

Definition at line 47 of file CApi.h.

◆ EnzymeTypeAnalysisRef

typedef struct EnzymeOpaqueTypeAnalysis* EnzymeTypeAnalysisRef

Definition at line 38 of file CApi.h.

Enumeration Type Documentation

◆ CBATCH_TYPE

Enumerator
BT_SCALAR 
BT_VECTOR 

Definition at line 131 of file CApi.h.

◆ CConcreteType

Enumerator
DT_Anything 
DT_Integer 
DT_Pointer 
DT_Half 
DT_Float 
DT_Double 
DT_Unknown 
DT_X86_FP80 
DT_BFloat16 
DT_FP128 

Definition at line 54 of file CApi.h.

◆ CDerivativeMode

Enumerator
DEM_ForwardMode 
DEM_ReverseModePrimal 
DEM_ReverseModeGradient 
DEM_ReverseModeCombined 
DEM_ForwardModeSplit 
DEM_ForwardModeError 

Definition at line 133 of file CApi.h.

◆ CDIFFE_TYPE

Enumerator
DFT_OUT_DIFF 
DFT_DUP_ARG 
DFT_CONSTANT 
DFT_DUP_NONEED 

Definition at line 120 of file CApi.h.

◆ CProbProgMode

Enumerator
DEM_Trace 
DEM_Condition 

Definition at line 142 of file CApi.h.

◆ CValueType

enum CValueType
Enumerator
VT_None 
VT_Primal 
VT_Shadow 
VT_Both 

Definition at line 79 of file CApi.h.

Function Documentation

◆ ClearEnzymeLogic()

void ClearEnzymeLogic ( EnzymeLogicRef Ref)

Definition at line 260 of file CApi.cpp.

References eunwrap().

◆ ClearTypeAnalysis()

void ClearTypeAnalysis ( EnzymeTypeAnalysisRef TAR)

Definition at line 312 of file CApi.cpp.

References TypeAnalysis::clear(), and eunwrap().

◆ CreateEnzymeDynamicTraceInterface()

EnzymeTraceInterfaceRef CreateEnzymeDynamicTraceInterface ( LLVMValueRef interface,
LLVMValueRef F )

Definition at line 255 of file CApi.cpp.

◆ CreateEnzymeLogic()

EnzymeLogicRef CreateEnzymeLogic ( uint8_t PostOpt)

Definition at line 213 of file CApi.cpp.

◆ CreateEnzymeStaticTraceInterface()

EnzymeTraceInterfaceRef CreateEnzymeStaticTraceInterface ( LLVMContextRef C,
LLVMValueRef getTraceFunction,
LLVMValueRef getChoiceFunction,
LLVMValueRef insertCallFunction,
LLVMValueRef insertChoiceFunction,
LLVMValueRef insertArgumentFunction,
LLVMValueRef insertReturnFunction,
LLVMValueRef insertFunctionFunction,
LLVMValueRef insertChoiceGradientFunction,
LLVMValueRef insertArgumentGradientFunction,
LLVMValueRef newTraceFunction,
LLVMValueRef freeTraceFunction,
LLVMValueRef hasCallFunction,
LLVMValueRef hasChoiceFunction )

Definition at line 229 of file CApi.cpp.

◆ CreateTypeAnalysis()

EnzymeTypeAnalysisRef CreateTypeAnalysis ( EnzymeLogicRef Log,
char ** customRuleNames,
CustomRuleType * customRules,
size_t numRules )

Definition at line 274 of file CApi.cpp.

References TypeAnalysis::CustomRules, IntList::data, eunwrap(), and IntList::size.

◆ EnzymeCreateForwardDiff()

LLVMValueRef EnzymeCreateForwardDiff ( EnzymeLogicRef Logic,
LLVMValueRef request_req,
LLVMBuilderRef request_ip,
LLVMValueRef todiff,
CDIFFE_TYPE retType,
CDIFFE_TYPE * constant_args,
size_t constant_args_size,
EnzymeTypeAnalysisRef TA,
uint8_t returnValue,
CDerivativeMode mode,
uint8_t freeMemory,
uint8_t runtimeActivity,
uint8_t strongZero,
unsigned width,
LLVMTypeRef additionalArg,
CFnTypeInfo typeInfo,
uint8_t subsequent_calls_may_write,
uint8_t * _overwritten_args,
size_t overwritten_args_size,
EnzymeAugmentedReturnPtr augmented )

Definition at line 661 of file CApi.cpp.

References eunwrap().

◆ EnzymeCreatePrimalAndGradient()

LLVMValueRef EnzymeCreatePrimalAndGradient ( EnzymeLogicRef Logic,
LLVMValueRef request_req,
LLVMBuilderRef request_ip,
LLVMValueRef todiff,
CDIFFE_TYPE retType,
CDIFFE_TYPE * constant_args,
size_t constant_args_size,
EnzymeTypeAnalysisRef TA,
uint8_t returnValue,
uint8_t dretUsed,
CDerivativeMode mode,
uint8_t runtimeActivity,
uint8_t strongZero,
unsigned width,
uint8_t freeMemory,
LLVMTypeRef additionalArg,
uint8_t forceAnonymousTape,
CFnTypeInfo typeInfo,
uint8_t subsequent_calls_may_write,
uint8_t * _overwritten_args,
size_t overwritten_args_size,
EnzymeAugmentedReturnPtr augmented,
uint8_t AtomicAdd )

Definition at line 687 of file CApi.cpp.

References eunwrap().

◆ EnzymeExtractFunctionFromAugmentation()

LLVMValueRef EnzymeExtractFunctionFromAugmentation ( EnzymeAugmentedReturnPtr ret)

Definition at line 801 of file CApi.cpp.

◆ EnzymeExtractReturnInfo()

void EnzymeExtractReturnInfo ( EnzymeAugmentedReturnPtr ret,
int64_t * data,
uint8_t * existed,
size_t len )

Definition at line 825 of file CApi.cpp.

References DifferentialReturn, Return, and Tape.

◆ EnzymeExtractTapeTypeFromAugmentation()

LLVMTypeRef EnzymeExtractTapeTypeFromAugmentation ( EnzymeAugmentedReturnPtr ret)

Definition at line 813 of file CApi.cpp.

References Tape.

◆ EnzymeFreeTypeTree()

void EnzymeFreeTypeTree ( CTypeTreeRef CTT)

Definition at line 872 of file CApi.cpp.

◆ EnzymeGetTypeAnalysisFromTypeAnalyzer()

EnzymeTypeAnalysisRef EnzymeGetTypeAnalysisFromTypeAnalyzer ( void * TAR)

Definition at line 333 of file CApi.cpp.

References TypeAnalyzer::interprocedural.

◆ EnzymeGradientUtilsGetAtomicAdd()

uint8_t EnzymeGradientUtilsGetAtomicAdd ( GradientUtils * gutils)

Definition at line 431 of file CApi.cpp.

References GradientUtils::AtomicAdd.

◆ EnzymeGradientUtilsGetExternalContext()

void * EnzymeGradientUtilsGetExternalContext ( GradientUtils * gutils)

Definition at line 423 of file CApi.cpp.

References EnzymeLogic::ExternalContext, and GradientUtils::Logic.

◆ EnzymeGradientUtilsNewFromOriginal()

LLVMValueRef EnzymeGradientUtilsNewFromOriginal ( GradientUtils * gutils,
LLVMValueRef val )

Definition at line 448 of file CApi.cpp.

References GradientUtils::getNewFromOriginal().

◆ EnzymeLogicGetExternalContext()

void * EnzymeLogicGetExternalContext ( EnzymeLogicRef Ref)

Definition at line 221 of file CApi.cpp.

References eunwrap().

◆ EnzymeLogicSetExternalContext()

void EnzymeLogicSetExternalContext ( EnzymeLogicRef Ref,
void * ExternalContext )

Definition at line 217 of file CApi.cpp.

References eunwrap().

◆ EnzymeMergeTypeTree()

uint8_t EnzymeMergeTypeTree ( CTypeTreeRef dst,
CTypeTreeRef src )

Definition at line 876 of file CApi.cpp.

◆ EnzymeNewTypeTree()

CTypeTreeRef EnzymeNewTypeTree ( )

Definition at line 865 of file CApi.cpp.

◆ EnzymeNewTypeTreeCT()

CTypeTreeRef EnzymeNewTypeTreeCT ( CConcreteType CT,
LLVMContextRef ctx )

Definition at line 866 of file CApi.cpp.

References eunwrap().

◆ EnzymeNewTypeTreeTR()

CTypeTreeRef EnzymeNewTypeTreeTR ( CTypeTreeRef CTR)

Definition at line 869 of file CApi.cpp.

◆ EnzymeRegisterAllocationHandler()

void EnzymeRegisterAllocationHandler ( char * Name,
CustomShadowAlloc AHandle,
CustomShadowFree FHandle )

Definition at line 352 of file CApi.cpp.

References Args, shadowErasers, and shadowHandlers.

◆ EnzymeRegisterCallHandler()

void EnzymeRegisterCallHandler ( const char * Name,
CustomAugmentedFunctionForward FwdHandle,
CustomFunctionReverse RevHandle )

Definition at line 370 of file CApi.cpp.

References customCallHandlers.

◆ EnzymeSetCLBool()

void EnzymeSetCLBool ( void * ptr,
uint8_t val )

Definition at line 188 of file CApi.cpp.

◆ EnzymeSetCLInteger()

void EnzymeSetCLInteger ( void * ptr,
int64_t val )

Definition at line 198 of file CApi.cpp.

◆ EnzymeSetCLString()

void EnzymeSetCLString ( void * ptr,
const char * val )

Definition at line 208 of file CApi.cpp.

◆ EnzymeSetTypeTree()

uint8_t EnzymeSetTypeTree ( CTypeTreeRef dst,
CTypeTreeRef src )

Definition at line 873 of file CApi.cpp.

◆ EnzymeTypeAnalysisGetLogic()

EnzymeLogicRef EnzymeTypeAnalysisGetLogic ( EnzymeTypeAnalysisRef TAR)

Definition at line 319 of file CApi.cpp.

References TypeAnalysis::Logic.

◆ EnzymeTypeTreeData0Eq()

void EnzymeTypeTreeData0Eq ( CTypeTreeRef dst)

Definition at line 893 of file CApi.cpp.

◆ EnzymeTypeTreeInsertEq()

void EnzymeTypeTreeInsertEq ( CTypeTreeRef dst,
const int64_t * indices,
size_t len,
CConcreteType ct,
LLVMContextRef ctx )

Definition at line 916 of file CApi.cpp.

References eunwrap().

◆ EnzymeTypeTreeOnlyEq()

void EnzymeTypeTreeOnlyEq ( CTypeTreeRef dst,
int64_t x )

Definition at line 889 of file CApi.cpp.

◆ EnzymeTypeTreeShiftIndiciesEq()

void EnzymeTypeTreeShiftIndiciesEq ( CTypeTreeRef dst,
const char * datalayout,
int64_t offset,
int64_t maxSize,
uint64_t addOffset )

Definition at line 909 of file CApi.cpp.

◆ EnzymeTypeTreeToString()

const char * EnzymeTypeTreeToString ( CTypeTreeRef src)

Definition at line 924 of file CApi.cpp.

◆ EnzymeTypeTreeToStringFree()

void EnzymeTypeTreeToStringFree ( const char * cstr)

Definition at line 933 of file CApi.cpp.

◆ FindEnzymeStaticTraceInterface()

EnzymeTraceInterfaceRef FindEnzymeStaticTraceInterface ( LLVMModuleRef M)

Definition at line 225 of file CApi.cpp.

◆ FreeEnzymeLogic()

void FreeEnzymeLogic ( EnzymeLogicRef Ref)

Definition at line 268 of file CApi.cpp.

◆ FreeTypeAnalysis()

void FreeTypeAnalysis ( EnzymeTypeAnalysisRef TAR)

Definition at line 314 of file CApi.cpp.