printf
Product Support
|
Product |
Supported |
|---|---|
|
|
√ |
|
|
√ |
|
|
x |
|
|
x |
|
|
x |
|
|
x |
Function
Provides the formatted output function in the AI CPU operator kernel debugging scenario. The output content is parsed and displayed on the screen by default. The header file aicpu_api.h must be included when this API is used.
Prototype
1
|
void printf(const char* fmt, ...) |
Parameters
|
Parameter |
Input/Output |
Description |
|---|---|---|
|
fmt |
Input |
Format control string, which contains two types of objects: common characters and conversion descriptions.
|
|
... |
Input |
Additional parameters (a parameter list with variable quantities and types). Depending on the fmt string, the function may require a series of additional parameters. Each parameter contains a value to be inserted and replaces each % tag specified in the fmt parameter. The number of parameters must be the same as the number of % tags. |
Returns
None
Restrictions
- This API can be called only through <<<...>>> and is used in the heterogeneous compilation scenario.
- This API does not allow the printing of escape characters, except for newline characters.
- This API uses the dump function. The total amount of dump data of all APIs using the dump function on each core cannot exceed 1 MB. You need to control the amount of data to be printed. If the limit is exceeded, no content will be printed.
- When using this API, if you use the bisheng command line for compilation, you need to manually link the related static library. However, if you use CMake for compilation, the framework automatically handles the linkage, and you do not need to pay attention to it. The specific compilation commands are as follows: Use --cce-aicpu-laicpu_api to link libaicpu_api.a to the device, and use --cce-aicpu-L to specify the library path of libaicpu_api.a.
$bisheng -O2 foo.aicpu --cce-aicpu-L${INSTALL_DIR}/lib64/device/lib64 --cce-aicpu-laicpu_api -I${INSTALL_DIR}/include/ascendc/aicpu_api -c -o foo.aicpu.o
Replace ${INSTALL_DIR} with the CANN component directory. For example, if the installation is performed by the root user, the default file storage path is /usr/local/Ascend/cann.
Example
Call the printf API to print required log information at the target position in the operator kernel implementation code. An example is as follows.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#include "aicpu_api.h" // Integer printing: AscendC::printf("fmt string %d\n", 0x123); // Floating-point printing: float a = 3.14; AscendC::printf("fmt string %f\n", a); // Pointer printing: int b = 10; int *c = &b; AscendC::printf("TEST %p\n", c); |
When the program is running, you will see the following print effect:
1 2 3 |
fmt string 291 fmt string 3.140000 TEST 0xdfffd6fddd1c |