Debug capabilities
AscTile provides four debug operations to inspect values and check assumptions while developing kernels. They fall into two groups, depending on when they run:
Group |
Operations |
When they run |
Needs a running kernel? |
|---|---|---|---|
Device-side |
|
During kernel execution on the NPU |
Yes |
Host-side |
|
During JIT compilation, before the kernel runs |
No |
Use the device-side operations for runtime values that only exist on the device (a loaded tile, a
computed scalar), and the host-side operations for compile-time values (a ConstExpr argument, a
tile shape, a dtype) — they are cheaper and work without hardware.
Enabling device-side debugging
Device-side operations are off by default. To turn them on, decorate the kernel with debug=True:
@asctile.jit(debug=True)
def kernel(x_ptr: asctile.GlobalAddress, size: int):
...
When debug is not set (the default), device_print and device_assert do nothing and add no
overhead to your kernel — keep it this way for production runs.
Warning
debug=True leads to slower compilation and may cause performance regressions. Enable it only while developing or
validating correctness, and switch it off for final builds.
Device-side output is produced only when the kernel is actually executed — on the NPU or the Model
simulator; nothing is printed if the kernel is compiled but never launched. The host-side operations
(static_print, static_assert) are different: they run during JIT compilation, before the kernel
runs, so they take effect even before the kernel is launched and without any hardware.
Device-side operations
These run during kernel execution on the device.
- asc.experimental.asctile.device_print(*values: Any, sep: str | None = None, end: str | None = None) None
Print values during kernel execution on the device.
Outputs values to the device console. Strings are printed as-is, scalars are formatted by type, and tensors are dumped in full.
- Parameters:
values – Values to print (strings, scalars, or tensors).
sep – Separator between values (default
" ").end – Line terminator (default
"\n").
Note
Only active when
debug=Trueis set in the JIT decorator. The built-inprint()function dispatches to this function inside JIT kernels.Examples
Print a mix of strings, scalars, and tensors:
@asctile.jit(debug=True) def kernel(): x = asctile.zeros([128], asctile.float32) asctile.device_print("block", asctile.block_idx(), "tensor", x)
- asc.experimental.asctile.device_assert(test: Any, message: str | None = None) None
Check a condition during kernel execution on the device.
If the condition is false, prints an error message with source location and stops execution.
- Parameters:
test – Condition to check (boolean, comparison, or value convertible to bool).
message – Optional error message to include in the report.
Note
Only active when
debug=Trueis set in the JIT decorator. The built-inassertstatement dispatches to this function inside JIT kernels.Examples
Assert that the block index is non-negative:
@asctile.jit(debug=True) def kernel(): asctile.device_assert(asctile.block_idx() >= 0, "block_idx must be non-negative")
Host-side operations
These run during JIT compilation, before the kernel runs, and work without any hardware.
- asc.experimental.asctile.static_print(*values: Any, sep: str | None = None, end: str | None = None, **kwargs) None
Print values during JIT compilation on the host.
Outputs values to the host console. Use this to trace compile-time constants and metadata.
- Parameters:
*args – Values to print.
**kwargs – Forwarded to the built-in
print().
Note
Always runs during compilation, regardless of the
debugoption. The built-inprint()function does NOT dispatch to this function — it dispatches todevice_print()instead. Use this function explicitly for compile-time output.Examples
Log the configured tile size at compile time:
@asctile.jit def kernel(TILE: asc.ConstExpr[int]): asctile.static_print("compiling kernel with TILE =", TILE)
- asc.experimental.asctile.static_assert(test: Any, message: str | None = None) None
Check a condition during JIT compilation on the host.
If the condition is false, raises
AssertionErrorand aborts compilation.- Parameters:
test – Condition to check (must be a compile-time value, not an IR value).
message – Optional error message for the exception.
Note
Always runs during compilation, regardless of the
debugoption. The built-inassertstatement does NOT dispatch to this function — it dispatches todevice_assert()instead. Use this function explicitly for compile-time checks.Examples
Validate a tile size constant at compile time:
@asctile.jit def kernel(TILE: asc.ConstExpr[int]): asctile.static_assert(TILE % 16 == 0, "TILE must be a multiple of 16")
Environment variables
These environment variables complement the debug operations and control what the toolchain keeps on disk and whether a compiled kernel is actually launched.
PYASC_DUMP_PATH=<dir>(optional)directory where the compiler keeps generated artifacts: intermediate IR (
.mlir), Ascend C source (.cpp) and the object file (.o)CAMODEL_LOG_PATH=<dir>(optional)directory for the
Modelsimulator logs; only used on theModelbackend — setting it persists the logs instead of a temp directory removed on exitPYASC_DRY_RUN=1(optional)when set, the kernel is compiled but not launched on the device — useful to validate compilation without hardware