triton.language.device_assert

triton.language.device_assert(cond, msg='', mask=None, _semantic=None)

在设备端运行时断言条件。需要将环境变量 TRITON_DEBUG 设置为非 0 的值,此函数才会生效。

使用 Python 的 assert 语句等同于调用此函数,区别在于必须提供第二个参数且该参数必须为字符串,例如 assert pid == 0, "pid != 0"。必须设置上述环境变量,该 assert 语句才会生效。

tl.device_assert(pid == 0)
assert pid == 0, f"pid != 0"
参数:
  • cond – 要断言的条件。必须是一个布尔张量。

  • msg – 断言失败时打印的消息。必须是一个字符串字面量。