#pragma once
#if defined(EXECUTORCH_RS_MODULE) && !defined(EXECUTORCH_RS_STD)
#error "EXECUTORCH_RS_MODULE requires EXECUTORCH_RS_STD"
#endif
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C"
{
#endif
enum Error : uint32_t
{
Error_Ok = 0x00,
Error_Internal = 0x01,
Error_InvalidState = 0x2,
Error_EndOfMethod = 0x03,
Error_NotSupported = 0x10,
Error_NotImplemented = 0x11,
Error_InvalidArgument = 0x12,
Error_InvalidType = 0x13,
Error_OperatorMissing = 0x14,
Error_RegistrationExceedingMaxKernels = 0x15,
Error_RegistrationAlreadyRegistered = 0x16,
Error_NotFound = 0x20,
Error_MemoryAllocationFailed = 0x21,
Error_AccessFailed = 0x22,
Error_InvalidProgram = 0x23,
Error_InvalidExternalData = 0x24,
Error_OutOfResources = 0x25,
Error_DelegateInvalidCompatibility = 0x30,
Error_DelegateMemoryAllocationFailed = 0x31,
Error_DelegateInvalidHandle = 0x32,
};
enum ProgramHeaderStatus : uint32_t
{
ProgramHeaderStatus_CompatibleVersion,
ProgramHeaderStatus_IncompatibleVersion,
ProgramHeaderStatus_NotPresent,
ProgramHeaderStatus_ShortData,
};
enum ProgramVerification : uint8_t
{
ProgramVerification_Minimal,
ProgramVerification_InternalConsistency,
};
enum MmapDataLoaderMlockConfig : uint32_t
{
MmapDataLoaderMlockConfig_NoMlock,
MmapDataLoaderMlockConfig_UseMlock,
MmapDataLoaderMlockConfig_UseMlockIgnoreErrors,
};
enum ModuleLoadMode : uint32_t
{
ModuleLoadMode_File,
ModuleLoadMode_Mmap,
ModuleLoadMode_MmapUseMlock,
ModuleLoadMode_MmapUseMlockIgnoreErrors,
};
enum Tag : uint32_t
{
Tag_None,
Tag_Tensor,
Tag_String,
Tag_Double,
Tag_Int,
Tag_Bool,
Tag_ListBool,
Tag_ListDouble,
Tag_ListInt,
Tag_ListTensor,
Tag_ListScalar,
Tag_ListOptionalTensor,
};
enum ScalarType : int8_t
{
ScalarType_Byte,
ScalarType_Char,
ScalarType_Short,
ScalarType_Int,
ScalarType_Long,
ScalarType_Half,
ScalarType_Float,
ScalarType_Double,
ScalarType_ComplexHalf,
ScalarType_ComplexFloat,
ScalarType_ComplexDouble,
ScalarType_Bool,
ScalarType_QInt8,
ScalarType_QUInt8,
ScalarType_QInt32,
ScalarType_BFloat16,
ScalarType_QUInt4x2,
ScalarType_QUInt2x4,
ScalarType_Bits1x8,
ScalarType_Bits2x4,
ScalarType_Bits4x2,
ScalarType_Bits8,
ScalarType_Bits16,
ScalarType_Float8_e5m2,
ScalarType_Float8_e4m3fn,
ScalarType_Float8_e5m2fnuz,
ScalarType_Float8_e4m3fnuz,
ScalarType_UInt16,
ScalarType_UInt32,
ScalarType_UInt64,
};
typedef int32_t SizesType;
typedef uint8_t DimOrderType;
typedef int32_t StridesType;
enum TensorShapeDynamism : uint8_t
{
TensorShapeDynamism_STATIC = 0,
TensorShapeDynamism_DYNAMIC_BOUND = 1,
TensorShapeDynamism_DYNAMIC_UNBOUND = 2,
};
struct TensorStorage
{
size_t _blob[1];
};
struct TensorRef
{
const void *ptr;
};
struct TensorRefMut
{
void *ptr;
};
struct TensorImpl
{
size_t _blob[8];
};
struct EValueStorage
{
union
{
int64_t _blob1;
double _blob2;
bool _blob3;
size_t _blob4;
size_t _blob5;
size_t _blob6;
size_t _blob7;
size_t _blob8;
size_t _blob9;
struct TensorStorage _blob10;
};
uint32_t _blob11;
};
struct EValueRef
{
const void *ptr;
};
struct EValueRefMut
{
void *ptr;
};
struct FreeableBuffer
{
union
{
struct
{
size_t _blob1[2];
};
struct
{
uint64_t _blob2;
size_t _blob3;
};
};
uint8_t _blob4;
size_t _blob5[2];
};
struct Program
{
struct FreeableBuffer _blob1;
size_t _blob2[3];
struct FreeableBuffer _blob3;
struct {
union
{
char _blob4_opt_dummy;
size_t _blob4_opt_val[5];
};
bool _blob4_opt_flag;
};
};
struct TensorInfo
{
size_t _blob1[6];
uint8_t _blob2;
bool _blob3;
size_t _blob4;
};
struct MethodMeta
{
size_t _blob[1];
};
struct Method
{
size_t _blob1[17];
uint8_t _blob2[1];
};
struct TensorLayout
{
size_t _blob1[4];
int8_t _blob2;
size_t _blob3;
};
struct DataLoaderRefMut
{
void *ptr;
};
struct NamedDataMapRef
{
const void *ptr;
};
struct NamedDataMapRefMut
{
void *ptr;
};
#if defined(EXECUTORCH_RS_FLAT_TENSOR)
struct FlatTensorDataMap
{
size_t _blob0[1];
uint64_t _blob1[4];
struct FreeableBuffer _blob2;
size_t _blob3[2];
};
#endif
struct BufferDataLoader
{
size_t _blob[3];
};
#if defined(EXECUTORCH_RS_DATA_LOADER)
struct FileDataLoader
{
size_t _blob[5];
};
struct MmapDataLoader
{
size_t _blob_1[4];
int _blob_2[2];
};
#endif
struct MemoryAllocator
{
size_t _blob_1[4];
uint32_t _blob_2[2];
};
struct HierarchicalAllocator
{
size_t _blob[34];
};
struct MemoryManager
{
size_t _blob[3];
};
struct OptionalTensorStorage
{
union
{
char _dummy;
struct TensorStorage _val;
};
bool _flag;
};
struct OptionalTensorRef
{
const void *ptr;
};
struct OptionalTensorRefMut
{
void *ptr;
};
#if defined(EXECUTORCH_RS_STD)
struct VecChar
{
char *data;
size_t len;
size_t cap;
};
void executorch_VecChar_destructor(struct VecChar *vec);
struct VecVecChar
{
struct VecChar *data;
size_t len;
size_t cap;
};
void executorch_VecVecChar_destructor(struct VecVecChar *vec);
struct VecEValue
{
struct EValueRefMut data;
size_t len;
size_t cap;
};
void executorch_VecEValue_destructor(struct VecEValue *vec);
#endif
struct ArrayRefChar
{
const char *data;
size_t len;
};
struct ArrayRefBool
{
const bool *data;
size_t len;
};
struct ArrayRefU8
{
const uint8_t *data;
size_t len;
};
struct ArrayRefI32
{
const int32_t *data;
size_t len;
};
struct ArrayRefI64
{
const int64_t *data;
size_t len;
};
struct ArrayRefF64
{
const double *data;
size_t len;
};
struct ArrayRefUsizeType
{
const size_t *data;
size_t len;
};
struct ArrayRefSizesType
{
const SizesType *data;
size_t len;
};
struct ArrayRefDimOrderType
{
const DimOrderType *data;
size_t len;
};
struct ArrayRefStridesType
{
const StridesType *data;
size_t len;
};
struct ArrayRefTensor
{
struct TensorRef data;
size_t len;
};
struct ArrayRefOptionalTensor
{
struct OptionalTensorRef data;
size_t len;
};
struct ArrayRefEValue
{
struct EValueRef data;
size_t len;
};
struct ArrayRefEValuePtr
{
const struct EValueRef *data;
size_t len;
};
struct SpanU8
{
uint8_t *data;
size_t len;
};
struct SpanSpanU8
{
struct SpanU8 *data;
size_t len;
};
struct SpanI64
{
int64_t *data;
size_t len;
};
struct SpanTensor
{
struct TensorRefMut data;
size_t len;
};
struct SpanOptionalTensor
{
struct OptionalTensorRefMut data;
size_t len;
};
struct BoxedEvalueListI64
{
struct ArrayRefEValuePtr wrapped_vals;
int64_t *unwrapped_vals;
};
struct BoxedEvalueListTensor
{
struct ArrayRefEValuePtr wrapped_vals;
struct TensorRefMut unwrapped_vals;
};
struct BoxedEvalueListOptionalTensor
{
struct ArrayRefEValuePtr wrapped_vals;
struct OptionalTensorRefMut unwrapped_vals;
};
struct EventTracerRefMut
{
void *ptr;
};
#if defined(EXECUTORCH_RS_ETDUMP)
struct ETDumpGen
{
size_t _blob0[1];
int _blob1[2];
bool _blob2[2];
int _blob3[3];
size_t _blob4[8];
int _blob5[2];
size_t _blob6[6];
size_t _blob7;
};
#endif
struct MemoryAllocator executorch_MemoryAllocator_new(uint32_t size, uint8_t *base_address);
void *executorch_MemoryAllocator_allocate(struct MemoryAllocator *self, size_t size, size_t alignment);
struct HierarchicalAllocator executorch_HierarchicalAllocator_new(struct SpanSpanU8 buffers);
void executorch_HierarchicalAllocator_destructor(struct HierarchicalAllocator *self);
struct MemoryManager executorch_MemoryManager_new(
struct MemoryAllocator *method_allocator,
struct HierarchicalAllocator *planned_memory,
struct MemoryAllocator *temp_allocator);
struct BufferDataLoader executorch_BufferDataLoader_new(const void *data, size_t size);
struct DataLoaderRefMut executorch_BufferDataLoader_as_data_loader_mut(struct BufferDataLoader *self);
#if defined(EXECUTORCH_RS_DATA_LOADER)
enum Error executorch_FileDataLoader_new(const char *file_path, size_t alignment, struct FileDataLoader *out);
void executorch_FileDataLoader_destructor(struct FileDataLoader *self);
struct DataLoaderRefMut executorch_FileDataLoader_as_data_loader_mut(struct FileDataLoader *self);
enum Error executorch_MmapDataLoader_new(const char *file_path, enum MmapDataLoaderMlockConfig mlock_config, struct MmapDataLoader *out);
void executorch_MmapDataLoader_destructor(struct MmapDataLoader *self);
struct DataLoaderRefMut executorch_MmapDataLoader_as_data_loader_mut(struct MmapDataLoader *self);
#endif
bool executorch_is_valid_dim_order_and_strides(size_t dim, const SizesType *sizes, const DimOrderType *dim_order, const StridesType *strides);
enum Error executorch_stride_to_dim_order(const StridesType *strides, size_t dims, DimOrderType *dim_order);
enum Error executorch_NamedDataMap_get_tensor_layout(
struct NamedDataMapRef self,
struct ArrayRefChar key,
struct TensorLayout *out);
enum Error executorch_NamedDataMap_get_num_keys(struct NamedDataMapRef self, uint32_t *out);
enum Error executorch_NamedDataMap_get_key(
struct NamedDataMapRef self,
uint32_t index,
const char **out_data);
#if defined(EXECUTORCH_RS_FLAT_TENSOR)
enum Error executorch_FlatTensorDataMap_load(struct DataLoaderRefMut loader, struct FlatTensorDataMap *out);
struct NamedDataMapRefMut executorch_FlatTensorDataMap_as_named_data_map_mut(struct FlatTensorDataMap *self);
#endif
void executorch_TensorImpl_new(
struct TensorImpl *self,
enum ScalarType type,
size_t dim,
SizesType *sizes,
void *data,
DimOrderType *dim_order,
StridesType *strides,
enum TensorShapeDynamism dynamism);
void executorch_Tensor_new(struct TensorRefMut self, struct TensorImpl *tensor_impl);
size_t executorch_Tensor_nbytes(struct TensorRef self);
size_t executorch_Tensor_size(struct TensorRef self, size_t dim);
size_t executorch_Tensor_dim(struct TensorRef self);
size_t executorch_Tensor_numel(struct TensorRef self);
enum ScalarType executorch_Tensor_scalar_type(struct TensorRef self);
size_t executorch_Tensor_element_size(struct TensorRef self);
struct ArrayRefSizesType executorch_Tensor_sizes(struct TensorRef self);
struct ArrayRefDimOrderType executorch_Tensor_dim_order(struct TensorRef self);
struct ArrayRefStridesType executorch_Tensor_strides(struct TensorRef self);
const void *executorch_Tensor_const_data_ptr(struct TensorRef self);
void *executorch_Tensor_mutable_data_ptr(struct TensorRef self);
int64_t executorch_Tensor_coordinate_to_index(struct TensorRef self, struct ArrayRefUsizeType coordinate);
int64_t executorch_Tensor_coordinate_to_index_unchecked(struct TensorRef self, struct ArrayRefUsizeType coordinate);
void executorch_Tensor_destructor(struct TensorRefMut self);
struct TensorRef executorch_OptionalTensor_get(struct OptionalTensorRef self);
struct ArrayRefI32 executorch_TensorLayout_sizes(const struct TensorLayout *self);
struct ArrayRefU8 executorch_TensorLayout_dim_order(const struct TensorLayout *self);
enum ScalarType executorch_TensorLayout_scalar_type(const struct TensorLayout *self);
size_t executorch_TensorLayout_nbytes(const struct TensorLayout *self);
void executorch_EValue_new_none(struct EValueRefMut self);
void executorch_EValue_new_from_i64(struct EValueRefMut self, int64_t value);
void executorch_EValue_new_from_i64_list(struct EValueRefMut self, const struct BoxedEvalueListI64 *value);
void executorch_EValue_new_from_f64(struct EValueRefMut self, double value);
void executorch_EValue_new_from_f64_list(struct EValueRefMut self, const struct ArrayRefF64 *value);
void executorch_EValue_new_from_bool(struct EValueRefMut self, bool value);
void executorch_EValue_new_from_bool_list(struct EValueRefMut self, const struct ArrayRefBool *value);
void executorch_EValue_new_from_string(struct EValueRefMut self, const struct ArrayRefChar *value);
void executorch_EValue_new_from_tensor(struct EValueRefMut self, struct TensorRef value);
void executorch_EValue_new_from_tensor_list(struct EValueRefMut self, const struct BoxedEvalueListTensor *value);
void executorch_EValue_new_from_optional_tensor_list(struct EValueRefMut self, const struct BoxedEvalueListOptionalTensor *value);
enum Tag executorch_EValue_tag(struct EValueRef self);
int64_t executorch_EValue_as_i64(struct EValueRef self);
struct ArrayRefI64 executorch_EValue_as_i64_list(struct EValueRef self);
double executorch_EValue_as_f64(struct EValueRef self);
struct ArrayRefF64 executorch_EValue_as_f64_list(struct EValueRef self);
bool executorch_EValue_as_bool(struct EValueRef self);
struct ArrayRefBool executorch_EValue_as_bool_list(struct EValueRef self);
struct ArrayRefChar executorch_EValue_as_string(struct EValueRef self);
struct TensorRef executorch_EValue_as_tensor(struct EValueRef self);
struct ArrayRefTensor executorch_EValue_as_tensor_list(struct EValueRef self);
struct ArrayRefOptionalTensor executorch_EValue_as_optional_tensor_list(struct EValueRef self);
void executorch_EValue_copy(struct EValueRef src, struct EValueRefMut dst);
void executorch_EValue_destructor(struct EValueRefMut self);
void executorch_EValue_move(struct EValueRefMut src, struct EValueRefMut dst);
enum ProgramHeaderStatus executorch_Program_check_header(const void *data, size_t size);
enum Error executorch_Program_load(struct DataLoaderRefMut loader, enum ProgramVerification verification, struct Program *out);
enum Error executorch_Program_load_method(
const struct Program *self,
const char *method_name,
struct MemoryManager *memory_manager,
struct EventTracerRefMut event_tracer,
struct NamedDataMapRef named_data_map,
struct Method *out);
enum Error executorch_Program_get_method_name(const struct Program *self, size_t method_index, const char **out);
enum Error executorch_Program_get_named_data_map(const struct Program *self, struct NamedDataMapRef *out);
enum Error executorch_Program_method_meta(const struct Program *self, const char *method_name, struct MethodMeta *method_meta_out);
size_t executorch_Program_num_methods(const struct Program *self);
void executorch_Program_destructor(struct Program *self);
size_t executorch_Method_inputs_size(const struct Method *self);
size_t executorch_Method_outputs_size(const struct Method *self);
enum Error executorch_Method_set_input(struct Method *self, struct EValueRef input_evalue, size_t input_idx);
struct EValueRef executorch_Method_get_output(const struct Method *self, size_t i);
enum Error executorch_Method_get_attribute(struct Method *self, struct ArrayRefChar name, struct TensorRefMut out);
enum Error executorch_Method_execute(struct Method *self);
void executorch_Method_destructor(struct Method *self);
const char *executorch_MethodMeta_name(const struct MethodMeta *self);
size_t executorch_MethodMeta_num_inputs(const struct MethodMeta *self);
size_t executorch_MethodMeta_num_outputs(const struct MethodMeta *self);
size_t executorch_MethodMeta_num_memory_planned_buffers(const struct MethodMeta *self);
enum Error executorch_MethodMeta_input_tag(const struct MethodMeta *self, size_t index, enum Tag *tag_out);
enum Error executorch_MethodMeta_output_tag(const struct MethodMeta *self, size_t index, enum Tag *tag_out);
enum Error executorch_MethodMeta_input_tensor_meta(const struct MethodMeta *self, size_t index, struct TensorInfo *tensor_info_out);
enum Error executorch_MethodMeta_output_tensor_meta(const struct MethodMeta *self, size_t index, struct TensorInfo *tensor_info_out);
size_t executorch_MethodMeta_num_attributes(const struct MethodMeta *self);
enum Error executorch_MethodMeta_attribute_tensor_meta(const struct MethodMeta *self, size_t index, struct TensorInfo *tensor_info_out);
enum Error executorch_MethodMeta_memory_planned_buffer_size(const struct MethodMeta *self, size_t index, int64_t *size_out);
bool executorch_MethodMeta_uses_backend(const struct MethodMeta *self, const char *backend_name);
size_t executorch_MethodMeta_num_backends(const struct MethodMeta *self);
enum Error executorch_MethodMeta_get_backend_name(const struct MethodMeta *self, size_t index, const char **backend_name_out);
struct ArrayRefI32 executorch_TensorInfo_sizes(const struct TensorInfo *self);
struct ArrayRefU8 executorch_TensorInfo_dim_order(const struct TensorInfo *self);
enum ScalarType executorch_TensorInfo_scalar_type(const struct TensorInfo *self);
bool executorch_TensorInfo_is_memory_planned(const struct TensorInfo *self);
size_t executorch_TensorInfo_nbytes(const struct TensorInfo *self);
struct ArrayRefChar executorch_TensorInfo_name(const struct TensorInfo *self);
#if defined(EXECUTORCH_RS_ETDUMP)
struct ETDumpGen executorch_ETDumpGen_new(struct SpanU8 buffer);
struct ArrayRefU8 executorch_ETDumpGen_get_etdump_data(struct ETDumpGen *self);
struct EventTracerRefMut executorch_ETDumpGen_as_event_tracer_mut(struct ETDumpGen *self);
#endif
typedef uint64_t executorch_timestamp_t;
struct executorch_tick_ratio
{
uint64_t numerator;
uint64_t denominator;
};
enum executorch_pal_log_level : uint32_t
{
EXECUTORCH_PAL_LOG_LEVEL_DEBUG = 'D',
EXECUTORCH_PAL_LOG_LEVEL_INFO = 'I',
EXECUTORCH_PAL_LOG_LEVEL_ERROR = 'E',
EXECUTORCH_PAL_LOG_LEVEL_FATAL = 'F',
EXECUTORCH_PAL_LOG_LEVEL_UNKNOWN = '?', };
struct ExecutorchPalImpl
{
void (*init)();
void (*abort)();
executorch_timestamp_t (*current_ticks)();
struct executorch_tick_ratio (*ticks_to_ns_multiplier)();
void (*emit_log_message)(
executorch_timestamp_t timestamp,
enum executorch_pal_log_level level,
const char *filename,
const char *function,
size_t line,
const char *message,
size_t length);
void *(*allocate)(size_t size);
void (*free)(void *ptr);
const char *source_filename;
};
bool executorch_register_pal(struct ExecutorchPalImpl impl);
const struct ExecutorchPalImpl *executorch_get_pal_impl();
void executorch_pal_init();
void executorch_pal_abort();
executorch_timestamp_t executorch_pal_current_ticks();
struct executorch_tick_ratio executorch_pal_ticks_to_ns_multiplier();
void executorch_pal_emit_log_message(
executorch_timestamp_t timestamp,
enum executorch_pal_log_level level,
const char *filename,
const char *function,
size_t line,
const char *message,
size_t length);
void *executorch_pal_allocate(size_t size);
void executorch_pal_free(void *ptr);
#ifdef __cplusplus
} #endif