set_printf_params

Description

Sets printf parameters.

Prototype

def set_printf_params(print_workspace_size=128, single_print_length=512, printf_file_path=None)

Parameters

Parameter

Input/Output

Description

print_workspace_size

Input

Print workspace size. If multiple blocks are enabled, the print workspace size is evenly allocated to the blocks.

Unit: MB.

Must be in the range of [1, 32768].

Defaults to 128 MB.

Must be an immediate of type int.

single_print_length

Input

Length of a single print statement. The space is allocated even if a single print statement takes less space.

Unit: byte.

Must be in the range of [64, print_workspace_size * 1024 * 1024//Block count – 32]. The block count is user-defined, which is equivalent to block_num in for_range.

Defaults to 512 bytes.

Must be an immediate of type int.

Must be an integral multiple of 32 bytes.

is_printf_to_screen

Input

A bool to specify whether to print the printf statement to the screen. The default value is True, indicating that information is printed to the screen. If the setting is False, information is not printed to the screen.

printf_file_path

Input

Print file path of the printf statement. The default value is None, indicating that the information is not printed to a file. You can use a string to indicate the file path. The printf result is saved in the [kernel_name].txt file in the path.

Applicability

Atlas 200/300/500 Inference Product

Atlas Training Series Product

Returns

None

Restrictions

  • set_printf_params must be called before printf. You can choose to use the printf call directly instead of set_printf_params.
  • In an operator, set_printf_params can be called only once. Errors are reported on repeated calls to this API.
  • Set an appropriate print workspace size based on the DDR size of the device. Otherwise, operator execution may fail.
  • print_workspace_size * 1024 * 1024 must be exactly divisible by block_num.
  • The following condition must be met: print_workspace_size * 1024 * 1024 >= block_num * (32 + single_print_length)
  • Ensure that the printf_file_path directory can be created.

Example

from tbe import tik
tik_instance = tik.Tik()
# Set the print workspace to 1 MB and the maximum length of a single print statement to 256 bytes.
tik_instance.set_printf_params(1, 256)
scalar = tik_instance.Scalar("int8", init_value=-128)
tik_instance.printf("scalar is: %d\n", scalar)
tik_instance.BuildCCE(inputs=[], outputs=[], kernel_name="print_scalar")
tik_instance.tikdb.start_debug({})
Input
[]
Output
scalar is: -128