| Files | Last commit | Last update |
|---|---|---|
| 2 months ago | ||
| 2 months ago | ||
| 2 months ago | ||
| 2 months ago | ||
| 2 months ago | ||
| 2 months ago |
7_binary_introspection
Description
This sample targets single-Device applications that inspect custom Kernel metadata after loading. It creates and loads an Ascend C Kernel binary from Host memory, verifies the Binary-to-Function association, parameter layout, AI Core/Vector Core code sizes, dynamic UB size, and the Device address of the binary, then writes and reads back a named Device global variable to validate its resolved address.
Product Support
| 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 |
Compile and Run
- Download the sample code to an environment where CANN is installed and switch to the sample directory.
cd ${git_clone_path}/example/2_advanced_features/kernel/7_binary_introspection
- Set the environment variables.
# Replace ${install_root} with the CANN installation root directory
source ${install_root}/set_env.sh
source ${git_clone_path}/example/set_sample_env.sh
- Build and run the sample.
bash run.sh
CANN RUNTIME API
The key functionality points and interfaces used in this sample are as follows:
- Initialization and deinitialization
- Call
aclInitto initialize the runtime environment. - Call
aclFinalizeto deinitialize it.
- Call
- Device management
- Call
aclrtSetDeviceto select the Device that loads the binary. - Call
aclrtResetDeviceForceto reset the Device and reclaim its resources.
- Call
- Binary lifecycle
- Call
aclrtCreateBinaryto create a descriptor from binary data in Host memory. - Call
aclrtBinaryLoadto parse the binary and load it on the Device for the current Context. - Call
aclrtBinaryUnLoadto unload the binary in the same Context. - Call
aclrtDestroyBinaryto destroy the Binary descriptor; the application still owns the original Host memory.
- Call
- Binary metadata
- Call
aclrtBinaryGetDevAddressto obtain the Device address and size of the loaded binary. - Call
aclrtBinaryGetGlobalto resolve the address and size of a named Device global variable.
- Call
- Function metadata
- Call
aclrtBinaryGetFunctionto obtain a Kernel function by name. - Call
aclrtFunctionGetBinaryto retrieve the Binary associated with the function. - Call
aclrtFunctionGetParamCountto query the Kernel parameter count. - Call
aclrtFunctionGetParamInfoto query each parameter offset and size. - Call
aclrtGetFunctionSizeto query the AI Core and Vector Core code sizes. - Call
aclrtFunctionGetAvailDynUbufPerBlockto query the dynamic UB available per Block. This sample uses a non-SIMT Kernel, so the expected value is 0.
- Call
- Global variable validation
- Call
aclrtMemcpyto write a probe value to the global variable and read it back for validation.
- Call
Sample Output
[INFO] Start to run the 7_binary_introspection sample.
[INFO] Loaded ... binary bytes from Host memory.
[INFO] Parameter[0]: offset=0, size=8.
[INFO] Parameter[1]: offset=8, size=8.
[INFO] Parameter[2]: offset=16, size=4.
[INFO] Function code size: aic=... bytes, aiv=... bytes; dynamic UB=0 bytes.
[INFO] Binary Device image: address=..., size=... bytes.
[INFO] Verified Device global g_binary_metadata_value: size=... bytes, value=0x13572468.
[INFO] Run the 7_binary_introspection sample successfully.