printf
Supported Products
|
Product |
Supported |
|---|---|
|
|
√ |
|
|
√ |
|
|
x |
|
|
x |
|
|
x |
|
|
x |
Function
This API is used to format the output in the AI CPU operator kernel debugging scenario. By default, the output is parsed and printed on the screen. To use this API, include the header file aicpu_api.h.
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 arguments (an output list with variable quantities and types). Depending on the fmt string, the function may require a series of additional arguments. Each argument contains a value to be inserted and replaces each % tag specified in the fmt parameter. The number of arguments must be the same as the number of % tags. |
Returns
None
Restrictions
- This API can be called only by using <<<...>>> and used in the heterogeneous compilation scenario.
- This API does not support the printing of escape characters except 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 |