liveBook · Manning

Triton.cdiv

As explained in GPU Programming with Triton

triton.cdiv is a Triton helper that computes integer ceiling division.

For a vector of n_elements, with each Triton program processing BLOCK_SIZE entries, triton.cdiv(n_elements, BLOCK_SIZE) gives the number of programs needed. Ceiling division includes a final program when the vector length is not an exact multiple of the block size. section 2.2.8 section 3.1.2

grid = lambda meta: (
    triton.cdiv(n_elements, meta['BLOCK_SIZE']),
)

A one-dimensional launch grid can compute its size from n_elements and the resolved BLOCK_SIZE. section 2.2.8

How GPU Programming with Triton covers it

How deep it goes
Defines ceiling division through element count and block size, but does not detail the helper's internals.
Examples
Uses n_elements divided by BLOCK_SIZE for a vector grid and N divided by BLOCK_SIZE for a SiLU kernel.
What you can do after
Apply it via Triton to calculate enough one-dimensional program instances to cover all elements, including a partial final block.
How it connects
Connects launch grids with block size, program instances, and Triton kernel launches.

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.