asc.experimental.asctile.range

class asc.experimental.asctile.range(stop: int, /, *, unroll_factor: int = 1, gm_barrier: bool = False)
class asc.experimental.asctile.range(start: int, stop: int, /, *, unroll_factor: int = 1, gm_barrier: bool = False)
class asc.experimental.asctile.range(start: int, stop: int, step: int, /, *, unroll_factor: int = 1, gm_barrier: bool = False)

A range loop construct for use in JIT functions.

This class provides a range-based loop similar to Python’s built-in range, with additional support for loop unrolling and memory barrier control on NPU.

In fact, built-in range automatically becomes asctile.range when used inside JIT function.

Parameters:
  • start – Start index of the loop (or stop index if only one argument provided).

  • stop – Stop index of the loop (exclusive). If None, start is treated as stop and start is 0.

  • step – Step size for the loop iteration.

  • unroll_factor – Number of iterations to unroll. Default is 1 (no unrolling).

  • gm_barrier – Whether to prevent parallel load/store optimization across iterations. Default is False. When True, a global memory barrier is inserted between iterations to prevent overlapping memory operations. Must be True if loop iterations depend on previous iterations’ memory writes.

Raises:

ValueError – If unroll_factor is less than 1

Note

The unroll_factor parameter controls loop unrolling during compilation. Higher values can improve performance but increase code size.

Examples

Basic loop from 0 to N:

for i in asctile.range(N):
    ...

Loop with unrolling:

for i in asctile.range(0, N, 1, unroll_factor=4):
    ...

Loop with a global memory barrier (prevent parallel memory optimizations):

for i in asctile.range(N, gm_barrier=True):
    ...
__init__(stop: int, /, *, unroll_factor: int = 1, gm_barrier: bool = False)
__init__(start: int, stop: int, /, *, unroll_factor: int = 1, gm_barrier: bool = False)
__init__(start: int, stop: int, step: int, /, *, unroll_factor: int = 1, gm_barrier: bool = False)

Methods

__init__()

handle_op(op)