triton.language.static_print

triton.language.static_print(*values, sep: str = ' ', end: str = '\n', file=None, flush=False, _semantic=None)

Print the values at compile time. The parameters are the same as the builtin print.

NOTE: Calling the Python builtin print is not the same as calling this, it instead maps to device_print, which has special requirements for the arguments.

tl.static_print(f"BLOCK_SIZE={BLOCK_SIZE}")

Example

import torch
import torch_npu

import triton
import triton.language as tl


@triton.jit
def static_print_kernel(x_ptr, out_ptr, BLOCK_SIZE: tl.constexpr):
    tl.static_print("BLOCK_SIZE =", BLOCK_SIZE)
    offsets = tl.arange(0, BLOCK_SIZE)
    x = tl.load(x_ptr + offsets)
    tl.store(out_ptr + offsets, x)


def test_static_print():
    BLOCK_SIZE = 128
    x = torch.randn(BLOCK_SIZE, device="npu", dtype=torch.float32)
    out = torch.empty(BLOCK_SIZE, device="npu", dtype=torch.float32)
    static_print_kernel[(1, )](x, out, BLOCK_SIZE=BLOCK_SIZE)
    torch.npu.synchronize()


if __name__ == "__main__":
    test_static_print()
    print("test_static_print PASSED!")

Special Restrictions

  • DataType: Ascend A2/A3 does not support uint16/uint32/uint64/fp64, Ascend 950 does not support fp64 (hardware limitation).