tvm
Classes | Typedefs | Functions
c_backend_api.h File Reference

TVM runtime backend API. More...

#include <tvm/runtime/c_runtime_api.h>
Include dependency graph for c_backend_api.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  TVMParallelGroupEnv
 Environment for TVM parallel task. More...
 

Typedefs

typedef int(* TVMBackendPackedCFunc) (TVMValue *args, int *type_codes, int num_args, TVMValue *out_ret_value, int *out_ret_tcode, void *resource_handle)
 Signature for backend functions exported as DLL. More...
 
typedef int(* FTVMParallelLambda) (int task_id, TVMParallelGroupEnv *penv, void *cdata)
 The callback function to execute a parallel lambda. More...
 

Functions

int TVMBackendGetFuncFromEnv (void *mod_node, const char *func_name, TVMFunctionHandle *out)
 Backend function for modules to get function from its environment mod_node (its imports and global function). The user do should not call TVMFuncFree on func. More...
 
int TVMBackendRegisterSystemLibSymbol (const char *name, void *ptr)
 Backend function to register system-wide library symbol. More...
 
void * TVMBackendAllocWorkspace (int device_type, int device_id, uint64_t nbytes, int dtype_code_hint, int dtype_bits_hint)
 Backend function to allocate temporal workspace. More...
 
int TVMBackendFreeWorkspace (int device_type, int device_id, void *ptr)
 Backend function to free temporal workspace. More...
 
int TVMBackendRegisterEnvCAPI (const char *name, void *ptr)
 Backend function to register execution environment(e.g. python) specific C APIs. More...
 
int TVMBackendParallelLaunch (FTVMParallelLambda flambda, void *cdata, int num_task)
 Backend function for running parallel jobs. More...
 
int TVMBackendParallelBarrier (int task_id, TVMParallelGroupEnv *penv)
 BSP barrrier between parallel threads. More...
 
int TVMBackendRunOnce (void **handle, int(*f)(void *), void *cdata, int nbytes)
 Simple static initialization function. Run f once and set handle to be not null. This function is mainly used for test purpose. More...
 

Detailed Description

TVM runtime backend API.

The functions defined in this header are intended to be used by compiled tvm operators, usually user do not need to use these function directly.

Typedef Documentation

◆ FTVMParallelLambda

typedef int(* FTVMParallelLambda) (int task_id, TVMParallelGroupEnv *penv, void *cdata)

The callback function to execute a parallel lambda.

Parameters
task_idthe task id of the function.
penvThe parallel environment backs the execution.
cdataThe supporting closure data.

◆ TVMBackendPackedCFunc

typedef int(* TVMBackendPackedCFunc) (TVMValue *args, int *type_codes, int num_args, TVMValue *out_ret_value, int *out_ret_tcode, void *resource_handle)

Signature for backend functions exported as DLL.

Parameters
argsThe arguments
type_codesThe type codes of the arguments
num_argsNumber of arguments.
out_ret_valueThe output value of the return value.
out_ret_tcodeThe output type code of the return value.
resource_handlePointer to associated resource.
Returns
0 if success, -1 if failure happens, set error via TVMAPISetLastError.

Function Documentation

◆ TVMBackendAllocWorkspace()

void* TVMBackendAllocWorkspace ( int  device_type,
int  device_id,
uint64_t  nbytes,
int  dtype_code_hint,
int  dtype_bits_hint 
)

Backend function to allocate temporal workspace.

Note
The result allocated space is ensured to be aligned to kTempAllocaAlignment.
Parameters
nbytesThe size of the space requested.
device_typeThe device type which the space will be allocated.
device_idThe device id which the space will be allocated.
dtype_code_hintThe type code of the array elements. Only used in certain backends such as OpenGL.
dtype_bits_hintThe type bits of the array elements. Only used in certain backends such as OpenGL.
Returns
nullptr when error is thrown, a valid ptr if success

◆ TVMBackendFreeWorkspace()

int TVMBackendFreeWorkspace ( int  device_type,
int  device_id,
void *  ptr 
)

Backend function to free temporal workspace.

Parameters
ptrThe result allocated space pointer.
device_typeThe device type which the space will be allocated.
device_idThe device id which the space will be allocated.
Returns
0 when no error is thrown, -1 when failure happens
See also
TVMBackendAllocWorkspace

◆ TVMBackendGetFuncFromEnv()

int TVMBackendGetFuncFromEnv ( void *  mod_node,
const char *  func_name,
TVMFunctionHandle out 
)

Backend function for modules to get function from its environment mod_node (its imports and global function). The user do should not call TVMFuncFree on func.

Parameters
mod_nodeThe module handle.
func_nameThe name of the function.
outThe result function.
Returns
0 when no error is thrown, -1 when failure happens

◆ TVMBackendParallelBarrier()

int TVMBackendParallelBarrier ( int  task_id,
TVMParallelGroupEnv penv 
)

BSP barrrier between parallel threads.

Parameters
task_idthe task id of the function.
penvThe parallel environment backs the execution.
Returns
0 when no error is thrown, -1 when failure happens

◆ TVMBackendParallelLaunch()

int TVMBackendParallelLaunch ( FTVMParallelLambda  flambda,
void *  cdata,
int  num_task 
)

Backend function for running parallel jobs.

Parameters
flambdaThe parallel function to be launched.
cdataThe closure data.
num_taskNumber of tasks to launch, can be 0, means launch with all available threads.
Returns
0 when no error is thrown, -1 when failure happens
Examples
/workspace/include/tvm/runtime/threading_backend.h.

◆ TVMBackendRegisterEnvCAPI()

int TVMBackendRegisterEnvCAPI ( const char *  name,
void *  ptr 
)

Backend function to register execution environment(e.g. python) specific C APIs.

Note
We only register the C API function when absolutely necessary (e.g. when signal handler cannot trap back into python). In most cases we should use the PackedFunc FFI.
Parameters
nameThe name of the symbol
ptrThe symbol address.
Returns
0 when no error is thrown, -1 when failure happens

◆ TVMBackendRegisterSystemLibSymbol()

int TVMBackendRegisterSystemLibSymbol ( const char *  name,
void *  ptr 
)

Backend function to register system-wide library symbol.

Parameters
nameThe name of the symbol
ptrThe symbol address.
Returns
0 when no error is thrown, -1 when failure happens

◆ TVMBackendRunOnce()

int TVMBackendRunOnce ( void **  handle,
int(*)(void *)  f,
void *  cdata,
int  nbytes 
)

Simple static initialization function. Run f once and set handle to be not null. This function is mainly used for test purpose.

Parameters
handleA global address to indicate f
fThe function to be run
cdataThe closure data to pass to the function.
nbytesNumber of bytes in the closure data.
Returns
0 when no error is thrown, -1 when failure happens