tvm
Loading...
Searching...
No Matches
Classes | Typedefs | Functions
c_backend_api.h File Reference

TVM runtime backend API. More...

#include <tvm/runtime/base.h>
Include dependency graph for c_backend_api.h:

Go to the source code of this file.

Classes

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

Typedefs

typedef int(* FTVMParallelLambda) (int task_id, TVMParallelGroupEnv *penv, void *cdata)
 The callback function to execute a parallel lambda.
 

Functions

TVM_RUNTIME_DLL int TVMBackendSetDevice (int device_type, int device_index)
 Select the runtime device for the calling host thread.
 
TVM_RUNTIME_DLL int TVMBackendGetDeviceIndex (int device_type, int *out_device_index)
 Query the selected runtime device index on the calling host thread.
 
TVM_RUNTIME_DLL 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.
 
TVM_RUNTIME_DLL int TVMBackendFreeWorkspace (int device_type, int device_id, void *ptr)
 Backend function to free temporal workspace.
 
TVM_RUNTIME_DLL int TVMBackendParallelLaunch (FTVMParallelLambda flambda, void *cdata, int num_task)
 Backend function for running parallel jobs.
 
TVM_RUNTIME_DLL int TVMBackendParallelBarrier (int task_id, TVMParallelGroupEnv *penv)
 BSP barrrier between parallel threads.
 

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.

Function Documentation

◆ TVMBackendAllocWorkspace()

TVM_RUNTIME_DLL 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()

TVM_RUNTIME_DLL 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

◆ TVMBackendGetDeviceIndex()

TVM_RUNTIME_DLL int TVMBackendGetDeviceIndex ( int  device_type,
int *  out_device_index 
)

Query the selected runtime device index on the calling host thread.

Dispatches to DeviceAPI::GetDeviceIndex without changing device selection. Getter support is optional and independent of setter support: the default implementation reports NotImplementedError, including for backends without device-selection state. RPC devices are not supported.

Parameters
device_typeLocal DLPack device type, not an RPC session-encoded type.
out_device_indexNon-null pointer receiving the runtime device index (DLDevice::device_id), not a device type or target configuration index. Written only on success; its previous value is unchanged on failure.
Returns
0 on success, -1 on invalid arguments, unavailable backend, unsupported query, or backend failure. Failure records the raised TVM FFI error on the calling thread; no C++ exception crosses this C entry point.

◆ TVMBackendParallelBarrier()

TVM_RUNTIME_DLL 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()

TVM_RUNTIME_DLL 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

◆ TVMBackendSetDevice()

TVM_RUNTIME_DLL int TVMBackendSetDevice ( int  device_type,
int  device_index 
)

Select the runtime device for the calling host thread.

Dispatches to DeviceAPI::SetDevice with the given local DLPack device type and runtime device index (DLDevice::device_id). This does not save or restore the previous selection. Backends without device-selection state may treat selection as a no-op. Valid indices and index validation are backend-specific.

Parameters
device_typeLocal DLPack device type, not an RPC session-encoded type.
device_indexNonnegative runtime device index, not a device type or target configuration index.
Returns
0 on success, -1 on invalid arguments, unavailable backend, or backend failure. Failure records the raised TVM FFI error on the calling thread; no C++ exception crosses this C entry point.