AXCL API
is divided into two parts: the Runtime API
and the Native API
. The Runtime API
is an independent set of APIs
, currently only including Memory
for memory management and Engine API
for driving the Axera(TM)
NPU
to work. When the AXCL API
is used in the form of a compute card without using codec functions, all computation tasks can be completed using only the Runtime API
. When codec functions are required, you need to understand the Native API
and the related contents of the FFMPEG
module.
Using the Runtime API
allows the NPU
to be called on the host system to perform computing functions. The Memory API
can allocate and free memory space on both the host and the compute card, while the Engine API
can complete all NPU
functionalities from model initialization and IO
settings to inference.
axclError axclInit(const char *config);
Description:
System initialization, synchronous interface.
Parameters:
config [IN]
: Specifies the path to the JSON configuration file.Limitations:
axclFinalize
for system cleanup.axclError axclFinalize();
Description:
System de-initialization, releasing AXCL resources within the process, synchronous interface.
Limitations:
axclInit
.axclError axclrtGetVersion(int32_t *major, int32_t *minor, int32_t *patch);
Description:
Query the system version number, synchronous interface.
Parameters:
major [OUT]
: Major version number.minor [OUT]
: Minor version number.patch [OUT]
: Patch version number.Limitations:
No special restrictions.
const char *axclrtGetSocName();
Description:
Query the current chip SOC name string, synchronous interface.
Limitations:
No special restrictions.
axclError axclrtSetDevice(int32_t deviceId);
Description:
Specify the device in the current process or thread, while implicitly creating a default Context, synchronous interface.
Parameters:
deviceId [IN]
: Device ID.Limitations:
axclrtResetDevice
and must not be explicitly destroyed using axclrtDestroyContext
.deviceId
specified in this interface is the same, the implicitly created Context will also be the same.axclrtResetDevice
to release the device resources used by this process; internally uses reference counting to allow multiple calls, and only releases resources when the reference count reaches 0.axclrtSetCurrentContext
.axclError axclrtResetDevice(int32_t deviceId);
Description:
Reset the device and release resources on the device, including both implicitly and explicitly created Contexts, synchronous interface.
Parameters:
deviceId [IN]
: Device ID.Limitations:
axclrtCreateContext
, it is recommended to explicitly destroy them using axclrtDestroyContext
before calling this interface to release device resources.axclrtSetDevice
; the system will automatically reclaim default Context resources.axclrtResetDevice
is called, especially after handling exception signals; otherwise, this may cause a C++ terminated abort
exception.axclError axclrtGetDevice(int32_t *deviceId);
Description:
Get the current device ID in use, synchronous interface.
Parameters:
deviceId [OUT]
: Device ID.Limitations:
axclrtSetDevice
nor axclrtCreateContext
has been called to specify a device, this interface will return an error.axclError axclrtGetDeviceCount(uint32_t *count);
Description:
Get the total number of connected devices, synchronous interface.
Parameters:
count [OUT]
: Number of devices.Limitations:
No special restrictions.
axclError axclrtGetDeviceList(axclrtDeviceList *deviceList);
Description:
Get the IDs of all connected devices, synchronous interface.
Parameters:
deviceList [OUT]
: Information of all connected device IDs.Limitations:
No special restrictions.
axclError axclrtSynchronizeDevice();
Description:
Synchronously execute all tasks on the current device, synchronous interface.
Limitations:
At least one device must be active.
axclError axclrtGetDeviceProperties(int32_t deviceId, axclrtDeviceProperties *properties);
Description:
Retrieve information such as device UID, CPU usage, NPU usage, and memory, synchronous interface.
Limitations:
No special restrictions.
axclError axclrtCreateContext(axclrtContext *context, int32_t deviceId);
Description:
Explicitly create a Context in the current thread, synchronous interface.
Parameters:
context [OUT]
: Handle for the created Context.deviceId [IN]
: Device ID.Limitations:
axclrtSetCurrentContext
.axclrtDestroyContext
to explicitly release Context resources.axclrtSetCurrentContext
), but task execution depends on the system’s thread scheduling order. Users must manage and maintain execution synchronization order between threads themselves. For multi-threading, it is recommended to create a dedicated Context for each thread to improve maintainability.axclError axclrtDestroyContext(axclrtContext context);
Description:
Explicitly destroy a Context, synchronous interface.
Parameters:
context [IN]
: Handle for the created Context.Limitations:
axclrtCreateContext
can be destroyed.axclError axclrtSetCurrentContext(axclrtContext context);
Description:
Bind the Context for a thread to run with, synchronous interface.
Parameters:
context [IN]
: Context handle.Limitations:
axclrtResetDevice
, the Context cannot be set for the thread, otherwise exceptions will occur.axclrtCreateContext
is called in Thread A and the Context is used in Thread B, the user must ensure the task execution order under the same Context is maintained between the two threads.axclError axclrtGetCurrentContext(axclrtContext *context);
Description:
Get the Context handle bound to the thread, synchronous interface.
Parameters:
context [OUT]
: The current Context handle.Limitations:
axclrtSetCurrentContext
or created one using axclrtCreateContext
before it can be retrieved.axclrtSetCurrentContext
has been called multiple times, the Context retrieved will be the one set most recently.axclError axclrtMalloc(void **devPtr, size_t size, axclrtMemMallocPolicy policy);
Description:
Allocate non-CACHED physical memory on the device side. The allocated memory pointer is returned via devPtr, synchronous interface.
Parameters:
devPtr [OUT]
: Pointer to the allocated device-side physical memory.size [IN]
: Size of the allocated memory in bytes.policy [IN]
: Memory allocation policy, currently unused.Limitations:
axclrtFree
to release memory.axclError axclrtMallocCached(void **devPtr, size_t size, axclrtMemMallocPolicy policy);
Description:
Allocate CACHED physical memory on the device side. The allocated memory pointer is returned via devPtr, synchronous interface.
Parameters:
devPtr [OUT]
: Pointer to the allocated device-side physical memory.size [IN]
: Size of the allocated memory in bytes.policy [IN]
: Memory allocation policy, currently unused.Limitations:
axclrtFree
to release memory.axclError axclrtFree(void *devPtr);
Description:
Release memory allocated on the device side, synchronous interface.
Parameters:
devPtr [IN]
: Device memory to be released.Limitations:
axclrtMalloc
or axclrtMallocCached
.axclError axclrtMemFlush(void *devPtr, size_t size);
Description:
Flush the data in the cache to DDR and invalidate the contents in the cache, synchronous interface.
Parameters:
devPtr [IN]
: Starting address pointer of the DDR memory to be flushed.size [IN]
: Size of the DDR memory to be flushed, in bytes.Limitations:
No special restrictions.
axclError axclrtMemInvalidate(void *devPtr, size_t size);
Description:
Invalidate the data in the cache, synchronous interface.
Parameters:
devPtr [IN]
: Starting address pointer of the DDR memory whose cache data will be invalidated.size [IN]
: Size of the DDR memory, in bytes.Limitations:
axclError axclrtMallocHost(void **hostPtr, size_t size);
Description:
Allocate virtual memory on the HOST, synchronous interface.
Parameters:
hostPtr [OUT]
: Start address of the allocated memory.size [IN]
: Size of the allocated memory, in bytes.Limitations:
axclrtMallocHost
must be released with axclrtFreeHost
.malloc
interface, but axclrtMallocHost
is recommended.axclError axclrtFreeHost(void *hostPtr);
Description:
Release memory allocated by axclrtMallocHost
, synchronous interface.
Parameters:
hostPtr [IN]
: Start address of the memory to be released.Limitations:
axclrtMallocHost
.axclError axclrtMemset(void *devPtr, uint8_t value, size_t count);
Description:
Only used to initialize device-side memory allocated by axclrtMalloc
or axclrtMallocCached
, synchronous interface.
Parameters:
devPtr [IN]
: Start address of the device-side memory to initialize.value [IN]
: Value to set.count [IN]
: Length of the memory to initialize, in bytes.Limitations:
axclrtMalloc
or axclrtMallocCached
can be initialized.axclrtMallocCached
requires a call to axclrtMemInvalidate
after initialization to maintain consistency.axclrtMallocHost
, please use the standard memset
function for initialization.axclError axclrtMemcpy(void *dstPtr, const void *srcPtr, size_t count, axclrtMemcpyKind kind);
Description:
Performs synchronous memory copy operations between HOST memory, between HOST and DEVICE memory, and within DEVICE memory.
Parameters:
devPtr [IN]
: Destination memory address pointer.srcPtr [IN]
: Source memory address pointer.count [IN]
: Length of memory to be copied, in bytes.kind [IN]
: Type of memory copy.AXCL_MEMCPY_HOST_TO_HOST
]: Memory copy within HOST memory.AXCL_MEMCPY_HOST_TO_DEVICE
]: Copy from HOST virtual memory to DEVICE memory.AXCL_MEMCPY_DEVICE_TO_HOST
]: Copy from DEVICE memory to HOST virtual memory.AXCL_MEMCPY_DEVICE_TO_DEVICE
]: Memory copy within DEVICE.AXCL_MEMCPY_HOST_PHY_TO_DEVICE
]: Copy from HOST continuous physical memory to DEVICE.AXCL_MEMCPY_DEVICE_TO_HOST_PHY
]: Copy from DEVICE to HOST continuous physical memory.Limitations:
kind
.axclError axclrtMemcmp(const void *devPtr1, const void *devPtr2, size_t count);
Description:
Performs memory comparison within the DEVICE, synchronous interface.
Parameters:
devPtr1 [IN]
: Pointer to device memory address #1.devPtr2 [IN]
: Pointer to device memory address #2.count [IN]
: Length to compare, in bytes.Limitations:
AXCL_SUCC(0)
only if the memory contents are the same.axclError axclrtEngineInit(axclrtEngineVNpuKind npuKind);
Description:
Initializes the Runtime Engine
. Must be called before using the Runtime Engine
.
Parameters:
npuKind [IN]
: Specifies the type of VNPU
to initialize.Limitations:
After using the Runtime Engine
, the user must call axclrtEngineFinalize
to clean up the Runtime Engine
.
axclError axclrtEngineGetVNpuKind(axclrtEngineVNpuKind *npuKind);
Description:
Retrieves the initialized VNPU
type of the Runtime Engine
.
Parameters:
npuKind [OUT]
: Returns the VNPU
type.Limitations:
The user must call axclrtEngineInit
to initialize the Runtime Engine
before calling this function.
axclError axclrtEngineFinalize();
Description:
Cleans up the Runtime Engine
. Must be called after completing all operations.
Limitations:
The user must call axclrtEngineInit
before calling this function.
axclError axclrtEngineLoadFromFile(const char *modelPath, uint64_t *modelId);
Description:
Loads model data from a file and creates a model ID
.
Parameters:
modelPath [IN]
: Path to the offline model file.modelId [OUT]
: The model ID
generated after loading, used as an identifier for subsequent operations.Limitations:
The user must call axclrtEngineInit
to initialize the Runtime Engine
before calling this function.
axclError axclrtEngineLoadFromMem(const void *model, uint64_t modelSize, uint64_t *modelId);
Description:
Loads offline model data from memory, with memory for model execution managed internally by the system.
Parameters:
model [IN]
: Model data stored in memory.modelSize [IN]
: Size of the model data.modelId [OUT]
: The model ID
generated after loading, used as an identifier for subsequent operations.Limitations:
axclError axclrtEngineUnload(uint64_t modelId);
Description:
This function is used to unload a model with the specified model ID
.
Parameters:
modelId [IN]
: The model ID
to unload.Limitations:
No special restrictions.
const char* axclrtEngineGetModelCompilerVersion(uint64_t modelId);
Description:
This function retrieves the version of the toolchain used to build the model.
Parameters:
modelId [IN]
: Model ID
.Limitations:
No special restrictions.
axclError axclrtEngineSetAffinity(uint64_t modelId, axclrtEngineSet set);
Description:
This function is used to set the model’s NPU affinity.
Parameters:
modelId [IN]
: Model ID
.set [OUT]
: Affinity set to apply.Limitations:
Cannot be zero, and the mask bits set must not exceed the affinity range.
axclError axclrtEngineGetAffinity(uint64_t modelId, axclrtEngineSet *set);
Description:
This function retrieves the model’s NPU affinity.
Parameters:
modelId [IN]
: Model ID
.set [OUT]
: Returned affinity set.Limitations:
No special restrictions.
axclError axclrtEngineGetUsage(const char *modelPath, int64_t *sysSize, int64_t *cmmSize);
Description:
This function retrieves the required system memory size and CMM memory size for executing a model based on its file.
Parameters:
modelPath [IN]
: Model path used to obtain memory information.sysSize [OUT]
: Working system memory size required to run the model.cmmSize [OUT]
: CMM memory size required to run the model.Limitations:
No special restrictions.
axclError axclrtEngineGetUsageFromMem(const void *model, uint64_t modelSize, int64_t *sysSize, int64_t *cmmSize);
Description:
This function retrieves the required system memory size and CMM memory size for executing a model based on its data in memory.
Parameters:
model [IN]
: User-managed model memory.modelSize [IN]
: Size of the model data.sysSize [OUT]
: Working system memory size required to run the model.cmmSize [OUT]
: CMM memory size required to run the model.Limitations:
Model memory must reside in device memory, which the user must manage and release.
axclError axclrtEngineGetUsageFromModelId(uint64_t modelId, int64_t *sysSize, int64_t *cmmSize);
Description:
This function retrieves the required system memory size and CMM memory size for executing a model based on its ID
.
Parameters:
modelId [IN]
: Model ID
.sysSize [OUT]
: Working system memory size required to run the model.cmmSize [OUT]
: CMM memory size required to run the model.Limitations:
No special restrictions.
axclError axclrtEngineGetModelType(const char *modelPath, axclrtEngineModelKind *modelType);
Description:
This function retrieves the model type based on its file.
Parameters:
modelPath [IN]
: Model path used to retrieve model type.modelType [OUT]
: Returned model type.Limitations:
No special restrictions.
axclError axclrtEngineGetModelTypeFromMem(const void *model, uint64_t modelSize, axclrtEngineModelKind *modelType);
Description:
This function retrieves the model type based on model data in memory.
Parameters:
model [IN]
: User-managed model memory.modelSize [IN]
: Size of the model data.modelType [OUT]
: Returned model type.Limitations:
Model memory must reside in device memory, which the user must manage and release.
axclError axclrtEngineGetModelTypeFromModelId(uint64_t modelId, axclrtEngineModelKind *modelType);
Description:
This function retrieves the model type based on the model ID
.
Parameters:
modelId [IN]
: Model ID
.modelType [OUT]
: Returned model type.Limitations:
No special restrictions.
axclError axclrtEngineGetIOInfo(uint64_t modelId, axclrtEngineIOInfo *ioInfo);
Description:
This function retrieves the model IO information based on the model ID
.
Parameters:
modelId [IN]
: Model ID
.ioInfo [OUT]
: Returned axclrtEngineIOInfo
pointer.Limitations:
The user should call axclrtEngineDestroyIOInfo
to release axclrtEngineIOInfo
before the model ID
is destroyed.
axclError axclrtEngineDestroyIOInfo(axclrtEngineIOInfo ioInfo);
Description:
This function destroys data of type axclrtEngineIOInfo
.
Parameters:
ioInfo [IN]
: axclrtEngineIOInfo
pointer.Limitations:
No special restrictions.
axclError axclrtEngineGetShapeGroupsCount(axclrtEngineIOInfo ioInfo, int32_t *count);
Description:
This function retrieves the number of IO shape groups.
Parameters:
ioInfo [IN]
: axclrtEngineIOInfo
pointer.count [OUT]
: Number of shape groups.Limitations:
The Pulsar2 toolchain can specify multiple shapes during model conversion. Standard models typically have only one shape, so calling this function for normally converted models is unnecessary.
uint32_t axclrtEngineGetNumInputs(axclrtEngineIOInfo ioInfo);
Description:
This function retrieves the number of model inputs from axclrtEngineIOInfo
.
Parameters:
ioInfo [IN]
: axclrtEngineIOInfo
pointer.Limitations:
No special restrictions.
uint32_t axclrtEngineGetNumOutputs(axclrtEngineIOInfo ioInfo);
Description:
This function retrieves the number of model outputs from axclrtEngineIOInfo
.
Parameters:
ioInfo [IN]
: axclrtEngineIOInfo
pointer.Limitations:
No special restrictions.
uint64_t axclrtEngineGetInputSizeByIndex(axclrtEngineIOInfo ioInfo, uint32_t group, uint32_t index);
Description:
This function retrieves the size of a specific input based on axclrtEngineIOInfo
.
Parameters:
ioInfo [IN]
: axclrtEngineIOInfo
pointer.group [IN]
: Input shape group index.index [IN]
: Index of the input whose size is to be retrieved, starting from 0.Limitations:
No special restrictions.
uint64_t axclrtEngineGetOutputSizeByIndex(axclrtEngineIOInfo ioInfo, uint32_t group, uint32_t index);
Description:
This function retrieves the size of a specific output based on axclrtEngineIOInfo
.
Parameters:
ioInfo [IN]
: axclrtEngineIOInfo
pointer.group [IN]
: Output shape group index.index [IN]
: Index of the output whose size is to be retrieved, starting from 0.Limitations:
No special restrictions.
const char *axclrtEngineGetInputNameByIndex(axclrtEngineIOInfo ioInfo, uint32_t index);
Description:
This function retrieves the name of a specific input.
Parameters:
ioInfo [IN]
: axclrtEngineIOInfo
pointer.index [IN]
: Input IO index.Limitations:
The returned input tensor name has the same lifecycle as ioInfo
.
const char *axclrtEngineGetOutputNameByIndex(axclrtEngineIOInfo ioInfo, uint32_t index);
Description:
This function retrieves the name of a specific output.
Parameters:
ioInfo [IN]
: axclrtEngineIOInfo
pointer.index [IN]
: Output IO index.Limitations:
The returned output tensor name has the same lifecycle as ioInfo
.
int32_t axclrtEngineGetInputIndexByName(axclrtEngineIOInfo ioInfo, const char *name);
Description:
This function retrieves the input index based on the name of the input tensor.
Parameters:
ioInfo [IN]
: Model description.name [IN]
: Input tensor name.Limitations:
No special restrictions.
int32_t axclrtEngineGetOutputIndexByName(axclrtEngineIOInfo ioInfo, const char *name);
Description:
This function retrieves the output index based on the name of the output tensor.
Parameters:
ioInfo [IN]
: Model description.name [IN]
: Output tensor name.Limitations:
No special restrictions.
axclError axclrtEngineGetInputDims(axclrtEngineIOInfo ioInfo, uint32_t group, uint32_t index, axclrtEngineIODims *dims);
Description:
This function retrieves the dimension information of a specified input.
Parameters:
ioInfo [IN]
: axclrtEngineIOInfo
pointer.group [IN]
: Input shape group index.index [IN]
: Input tensor index.dims [OUT]
: Returned dimension information.Limitations:
The storage space for axclrtEngineIODims
is allocated by the user, and should be released before axclrtEngineIOInfo
is destroyed.
axclError axclrtEngineGetOutputDims(axclrtEngineIOInfo ioInfo, uint32_t group, uint32_t index, axclrtEngineIODims *dims);
Description:
This function retrieves the dimension information of a specified output.
Parameters:
ioInfo [IN]
: axclrtEngineIOInfo
pointer.group [IN]
: Output shape group index.index [IN]
: Output tensor index.dims [OUT]
: Returned dimension information.Limitations:
The storage space for axclrtEngineIODims
is allocated by the user, and should be released before axclrtEngineIOInfo
is destroyed.
axclError axclrtEngineCreateIO(axclrtEngineIOInfo ioInfo, axclrtEngineIO *io);
Description:
This function creates data of type axclrtEngineIO
.
Parameters:
ioInfo [IN]
: axclrtEngineIOInfo
pointer.io [OUT]
: Created axclrtEngineIO
pointer.Limitations:
The user should call axclrtEngineDestroyIO
to release axclrtEngineIO
before the model ID
is destroyed.
axclError axclrtEngineDestroyIO(axclrtEngineIO io);
Description:
This function destroys data of type axclrtEngineIO
.
Parameters:
io [IN]
: The axclrtEngineIO
pointer to be destroyed.Limitations:
No special restrictions.
axclError axclrtEngineSetInputBufferByIndex(axclrtEngineIO io, uint32_t index, const void *dataBuffer, uint64_t size);
Description:
This function sets the input data buffer by IO index.
Parameters:
io [IN]
: Address of the axclrtEngineIO
data buffer.index [IN]
: Input tensor index.dataBuffer [IN]
: Address of the data buffer to add.size [IN]
: Size of the data buffer.Limitations:
The data buffer must be in device memory, and the user is responsible for managing and releasing it.
axclError axclrtEngineSetOutputBufferByIndex(axclrtEngineIO io, uint32_t index, const void *dataBuffer, uint64_t size);
Description:
This function sets the output data buffer by IO index.
Parameters:
io [IN]
: Address of the axclrtEngineIO
data buffer.index [IN]
: Output tensor index.dataBuffer [IN]
: Address of the data buffer to add.size [IN]
: Size of the data buffer.Limitations:
The data buffer must be in device memory, and the user is responsible for managing and releasing it.
axclError axclrtEngineSetInputBufferByName(axclrtEngineIO io, const char *name, const void *dataBuffer, uint64_t size);
Description:
This function sets the input data buffer by IO name.
Parameters:
io [IN]
: Address of the axclrtEngineIO
data buffer.name [IN]
: Input tensor name.dataBuffer [IN]
: Address of the data buffer to add.size [IN]
: Size of the data buffer.Limitations:
The data buffer must be in device memory, and the user is responsible for managing and releasing it.
axclError axclrtEngineSetOutputBufferByName(axclrtEngineIO io, const char *name, const void *dataBuffer, uint64_t size);
Description:
This function sets the output data buffer by IO name.
Parameters:
io [IN]
: Address of the axclrtEngineIO
data buffer.name [IN]
: Output tensor name.dataBuffer [IN]
: Address of the data buffer to add.size [IN]
: Size of the data buffer.Limitations:
The data buffer must be in device memory, and the user is responsible for managing and releasing it.
axclError axclrtEngineGetInputBufferByIndex(axclrtEngineIO io, uint32_t index, void **dataBuffer, uint64_t *size);
Description:
This function retrieves the input data buffer by IO index.
Parameters:
io [IN]
: Address of the axclrtEngineIO
data buffer.index [IN]
: Input tensor index.dataBuffer [OUT]
: Address of the data buffer.size [IN]
: Size of the data buffer.Limitations:
The data buffer must be in device memory, and the user is responsible for managing and releasing it.
axclError axclrtEngineGetOutputBufferByIndex(axclrtEngineIO io, uint32_t index, void **dataBuffer, uint64_t *size);
Description:
This function retrieves the output data buffer by IO index.
Parameters:
io [IN]
: Address of the axclrtEngineIO
data buffer.index [IN]
: Output tensor index.dataBuffer [OUT]
: Address of the data buffer.size [IN]
: Size of the data buffer.Limitations:
The data buffer must be in device memory, and the user is responsible for managing and releasing it.
axclError axclrtEngineGetInputBufferByName(axclrtEngineIO io, const char *name, void **dataBuffer, uint64_t *size);
Description:
This function retrieves the input data buffer by IO name.
Parameters:
io [IN]
: Address of the axclrtEngineIO
data buffer.name [IN]
: Input tensor name.dataBuffer [OUT]
: Address of the data buffer.Limitations:
The data buffer must be in device memory, and the user is responsible for managing and releasing it.
axclError axclrtEngineGetOutputBufferByName(axclrtEngineIO io, const char *name, void **dataBuffer, uint64_t *size);
Description:
This function retrieves the output data buffer by IO name.
Parameters:
io [IN]
: Address of the axclrtEngineIO
data buffer.name [IN]
: Output tensor name.dataBuffer [OUT]
: Address of the data buffer.Limitations:
The data buffer must be in device memory, and the user is responsible for managing and releasing it.
axclError axclrtEngineSetDynamicBatchSize(axclrtEngineIO io, uint32_t batchSize);
Description:
This function sets the number of images processed at one time in a dynamic batching scenario.
Parameters:
io [IN]
: Model inference IO.batchSize [IN]
: Number of images processed at one time.Limitations:
No special restrictions.
axclError axclrtEngineCreateContext(uint64_t modelId, uint64_t *contextId);
Description:
This function creates a model runtime context for the given model ID
.
Parameters:
modelId [IN]
: Model ID
.contextId [OUT]
: Created context ID
.Limitations:
A model ID
can have multiple runtime contexts, each running with its own settings and memory space.
axclError axclrtEngineExecute(uint64_t modelId, uint64_t contextId, uint32_t group, axclrtEngineIO io);
Description:
This function performs synchronous inference for the model until the inference result is returned.
Parameters:
modelId [IN]
: Model ID
.contextId [IN]
: Model inference context.group [IN]
: Model shape group index.io [IN]
: Model inference IO.Limitations:
No special restrictions.
axclError axclrtEngineExecuteAsync(uint64_t modelId, uint64_t contextId, uint32_t group, axclrtEngineIO io, axclrtStream stream);
Description:
This function performs asynchronous inference for the model.
Parameters:
modelId [IN]
: Model ID
.contextId [IN]
: Model inference context.group [IN]
: Model shape group index.io [IN]
: Model inference IO.stream [IN]
: Stream.Limitations:
No special restrictions.
The AXCL NATIVE module supports the SYS, VDEC, VENC, IVPS, DMADIM, ENGINE, and IVE modules.
The AXCL NATIVE API parameters are exactly the same as those of the AX SDK API, the only difference being that the function names change from the original AX prefix to AXCL.
Example:
AX_S32 AXCL_SYS_Init(AX_VOID);
AX_S32 AXCL_SYS_Deinit(AX_VOID);
/* CMM API */
AX_S32 AXCL_SYS_MemAlloc(AX_U64 *phyaddr, AX_VOID **pviraddr, AX_U32 size, AX_U32 align, const AX_S8 *token);
AX_S32 AXCL_SYS_MemAllocCached(AX_U64 *phyaddr, AX_VOID **pviraddr, AX_U32 size, AX_U32 align, const AX_S8 *token);
AX_S32 AXCL_SYS_MemFree(AX_U64 phyaddr, AX_VOID *pviraddr);
...
AX_S32 AXCL_VDEC_Init(const AX_VDEC_MOD_ATTR_T *pstModAttr);
AX_S32 AXCL_VDEC_Deinit(AX_VOID);
AX_S32 AXCL_VDEC_ExtractStreamHeaderInfo(const AX_VDEC_STREAM_T *pstStreamBuf, AX_PAYLOAD_TYPE_E enVideoType,
AX_VDEC_BITSTREAM_INFO_T *pstBitStreamInfo);
AX_S32 AXCL_VDEC_CreateGrp(AX_VDEC_GRP VdGrp, const AX_VDEC_GRP_ATTR_T *pstGrpAttr);
AX_S32 AXCL_VDEC_CreateGrpEx(AX_VDEC_GRP *VdGrp, const AX_VDEC_GRP_ATTR_T *pstGrpAttr);
AX_S32 AXCL_VDEC_DestroyGrp(AX_VDEC_GRP VdGrp);
...
Please refer to the AX SDK API documentation, such as "AX SYS API Documentation.docx", "AX VDEC API Documentation.docx", etc.
The dynamic library .so
naming has changed from the original libax_xxx.so
to libaxcl_xxx.so
. The comparison table is as follows:
Module | AX SDK | AXCL NATIVE SDK |
---|---|---|
SYS | libax_sys.so | libaxcl_sys.so |
VDEC | libax_vdec.so | libaxcl_vdec.so |
VENC | libax_venc.so | libaxcl_venc.so |
IVPS | libax_ivps.so | libaxcl_ivps.so |
DMADIM | libax_dmadim.so | libaxcl_dmadim.so |
ENGINE | libax_engine.so | libaxcl_engine.so |
IVE | libax_ive.so | libaxcl_ive.so |
Module | AXCL NATIVE API | Description |
---|---|---|
SYS | AXCL_SYS_EnableTimestamp | |
AXCL_SYS_Sleep | ||
AXCL_SYS_WakeLock | ||
AXCL_SYS_WakeUnlock | ||
AXCL_SYS_RegisterEventCb | ||
AXCL_SYS_UnregisterEventCb | ||
VENC | AXCL_VENC_GetFd | |
AXCL_VENC_JpegGetThumbnail | ||
IVPS | AXCL_IVPS_GetChnFd | |
AXCL_IVPS_CloseAllFd | ||
DMADIM | AXCL_DMADIM_Cfg | Callback function not supported, i.e., AX_DMADIM_MSG_T.pfnCallBack |
IVE | AXCL_IVE_NPU_CreateMatMulHandle | |
AX_IVE_NPU_DestroyMatMulHandle | ||
AX_IVE_NPU_MatMul |
libaxcl_ppl.so is a highly integrated module that implements typical pipeline (PPL). The architecture diagram is as follows:
| ----------------------------- |
| application |
| ----------------------------- |
| libaxcl_ppl.so |
| ----------------------------- |
| libaxcl_lite.so |
| ----------------------------- |
| axcl sdk |
| ----------------------------- |
| pcie driver |
| ----------------------------- |
libaxcl_lite.so
and libaxcl_ppl.so
are open-source libraries which located in axcl/sample/axclit
and axcl/sample/ppl
directories.Refer to the source code of axcl_transcode_sample which located in path: axcl/sample/ppl/transode
.
axcl runtime system and ppl initialization.
axclError axcl_ppl_init(const axcl_ppl_init_param* param);
parameter | description | in/out |
---|---|---|
param | in |
typedef enum {
AXCL_LITE_NONE = 0,
AXCL_LITE_VDEC = (1 << 0),
AXCL_LITE_VENC = (1 << 1),
AXCL_LITE_IVPS = (1 << 2),
AXCL_LITE_JDEC = (1 << 3),
AXCL_LITE_JENC = (1 << 4),
AXCL_LITE_DEFAULT = (AXCL_LITE_VDEC | AXCL_LITE_VENC | AXCL_LITE_IVPS),
AXCL_LITE_MODULE_BUTT
} AXCLITE_MODULE_E;
typedef struct {
const char *json; /* axcl.json path */
AX_S32 device;
AX_U32 modules;
AX_U32 max_vdec_grp;
AX_U32 max_venc_thd;
} axcl_ppl_init_param;
parameter | description | in/out |
---|---|---|
json | json file path pass to axclInit API. | in |
device | device id | in |
modules | bitmask of AXCLITE_MODULE_E according to PPL | in |
max_vdec_grp | total VDEC groups of all processes | in |
max_venc_thrd | max VENC threads of each process | in |
IMPORTANT:
0 (AXCL_SUCC) if success, otherwise failure.
axcl runtime system and ppl deinitialization.
axclError axcl_ppl_deinit();
0 (AXCL_SUCC) if success, otherwise failure.
create ppl.
axclError axcl_ppl_create(axcl_ppl* ppl, const axcl_ppl_param* param);
parameter | description | in/out |
---|---|---|
ppl | ppl handle created | out |
param | parameters related to specified ppl | in |
typedef enum {
AXCL_PPL_TRANSCODE = 0, /* VDEC -> IVPS ->VENC */
AXCL_PPL_BUTT
} axcl_ppl_type;
typedef struct {
axcl_ppl_type ppl;
void *param;
} axcl_ppl_param;
AXCL_PPL_TRANSCODE parameters as shown as follows:
typedef AX_VENC_STREAM_T axcl_ppl_encoded_stream;
typedef void (*axcl_ppl_encoded_stream_callback_func)(axcl_ppl ppl, const axcl_ppl_encoded_stream *stream, AX_U64 userdata);
typedef struct {
axcl_ppl_transcode_vdec_attr vdec;
axcl_ppl_transcode_venc_attr venc;
axcl_ppl_encoded_stream_callback_func cb;
AX_U64 userdata;
} axcl_ppl_transcode_param;
parameter | description | in/out |
---|---|---|
vdec | decoder attribute | in |
venc | encoder attribute | in |
cb | callback function to receive encoded nalu frame data | in |
userdata | userdata bypass to axcl_ppl_encoded_stream_callback_func | in |
typedef struct {
AX_PAYLOAD_TYPE_E payload;
AX_U32 width;
AX_U32 height;
AX_VDEC_OUTPUT_ORDER_E output_order;
AX_VDEC_DISPLAY_MODE_E display_mode;
} axcl_ppl_transcode_vdec_attr;
parameter | description | in/out |
---|---|---|
payload | PT_H2644 \ PT_H265 | in |
width | max. width of input stream | in |
height | max. height of input stream | in |
output_order | AX_VDEC_OUTPUT_ORDER_DISP \ AX_VDEC_OUTPUT_ORDER_DEC | in |
display_mode | AX_VDEC_DISPLAY_MODE_PREVIEW \ AX_VDEC_DISPLAY_MODE_PLAYBACK | in |
Important:
typedef struct {
AX_PAYLOAD_TYPE_E payload;
AX_U32 width;
AX_U32 height;
AX_VENC_PROFILE_E profile;
AX_VENC_LEVEL_E level;
AX_VENC_TIER_E tile;
AX_VENC_RC_ATTR_T rc;
AX_VENC_GOP_ATTR_T gop;
} axcl_ppl_transcode_venc_attr;
parameter | description | in/out |
---|---|---|
payload | PT_H264 \ PT_H265 | in |
width | output width of encoded nalu frame | in |
height | output height of encoded nalu frame | in |
profile | h264 or h265 profile | in |
level | h264 or h265 level | in |
tile | tile | in |
rc | rate control settings | in |
gop | gop settings | in |
0 (AXCL_SUCC) if success, otherwise failure.
destroy ppl.
axclError axcl_ppl_destroy(axcl_ppl ppl)
parameter | description | in/out |
---|---|---|
ppl | ppl handle created | in |
0 (AXCL_SUCC) if success, otherwise failure.
start ppl.
axclError axcl_ppl_start(axcl_ppl ppl);
parameter | description | in/out |
---|---|---|
ppl | ppl handle created | in |
0 (AXCL_SUCC) if success, otherwise failure.
stop ppl.
axclError axcl_ppl_stop(axcl_ppl ppl);
parameter | description | in/out |
---|---|---|
ppl | ppl handle created | in |
0 (AXCL_SUCC) if success, otherwise failure.
send nalu frame to ppl.
axclError axcl_ppl_send_stream(axcl_ppl ppl, const axcl_ppl_input_stream* stream, AX_S32 timeout);
parameter | description | in/out |
---|---|---|
ppl | ppl handle created | in |
stream | nalu frame | in |
timeout | timeout in milliseconds | in |
typedef struct {
AX_U8 *nalu;
AX_U32 nalu_len;
AX_U64 pts;
AX_U64 userdata;
} axcl_ppl_input_stream;
parameter | description | in/out |
---|---|---|
nalu | pointer to nalu frame data | in |
nalu_len | bytes of nalu frame data | in |
pts | timestamp of nalu frame | in |
userdata | userdata bypass to axcl_ppl_encoded_stream.stPack.u64UserData | in |
0 (AXCL_SUCC) if success, otherwise failure.
get attribute of ppl.
axclError axcl_ppl_get_attr(axcl_ppl ppl, const char* name, void* attr);
parameter | description | in/out |
---|---|---|
ppl | ppl handle created | in |
name | attribute name | in |
attr | attribute value | out |
/**
* name attr type default
* axcl.ppl.id [R ] int32_t increment +1 for each axcl_ppl_create
*
* axcl.ppl.transcode.vdec.grp [R ] int32_t allocated by ax_vdec.ko
* axcl.ppl.transcode.ivps.grp [R ] int32_t allocated by ax_ivps.ko
* axcl.ppl.transcode.venc.chn [R ] int32_t allocated by ax_venc.ko
*
* the following attributes take effect BEFORE the axcl_ppl_create function is called:
* axcl.ppl.transcode.vdec.blk.cnt [R/W] uint32_t 8 depend on stream DPB size and decode mode
* axcl.ppl.transcode.vdec.out.depth [R/W] uint32_t 4 out fifo depth
* axcl.ppl.transcode.ivps.in.depth [R/W] uint32_t 4 in fifo depth
* axcl.ppl.transcode.ivps.out.depth [R ] uint32_t 0 out fifo depth
* axcl.ppl.transcode.ivps.blk.cnt [R/W] uint32_t 4
* axcl.ppl.transcode.ivps.engine [R/W] uint32_t AX_IVPS_ENGINE_VPP AX_IVPS_ENGINE_VPP|AX_IVPS_ENGINE_VGP|AX_IVPS_ENGINE_TDP
* axcl.ppl.transcode.venc.in.depth [R/W] uint32_t 4 in fifo depth
* axcl.ppl.transcode.venc.out.depth [R/W] uint32_t 4 out fifo depth
*/
0 (AXCL_SUCC) if success, otherwise failure.
set attribute of ppl.
axclError axcl_ppl_set_attr(axcl_ppl ppl, const char* name, const void* attr);
parameter | description | in/out |
---|---|---|
ppl | ppl handle created | in |
name | attribute name, refer to axcl_ppl_get_attr | in |
attr | attribute value | in |
0 (AXCL_SUCC) if success, otherwise failure.
typedef int32_t axclError;
typedef enum {
AXCL_SUCC = 0x00,
AXCL_FAIL = 0x01,
AXCL_ERR_UNKNOWN = AXCL_FAIL,
AXCL_ERR_NULL_POINTER = 0x02,
AXCL_ERR_ILLEGAL_PARAM = 0x03,
AXCL_ERR_UNSUPPORT = 0x04,
AXCL_ERR_TIMEOUT = 0x05,
AXCL_ERR_BUSY = 0x06,
AXCL_ERR_NO_MEMORY = 0x07,
AXCL_ERR_ENCODE = 0x08,
AXCL_ERR_DECODE = 0x09,
AXCL_ERR_UNEXPECT_RESPONSE = 0x0A,
AXCL_ERR_OPEN = 0x0B,
AXCL_ERR_EXECUTE_FAIL = 0x0C,
AXCL_ERR_BUTT = 0x7F
} AXCL_ERROR_E;
#define AX_ID_AXCL (0x30)
/* module */
#define AXCL_RUNTIME (0x00)
#define AXCL_NATIVE (0x01)
#define AXCL_LITE (0x02)
/* runtime sub module */
#define AXCL_RUNTIME_DEVICE (0x01)
#define AXCL_RUNTIME_CONTEXT (0x02)
#define AXCL_RUNTIME_STREAM (0x03)
#define AXCL_RUNTIME_TASK (0x04)
#define AXCL_RUNTIME_MEMORY (0x05)
#define AXCL_RUNTIME_CONFIG (0x06)
#define AXCL_RUNTIME_ENGINE (0x07)
#define AXCL_RUNTIME_SYSTEM (0x08)
/**
* |---------------------------------------------------------|
* | | MODULE | AX_ID_AXCL | SUB_MODULE | ERR_ID |
* |1|--- 7bits ---|--- 8bits ---|--- 8bits ---|--- 8bits ---|
**/
#define AXCL_DEF_ERR(module, sub, errid) \
((axclError)((0x80000000L) | (((module) & 0x7F) << 24) | ((AX_ID_AXCL) << 16 ) | ((sub) << 8) | (errid)))
#define AXCL_DEF_RUNTIME_ERR(sub, errid) AXCL_DEF_ERR(AXCL_RUNTIME, (sub), (errid))
#define AXCL_DEF_NATIVE_ERR(sub, errid) AXCL_DEF_ERR(AXCL_NATIVE, (sub), (errid))
#define AXCL_DEF_LITE_ERR(sub, errid) AXCL_DEF_ERR(AXCL_LITE, (sub), (errid))
Note:
Error codes are divided into two types: AXCL Runtime Library and AX NATIVE SDK error codes, distinguished by the third byte of axclError
.
If the third byte is equal to AX_ID_AXCL (0x30), it indicates an AXCL Runtime Library error code; otherwise, it indicates a Device-side AX NATIVE SDK module error code passed through to the HOST side.
axcl_rt_xxx.h
header file.Visit AXCL Error Code Parser to parse error codes online.