Bolt
bolt.h File Reference

C API Document. More...

Go to the source code of this file.

Typedefs

typedef void * ModelHandle
 
typedef void * ResultHandle
 

Enumerations

enum  AFFINITY_TYPE { CPU_HIGH_PERFORMANCE = 0, CPU_LOW_POWER = 1, GPU = 2 }
 
enum  DEVICE_TYPE {
  CPU_SERIAL = 0, CPU_ARM_V7 = 1, CPU_ARM_V8 = 2, CPU_ARM_A55 = 3,
  CPU_ARM_A76 = 4, CPU_X86_AVX2 = 5, CPU_X86_AVX512 = 6, GPU_MALI = 10,
  GPU_QUALCOMM = 11
}
 
enum  DATA_TYPE { FP_32 = 0, FP_16 = 1, INT_32 = 2, UINT_32 = 3 }
 
enum  DATA_FORMAT {
  NCHW = 0, NHWC = 1, NCHWC8 = 2, MTK = 3,
  NORMAL = 4, NCHWC4 = 5
}
 

Functions

const char *const * GetDataTypeString ()
 
const char *const * GetDataFormatString ()
 
ModelHandle CreateModel (const char *modelPath, AFFINITY_TYPE affinity, const char *algorithmMapPath)
 create model from file More...
 
int GetNumInputsFromModel (ModelHandle ih)
 get the number of model input from ModelHandle More...
 
void GetInputDataInfoFromModel (ModelHandle ih, int num_inputs, char **name, int *n, int *c, int *h, int *w, DATA_TYPE *dt, DATA_FORMAT *df)
 get input data info set in model handle, which is read from .bolt More...
 
void PrepareModel (ModelHandle ih, const int num_inputs, const char **name, const int *n, const int *c, const int *h, const int *w, const DATA_TYPE *dt, const DATA_FORMAT *df)
 complete model inference engine prepare More...
 
ResultHandle AllocAllResultHandle (ModelHandle ih)
 malloc result data memory More...
 
void RunModel (ModelHandle ih, ResultHandle ir, int num_inputs, const char **name, void **data)
 inference result from input More...
 
int GetNumOutputsFromResultHandle (ResultHandle ir)
 get the number of model output from ResultHandle More...
 
void GetOutputDataInfoFromResultHandle (ResultHandle ir, int num_outputs, char **outputNames, int *n, int *c, int *h, int *w, DATA_TYPE *dt, DATA_FORMAT *df)
 get output Data info from ResultHandle More...
 
void GetOutputDataFromResultHandle (ResultHandle ir, int num_outputs, void **data)
 get output data from ResultHandle, default to pass value of output ptr, More...
 
void FreeResultHandle (ResultHandle ir)
 free result data memory More...
 
void DestroyModel (ModelHandle ih)
 destroy model More...
 
void GetGpuDeviceName (char *gpuDeviceName)
 
ModelHandle CreateModelWithFileStream (const char *modelFileStream, AFFINITY_TYPE affinity, const char *algorithmMapFileStream)
 create model from file stream Other info is the same with CreateModel
 
void GetInputDataInfoFromModel5D (ModelHandle ih, int num_inputs, char **name, int *n, int *c, int *t, int *h, int *w, DATA_TYPE *dt, DATA_FORMAT *df)
 get input Data info set in model handle, when input data is 5d input dims (n,c,t,h,w) other info please reference GetInputDataInfoFromModel
 
void PrepareModel5D (ModelHandle ih, int num_input, const char **name, const int *n, const int *c, const int *t, const int *h, const int *w, const DATA_TYPE *dt_input, const DATA_FORMAT *df_input)
 complete model inference engine prepare when input data dim is 5d input dims (n,c,t,h,w) other info please reference PrepareModel
 
void ResizeModelInput (ModelHandle ih, int num_inputs, const char **name, const int *n, const int *c, const int *h, const int *w, const DATA_TYPE *dt, const DATA_FORMAT *df)
 resize model input size More...
 
ResultHandle AllocSpecificResultHandle (ModelHandle ih, int num_outputs, const char **name)
 malloc result data memory according to user specification More...
 
ModelHandle CloneModel (ModelHandle ih)
 clone model from a model More...
 
ResultHandle CloneResultHandle (ResultHandle ir)
 clone result handle More...
 
void SetRuntimeDevice (ModelHandle ih, int cpu_id, DEVICE_TYPE device)
 set process to run on specified CPU core More...
 
void SetRuntimeDeviceDynamic (ModelHandle ih)
 set process cpu affinity according cpu average occupy More...
 
void SetNumThreads (int threads)
 set parallel threads num More...
 

Detailed Description

C API Document.

Definition in file bolt.h.

Typedef Documentation

◆ ModelHandle

typedef void* ModelHandle

inference pipeline handle

Definition at line 29 of file bolt.h.

◆ ResultHandle

typedef void* ResultHandle

result data memory handle

Definition at line 32 of file bolt.h.

Enumeration Type Documentation

◆ AFFINITY_TYPE

CPU affinity policy

Enumerator
CPU_HIGH_PERFORMANCE 

performance is high priority(use big core)

CPU_LOW_POWER 

power is high priority(use small core)

GPU 

use GPU

Definition at line 35 of file bolt.h.

◆ DATA_FORMAT

multi-dimension data format

Enumerator
NCHW 

batch->channel->high->width data order

NHWC 

batch->high->width->channel data order

NCHWC8 

batch->channel/8->high->width->channel four element data order

MTK 

batch->time->unit data order

NORMAL 

batch->unit data order

NCHWC4 

batch->channel/4->width->high->channel four element data order

Definition at line 70 of file bolt.h.

◆ DATA_TYPE

enum DATA_TYPE

data precision

Enumerator
FP_32 

32 bit float

FP_16 

16 bit float

INT_32 

32 bit integer

UINT_32 

32 bit unsigned integer

Definition at line 55 of file bolt.h.

◆ DEVICE_TYPE

heterogeneous device type

Enumerator
CPU_SERIAL 

CPU serial.

CPU_ARM_V7 

ARMv7 CPU.

CPU_ARM_V8 

ARMv8 CPU.

CPU_ARM_A55 

ARM A55 CPU.

CPU_ARM_A76 

ARM A76 CPU.

CPU_X86_AVX2 

X86_64 AVX2 CPU.

CPU_X86_AVX512 

X86_64 AVX512 CPU.

GPU_MALI 

ARM MALI GPU.

GPU_QUALCOMM 

ARM MALI GPU.

Definition at line 42 of file bolt.h.

Function Documentation

◆ AllocAllResultHandle()

ResultHandle AllocAllResultHandle ( ModelHandle  ih)

malloc result data memory

Parameters
ihinference pipeline handle
Returns
result data memory handle

Referenced by GetDataFormatString().

◆ AllocSpecificResultHandle()

ResultHandle AllocSpecificResultHandle ( ModelHandle  ih,
int  num_outputs,
const char **  name 
)

malloc result data memory according to user specification

Parameters
ihinference pipeline handle
num_outputsthe number of tensor that needed
namethe array of tesor name that needed
Returns
result data memory handle

Referenced by GetDataFormatString().

◆ CloneModel()

ModelHandle CloneModel ( ModelHandle  ih)

clone model from a model

Parameters
iha inference pipeline handle pointer of a model
Returns
inference pipeline handle
Note
This function can not be called before PrepareModel. The model that being cloned can not be changed before all threads complete clone function.
ModelHandle handle = CreateModel(...);
PrepareModel(handle);
ModelHandle clone_handle = CloneModel(handle);
...
DestroyModel(handle);
DestroyModel(clone_handle);

Referenced by GetDataFormatString().

◆ CloneResultHandle()

ResultHandle CloneResultHandle ( ResultHandle  ir)

clone result handle

Parameters
ira result data handle
Returns
result data memory handle
Note
The result handle that being cloned can not be changed before all threads complete clone function.

Referenced by GetDataFormatString().

◆ CreateModel()

ModelHandle CreateModel ( const char *  modelPath,
AFFINITY_TYPE  affinity,
const char *  algorithmMapPath 
)

create model from file

Parameters
modelPathmodel file path
affinityCPU affinity setting
algorithmMapPaththe file path to save and load algorithm map file
Returns
inference pipeline handle
Note
destroy model when pipeline end
ModelHandle handle = CreateModel(...);
...
DestroyModel(handle);
algorithmMapPath is for GPU. If you don't need it, please set it NULL. If algorithmMapPath is set to a existed valid algorithm map file, inference will directly use it. If algorithmMapPath is not existed, inference will run algorithm tuning, which is usually time consuming. Inference will write algorithm tuning result to file.
If your input tensor size or model is changed, please delete the old algorithm map file. If any unexpected error happen, you can try to delete algorithm file and run it again.

Referenced by GetDataFormatString().

◆ DestroyModel()

void DestroyModel ( ModelHandle  ih)

destroy model

Parameters
ihinference pipeline handle
Returns

Referenced by GetDataFormatString().

◆ FreeResultHandle()

void FreeResultHandle ( ResultHandle  ir)

free result data memory

Parameters
irresult data memory handle
Returns

Referenced by GetDataFormatString().

◆ GetDataFormatString()

◆ GetDataTypeString()

const char* const* GetDataTypeString ( )

Get DATA_TYPE String

Definition at line 63 of file bolt.h.

◆ GetGpuDeviceName()

void GetGpuDeviceName ( char *  gpuDeviceName)

Copy current GPU device name to gpuDeviceName User need to alloc memory of gpuDeviceName used with CreateModelWithFileStream to help user choose algoFile

Referenced by GetDataFormatString().

◆ GetInputDataInfoFromModel()

void GetInputDataInfoFromModel ( ModelHandle  ih,
int  num_inputs,
char **  name,
int *  n,
int *  c,
int *  h,
int *  w,
DATA_TYPE dt,
DATA_FORMAT df 
)

get input data info set in model handle, which is read from .bolt

Parameters
ihinference pipeline handle
num_inputsthe number of input
namethe array of all input data's name
nthe array of all input data's n dimension
cthe array of all input data's c dimension
hthe array of all input data's h dimension
wthe array of all input data's w dimension
dtthe array of all input data's data type
dfthe array of all input data's data format
Returns
Note
name/n/c/h/w/dt/df array space must be allocated before calling, the array length must be equal to num_inputs. each element of name must be allocated, the array length must be equal to 128.

Referenced by GetDataFormatString().

◆ GetNumInputsFromModel()

int GetNumInputsFromModel ( ModelHandle  ih)

get the number of model input from ModelHandle

Parameters
ihinference pipeline handle
Returns
the number of input

Referenced by GetDataFormatString().

◆ GetNumOutputsFromResultHandle()

int GetNumOutputsFromResultHandle ( ResultHandle  ir)

get the number of model output from ResultHandle

Parameters
irresult data memory handle
Returns
the number of output

Referenced by GetDataFormatString().

◆ GetOutputDataFromResultHandle()

void GetOutputDataFromResultHandle ( ResultHandle  ir,
int  num_outputs,
void **  data 
)

get output data from ResultHandle, default to pass value of output ptr,

Parameters
irresult data memory handle
num_outputsthe number of output data
datathe array of all output data's content
Returns

Referenced by GetDataFormatString().

◆ GetOutputDataInfoFromResultHandle()

void GetOutputDataInfoFromResultHandle ( ResultHandle  ir,
int  num_outputs,
char **  outputNames,
int *  n,
int *  c,
int *  h,
int *  w,
DATA_TYPE dt,
DATA_FORMAT df 
)

get output Data info from ResultHandle

Parameters
irresult data memory handle
num_outputsthe number of output data
outputNamesthe array of all output data's name
nthe array of all output data's n dimension
cthe array of all output data's c dimension
hthe array of all output data's h dimension
wthe array of all output data's w dimension
dtthe array of all output data's data type
dfthe array of all output data's data format
Returns
Note
name/n/c/h/w/dt/df array space must be allocated before calling, the array length must be equal to num_inputs. each element of name must be allocated, the array length must be equal to 128.

Referenced by GetDataFormatString().

◆ PrepareModel()

void PrepareModel ( ModelHandle  ih,
const int  num_inputs,
const char **  name,
const int *  n,
const int *  c,
const int *  h,
const int *  w,
const DATA_TYPE dt,
const DATA_FORMAT df 
)

complete model inference engine prepare

Parameters
ihmodel inference handle
num_inputsthe number of input data
namethe array of all input data's name in string format
nthe array of all input data's n dimension
cthe array of all input data's c dimension
hthe array of all input data's h dimension
wthe array of all input data's w dimension
dtthe array of all input data's data type
dfthe array of all input data's data format
Returns
Note
name/n/c/h/w/dt/df array space must be allocated before calling, the array length must be equal to num_inputs. each element of name must be allocated, the array length must be equal to 128.

Referenced by GetDataFormatString().

◆ ResizeModelInput()

void ResizeModelInput ( ModelHandle  ih,
int  num_inputs,
const char **  name,
const int *  n,
const int *  c,
const int *  h,
const int *  w,
const DATA_TYPE dt,
const DATA_FORMAT df 
)

resize model input size

Parameters
ihmodel inference handle
num_inputsthe number of input data
namethe array of all input data's name in string format
nthe array of all input data's n dimension
cthe array of all input data's c dimension
hthe array of all input data's h dimension
wthe array of all input data's w dimension
dtthe array of all input data's data type
dfthe array of all input data's data format
Returns
Note
name/n/c/h/w/dt/df array space must be allocated before calling, the array length must be equal to num_inputs. each element of name must be allocated, the array length must be equal to 128.
// model_resize must behind PrepareModel;
RunModel(...);

Referenced by GetDataFormatString().

◆ RunModel()

void RunModel ( ModelHandle  ih,
ResultHandle  ir,
int  num_inputs,
const char **  name,
void **  data 
)

inference result from input

Parameters
ihinference pipeline handle
irresult data memory handle
num_inputsthe number of input data
namethe array of all input data's name
datathe array of all input data
Returns

Referenced by GetDataFormatString().

◆ SetNumThreads()

void SetNumThreads ( int  threads)

set parallel threads num

Parameters
threadsnumber of threads
Note
This can only be used before RunModel. If you use it before PrepareModel, this will affect tmp buffer allocation. Then you are limited that next setting can not greater than before one. This setting is global to each inference threads.
Returns

Referenced by GetDataFormatString().

◆ SetRuntimeDevice()

void SetRuntimeDevice ( ModelHandle  ih,
int  cpu_id,
DEVICE_TYPE  device 
)

set process to run on specified CPU core

Parameters
ihinference pipeline handle
cpu_idcpu core id(0, 1, 2...)
devicecpu core architecture(ARM_A76)
Returns

Referenced by GetDataFormatString().

◆ SetRuntimeDeviceDynamic()

void SetRuntimeDeviceDynamic ( ModelHandle  ih)

set process cpu affinity according cpu average occupy

Parameters
ihinference pipeline handle
Returns

Referenced by GetDataFormatString().