IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).

Mojo function

coop_group_size

def coop_group_size(ctx: DeviceContext, batch_size: Int, block_size: Int, n_vec: Int, requested: Int = Int(0)) -> Int

Chooses a resident block group for each row.

Every block must be resident because the barrier spins until all blocks arrive, so a launch never asks for more blocks than the device has multiprocessors: one block lands on each of them, and a block waiting for the rest of its group holds the multiprocessor that the peer it waits on would need. The count comes from the device rather than from a constant because it is what decides whether a group fits. The timeout in the barrier turns contention that keeps a group from becoming resident into an error instead of a hang.

Args:

  • ​ctx (DeviceContext): Device the launch targets.
  • ​batch_size (Int): Number of rows in the launch.
  • ​block_size (Int): Threads per block.
  • ​n_vec (Int): Vectors in one row.
  • ​requested (Int): Blocks per row the caller wants. Values that are not powers of two, and values above what the device can keep resident, fall back to the largest group that fits. Zero derives the group from the device.

Returns:

Int: Blocks per row, or 1 when the row should not be split.

Was this page helpful?