| Files | Last commit | Last update |
|---|---|---|
| 1 month ago | ||
| 1 month ago | ||
| 2 months ago | ||
| 2 months ago | ||
| 3 months ago | ||
| 1 month ago |
3_binary_get_function_count
Description
This sample demonstrates how to use the aclrtBinaryGetFunctionCount interface to query the number of kernel functions in an operator binary file, and then perform a complete workflow including function lookup, information query, kernel launch, and result verification. The sample compiles three AscendC kernel functions (add_custom, sub_custom, and mul_custom) into a single standalone operator binary, queries the total number of kernel functions, obtains handles by name, queries function information, prepares FP16 input data, and finally launches each kernel and verifies computation results.
Product Support
This sample supports the following products:
| Product | Supported |
|---|---|
| Ascend 950PR/Ascend 950DT | Yes |
| Atlas A3 training series products/Atlas A3 inference series products | Yes |
| Atlas A2 training series products/Atlas A2 inference series products | Yes |
Build and Run
- Download sample code to environment with CANN software installed, switch to sample directory.
cd ${git_clone_path}/example/2_advanced_features/kernel/3_binary_get_function_count
- Set environment variables.
# Replace ${install_root} with CANN installation root directory, default installation at /usr/local/Ascend
source ${install_root}/cann/set_env.sh
# Automatically identify SOC_VERSION and ASCENDC_CMAKE_DIR.
source ${git_clone_path}/example/set_sample_env.sh
- Run the following command to execute the sample.
bash run.sh
CANN RUNTIME API
Key features and interfaces in this sample:
- Initialization
- Call
aclInitinterface to initialize configuration. - Call
aclFinalizeinterface to deinitialize.
- Call
- Device Management
- Call
aclrtSetDeviceinterface to specify Device for computation. - Call
aclrtResetDeviceForceinterface to forcibly reset current computation Device and reclaim Device resources.
- Call
- Stream Management
- Call
aclrtCreateStreaminterface to create Stream. - Call
aclrtSynchronizeStreaminterface to block waiting for Stream task execution completion. - Call
aclrtDestroyStreamForceinterface to forcibly destroy Stream.
- Call
- Memory Management
- Call
aclrtMallocHostinterface to allocate Host memory. - Call
aclrtMallocinterface to allocate Device memory. - Call
aclrtMemcpyinterface to perform memory copy between Host and Device. - Call
aclrtFreeHostinterface to free Host memory. - Call
aclrtFreeinterface to free Device memory.
- Call
- Binary Management
- Call
aclrtBinaryLoadFromFileinterface to load and parse an operator binary file from disk, outputting a binHandle. - Call
aclrtBinaryGetFunctionCountinterface to get the total number of kernel function handles in the binary. - Call
aclrtBinaryGetFunctioninterface to get a kernel function handle by its name. - Call
aclrtGetFunctionNameinterface to get the kernel function name from a function handle. - Call
aclrtGetFunctionAddrinterface to get the Device-side kernel code address from a function handle. - Call
aclrtLaunchKernelWithHostArgsinterface to launch a kernel with Host-side arguments that are automatically copied to Device. - Call
aclrtBinaryUnLoadinterface to unload the operator binary file and release associated resources.
- Call
Sample Output
[INFO] ASCEND_HOME_PATH=...
[INFO] ASCENDC_CMAKE_DIR=...
[INFO] SOC_VERSION=...
Configuring CMake...
Building...
[INFO] Querying the number of kernel functions in the binary
[INFO] aclrtBinaryGetFunctionCount returned 3 functions
[INFO] Getting function handles by name
[INFO] Querying function names and addresses
[INFO] function[0]: name=add_custom, handle=..., aic=..., aiv=...
[INFO] function[1]: name=sub_custom, handle=..., aic=..., aiv=...
[INFO] function[2]: name=mul_custom, handle=..., aic=..., aiv=...
[INFO] Preparing input data
[INFO] Launching kernels and verifying results
[INFO] add_custom result verified
[INFO] sub_custom result verified
[INFO] mul_custom result verified
[INFO] aclrtBinaryGetFunctionCount sample PASSED