41 #ifndef TVM_RUNTIME_C_RUNTIME_API_H_ 42 #define TVM_RUNTIME_C_RUNTIME_API_H_ 46 #define TVM_WEAK __declspec(selectany) 48 #define TVM_WEAK __attribute__((weak)) 52 #include <emscripten/emscripten.h> 53 #define TVM_DLL EMSCRIPTEN_KEEPALIVE 58 #define TVM_ATTRIBUTE_UNUSED __attribute__((unused)) 60 #define TVM_ATTRIBUTE_UNUSED 66 #define TVM_DLL __declspec(dllexport) 68 #define TVM_DLL __declspec(dllimport) 71 #define TVM_DLL __attribute__((visibility("default"))) 76 #define TVM_VERSION "0.12.0" 79 #include <dlpack/dlpack.h> 114 typedef enum : int32_t {
133 #define TVM_HARCODED_INTEGER_CHANGED_MSG \ 134 "Change in compile-time integer. Make sure hardcoded uses of this integer throughout TVM are " \ 136 static_assert(kDLCPU == 1, TVM_HARCODED_INTEGER_CHANGED_MSG);
137 static_assert(kDLCUDA == 2, TVM_HARCODED_INTEGER_CHANGED_MSG);
138 static_assert(kDLCUDAHost == 3, TVM_HARCODED_INTEGER_CHANGED_MSG);
139 static_assert(kDLOpenCL == 4, TVM_HARCODED_INTEGER_CHANGED_MSG);
140 static_assert(kDLVulkan == 7, TVM_HARCODED_INTEGER_CHANGED_MSG);
141 static_assert(kDLMetal == 8, TVM_HARCODED_INTEGER_CHANGED_MSG);
142 static_assert(kDLVPI == 9, TVM_HARCODED_INTEGER_CHANGED_MSG);
143 static_assert(kDLROCM == 10, TVM_HARCODED_INTEGER_CHANGED_MSG);
144 static_assert(kDLROCMHost == 11, TVM_HARCODED_INTEGER_CHANGED_MSG);
145 static_assert(kDLExtDev == 12, TVM_HARCODED_INTEGER_CHANGED_MSG);
146 static_assert(kDLCUDAManaged == 13, TVM_HARCODED_INTEGER_CHANGED_MSG);
147 static_assert(kDLOneAPI == 14, TVM_HARCODED_INTEGER_CHANGED_MSG);
148 static_assert(kDLWebGPU == 15, TVM_HARCODED_INTEGER_CHANGED_MSG);
149 static_assert(kDLHexagon == 16, TVM_HARCODED_INTEGER_CHANGED_MSG);
151 static_assert(
kDLAOCL == 32, TVM_HARCODED_INTEGER_CHANGED_MSG);
152 static_assert(
kDLSDAccel == 33, TVM_HARCODED_INTEGER_CHANGED_MSG);
153 static_assert(
kOpenGL == 34, TVM_HARCODED_INTEGER_CHANGED_MSG);
154 static_assert(
kDLMicroDev == 35, TVM_HARCODED_INTEGER_CHANGED_MSG);
155 #undef TVM_HARCODED_INTEGER_CHANGED_MSG 267 TVM_DLL
int TVMModLoadFromFile(
const char* file_name,
const char* format, TVMModuleHandle* out);
288 TVMFunctionHandle* out);
330 TVM_DLL
int TVMFuncCall(TVMFunctionHandle func,
TVMValue* arg_values,
int* type_codes,
int num_args,
331 TVMValue* ret_val,
int* ret_type_code);
370 void* resource_handle);
454 TVM_DLL
int TVMArrayAlloc(
const tvm_index_t*
shape,
int ndim,
int dtype_code,
int dtype_bits,
489 TVM_DLL
int TVMArrayCopyFromTo(TVMArrayHandle from, TVMArrayHandle to, TVMStreamHandle stream);
568 TVMStreamHandle dst);
632 DLDataType type_hint,
void** out_data);
648 DLDataType dtype,
const char* mem_scope,
683 #endif // TVM_RUNTIME_C_RUNTIME_API_H_ Definition: c_runtime_api.h:194
int64_t v_int64
Definition: c_runtime_api.h:209
int(* TVMPackedCFunc)(TVMValue *args, int *type_codes, int num_args, TVMRetValueHandle ret, void *resource_handle)
C type of packed function.
Definition: c_runtime_api.h:369
void TVMAPISetLastError(const char *msg)
Used for implementing C API function. Set last error message before return.
constexpr const char * device_type
The device type.
Definition: stmt.h:1355
Definition: c_runtime_api.h:125
int TVMFuncFree(TVMFunctionHandle func)
Free the function when it is no longer needed.
int TVMArrayFree(TVMArrayHandle handle)
Free the TVM Array.
Definition: c_runtime_api.h:122
void * TVMModuleHandle
Handle to TVM runtime modules.
Definition: c_runtime_api.h:227
int TVMModImport(TVMModuleHandle mod, TVMModuleHandle dep)
Add dep to mod's dependency. This allows functions in this module to use modules. ...
void * v_handle
Definition: c_runtime_api.h:211
int TVMDeviceAllocDataSpaceWithScope(DLDevice dev, int ndim, const int64_t *shape, DLDataType dtype, const char *mem_scope, void **out_data)
Allocate a data space on device with special memory scope.
Definition: c_runtime_api.h:188
int TVMFuncListGlobalNames(int *out_size, const char ***out_array)
List all the globally registered function name.
Definition: c_runtime_api.h:175
Definition: c_runtime_api.h:183
const char * v_str
Definition: c_runtime_api.h:212
int TVMFuncCreateFromCFunc(TVMPackedCFunc func, void *resource_handle, TVMPackedCFuncFinalizer fin, TVMFunctionHandle *out)
Wrap a TVMPackedCFunc to become a FunctionHandle.
DLTensor * TVMArrayHandle
the array handle
Definition: c_runtime_api.h:202
Definition: c_runtime_api.h:179
int TVMArrayCopyToBytes(TVMArrayHandle handle, void *data, size_t nbytes)
Copy array data to CPU byte array.
int TVMModLoadFromFile(const char *file_name, const char *format, TVMModuleHandle *out)
Load module from file.
Definition: c_runtime_api.h:184
size_t size
Definition: c_runtime_api.h:223
Definition: c_runtime_api.h:121
Union type of values being passed through API and function calls.
Definition: c_runtime_api.h:208
Definition: c_runtime_api.h:182
const char * data
Definition: c_runtime_api.h:222
const char * TVMGetLastError(void)
return str message of the last error all function in this file will return 0 when success and nonzero...
Byte array type used to pass in byte array When kTVMBytes is used as data type.
Definition: c_runtime_api.h:221
void * TVMStreamHandle
The stream that is specific to device can be NULL, which indicates the default one.
Definition: c_runtime_api.h:236
int TVMCFuncSetReturn(TVMRetValueHandle ret, TVMValue *value, int *type_code, int num_ret)
Set the return value of TVMPackedCFunc.
int TVMFuncCall(TVMFunctionHandle func, TVMValue *arg_values, int *type_codes, int num_args, TVMValue *ret_val, int *ret_type_code)
Call a Packed TVM Function.
int TVMStreamStreamSynchronize(int device_type, int device_id, TVMStreamHandle src, TVMStreamHandle dst)
Synchronize two streams of execution.
int TVMCbArgToReturn(TVMValue *value, int *code)
Inplace translate callback argument value to return value. This is only needed for non-POD arguments...
constexpr const char * device_id
The allocation device for global malloc in host.
Definition: stmt.h:1353
int TVMFuncRemoveGlobal(const char *name)
Remove a global function.
int TVMFuncGetGlobal(const char *name, TVMFunctionHandle *out)
Get a global function.
Definition: c_runtime_api.h:198
TVMDeviceExtType
Extension device types in TVM.
Definition: c_runtime_api.h:116
int TVMSynchronize(int device_type, int device_id, TVMStreamHandle stream)
Wait until all computations on stream completes.
int TVMModFree(TVMModuleHandle mod)
Free the Module.
int TVMByteArrayFree(TVMByteArray *arr)
Free a TVMByteArray returned from TVMFuncCall, and associated memory.
void TVMDLManagedTensorCallDeleter(DLManagedTensor *dltensor)
Delete (free) a DLManagedTensor's data.
int TVMModGetFunction(TVMModuleHandle mod, const char *func_name, int query_imports, TVMFunctionHandle *out)
Get function from the module.
int TVMObjectFree(TVMObjectHandle obj)
Free the object.
Definition: c_runtime_api.h:124
Definition: c_runtime_api.h:123
TVMArgTypeCode
The type code in used and only used in TVM FFI for argument passing.
Definition: c_runtime_api.h:174
Definition: c_runtime_api.h:187
int TVMStreamFree(int device_type, int device_id, TVMStreamHandle stream)
Free a created stream handle.
int(* TVMExtensionFuncDeclarer)(TVMFunctionHandle register_func_handle)
Signature for extension function declarer.
Definition: c_runtime_api.h:387
DLDevice v_device
Definition: c_runtime_api.h:214
int TVMDeviceAllocDataSpace(DLDevice dev, size_t nbytes, size_t alignment, DLDataType type_hint, void **out_data)
Allocate a data space on device.
int TVMArrayCopyFromTo(TVMArrayHandle from, TVMArrayHandle to, TVMStreamHandle stream)
Copy the array, both from and to must be valid during the copy.
int TVMArrayToDLPack(TVMArrayHandle from, DLManagedTensor **out)
Produce a DLMangedTensor from the array that shares data memory with the array.
void * TVMRetValueHandle
Handle to hold return value.
Definition: c_runtime_api.h:231
void * TVMFunctionHandle
Handle to packed function handle.
Definition: c_runtime_api.h:229
Tensor shape(const Tensor &src, DataType dtype, const std::string name="T_shape", const std::string tag=kInjective)
Get the shape of input tensor.
Definition: transform.h:1768
int64_t tvm_index_t
type of array index.
Definition: c_runtime_api.h:88
Definition: c_runtime_api.h:177
int TVMObjectRetain(TVMObjectHandle obj)
Increase the reference count of an object.
DLDataType v_type
Definition: c_runtime_api.h:213
int TVMObjectDerivedFrom(uint32_t child_type_index, uint32_t parent_type_index, int *is_derived)
Check that an object is derived from another.
int TVMObjectTypeIndex2Key(unsigned tindex, char **out_type_key)
Convert type index to type key.
int TVMStreamCreate(int device_type, int device_id, TVMStreamHandle *out)
Create a new runtime stream.
Definition: c_runtime_api.h:193
int TVMFuncRegisterGlobal(const char *name, TVMFunctionHandle f, int override)
Register the function to runtime's global table.
Definition: c_runtime_api.h:176
void * TVMObjectHandle
Handle to Object.
Definition: c_runtime_api.h:238
Definition: c_runtime_api.h:178
int TVMObjectTypeKey2Index(const char *type_key, unsigned *out_tindex)
Convert type key to type index.
Definition: c_runtime_api.h:195
int TVMObjectGetTypeIndex(TVMObjectHandle obj, unsigned *out_tindex)
Get the type_index from an object.
int TVMSetStream(int device_type, int device_id, TVMStreamHandle handle)
Set the runtime stream of current thread to be stream. The subsequent calls to the same device_type w...
int TVMArrayAlloc(const tvm_index_t *shape, int ndim, int dtype_code, int dtype_bits, int dtype_lanes, int device_type, int device_id, TVMArrayHandle *out)
Allocate a nd-array's memory, including space of shape, of given spec.
int TVMArrayCopyFromBytes(TVMArrayHandle handle, void *data, size_t nbytes)
Copy array data from CPU byte array.
tvm::PrimExpr mod(const tvm::PrimExpr &a, const tvm::PrimExpr &b)
Definition: broadcast.h:290
int TVMArrayFromDLPack(DLManagedTensor *from, TVMArrayHandle *out)
Produce an array from the DLManagedTensor that shares data memory with the DLManagedTensor.
Definition: c_runtime_api.h:180
const Op & ret()
Return value.
Definition: c_runtime_api.h:186
int TVMDeviceCopyDataFromTo(DLTensor *from, DLTensor *to, TVMStreamHandle stream)
Copy data from one place to another.
int TVMDeviceFreeDataSpace(DLDevice dev, void *ptr)
Free a data space on device.
Definition: c_runtime_api.h:185
Definition: c_runtime_api.h:197
double v_float64
Definition: c_runtime_api.h:210
Definition: c_runtime_api.h:181
void(* TVMPackedCFuncFinalizer)(void *resource_handle)
C callback to free the resource handle in C packed function.
Definition: c_runtime_api.h:376