liveBook · Manning

Tl.arange

As explained in GPU Programming with Triton

tl.arange is a Triton operation that constructs a sequence of regularly spaced integer offsets over a specified range.

tl.arange(0, n) creates local integer positions from 0 to n − 1. Add a block’s starting offset to turn them into global array positions for memory access. section 2.2.5

Shift local positions

If a block starts at 128, tl.arange(0, 4) produces [0, 1, 2, 3]; adding 128 gives the global positions [128, 129, 130, 131]. section 2.2.5

In a pairwise feature calculation, local_idx = tl.arange(0, BLOCK_SIZE) supplies pair indices. A mask such as local_idx < half_dim limits work when the block is larger than the number of pairs. section 3.5.3

Figure 2.6 Each program computes its global offsets by adding its block start position to the local indices inside the block. block_start and tl.arange combine to produce the exact positions this program will read and write.
CH02 F06 Fartale

Shows how local indices combine with a block start to produce global offsets. section 2.2.5

How GPU Programming with Triton covers it

How deep it goes
Builds from a sequence of local indices to global offsets and masked pair indexing.
Examples
Uses a four-position sequence shifted by 128 and pair indices across an eight-feature row.
What you can do after
Apply it to generate local offsets and combine them with a block or row start for data access.
How it connects
Connects local indices to block starts, program instances, memory offsets, and masks.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of GPU Programming with Triton. The section links point to the parts of the book it draws on.