asc2.range

class asc2.range(start: int, stop: int | None = None, step: int = 1, /, *, unroll_factor: int = 1, parallel: 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 parallel execution on NPU. In fact, built-in range automatically becomes asc2.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).

  • parallel – Whether to enable software pipelining. Default is False. When True, iterations may overlap to enable software pipelining optimizations. Must be False if loop iterations depend on previous iterations.

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 asc2.range(N):
    ...

Loop with unrolling:

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

Parallel loop:

for i in asc2.range(N, parallel=True):
    ...
__init__(start: int, stop: int | None = None, step: int = 1, /, *, unroll_factor: int = 1, parallel: bool = False)

Methods

__init__(start[, stop, step, unroll_factor, ...])

handle_op(op)