tvm
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Classes | Macros | Typedefs | Functions
func_registry.h File Reference

Defines generic string-based function lookup structs. More...

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

Go to the source code of this file.

Classes

struct  TVMFuncRegistry
 A data structure that facilitates function lookup by C-string name. More...
 
struct  TVMMutableFuncRegistry
 A TVMFuncRegistry that supports adding and changing the functions. More...
 

Macros

#define TVM_AVERAGE_FUNCTION_NAME_STRLEN_BYTES   10
 

Typedefs

typedef uint16_t tvm_function_index_t
 
typedef uint16_t tvm_module_index_t
 
typedef struct TVMFuncRegistry TVMFuncRegistry
 A data structure that facilitates function lookup by C-string name. More...
 
typedef struct TVMMutableFuncRegistry TVMMutableFuncRegistry
 A TVMFuncRegistry that supports adding and changing the functions. More...
 

Functions

uint16_t TVMFuncRegistry_GetNumFuncs (const TVMFuncRegistry *reg)
 Get the of the number of functions from registry. More...
 
int TVMFuncRegistry_SetNumFuncs (const TVMFuncRegistry *reg, const uint16_t num_funcs)
 Set the number of functions to registry. More...
 
const char * TVMFuncRegistry_Get0thFunctionName (const TVMFuncRegistry *reg)
 Get the address of 0th function from registry. More...
 
tvm_crt_error_t TVMFuncRegistry_Lookup (const TVMFuncRegistry *reg, const char *name, tvm_function_index_t *function_index)
 Get packed function from registry by name. More...
 
tvm_crt_error_t TVMFuncRegistry_GetByIndex (const TVMFuncRegistry *reg, tvm_function_index_t index, TVMBackendPackedCFunc *out_func)
 Fetch TVMBackendPackedCFunc given a function index. More...
 
tvm_crt_error_t TVMMutableFuncRegistry_Create (TVMMutableFuncRegistry *reg, uint8_t *buffer, size_t buffer_size_bytes)
 Create a new mutable function registry from a block of memory. More...
 
tvm_crt_error_t TVMMutableFuncRegistry_Set (TVMMutableFuncRegistry *reg, const char *name, TVMBackendPackedCFunc func, int override)
 Add or set a function in the registry. More...
 

Detailed Description

Defines generic string-based function lookup structs.

Macro Definition Documentation

◆ TVM_AVERAGE_FUNCTION_NAME_STRLEN_BYTES

#define TVM_AVERAGE_FUNCTION_NAME_STRLEN_BYTES   10

Typedef Documentation

◆ tvm_function_index_t

typedef uint16_t tvm_function_index_t

◆ tvm_module_index_t

typedef uint16_t tvm_module_index_t

◆ TVMFuncRegistry

A data structure that facilitates function lookup by C-string name.

◆ TVMMutableFuncRegistry

A TVMFuncRegistry that supports adding and changing the functions.

Function Documentation

◆ TVMFuncRegistry_Get0thFunctionName()

const char* TVMFuncRegistry_Get0thFunctionName ( const TVMFuncRegistry reg)

Get the address of 0th function from registry.

Parameters
regTVMFunctionRegistry instance that contains the function.
Returns
the address of 0th function from registry

◆ TVMFuncRegistry_GetByIndex()

tvm_crt_error_t TVMFuncRegistry_GetByIndex ( const TVMFuncRegistry reg,
tvm_function_index_t  index,
TVMBackendPackedCFunc out_func 
)

Fetch TVMBackendPackedCFunc given a function index.

Parameters
regTVMFunctionRegistry instance that contains the function.
indexIndex of the function.
out_funcPointer which receives the function pointer at index, if a valid index was given. Unmodified otherwise.
Returns
kTvmErrorNoError when successful. kTvmErrorFunctionIndexInvalid when index was out of range.

◆ TVMFuncRegistry_GetNumFuncs()

uint16_t TVMFuncRegistry_GetNumFuncs ( const TVMFuncRegistry reg)

Get the of the number of functions from registry.

Parameters
regTVMFunctionRegistry instance that contains the function.
Returns
The number of functions from registry.

◆ TVMFuncRegistry_Lookup()

tvm_crt_error_t TVMFuncRegistry_Lookup ( const TVMFuncRegistry reg,
const char *  name,
tvm_function_index_t function_index 
)

Get packed function from registry by name.

Parameters
regTVMFunctionRegistry instance that contains the function. , *
nameThe function name
function_indexPointer to receive the 0-based index of the function in the registry, if it was found. Unmodified otherwise.
Returns
kTvmErrorNoError when successful. kTvmErrorFunctionNameNotFound when no function matched name.

◆ TVMFuncRegistry_SetNumFuncs()

int TVMFuncRegistry_SetNumFuncs ( const TVMFuncRegistry reg,
const uint16_t  num_funcs 
)

Set the number of functions to registry.

Parameters
regTVMFunctionRegistry instance that contains the function.
num_funcsThe number of functions
Returns
0 when successful.

◆ TVMMutableFuncRegistry_Create()

tvm_crt_error_t TVMMutableFuncRegistry_Create ( TVMMutableFuncRegistry reg,
uint8_t *  buffer,
size_t  buffer_size_bytes 
)

Create a new mutable function registry from a block of memory.

Parameters
regTVMMutableFuncRegistry to create.
bufferBacking memory available for this function registry.
buffer_size_bytesNumber of bytes available in buffer.
Returns
kTvmErrorNoError when successful. kTvmErrorBufferTooSmall when buffer_size_bytes is so small that a single function cannot be registered.

◆ TVMMutableFuncRegistry_Set()

tvm_crt_error_t TVMMutableFuncRegistry_Set ( TVMMutableFuncRegistry reg,
const char *  name,
TVMBackendPackedCFunc  func,
int  override 
)

Add or set a function in the registry.

Parameters
regThe mutable function registry to affect.
nameName of the function.
funcThe function pointer.
overridenon-zero if an existing entry should be overridden.
Returns
kTvmErrorNoError when successful. kTvmErrorRegistryFull when reg already contains max_functions entries. kTvmErrorFunctionAlreadyDefined when a function named name is already present in the registry, and override == 0.