14. Kernel Loading and Execution
This topic describes the kernel loading and execution APIs of CANN Runtime, including binary loading, function obtaining, argument assembly, and kernel launch.
- Concept and Usage
aclError aclrtBinaryLoadFromFile(const char* binPath, aclrtBinaryLoadOptions *options, aclrtBinHandle *binHandle): Loads and parses an operator binary file from a file, and outputs binHandle pointing to the operator binary.aclError aclrtBinaryLoadFromData(const void *data, size_t length, const aclrtBinaryLoadOptions *options, aclrtBinHandle *binHandle): Loads and parses operator binary data from memory, and outputs binHandle pointing to the operator binary.aclError aclrtBinaryGetFunction(const aclrtBinHandle binHandle, const char *kernelName, aclrtFuncHandle *funcHandle): Obtains the kernel function based on its name, and expresses it using funcHandle.aclError aclrtBinaryGetFunctionByEntry(aclrtBinHandle binHandle, uint64_t funcEntry, aclrtFuncHandle *funcHandle): Obtains the kernel function handle based on the Function Entry.aclError aclrtBinaryGetFunctionCount(const aclrtBinHandle binHandle, uint32_t *count): Obtains the total number of kernel functions in the operator binary.aclError aclrtBinaryGetDevAddress(const aclrtBinHandle binHandle, void **binAddr, size_t *binSize): Obtains the memory address and memory size of the operator binary data on the device.aclError aclrtBinaryGetGlobal(aclrtBinHandle binHandle, const char *name, void **dptr, size_t *size): Obtains the address and size of the device-side global variable based on the global variable name.aclError aclrtBinarySetExceptionCallback(aclrtBinHandle binHandle, aclrtOpExceptionCallback callback, void *userData): Registers a callback function. If the callback function is set multiple times, the last setting takes effect.aclError aclrtGetArgsFromExceptionInfo(const aclrtExceptionInfo *info, void **devArgsPtr, uint32_t *devArgsLen): Obtains the arguments used when the user dispatches an operator execution task from the aclrtExceptionInfo exception information.aclError aclrtGetFuncHandleFromExceptionInfo(const aclrtExceptionInfo *info, aclrtFuncHandle *func): Obtains the kernel function handle from the aclrtExceptionInfo exception information.aclError aclrtGetFunctionAddr(const void *func, void **aicAddr, void **aivAddr): Obtains the start address of the operator on the device side of the kernel function.aclError aclrtGetFunctionSize(const void *func, size_t *aicSize, size_t *aivSize): Obtains the size of the kernel function code segment.aclError aclrtGetFunctionName(const void *func, uint32_t maxLen, char *name): Obtains the kernel function name.aclError aclrtGetFunctionAttribute(const void *func, aclrtFuncAttribute attrType, int64_t *attrValue): Obtains the kernel function attribute information.aclError aclrtGetHardwareSyncAddr(void **addr): Obtains the synchronization address between the Cube Core and the Vector Core.aclError aclrtRegisterCpuFunc(const aclrtBinHandle handle, const char *funcName, const char *kernelName, aclrtFuncHandle *funcHandle): Registers AI CPU operator information to obtain the corresponding funcHandle if the aclrtBinaryLoadFromData API is used to load AI CPU operator binary data.aclError aclrtKernelArgsInit(aclrtFuncHandle funcHandle, aclrtArgsHandle *argsHandle): Initializes the argument list based on the kernel function handle and obtains the handle that identifies the argument list.aclError aclrtKernelArgsInitByUserMem(aclrtFuncHandle funcHandle, aclrtArgsHandle argsHandle, void *userHostMem, size_t actualArgsSize): Initializes the argument list based on the kernel function handle and obtains the handle that identifies the argument list.aclError aclrtKernelArgsGetMemSize(aclrtFuncHandle funcHandle, size_t userArgsSize, size_t *actualArgsSize): Obtains the actual memory size required by the argument list during kernel launch.aclError aclrtKernelArgsGetHandleMemSize(aclrtFuncHandle funcHandle, size_t *memSize): Obtains the memory size occupied by the argument list handle.aclError aclrtKernelArgsAppend(aclrtArgsHandle argsHandle, void *param, size_t paramSize, aclrtParamHandle *paramHandle): Appends the argument values set by the user to the argument data area pointed to by argsHandle. If the argument list contains multiple arguments, append the arguments in sequence.aclError aclrtKernelArgsAppendPlaceHolder(aclrtArgsHandle argsHandle, aclrtParamHandle *paramHandle): Appends a placeholder for placeholder arguments. The return value is the paramHandle placeholder.aclError aclrtKernelArgsGetPlaceHolderBuffer(aclrtArgsHandle argsHandle, aclrtParamHandle paramHandle, size_t dataSize, void **bufferAddr): Obtains the memory address pointed to by the paramHandle placeholder based on the memory size specified by the user.aclError aclrtKernelArgsParaUpdate(aclrtArgsHandle argsHandle, aclrtParamHandle paramHandle, void *param, size_t paramSize): Updates values for arguments appended through the aclrtKernelArgsAppend API.aclError aclrtKernelArgsFinalize(aclrtArgsHandle argsHandle): Finalizes argument assembly after all arguments are appended.aclError aclrtLaunchKernel(aclrtFuncHandle funcHandle, uint32_t numBlocks, const void *argsData, size_t argsSize, aclrtStream stream): Launches the computation task of the corresponding operator. This is an asynchronous API. The operator here is a custom operator developed using Ascend C.aclError aclrtLaunchKernelV2(aclrtFuncHandle funcHandle, uint32_t numBlocks, const void *argsData, size_t argsSize, aclrtLaunchKernelCfg *cfg, aclrtStream stream): Specifies the configuration information for task dispatch and launches the computation task of the corresponding operator. This is an asynchronous API.aclError aclrtLaunchKernelWithConfig(aclrtFuncHandle funcHandle, uint32_t numBlocks, aclrtStream stream, aclrtLaunchKernelCfg *cfg, aclrtArgsHandle argsHandle, void *reserve): Specifies the configuration information for task dispatch and launches the computation task of the corresponding operator. This is an asynchronous API.aclError aclrtLaunchKernelWithHostArgs(aclrtFuncHandle funcHandle, uint32_t numBlocks, aclrtStream stream, aclrtLaunchKernelCfg *cfg, void *hostArgs, size_t argsSize, aclrtPlaceHolderInfo *placeHolderArray, size_t placeHolderNum): Specifies the configuration information for task dispatch and launches the computation task of the corresponding operator. This is an asynchronous API.aclError aclrtLaunchKernelWithArgsArray(void *func, uint32_t numBlocks, aclrtStream stream, aclrtLaunchKernelCfg *cfg, void **args): Launches the kernel function computation task using an argument array. This is an asynchronous API.aclrtBinary aclrtCreateBinary(const void *data, size_t dataLen): Creates data of the aclrtBinary type, which is used to describe operator binary information. The operator here is a custom operator developed using Ascend C.aclError aclrtDestroyBinary(aclrtBinary binary): Destroys data of the aclrtBinary type created through the aclrtCreateBinary API.aclError aclrtBinaryLoad(const aclrtBinary binary, aclrtBinHandle *binHandle): Parses and loads the operator binary file, outputs the binHandle pointing to the operator binary, and copies the operator binary file data to the device corresponding to the current context.aclError aclrtBinaryUnLoad(aclrtBinHandle binHandle): Deletes the operator binary data pointed to by binHandle, and also deletes the operator binary data copied to the device when loading the operator binary file.aclError aclrtFunctionGetBinary(const void *func, aclrtBinHandle *binHandle): Obtains the operator binary handle.aclError aclrtFunctionGetParamCount(const void *func, size_t *paramCount): Obtains the number of kernel function parameters.aclError aclrtFunctionGetParamInfo(const void *func, size_t paramIndex, size_t *paramOffset, size_t *paramSize): Obtains kernel function parameter information.aclError aclrtFunctionGetAvailDynUbufPerBlock(const void *func, uint32_t flags, size_t *dynamicUbufSize): Obtains the size of the dynamic UB buffer available for each block.aclError aclrtGetFuncBySymbol(const void *symbol, aclrtFuncHandle *funcHandle): Obtains the kernel function handle based on the kernel function name.aclError aclrtLaunchSIMTKernelWithArgsArray(void *func, dim3 gridDim, dim3 blockDim, size_t dynUbufSize, aclrtStream stream, aclrtLaunchKernelCfg *cfg, void **args): Launches a SIMT kernel function computation task using an argument array. This is an asynchronous API.aclError aclrtLaunchSIMTKernelWithHostArgs(void *func, dim3 gridDim, dim3 blockDim, size_t dynUbufSize, aclrtStream stream, aclrtLaunchKernelCfg *cfg, void *hostArgs, size_t argsSize, aclrtPlaceHolderInfo *placeHolderArray, size_t placeHolderNum): Launches a SIMT kernel function computation task using host arguments. This is an asynchronous API.aclError aclrtBinaryEnumerateFunctions(const aclrtBinHandle binHandle, aclrtFuncHandle *funcHandles, uint32_t numFunctions): Obtains a specified number of kernel function handles from the operator binary.
Concept and Usage
Concepts
The APIs in this topic involve operations on the operator binary, kernel function, kernel function argument list, and parameters of an operator. For easier understanding, you can first refer to the following figure to see the relationships among them.

-
Operator binary: Compile the operator source code to obtain the operator binary file *.o. For CANN built-in operators, you can obtain the operator binary file from the operator binary package (package name: Ascend-cann-*-ops-*.run). For custom operators, you can obtain the operator binary file after compiling the operator and publishing the binary.
For the development and compilation of custom operators, see Ascend C Operator Development Guide.
-
Kernel function: an entry function of the device-side implementation of an operator. Currently, the syntax extension of C/C++ functions is allowed for writing device-side execution code. Users perform data access and computation operations in the kernel function, thereby implementing all features of the operator.
Kernel Loading and Execution API Call Flow

The key process is described as follows:
-
Call the aclInit API for initialization.
-
Apply for runtime resources, including calling the aclrtSetDevice API to specify the device used for computation and calling the aclrtCreateStream API to create a stream.
-
Call the aclrtBinaryLoadFromFile API to load the operator binary file.
AI CPU operators also support loading operator binary data from memory (by calling the aclrtBinaryLoadFromData API). However, after loading the operator binary data, you also need to use the aclrtRegisterCpuFunc API to register the AI CPU operator information.
-
Call the aclrtBinaryGetFunctionByEntry or aclrtBinaryGetFunction API to obtain the kernel function handle.
-
(Optional) Operate the argument list based on the kernel function handle. The operations include:
-
Initialize the argument list
Currently, two methods are supported: memory managed by the system (by calling the aclrtKernelArgsInit API) and memory managed by the user (by calling the aclrtKernelArgsInitByUserMem API).
-
Append arguments and update the values
The kernel function argument list contains arguments of different types, such as pointer-type arguments, placeholders, and uint8_t-type arguments, where:
- Pointer-type argument: Its value is a device memory address. Generally, the inputs and outputs of an operator are arguments of this type. The user needs to call a device memory request API (for example, the aclrtMalloc API) in advance to request memory and copy data to the device side.
- Placeholder: This is also a pointer-type argument, but the difference is that the user does not need to manually copy the argument data to the device; this operation is completed by Runtime. When appending arguments, Runtime does not fill in the actual device address. Instead, the actual device address is refreshed only when the kernel is launched, hence the name "placeholder". For non-input and non-output arguments of an operator, the placeholder can be used to merge the host->device copy of small blocks of data (recommended to be less than 2 KB) into a single copy operation at kernel launch, reducing the number of copies and improving performance.

Call different argument appending APIs for different types of arguments.
- For placeholder arguments, because the associated memory must be placed after all arguments, when appending arguments, first call the aclrtKernelArgsAppendPlaceHolder API to reserve a placeholder. After all arguments have been appended, call the aclrtKernelArgsGetPlaceHolderBuffer API to obtain the memory address pointed to by the corresponding placeholder. The user can manage the data in that memory based on the obtained memory address.
- For non-placeholder arguments (for example, pointer-type arguments and uint8_t-type arguments), call the aclrtKernelArgsAppend API to append the argument values set by the user to the argument data area pointed to by argsHandle. To update argument values, call the aclrtKernelArgsParaUpdate API.
Note: The kernel function argument list may actually contain multiple arguments, and arguments of different types may appear interleaved. Therefore, arguments must be appended from left to right in the order in which they appear in the argument list, and a maximum of 128 arguments can be appended.
-
End appending to the argument list and update argument values
After all arguments are appended, call aclrtKernelArgsFinalize to finalize the argument assembly. However, after aclrtKernelArgsFinalize, argument values can still be updated. After the update, call aclrtKernelArgsFinalize once again.
-
-
Call the kernel launch API to launch the computation task of the corresponding operator.
If the aclrtArgsHandle argument list handle is used to assemble the input argument data of the kernel function, call aclrtLaunchKernelWithConfig to launch the computation task of the corresponding operator. In this mode, you only need to append arguments to the argument list in sequence, without paying attention to the assembly details in memory or the internal arguments.
If the input argument data of the kernel function is all stored in host or device memory, call aclrtLaunchKernel, aclrtLaunchKernelV2, or aclrtLaunchKernelWithHostArgs to launch the computation task of the corresponding operator.
-
Call aclrtBinaryUnLoad to unload the operator binary file.
-
Release runtime resources, including calling aclrtDestroyStream to release the stream and calling aclrtResetDevice to release resources on the device.
-
Call aclFinalize for deinitialization.
aclrtBinaryLoadFromFile
aclError aclrtBinaryLoadFromFile(const char* binPath, aclrtBinaryLoadOptions *options, aclrtBinHandle *binHandle)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Loads and parses an operator binary file from a file, and outputs binHandle pointing to the operator binary.
For AI Core operators, if this API is used to load and parse an operator binary file, it must be used together with aclrtLaunchKernelWithConfig, aclrtLaunchKernelV2, or aclrtLaunchKernelWithHostArgs to dispatch a computation task.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| binPath | Input | Path of the operator binary file (.o file), which must be an absolute path. For AI CPU operators, this parameter supports passing the operator information library file (*.json). |
| options | Input | Optional parameters for loading the operator binary file. For details about the type definition, see aclrtBinaryLoadOptions. |
| binHandle | Output | Handle that identifies the operator binary. For details about the type definition, see aclrtBinHandle. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
Constraints
An operator binary compiled for a specific product model must be used on a product of the same model.
aclrtBinaryLoadFromData
aclError aclrtBinaryLoadFromData(const void *data, size_t length, const aclrtBinaryLoadOptions *options, aclrtBinHandle *binHandle)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Loads and parses operator binary data from memory, and outputs binHandle pointing to the operator binary.
When this API is used to load AI CPU operator information (aclrtBinaryLoadOption.type contains ACL_RT_BINARY_LOAD_OPT_CPU_KERNEL_MODE), it also needs to cooperate with the aclrtRegisterCpuFunc API to register the AI CPU operator.
Note that the system only loads the operator to the device corresponding to the current context. Therefore, when calling the aclrtLaunchKernelWithConfig API to launch the operator computation task, the device must be the same as the device on which the operator is loaded.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| data | Input | Host memory address that stores the operator binary data. It cannot be empty. |
| length | Input | Memory size of the operator binary data. It must be greater than 0, in bytes. |
| options | Input | Optional parameters for loading the operator binary file. For details about the type definition, see aclrtBinaryLoadOptions. |
| binHandle | Output | Handle that identifies the operator binary. For details about the type definition, see aclrtBinHandle. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
aclrtBinaryGetFunction
aclError aclrtBinaryGetFunction(const aclrtBinHandle binHandle, const char *kernelName, aclrtFuncHandle *funcHandle)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Obtains the kernel function based on its name, and expresses it using funcHandle.
For the same binHandle, when the aclrtBinaryGetFunction API is called for the first time, the operator binary data associated with binHandle is copied to the device corresponding to the current context by default.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| binHandle | Input | Operator binary handle. For details about the type definition, see aclrtBinHandle. Call the aclrtBinaryLoadFromFile API or the aclrtBinaryLoadFromData API to obtain the operator binary handle, and then pass it as an input parameter to this API. |
| kernelName | Input | Kernel function name. |
| funcHandle | Output | Kernel function handle. For details about the type definition, see aclrtFuncHandle. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
aclrtBinaryGetFunctionByEntry
aclError aclrtBinaryGetFunctionByEntry(aclrtBinHandle binHandle, uint64_t funcEntry, aclrtFuncHandle *funcHandle)
Caution: This API is reserved and not supported yet.
Description
Obtains the kernel function handle based on the Function Entry.
For the same binHandle, when the aclrtBinaryGetFunctionByEntry API is called for the first time, the operator binary data associated with binHandle is copied to the device corresponding to the current context by default.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| binHandle | Input | Operator binary handle. For details about the type definition, see aclrtBinHandle. Call the aclrtBinaryLoadFromFile API or the aclrtBinaryLoadFromData API to obtain the operator binary handle, and then pass it as an input parameter to this API. |
| funcEntry | Input | Keyword that identifies the kernel function. |
| funcHandle | Output | Kernel function handle. For details about the type definition, see aclrtFuncHandle. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
aclrtBinaryGetDevAddress
aclError aclrtBinaryGetDevAddress(const aclrtBinHandle binHandle, void **binAddr, size_t *binSize)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Obtains the memory address and memory size of the operator binary data on the device.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| binHandle | Input | Operator binary handle. For details about the type definition, see aclrtBinHandle. Call the aclrtBinaryLoadFromFile API or the aclrtBinaryLoadFromData API to obtain the operator binary handle, and then pass it as an input parameter to this API. |
| binAddr | Output | Memory address of the operator binary data on the device. If the lazy loading flag is set when loading the operator binary (set aclrtBinaryLoadOptions.aclrtBinaryLoadOption.aclrtBinaryLoadOptionValue.isLazyLoad to 1), the binAddr obtained by calling this API is a null pointer. |
| binSize | Output | Size of the operator binary data, in bytes. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
aclrtBinaryGetGlobal
aclError aclrtBinaryGetGlobal(aclrtBinHandle binHandle, const char *name, void **dptr, size_t *size)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Obtains the memory address and size of the device-side global variable in the operator binary based on the global variable name.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| binHandle | Input | Operator binary handle. For details about the type definition, see aclrtBinHandle. Call the aclrtBinaryLoadFromFile API or the aclrtBinaryLoadFromData API to obtain the operator binary handle, and then pass it as an input parameter to this API. |
| name | Input | Global variable name. It must be consistent with the global variable name defined in the operator binary. |
| dptr | Output | Pointer to the address of the global variable on the device side. If nullptr is passed here, the address is not obtained. |
| size | Output | Size of the global variable on the device side, in bytes. If nullptr is passed here, the size is not obtained. dptr and size cannot both be nullptr. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
aclrtBinarySetExceptionCallback
aclError aclrtBinarySetExceptionCallback(aclrtBinHandle binHandle, aclrtOpExceptionCallback callback, void *userData)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Registers a callback function. If the callback function is set multiple times, the last setting takes effect.
Before executing an operator, call this API to register a callback function. If an exception occurs during operator execution, the callback function is triggered, and the exception information is stored in the aclrtExceptionInfo struct. Then, you can call aclrtGetArgsFromExceptionInfo and aclrtGetFuncHandleFromExceptionInfo to obtain, from the exception information, the arguments and the kernel function handle used when the user dispatches the operator execution task. Currently, exception information can be obtained for AI Core operators or AI CPU operators.
Parameters
| Parameter | Input/Output | Description |
|---|---|---|
| binHandle | Input | Operator binary handle. Call aclrtBinaryLoadFromFile or aclrtBinaryLoadFromData to obtain the operator binary handle, and then pass it as an input parameter to this API. For details about the value, see aclrtBinHandle. |
| callback | Input | Callback function to be registered. The prototype of the callback function is: typedef void (aclrtOpExceptionCallback)(aclrtExceptionInfoexceptionInfo, void *userData); |
| userData | Input | Pointer to the user data to be passed to the callback function. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
aclrtGetArgsFromExceptionInfo
aclError aclrtGetArgsFromExceptionInfo(const aclrtExceptionInfo *info, void **devArgsPtr, uint32_t *devArgsLen)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Obtains the arguments used when the user dispatches an operator execution task from the aclrtExceptionInfo exception information. This API is used together with the aclrtBinarySetExceptionCallback API.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| info | Input | Pointer to exception information. |
| devArgsPtr | Output | Arguments used when the user dispatches an operator execution task. |
| devArgsLen | Output | Number of arguments. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
Returns ACL_ERROR_INVALID_EXCEPTION_INFO when info is a null pointer.
aclrtGetFuncHandleFromExceptionInfo
aclError aclrtGetFuncHandleFromExceptionInfo(const aclrtExceptionInfo *info, aclrtFuncHandle *func)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Obtains the kernel function handle from the aclrtExceptionInfo exception information. This API is used together with the aclrtBinarySetExceptionCallback API.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| info | Input | Pointer to exception information. |
| func | Output | Kernel function handle. For details about the type definition, see aclrtFuncHandle. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
Returns ACL_ERROR_INVALID_EXCEPTION_INFO when info is a null pointer.
aclrtGetFunctionAddr
aclError aclrtGetFunctionAddr(const void *func, void **aicAddr, void **aivAddr)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Obtains the start address of the operator on the device side of the kernel function.
The AI data processing core units vary across products. For the definition and details of Core, see aclrtDevAttr.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| func | Input | Kernel function pointer. This can be a kernel function name declared with __global__ (for example, myKernel, applicable only to the scenario where custom operators are developed in Ascend C and host and device code are compiled together based on the BiSheng compiler), or a kernel function handle of the aclrtFuncHandle type. |
| aicAddr | Output | Start address of the operator on the AI Core or Cube Core. - For the following products, the start address of the operator on the Cube Core is returned here: Ascend 950PR/Ascend 950DT Atlas A3 training products/Atlas A3 inference products Atlas A2 training products/Atlas A2 inference products |
| aivAddr | Output | Start address of the operator on the Vector Core. If the aivAddr obtained through this API is empty, the operator is not executed on the Vector Core. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
aclrtGetFunctionSize
aclError aclrtGetFunctionSize(const void *func, size_t *aicSize, size_t *aivSize)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Not supported
- Atlas inference products: Supported
- Atlas training products: Not supported
Description
Obtains the size of the kernel function code segment.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| func | Input | Kernel function pointer. This can be a kernel function name declared with __global__ (for example, myKernel, which is applicable only to the scenario where custom operators are developed in Ascend C and host and device code are compiled together based on the BiSheng compiler), or a kernel function handle of the aclrtFuncHandle type. |
| aicSize | Output | Size of the code segment for executing the operator on the AI Core or Cube Core, in bytes. If the operator is executed only on the Vector Core, this value is 0. |
| aivSize | Output | Size of the code segment for executing the operator on the Vector Core, in bytes. If the operator is executed only on the AI Core or Cube Core, this value is 0. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
aclrtGetFunctionName
aclError aclrtGetFunctionName(const void *func, uint32_t maxLen, char *name)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Obtains the kernel function name.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| func | Input | Kernel function pointer. This can be a kernel function name declared with __global__ (for example, myKernel, which is applicable only to the scenario where custom operators are developed in Ascend C and host and device code are compiled together based on the BiSheng compiler), or a kernel function handle of the aclrtFuncHandle type. |
| maxLen | Input | Buffer capacity, in bytes, that the user requests to store the kernel function name. The value of maxLen must be greater than or equal to the byte length of the kernel function name plus 1 to accommodate the trailing null character \0. If the capacity is insufficient, the API returns a parameter error. |
| name | Output | Kernel function name. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
aclrtGetFunctionAttribute
aclError aclrtGetFunctionAttribute(const void *func, aclrtFuncAttribute attrType, int64_t *attrValue)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Obtains the kernel function attribute information in the operator binary file.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| func | Input | Kernel function pointer. This can be a kernel function name declared with __global__ (for example, myKernel, which is applicable only to the scenario where custom operators are developed in Ascend C and host and device code are compiled together based on the BiSheng compiler), or a kernel function handle of the aclrtFuncHandle type. |
| attrType | Input | Attribute. For details about the type definition, see aclrtFuncAttribute. |
| attrValue | Output | Attribute value. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
aclrtGetHardwareSyncAddr
aclError aclrtGetHardwareSyncAddr(void **addr)
Applicable Products
- Ascend 950PR&950DT products: Not supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Not supported
- Atlas inference products: Not supported
- Atlas training products: Not supported
Description
Obtains the synchronization address between the Cube Core and the Vector Core.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| addr | Output | Synchronization address. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
aclrtRegisterCpuFunc
aclError aclrtRegisterCpuFunc(const aclrtBinHandle handle, const char *funcName, const char *kernelName, aclrtFuncHandle *funcHandle)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Registers AI CPU operator information to obtain the corresponding funcHandle if the aclrtBinaryLoadFromData API is used to load AI CPU operator binary data.
This API is used only for AI CPU operators. For other operators, error ACL_ERROR_RT_PARAM_INVALID is returned.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| handle | Input | Operator binary handle. For the type definition, see aclrtBinHandle Call the aclrtBinaryLoadFromData API to obtain the operator binary handle, and then pass it as an input parameter to this API. |
| funcName | Input | Entry function for executing the AI CPU operator. It cannot be empty. |
| kernelName | Input | opType of the AI CPU operator. It cannot be empty. |
| funcHandle | Output | Function handle. For the type definition, see aclrtFuncHandle. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
aclrtKernelArgsInit
aclError aclrtKernelArgsInit(aclrtFuncHandle funcHandle, aclrtArgsHandle *argsHandle)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Initializes the argument list based on the kernel function handle and obtains the handle that identifies the argument list.
The difference from the aclrtKernelArgsInitByUserMem API is that calling this API indicates that the memory is managed by the system.
After the argument list is initialized, when arguments are appended through APIs such as aclrtKernelArgsAppend and aclrtKernelArgsAppendPlaceHolder, it is recommended that the number of appended arguments be consistent with the number of arguments required by the kernel function. For compatibility with operator kernel functions in earlier versions, the upper limit of the number of arguments checked by Runtime is 128. If the number of appended arguments exceeds this upper limit, the API returns an error.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| funcHandle | Input | Kernel function handle. For details about the type definition, see aclrtFuncHandle. Call aclrtBinaryGetFunctionByEntry or aclrtBinaryGetFunction to obtain the kernel function handle, and then pass it as an input parameter to this API. |
| argsHandle | Output | Argument list handle. For details about the type definition, see aclrtArgsHandle. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
aclrtKernelArgsInitByUserMem
aclError aclrtKernelArgsInitByUserMem(aclrtFuncHandle funcHandle, aclrtArgsHandle argsHandle, void *userHostMem, size_t actualArgsSize)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Initializes the argument list based on the kernel function handle and obtains the handle that identifies the argument list.
The difference from the aclrtKernelArgsInit API is that calling this API indicates that the memory is managed by the user.
After the argument list is initialized, when arguments are appended through APIs such as aclrtKernelArgsAppend and aclrtKernelArgsAppendPlaceHolder, it is recommended that the number of appended arguments be consistent with the number of arguments required by the kernel function. For compatibility with operator kernel functions in earlier versions, the upper limit of the number of arguments checked by Runtime is 128. If the number of appended arguments exceeds this upper limit, the API returns an error.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| funcHandle | Input | Kernel function handle. For details about the type definition, see aclrtFuncHandle. Call aclrtBinaryGetFunctionByEntry or aclrtBinaryGetFunction to obtain the kernel function handle, and then pass it as an input parameter to this API. |
| argsHandle | Output | Argument list handle. For details about the type definition, see aclrtArgsHandle. Call the aclrtKernelArgsGetHandleMemSize API in advance to obtain the memory size, request host memory, and then pass the host memory address as an input parameter here. |
| userHostMem | Input | Host memory address. Call the aclrtKernelArgsGetMemSize API in advance to obtain the memory size, request host memory, and then pass the host memory address as an input parameter here. |
| actualArgsSize | Input | Memory size. Call the aclrtKernelArgsGetMemSize API in advance to obtain the memory size, and then pass it as an input parameter here. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
aclrtKernelArgsGetMemSize
aclError aclrtKernelArgsGetMemSize(aclrtFuncHandle funcHandle, size_t userArgsSize, size_t *actualArgsSize)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Obtains the actual memory size required by the argument list during kernel launch.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| funcHandle | Input | Kernel function handle. For details about the type definition, see aclrtFuncHandle. |
| userArgsSize | Input | Size required to store the argument list data in memory, in bytes. The memory size of each argument data must be 8-byte aligned. userArgsSize here is the sum of the memory sizes of these aligned argument data. |
| actualArgsSize | Output | Actual memory size required by the argument list during kernel launch, in bytes. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
aclrtKernelArgsGetHandleMemSize
aclError aclrtKernelArgsGetHandleMemSize(aclrtFuncHandle funcHandle, size_t *memSize)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Obtains the memory size occupied by the argument list handle.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| funcHandle | Input | Kernel function handle. For details about the type definition, see aclrtFuncHandle. |
| memSize | Output | Memory size occupied by the argument list handle, in bytes. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
aclrtKernelArgsAppend
aclError aclrtKernelArgsAppend(aclrtArgsHandle argsHandle, void *param, size_t paramSize, aclrtParamHandle *paramHandle)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Appends the argument values set by the user to the argument data area pointed to by argsHandle. If the argument list contains multiple arguments, append the arguments in sequence.
To update an argument value, call aclrtKernelArgsParaUpdate.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| argsHandle | Input | Argument list handle. For details about the type definition, see aclrtArgsHandle. |
| param | Input | Memory address of the argument value to be appended. This is a host memory address. |
| paramSize | Input | Memory size, in bytes. |
| paramHandle | Output | Parameter handle. For details about the type definition, see aclrtParamHandle. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
aclrtKernelArgsAppendPlaceHolder
aclError aclrtKernelArgsAppendPlaceHolder(aclrtArgsHandle argsHandle, aclrtParamHandle *paramHandle)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Appends a placeholder for placeholder arguments. The return value is the paramHandle placeholder.
If the argument list contains multiple arguments, append them in sequence. After all arguments are appended, call aclrtKernelArgsGetPlaceHolderBuffer to obtain the memory address pointed to by the paramHandle placeholder.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| argsHandle | Input | Argument list handle. For details about the type definition, see aclrtArgsHandle. |
| paramHandle | Output | Parameter handle. For details about the type definition, see aclrtParamHandle. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
aclrtKernelArgsGetPlaceHolderBuffer
aclError aclrtKernelArgsGetPlaceHolderBuffer(aclrtArgsHandle argsHandle, aclrtParamHandle paramHandle, size_t dataSize, void **bufferAddr)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Obtains the memory address pointed to by the paramHandle placeholder based on the memory size specified by the user.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| argsHandle | Input | Argument list handle. For details about the type definition, see aclrtArgsHandle. |
| paramHandle | Input | Parameter handle. For details about the type definition, see aclrtParamHandle. The paramHandle here must be consistent with the paramHandle in the aclrtKernelArgsAppendPlaceHolder API. |
| dataSize | Input | Memory size. |
| bufferAddr | Output | Memory address pointed to by the paramHandle placeholder. The data in this memory is subsequently managed by the user, but the user does not need to manage the lifecycle of this memory. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
aclrtKernelArgsParaUpdate
aclError aclrtKernelArgsParaUpdate(aclrtArgsHandle argsHandle, aclrtParamHandle paramHandle, void *param, size_t paramSize)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Updates values for arguments appended through the aclrtKernelArgsAppend API.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| argsHandle | Input | Argument list handle. For details about the type definition, see aclrtArgsHandle. |
| paramHandle | Input | Parameter handle. For details about the type definition, see aclrtParamHandle. |
| param | Input | Memory address of the argument value to be updated. This is a host memory address. |
| paramSize | Input | Memory size, in bytes. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
aclrtKernelArgsFinalize
aclError aclrtKernelArgsFinalize(aclrtArgsHandle argsHandle)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Finalizes argument assembly after all arguments are appended.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| argsHandle | Input | Argument list handle. For details about the type definition, see aclrtArgsHandle. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
aclrtLaunchKernel
aclError aclrtLaunchKernel(aclrtFuncHandle funcHandle, uint32_t numBlocks, const void *argsData, size_t argsSize, aclrtStream stream)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Launches the computation task of the corresponding operator. This is an asynchronous API. The operator here is a custom operator developed using the Ascend C language.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| funcHandle | Input | Kernel function handle. For details about the type definition, see aclrtFuncHandle. Call aclrtBinaryGetFunction to obtain funcHandle based on kernelName. |
| numBlocks | Input | Number of cores on which the kernel function will be executed. |
| argsData | Input | Pointer to the device memory address that stores all input argument data of the kernel function. For details about the memory request API, see Memory Management. Note that the device that executes the task dispatched by this API must be the same device as the one whose memory is used in argsData. |
| argsSize | Input | Size of the argsData argument value, in bytes. |
| stream | Input | Stream on which the task is executed. For details about the type definition, see aclrtStream. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
Reference Resources
The following APIs are all used to launch the computation task of the corresponding operator, but they differ in functionality and usage.
| API | Method of Passing Kernel Function Argument Values | Position of Storing Kernel Function Argument Values | Whether Task Dispatch Configuration Can Be Specified |
|---|---|---|---|
| aclrtLaunchKernel | Specifies the device memory address pointer that stores all input argument data of the kernel function in the API. | Device memory | No |
| aclrtLaunchKernelV2 | Specifies the device memory address pointer that stores all input parameter data of the kernel function in the API. | Device memory | Yes |
| aclrtLaunchKernelWithConfig | Specifies the argument list handle aclrtArgsHandle in the API. | Host memory | Yes |
| aclrtLaunchKernelWithHostArgs | Specifies the host memory address pointer that stores all input argument data of the kernel function in the API. | Host memory | Yes |
| aclrtLaunchKernelWithArgsArray | Specifies an argument array pointer in the API, where each element points to a parameter data record. | Host memory | Yes |
| aclrtLaunchSIMTKernelWithArgsArray | Used for SIMT kernel functions to specify an argument array pointer in the API, where each element points to a parameter data record. | Host memory | Yes |
| aclrtLaunchSIMTKernelWithHostArgs | Used for SIMT kernel functions to specify the host memory address pointer that stores all input argument data of the kernel function in the API. | Host memory | Yes |
aclrtLaunchKernelV2
aclError aclrtLaunchKernelV2(aclrtFuncHandle funcHandle, uint32_t numBlocks, const void *argsData, size_t argsSize, aclrtLaunchKernelCfg *cfg, aclrtStream stream)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Specifies the configuration information for task dispatch and launches the computation task of the corresponding operator. This is an asynchronous API.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| funcHandle | Input | Kernel function handle. For details about the type definition, see aclrtFuncHandle. |
| numBlocks | Input | Number of cores on which the kernel function will be executed. |
| argsData | Input | Device memory address pointer that stores all input argument data of the kernel function. For details about the memory request API, see Memory Management. Note that the device that executes the task dispatched by this API must be the same device as the one whose memory is used in argsData. |
| argsSize | Input | Size of the argsData argument value, in bytes. |
| cfg | Input | Configuration information for task dispatch. For details about the type definition, see aclrtLaunchKernelCfg. If no configuration is specified, NULL can be passed here. |
| stream | Input | Stream on which the task is executed. For details about the type definition, see aclrtStream. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
Reference Resources
For a comparison of the features and usage of each launch API, see the launch API comparison table.
aclrtLaunchKernelWithConfig
aclError aclrtLaunchKernelWithConfig(aclrtFuncHandle funcHandle, uint32_t numBlocks, aclrtStream stream, aclrtLaunchKernelCfg *cfg, aclrtArgsHandle argsHandle, void *reserve)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Specifies the configuration information for task dispatch and launches the computation task of the corresponding operator. This is an asynchronous API.
If this API is used to dispatch the computation task of an AI Core operator, it must be used together with the aclrtBinaryLoadFromFile API to load and parse the operator binary file.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| funcHandle | Input | Kernel function handle. For details about the type definition, see aclrtFuncHandle. |
| numBlocks | Input | Number of cores on which the kernel function will be executed. |
| stream | Input | Stream on which the task is executed. For details about the type definition, see aclrtStream. |
| cfg | Input | Configuration information for task dispatch. For details about the type definition, see aclrtLaunchKernelCfg. If no configuration is specified, NULL can be passed here. |
| argsHandle | Input | Argument list handle. For details about the type definition, see aclrtArgsHandle. |
| reserve | Input | Reserved parameter. Currently, NULL must be passed. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
Reference Resources
For a comparison of the features and usage of each launch API, see the launch API comparison table.
aclrtLaunchKernelWithHostArgs
aclError aclrtLaunchKernelWithHostArgs(aclrtFuncHandle funcHandle, uint32_t numBlocks, aclrtStream stream, aclrtLaunchKernelCfg *cfg, void *hostArgs, size_t argsSize, aclrtPlaceHolderInfo *placeHolderArray, size_t placeHolderNum)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Specifies the configuration information for task dispatch and launches the computation task of the corresponding operator. This is an asynchronous API.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| funcHandle | Input | Kernel function handle. For details about the type definition, see aclrtFuncHandle. |
| numBlocks | Input | Number of cores on which the kernel function will be executed. |
| stream | Input | Stream on which the task is executed. For details about the type definition, see aclrtStream. |
| cfg | Input | Configuration information for task dispatch. For details about the type definition, see aclrtLaunchKernelCfg. If no configuration is specified, NULL can be passed here. |
| hostArgs | Input | Host memory address pointer that stores all input argument data of the kernel function. |
| argsSize | Input | Size of the hostArgs parameter value, in bytes. |
| placeHolderArray | Input | Placeholder parameter array. For details about the type definition, see aclrtPlaceHolderInfo. |
| placeHolderNum | Input | Size of the placeholder parameter array. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
Reference Resources
For a comparison of the features and usage of each launch API, see the launch API comparison table.
aclrtLaunchKernelWithArgsArray
aclError aclrtLaunchKernelWithArgsArray(void *func, uint32_t numBlocks, aclrtStream stream, aclrtLaunchKernelCfg *cfg, void **args)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Passes kernel function input arguments in the form of an argument array and launches the computation task of the corresponding operator. This is an asynchronous API.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| func | Input | Kernel function pointer. This can be a kernel function name declared with __global__ (for example, myKernel, which is applicable only to the scenario where custom operators are developed in Ascend C and host and device code are compiled together based on the BiSheng compiler), or a kernel function handle of the aclrtFuncHandle type. |
| numBlocks | Input | Number of cores on which the kernel function will be executed. |
| stream | Input | Stream on which the task is executed. For details about the type definition, see aclrtStream. |
| cfg | Input | Configuration information for task dispatch. For details about the type definition, see aclrtLaunchKernelCfg. If no configuration is specified, NULL can be passed here. |
| args | Input | Argument array pointer. Each element in the argument array points to the memory address of the kernel function argument data on the host side. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
Constraints
- This API does not support dispatching AI CPU operators; otherwise, ACL_ERROR_RT_FEATURE_NOT_SUPPORT is returned.
- The order of elements in the argument array must be consistent with the order of kernel function arguments, and the size of the argument array must be consistent with the number of kernel function arguments; otherwise, undefined behavior occurs.
Reference Resources
For a comparison of the features and usage of each launch API, see the launch API comparison table.
aclrtCreateBinary
aclrtBinary aclrtCreateBinary(const void *data, size_t dataLen)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Creates data of the aclrtBinary type, which is used to describe operator binary information. The operator here refers to a custom operator developed using the Ascend C language.
To destroy data of the aclrtBinary type, see aclrtDestroyBinary.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| data | Input | Memory address pointer that stores the operator binary file (*.o file) data. In the Ascend EP standard form, memory on the host must be requested here; in the Ascend RC form or the control CPU open form, memory on the device must be requested here. |
| dataLen | Input | Memory size, in bytes. |
Return Values
Returns a pointer of the aclrtBinary type.
Constraints
In the Ascend EP standard form, the data parameter requires memory requested on the host.
In the Ascend RC form or control CPU open form, the data parameter requires memory requested on the device.
aclrtDestroyBinary
aclError aclrtDestroyBinary(aclrtBinary binary)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Destroys data of the aclrtBinary type created by the aclrtCreateBinary API. The operator here is a custom operator developed using Ascend C.
Note that this API only destroys the aclrtBinary data. The data memory passed in when calling the aclrtCreateBinary API must be released by the user in a timely manner; otherwise, memory exceptions may occur.
Parameters
| Parameter | Input/Output | Description |
|---|---|---|
| binary | Input | aclrtBinary data to be destroyed. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
aclrtBinaryLoad
aclError aclrtBinaryLoad(const aclrtBinary binary, aclrtBinHandle *binHandle)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Loads and parses the operator binary file, outputs the binHandle pointing to the operator binary, and copies the operator binary file data to the device corresponding to the current context. The operator here is a custom operator developed using the Ascend C language.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| binary | Input | Operator binary information. Before calling this API, call aclrtCreateBinary to obtain the pointer to the data of the aclrtBinary type. |
| binHandle | Output | Handle pointing to the binary. For details about the type definition, see aclrtBinHandle. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
aclrtBinaryUnLoad
aclError aclrtBinaryUnLoad(aclrtBinHandle binHandle)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Deletes the operator binary data pointed to by binHandle, and also deletes the operator binary data copied to the device when the operator binary file is loaded.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| binHandle | Input | Operator binary handle. For details about the type definition, see aclrtBinHandle. This handle is generated when calling aclrtBinaryLoadFromFile, aclrtBinaryLoadFromData, or aclrtBinaryLoad. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
Constraints
- When calling this API to delete operator binary data, it must be used in the same context as aclrtBinaryLoadFromFile, aclrtBinaryLoadFromData, or aclrtBinaryLoad, so that the operator binary data copied to the device when loading the operator binary file can be deleted together. Otherwise, the operator binary data on the device may be deleted abnormally.
- If operator binary data is loaded and unloaded frequently, the Program Counter (PC) virtual addresses within the same process may be reused and hit the cache, which may cause operator execution exceptions or precision issues. Therefore, it is not recommended to call this API frequently. Call this API to unload the operator binary data only after all operator-related tasks have been completed.
aclrtFunctionGetBinary
aclError aclrtFunctionGetBinary(const void *func, aclrtBinHandle *binHandle)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Obtains the operator binary handle.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| func | Input | Kernel function pointer. This can be a kernel function name declared with __global__ (for example, myKernel, which is applicable only to the scenario where custom operators are developed in Ascend C and host and device code are compiled together based on the BiSheng compiler), or a kernel function handle of the aclrtFuncHandle type. |
| binHandle | Output | Operator binary handle. For details about the type definition, see aclrtBinHandle. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
aclrtFunctionGetParamCount
aclError aclrtFunctionGetParamCount(const void *func, size_t *paramCount)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Obtains the number of parameters contained in the kernel function argument list.
After using this API to query the number of parameters contained in the kernel function argument list, use it together with the aclrtFunctionGetParamInfo API to traverse and obtain the detailed information (offset and size) of each parameter.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| func | Input | Kernel function pointer. This can be a kernel function name declared with __global__ (for example, myKernel, which is applicable only to the scenario where custom operators are developed in Ascend C and host and device code are compiled together based on the BiSheng compiler), or a kernel function handle of the aclrtFuncHandle type. |
| paramCount | Output | Number of parameters contained in the kernel function argument list. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
aclrtFunctionGetParamInfo
aclError aclrtFunctionGetParamInfo(const void *func, size_t paramIndex, size_t *paramOffset, size_t *paramSize)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Obtains the kernel function parameter information (offset and size) based on the index.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| func | Input | Kernel function pointer. This can be a kernel function name declared with __global__ (for example, myKernel, which is applicable only to the scenario where custom operators are developed in Ascend C and host and device code are compiled together based on the BiSheng compiler), or a kernel function handle of the aclrtFuncHandle type. |
| paramIndex | Input | Parameter index. After calling aclrtFunctionGetParamCount to obtain the number of available parameters, the value range of paramIndex is [0, (Number of parameters - 1)]. |
| paramOffset | Output | Offset of the parameter in the argument data area, in bytes. |
| paramSize | Output | Size of the parameter, in bytes. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
aclrtFunctionGetAvailDynUbufPerBlock
aclError aclrtFunctionGetAvailDynUbufPerBlock(const void *func, uint32_t flags, size_t *dynamicUbufSize)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Outputs the maximum dynamic UB buffer size that can be set before kernel launch through dynamicUbufSize for Single Instruction Multiple Thread (SIMT) kernel functions.
For non-SIMT kernel functions, this API returns success, and dynamicUbufSize is fixed to 0.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| func | Input | Kernel function pointer. This can be a kernel function name declared with __global__ (for example, myKernel, which is applicable only to the scenario where custom operators are developed in Ascend C and host and device code are compiled together based on the BiSheng compiler), or a kernel function handle of the aclrtFuncHandle type. |
| flags | Input | Reserved parameter, currently fixed to 0. |
| dynamicUbufSize | Output | Dynamic UB buffer size available for each block, in bytes. It cannot be empty. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
aclrtGetFuncBySymbol
aclError aclrtGetFuncBySymbol(const void *symbol, aclrtFuncHandle *funcHandle)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Not supported
- Atlas inference products: Supported
- Atlas training products: Not supported
Description
Obtains the kernel function handle based on the kernel function name (the function name declared with __global__, for example, myKernel).
This API applies only to the scenario where custom operators are developed using the Ascend C language and host and device code are compiled together based on the BiSheng compiler. It does not apply to the scenario of directly loading operator binary files. After a user defines a device-side kernel function, this API can be used to find the corresponding kernel function in the internal symbol table based on the kernel function name, and express it with funcHandle for subsequent kernel launch.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| symbol | Input | Kernel function name. |
| funcHandle | Output | Kernel function handle. For details about the type definition, see aclrtFuncHandle. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
Constraints
- This API can be used only in static operator shape scenarios and supports only AI Core operators.
- The kernel function handle is valid only on the current device. After switching the device, you need to obtain the handle again.
aclrtLaunchSIMTKernelWithArgsArray
aclError aclrtLaunchSIMTKernelWithArgsArray(void *func, dim3 gridDim, dim3 blockDim, size_t dynUbufSize, aclrtStream stream, aclrtLaunchKernelCfg *cfg, void **args)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Not supported
- Atlas A2 products: Not supported
- Atlas 200I/500 A2 inference products: Not supported
- Atlas inference products: Not supported
- Atlas training products: Not supported
Description
Passes the Single Instruction Multiple Thread (SIMT) kernel function input arguments in the form of an argument array and launches the computation task of the corresponding operator. This is an asynchronous API.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| func | Input | Kernel function pointer. This can be a kernel function name declared with __global__ (for example, myKernel, which is applicable only to the scenario where custom operators are developed in Ascend C and host and device code are compiled together based on the BiSheng compiler), or a kernel function handle of the aclrtFuncHandle type. |
| gridDim | Input | Thread block grid, composed of multiple thread blocks. The grid uses a three-dimensional structure, and its dimensions X, Y, and Z respectively represent the size of the thread blocks in different dimensions. For details about the type definition, see dim3. |
| blockDim | Input | Thread block, which uses a three-dimensional structure. Its dimensions X, Y, and Z respectively represent the number of threads in the three dimensions of the thread block. For details about the type definition, see dim3. |
| dynUbufSize | Input | Dynamic memory size of the Unified Buffer (UB) required for Single Instruction Multiple Thread (SIMT) operator execution, in bytes. If the ACL_RT_LAUNCH_KERNEL_ATTR_DYN_UBUF_SIZE attribute is also set in cfg, this parameter takes higher priority. |
| stream | Input | Stream on which the task is executed. For details about the type definition, see aclrtStream. |
| cfg | Input | Configuration information for task dispatch. For details about the type definition, see aclrtLaunchKernelCfg. If no configuration is specified, NULL can be passed here. |
| args | Input | Pointer to the argument array. Each element in the argument array points to the memory address of the kernel function parameter data on the Host side. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
Constraints
The order of elements in the argument array must be consistent with the order of the kernel function arguments, and the size of the argument array must be consistent with the number of kernel function arguments; otherwise, undefined behavior occurs.
Reference Resources
For a comparison of the features and usage of each launch API, see the launch API comparison table.
aclrtLaunchSIMTKernelWithHostArgs
aclError aclrtLaunchSIMTKernelWithHostArgs(void *func, dim3 gridDim, dim3 blockDim, size_t dynUbufSize, aclrtStream stream, aclrtLaunchKernelCfg *cfg, void *hostArgs, size_t argsSize, aclrtPlaceHolderInfo *placeHolderArray, size_t placeHolderNum)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Not supported
- Atlas A2 products: Not supported
- Atlas 200I/500 A2 inference products: Not supported
- Atlas inference products: Not supported
- Atlas training products: Not supported
Description
Passes the input arguments of a Single Instruction Multiple Thread (SIMT) kernel function based on host memory parameters, and launches the computation task of the corresponding operator. This is an asynchronous API.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| func | Input | Kernel function pointer. This can be a kernel function name declared with __global__ (for example, myKernel, which is applicable only to the scenario where custom operators are developed in Ascend C and host and device code are compiled together based on the BiSheng compiler), or a kernel function handle of the aclrtFuncHandle type. |
| gridDim | Input | Thread block grid, which consists of multiple thread blocks. The grid uses a three-dimensional structure, and its dimensions X, Y, and Z respectively indicate the size of the thread block in different dimensions. For details about the type definition, see dim3. |
| blockDim | Input | Thread block, which uses a three-dimensional structure, and its dimensions X, Y, and Z respectively indicate the number of threads in the three dimensions of the thread block. For details about the type definition, see dim3. |
| dynUbufSize | Input | Dynamic memory size of the Unified Buffer (UB) required for executing the Single Instruction Multiple Thread (SIMT) operator, in bytes. If the ACL_RT_LAUNCH_KERNEL_ATTR_DYN_UBUF_SIZE attribute is also set in cfg, this parameter takes precedence. |
| stream | Input | Stream on which the task is executed. For details about the type definition, see aclrtStream. |
| cfg | Input | Configuration information for task dispatch. For details about the type definition, see aclrtLaunchKernelCfg. If no configuration is specified, NULL can be passed here. |
| hostArgs | Input | Host memory address pointer that stores all input argument data of the kernel function. |
| argsSize | Input | Size of the hostArgs parameter value, in bytes. |
| placeHolderArray | Input | Placeholder parameter array. For details about the type definition, see aclrtPlaceHolderInfo. |
| placeHolderNum | Input | Size of the placeholder parameter array. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
Constraints
- The hostArgs memory must be compactly arranged in the order of the kernel function arguments, and argsSize must match the actual total size of the arguments.
- The address offsets in placeHolderArray must correspond to the actual positions of the placeholder arguments in hostArgs.
Reference Resources
For a comparison of the features and usage of each launch API, see the launch API comparison table.
aclrtBinaryGetFunctionCount
aclError aclrtBinaryGetFunctionCount(const aclrtBinHandle binHandle, uint32_t *count)
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Obtains the number of kernel functions in the operator binary.
After loading the operator binary through aclrtBinaryLoadFromFile or aclrtBinaryLoadFromData, the user can call this API to obtain the number of kernel functions contained in the operator binary.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| binHandle | Input | Operator binary handle. For details about the type definition, see aclrtBinHandle. Call the aclrtBinaryLoadFromFile API or the aclrtBinaryLoadFromData API to obtain the operator binary handle, and then pass it as an input parameter to this API. |
| count | Output | Number of kernel functions. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.
aclrtBinaryEnumerateFunctions
aclError aclrtBinaryEnumerateFunctions(const aclrtBinHandle binHandle, aclrtFuncHandle *funcHandles, uint32_t numFunctions)
Applicable Products
- Ascend 950PR&950DT: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Description
Obtains the specified number of kernel function handles in the operator binary.
Parameters
| Name | Input/Output | Description |
|---|---|---|
| binHandle | Input | Operator binary handle. For details about the type definition, see aclrtBinHandle. Call aclrtBinaryLoadFromFile or aclrtBinaryLoadFromData to obtain the operator binary handle, and then pass it as an input parameter to this API. |
| funcHandles | Output | Kernel function handle array. For details about the type definition, see aclrtFuncHandle. |
| numFunctions | Input | Number of kernel function handles to obtain, which can be obtained by calling aclrtBinaryGetFunctionCount first. When numFunctions==0, no kernel function handle needs to be obtained. When numFunctions≤len(funcHandles), numFunctions kernel function handles are returned. When numFunctions>len(funcHandles), len(funcHandles) kernel function handles are returned. |
Return Values
Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.