Choose tile size and work partitioning

From tensormux/kernel-skills · View interactive version

Choose tile size and work partitioning is an AI agent skill from the GitHub repository tensormux/kernel-skills. Guide the agent through selecting tile sizes and work partitioning strategies for a CUDA or Triton kernel, based on shared memory budget, register pressure, occupancy targets, problem shape, and acces

How to use this skill

Skill file

Skill: Choose Tile Size and Work Partitioning

Purpose

Guide the agent through selecting tile sizes and work partitioning strategies for a CUDA or Triton kernel, based on shared memory budget, register pressure, occupancy targets, problem shape, and access pattern.

Use this when

Do not use this when

Inputs the agent should gather first

Required reasoning process

  1. Determine what is loaded into shared memory per block. For a GEMM-style kernel with tiles BLOCK_M x BLOCK_N and accumulation tile BLOCK_K:
  1. Compute smem usage for candidate tile sizes. Start from the hardware smem limit and work downward. A common starting constraint:
  1. Estimate register usage per thread. A precise count requires compiling and inspecting with --ptxas-info-registers or cuobjdump. As a first estimate:
  1. Compute occupancy for candidate configurations. Occupancy = (active warps per SM) / (max warps per SM). Constraints that limit occupancy:
  1. Check warp efficiency in the last tile. If the problem dimension is not a multiple of the tile size, the last block has fewer valid elements than the tile size. The fraction of useful work in that block = (N % TILE_SIZE) / TILE_SIZE. If this fraction is very small (e.g., < 0.1) and many blocks hit this case, the waste is significant. Pad to a tile multiple or choose a smaller tile size.
  1. Check alignment and divisibility for vectorized loads. Vectorized loads (float4, half2) require the pointer to be aligned to the vector width. For a tile of width W loaded with 128-bit (float4) loads, W must be a multiple of 4 (for float4). If W is not aligned, scalar fallback loads are needed, which reduces memory throughput.
  1. Choose the work partitioning shape. Options:
  1. For Triton: choose num_warps and num_stages.

Kernel design rules

Correctness requirements

Performance requirements

Output format

The agent should produce:

  1. Tile size analysis table: for each candidate tile size configuration, a table showing: smem per block, estimated registers per thread, occupancy estimate, warp efficiency on the last tile, alignment compatibility.
  2. Selected configuration with justification: the chosen tile size(s) and launch configuration, with explicit reasoning for why it was selected over alternatives.
  3. Work partitioning description: the grid decomposition (1D/2D/3D/persistent), grid dimensions as a function of problem size, and block/warp dimensions.
  4. Kernel implementation skeleton: the launch configuration and thread-to-data mapping code, even if the full kernel is not yet written.
  5. Autotuning plan (if applicable): the parameter space to sweep and the metric to optimize (throughput, latency).

Common failure modes

Review checklist

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.