|
tvm
|
#include <dlpack/dlpack.h>#include <stddef.h>#include <stdint.h>Go to the source code of this file.
Classes | |
| union | TVMValue |
| Union type of values being passed through API and function calls. More... | |
| struct | TVMByteArray |
| Byte array type used to pass in byte array When kTVMBytes is used as data type. More... | |
Macros | |
| #define | TVM_WEAK __attribute__((weak)) |
| #define | TVM_VERSION "0.11.dev0" |
Typedefs | |
| typedef int64_t | tvm_index_t |
| type of array index. More... | |
| typedef DLTensor * | TVMArrayHandle |
| the array handle More... | |
| typedef void * | TVMModuleHandle |
| Handle to TVM runtime modules. More... | |
| typedef void * | TVMFunctionHandle |
| Handle to packed function handle. More... | |
| typedef void * | TVMRetValueHandle |
| Handle to hold return value. More... | |
| typedef void * | TVMStreamHandle |
| The stream that is specific to device can be NULL, which indicates the default one. More... | |
| typedef void * | TVMObjectHandle |
| Handle to Object. More... | |
| typedef int(* | TVMPackedCFunc) (TVMValue *args, int *type_codes, int num_args, TVMRetValueHandle ret, void *resource_handle) |
| C type of packed function. More... | |
| typedef void(* | TVMPackedCFuncFinalizer) (void *resource_handle) |
| C callback to free the resource handle in C packed function. More... | |
| typedef int(* | TVMExtensionFuncDeclarer) (TVMFunctionHandle register_func_handle) |
| Signature for extension function declarer. More... | |
Enumerations | |
| enum | TVMDeviceExtType { kDLAOCL = 32, kDLSDAccel, kOpenGL, kDLMicroDev, TVMDeviceExtType_End } |
| Extension device types in TVM. More... | |
| enum | TVMArgTypeCode { kTVMArgInt = kDLInt, kTVMArgFloat = kDLFloat, kTVMOpaqueHandle = 3U, kTVMNullptr = 4U, kTVMDataType = 5U, kDLDevice = 6U, kTVMDLTensorHandle = 7U, kTVMObjectHandle = 8U, kTVMModuleHandle = 9U, kTVMPackedFuncHandle = 10U, kTVMStr = 11U, kTVMBytes = 12U, kTVMNDArrayHandle = 13U, kTVMObjectRValueRefArg = 14U, kTVMExtBegin = 15U, kTVMNNVMFirst = 16U, kTVMNNVMLast = 20U, kTVMExtReserveEnd = 64U, kTVMExtEnd = 128U } |
| The type code in used and only used in TVM FFI for argument passing. More... | |
Functions | |
| void | TVMAPISetLastError (const char *msg) |
| Used for implementing C API function. Set last error message before return. More... | |
| const char * | TVMGetLastError (void) |
| return str message of the last error all function in this file will return 0 when success and nonzero when an error occurred, TVMGetLastError can be called to retrieve the error More... | |
| int | TVMModLoadFromFile (const char *file_name, const char *format, TVMModuleHandle *out) |
| Load module from file. More... | |
| int | TVMModImport (TVMModuleHandle mod, TVMModuleHandle dep) |
| Add dep to mod's dependency. This allows functions in this module to use modules. More... | |
| int | TVMModGetFunction (TVMModuleHandle mod, const char *func_name, int query_imports, TVMFunctionHandle *out) |
| Get function from the module. More... | |
| int | TVMModFree (TVMModuleHandle mod) |
| Free the Module. More... | |
| int | TVMFuncFree (TVMFunctionHandle func) |
| Free the function when it is no longer needed. More... | |
| 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. More... | |
| int | TVMCFuncSetReturn (TVMRetValueHandle ret, TVMValue *value, int *type_code, int num_ret) |
| Set the return value of TVMPackedCFunc. More... | |
| int | TVMCbArgToReturn (TVMValue *value, int *code) |
| Inplace translate callback argument value to return value. This is only needed for non-POD arguments. More... | |
| int | TVMFuncCreateFromCFunc (TVMPackedCFunc func, void *resource_handle, TVMPackedCFuncFinalizer fin, TVMFunctionHandle *out) |
| Wrap a TVMPackedCFunc to become a FunctionHandle. More... | |
| int | TVMFuncRegisterGlobal (const char *name, TVMFunctionHandle f, int override) |
| Register the function to runtime's global table. More... | |
| int | TVMFuncGetGlobal (const char *name, TVMFunctionHandle *out) |
| Get a global function. More... | |
| int | TVMFuncListGlobalNames (int *out_size, const char ***out_array) |
| List all the globally registered function name. More... | |
| int | TVMFuncRemoveGlobal (const char *name) |
| Remove a global function. More... | |
| 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. More... | |
| int | TVMArrayFree (TVMArrayHandle handle) |
| Free the TVM Array. More... | |
| int | TVMArrayCopyFromBytes (TVMArrayHandle handle, void *data, size_t nbytes) |
| Copy array data from CPU byte array. More... | |
| int | TVMArrayCopyToBytes (TVMArrayHandle handle, void *data, size_t nbytes) |
| Copy array data to CPU byte array. More... | |
| int | TVMArrayCopyFromTo (TVMArrayHandle from, TVMArrayHandle to, TVMStreamHandle stream) |
| Copy the array, both from and to must be valid during the copy. More... | |
| int | TVMArrayFromDLPack (DLManagedTensor *from, TVMArrayHandle *out) |
| Produce an array from the DLManagedTensor that shares data memory with the DLManagedTensor. More... | |
| int | TVMArrayToDLPack (TVMArrayHandle from, DLManagedTensor **out) |
| Produce a DLMangedTensor from the array that shares data memory with the array. More... | |
| void | TVMDLManagedTensorCallDeleter (DLManagedTensor *dltensor) |
| Delete (free) a DLManagedTensor's data. More... | |
| int | TVMStreamCreate (int device_type, int device_id, TVMStreamHandle *out) |
| Create a new runtime stream. More... | |
| int | TVMStreamFree (int device_type, int device_id, TVMStreamHandle stream) |
| Free a created stream handle. More... | |
| 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 will use the setted stream handle. The specific type of stream is runtime device dependent. More... | |
| int | TVMSynchronize (int device_type, int device_id, TVMStreamHandle stream) |
| Wait until all computations on stream completes. More... | |
| int | TVMStreamStreamSynchronize (int device_type, int device_id, TVMStreamHandle src, TVMStreamHandle dst) |
| Synchronize two streams of execution. More... | |
| int | TVMObjectGetTypeIndex (TVMObjectHandle obj, unsigned *out_tindex) |
| Get the type_index from an object. More... | |
| int | TVMObjectTypeKey2Index (const char *type_key, unsigned *out_tindex) |
| Convert type key to type index. More... | |
| int | TVMObjectTypeIndex2Key (unsigned tindex, char **out_type_key) |
| Convert type index to type key. More... | |
| int | TVMObjectRetain (TVMObjectHandle obj) |
| Increase the reference count of an object. More... | |
| int | TVMObjectFree (TVMObjectHandle obj) |
| Free the object. More... | |
| int | TVMByteArrayFree (TVMByteArray *arr) |
| Free a TVMByteArray returned from TVMFuncCall, and associated memory. More... | |
| int | TVMDeviceAllocDataSpace (DLDevice dev, size_t nbytes, size_t alignment, DLDataType type_hint, void **out_data) |
| Allocate a data space on device. More... | |
| 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. More... | |
| int | TVMDeviceFreeDataSpace (DLDevice dev, void *ptr) |
| Free a data space on device. More... | |
| int | TVMDeviceCopyDataFromTo (DLTensor *from, DLTensor *to, TVMStreamHandle stream) |
| Copy data from one place to another. More... | |
| int | TVMObjectDerivedFrom (uint32_t child_type_index, uint32_t parent_type_index, int *is_derived) |
| Check that an object is derived from another. More... | |
| #define TVM_VERSION "0.11.dev0" |
| #define TVM_WEAK __attribute__((weak)) |
| typedef int64_t tvm_index_t |
type of array index.
| typedef DLTensor* TVMArrayHandle |
the array handle
| typedef int(* TVMExtensionFuncDeclarer) (TVMFunctionHandle register_func_handle) |
Signature for extension function declarer.
TVM call this function to get the extension functions The declarer will call register_func to register function and their name.
| register_func_handle | The register function |
| typedef void* TVMFunctionHandle |
Handle to packed function handle.
| typedef void* TVMModuleHandle |
Handle to TVM runtime modules.
| typedef void* TVMObjectHandle |
Handle to Object.
| typedef int(* TVMPackedCFunc) (TVMValue *args, int *type_codes, int num_args, TVMRetValueHandle ret, void *resource_handle) |
C type of packed function.
| args | The arguments |
| type_codes | The type codes of the arguments |
| num_args | Number of arguments. |
| ret | The return value handle. |
| resource_handle | The handle additional resouce handle from front-end. |
| typedef void(* TVMPackedCFuncFinalizer) (void *resource_handle) |
C callback to free the resource handle in C packed function.
| resource_handle | The handle additional resouce handle from front-end. |
| typedef void* TVMRetValueHandle |
Handle to hold return value.
| typedef void* TVMStreamHandle |
The stream that is specific to device can be NULL, which indicates the default one.
| enum TVMArgTypeCode |
The type code in used and only used in TVM FFI for argument passing.
DLPack consistency: 1) kTVMArgInt is compatible with kDLInt 2) kTVMArgFloat is compatible with kDLFloat 3) kDLUInt is not in ArgTypeCode, but has a spared slot
Downstream consistency: The kDLInt, kDLUInt, kDLFloat are kept consistent with the original ArgType code
It is only used in argument passing, and should not be confused with DataType::TypeCode, which is DLPack-compatible.
| enum TVMDeviceExtType |
Extension device types in TVM.
Additional enumerators to supplement those provided by DLPack's DLDeviceType enumeration.
MAINTAINERS NOTE #1: We need to ensure that the two devices are identified by the same integer. Currently this requires manual verification. Discussed here: https://github.com/dmlc/dlpack/issues/111 As of DLPack v0.7, the highest-valued enumerator in DLDeviceType is kDLHexagon = 16.
MAINTAINERS NOTE #2: As of DLPack v0.7, the definition for DLDeviceType specifies an underlying storage type of int32_t. That guarantees a variable of type DLDeviceType is capable of holding any integers provided by either of these enumerations.
However, the int32_t specification only applies when the header file is compiled as C++, and this header file is also meant to work as C code. So the unspecified storage type could be a latent bug when compiled as C.
| Enumerator | |
|---|---|
| kDLAOCL | |
| kDLSDAccel | |
| kOpenGL | |
| kDLMicroDev | |
| TVMDeviceExtType_End | |
| void TVMAPISetLastError | ( | const char * | msg | ) |
Used for implementing C API function. Set last error message before return.
| msg | The error message to be set. |
| 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.
| shape | The shape of the array, the data content will be copied to out |
| ndim | The number of dimension of the array. |
| dtype_code | The type code of the dtype |
| dtype_bits | The number of bits of dtype |
| dtype_lanes | The number of lanes in the dtype. |
| device_type | The device type. |
| device_id | The device id. |
| out | The output handle. |
| int TVMArrayCopyFromBytes | ( | TVMArrayHandle | handle, |
| void * | data, | ||
| size_t | nbytes | ||
| ) |
Copy array data from CPU byte array.
| handle | The array handle. |
| data | the data pointer |
| nbytes | The number of bytes to copy. |
| int TVMArrayCopyFromTo | ( | TVMArrayHandle | from, |
| TVMArrayHandle | to, | ||
| TVMStreamHandle | stream | ||
| ) |
Copy the array, both from and to must be valid during the copy.
| from | The array to be copied from. |
| to | The target space. |
| stream | The stream where the copy happens, can be NULL. |
| int TVMArrayCopyToBytes | ( | TVMArrayHandle | handle, |
| void * | data, | ||
| size_t | nbytes | ||
| ) |
Copy array data to CPU byte array.
| handle | The array handle. |
| data | the data pointer |
| nbytes | The number of bytes to copy. |
| int TVMArrayFree | ( | TVMArrayHandle | handle | ) |
Free the TVM Array.
| handle | The array handle to be freed. |
| int TVMArrayFromDLPack | ( | DLManagedTensor * | from, |
| TVMArrayHandle * | out | ||
| ) |
Produce an array from the DLManagedTensor that shares data memory with the DLManagedTensor.
| from | The source DLManagedTensor. |
| out | The output array handle. |
| int TVMArrayToDLPack | ( | TVMArrayHandle | from, |
| DLManagedTensor ** | out | ||
| ) |
Produce a DLMangedTensor from the array that shares data memory with the array.
| from | The source array. |
| out | The DLManagedTensor handle. |
| int TVMByteArrayFree | ( | TVMByteArray * | arr | ) |
Free a TVMByteArray returned from TVMFuncCall, and associated memory.
| arr | The TVMByteArray instance. |
| int TVMCbArgToReturn | ( | TVMValue * | value, |
| int * | code | ||
| ) |
Inplace translate callback argument value to return value. This is only needed for non-POD arguments.
| value | The value to be translated. |
| code | The type code to be translated. |
| int TVMCFuncSetReturn | ( | TVMRetValueHandle | ret, |
| TVMValue * | value, | ||
| int * | type_code, | ||
| int | num_ret | ||
| ) |
Set the return value of TVMPackedCFunc.
This function is called by TVMPackedCFunc to set the return value. When this function is not called, the function returns null by default.
| ret | The return value handle, pass by ret in TVMPackedCFunc |
| value | The value to be returned. |
| type_code | The type of the value to be returned. |
| num_ret | Number of return values, for now only 1 is supported. |
| int TVMDeviceAllocDataSpace | ( | DLDevice | dev, |
| size_t | nbytes, | ||
| size_t | alignment, | ||
| DLDataType | type_hint, | ||
| void ** | out_data | ||
| ) |
Allocate a data space on device.
| dev | The device to perform operation. |
| nbytes | The number of bytes in memory. |
| alignment | The alignment of the memory. |
| type_hint | The type of elements. Only needed by certain backends such as nbytes & alignment are sufficient for most backends. |
| out_data | The allocated device pointer. |
| 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.
| dev | The device to perform operation. |
| ndim | The number of dimension of the tensor. |
| shape | The shape of the tensor. |
| dtype | The type of elements. |
| mem_scope | The memory scope of the tensor, can be nullptr, which indicate the default global DRAM |
| out_data | The allocated device pointer. |
| int TVMDeviceCopyDataFromTo | ( | DLTensor * | from, |
| DLTensor * | to, | ||
| TVMStreamHandle | stream | ||
| ) |
Copy data from one place to another.
| from | The source tensor. |
| to | The target tensor. |
| stream | Optional stream object. |
| int TVMDeviceFreeDataSpace | ( | DLDevice | dev, |
| void * | ptr | ||
| ) |
Free a data space on device.
| dev | The device to perform operation. |
| ptr | The data space. |
| void TVMDLManagedTensorCallDeleter | ( | DLManagedTensor * | dltensor | ) |
Delete (free) a DLManagedTensor's data.
| dltensor | Pointer to the DLManagedTensor. |
| 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.
| func | node handle of the function. |
| arg_values | The arguments |
| type_codes | The type codes of the arguments |
| num_args | Number of arguments. |
| ret_val | The return value. |
| ret_type_code | the type code of return value. |
| int TVMFuncCreateFromCFunc | ( | TVMPackedCFunc | func, |
| void * | resource_handle, | ||
| TVMPackedCFuncFinalizer | fin, | ||
| TVMFunctionHandle * | out | ||
| ) |
Wrap a TVMPackedCFunc to become a FunctionHandle.
The resource_handle will be managed by TVM API, until the function is no longer used.
| func | The packed C function. |
| resource_handle | The resource handle from front-end, can be NULL. |
| fin | The finalizer on resource handle when the FunctionHandle get freed, can be NULL |
| out | the result function handle. |
| int TVMFuncFree | ( | TVMFunctionHandle | func | ) |
Free the function when it is no longer needed.
| func | The function handle |
| int TVMFuncGetGlobal | ( | const char * | name, |
| TVMFunctionHandle * | out | ||
| ) |
Get a global function.
| name | The name of the function. |
| out | the result function pointer, NULL if it does not exist. |
| int TVMFuncListGlobalNames | ( | int * | out_size, |
| const char *** | out_array | ||
| ) |
List all the globally registered function name.
| out_size | The number of functions |
| out_array | The array of function names. |
| int TVMFuncRegisterGlobal | ( | const char * | name, |
| TVMFunctionHandle | f, | ||
| int | override | ||
| ) |
Register the function to runtime's global table.
The registered function then can be pulled by the backend by the name.
| name | The name of the function. |
| f | The function to be registered. |
| override | Whether allow override already registered function. |
| int TVMFuncRemoveGlobal | ( | const char * | name | ) |
Remove a global function.
| name | The name of the function. |
| const char* TVMGetLastError | ( | void | ) |
return str message of the last error all function in this file will return 0 when success and nonzero when an error occurred, TVMGetLastError can be called to retrieve the error
this function is threadsafe and can be called by different thread
| int TVMModFree | ( | TVMModuleHandle | mod | ) |
Free the Module.
| mod | The module to be freed. |
The all functions remains valid until TVMFuncFree is called.
| int TVMModGetFunction | ( | TVMModuleHandle | mod, |
| const char * | func_name, | ||
| int | query_imports, | ||
| TVMFunctionHandle * | out | ||
| ) |
Get function from the module.
| mod | The module handle. |
| func_name | The name of the function. |
| query_imports | Whether to query imported modules |
| out | The result function, can be NULL if it is not available. |
| int TVMModImport | ( | TVMModuleHandle | mod, |
| TVMModuleHandle | dep | ||
| ) |
Add dep to mod's dependency. This allows functions in this module to use modules.
| mod | The module handle. |
| dep | The dependent module to be imported. |
| int TVMModLoadFromFile | ( | const char * | file_name, |
| const char * | format, | ||
| TVMModuleHandle * | out | ||
| ) |
Load module from file.
| file_name | The file name to load the module from. |
| format | The format of the module. |
| out | The result module |
| int TVMObjectDerivedFrom | ( | uint32_t | child_type_index, |
| uint32_t | parent_type_index, | ||
| int * | is_derived | ||
| ) |
Check that an object is derived from another.
| child_type_index | The type index of the derived type. |
| parent_type_index | The type index of the parent type. |
| is_derived | A boolean representing whether this predicate holds. |
| int TVMObjectFree | ( | TVMObjectHandle | obj | ) |
Free the object.
| obj | The object handle. |
| int TVMObjectGetTypeIndex | ( | TVMObjectHandle | obj, |
| unsigned * | out_tindex | ||
| ) |
Get the type_index from an object.
| obj | The object handle. |
| out_tindex | the output type index. |
| int TVMObjectRetain | ( | TVMObjectHandle | obj | ) |
Increase the reference count of an object.
| obj | The object handle. |
| int TVMObjectTypeIndex2Key | ( | unsigned | tindex, |
| char ** | out_type_key | ||
| ) |
Convert type index to type key.
| tindex | The type index. |
| out_type_key | The output type key. |
| int TVMObjectTypeKey2Index | ( | const char * | type_key, |
| unsigned * | out_tindex | ||
| ) |
Convert type key to type index.
| type_key | The key of the type. |
| out_tindex | the corresponding type index. |
| 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 will use the setted stream handle. The specific type of stream is runtime device dependent.
| device_type | The device type. |
| device_id | The device id. |
| handle | The stream handle. |
| int TVMStreamCreate | ( | int | device_type, |
| int | device_id, | ||
| TVMStreamHandle * | out | ||
| ) |
Create a new runtime stream.
| device_type | The device type. |
| device_id | The device id. |
| out | The new stream handle. |
| int TVMStreamFree | ( | int | device_type, |
| int | device_id, | ||
| TVMStreamHandle | stream | ||
| ) |
Free a created stream handle.
| device_type | The device type. |
| device_id | The device id. |
| stream | The stream to be freed. |
| int TVMStreamStreamSynchronize | ( | int | device_type, |
| int | device_id, | ||
| TVMStreamHandle | src, | ||
| TVMStreamHandle | dst | ||
| ) |
Synchronize two streams of execution.
| device_type | The device type. |
| device_id | The device id. |
| src | The source stream to synchronize. |
| dst | The destination stream to synchronize. |
| int TVMSynchronize | ( | int | device_type, |
| int | device_id, | ||
| TVMStreamHandle | stream | ||
| ) |
Wait until all computations on stream completes.
| device_type | The device type. |
| device_id | The device id. |
| stream | The stream to be synchronized. |
1.8.13