Inferensys

Glossary

Workgroup Size

Workgroup size is the number of threads grouped together for cooperative execution and synchronization within a single compute unit on an NPU or GPU, a critical tunable parameter for performance.
Product manager reviewing autonomous task execution dashboard on laptop, completed tasks visible, casual work session.
NPU PERFORMANCE TUNING

What is Workgroup Size?

A fundamental parameter for optimizing parallel execution on hardware accelerators.

Workgroup size is the number of threads grouped together for cooperative execution and synchronization within a single compute unit on a Neural Processing Unit (NPU) or GPU. This tunable parameter directly controls the granularity of parallelism and is critical for balancing occupancy (hardware utilization) with efficient memory coalescing and minimizing thread divergence. Selecting the optimal size is a primary target for auto-tuning systems.

The ideal workgroup size is determined by hardware constraints like register file and shared memory capacity, as well as the algorithm's data access patterns. A poorly chosen size can lead to resource contention or leave hardware underutilized, making it a key variable in bottleneck analysis. Performance engineers use kernel profilers to measure metrics like compute throughput and memory bandwidth to guide this selection within the configuration space.

NPU PERFORMANCE TUNING

Key Characteristics of Workgroup Size

Workgroup size is a fundamental tunable parameter that determines how threads are grouped for cooperative execution on a Neural Processing Unit. Optimizing it balances parallelism, resource utilization, and synchronization overhead.

01

Definition and Hardware Mapping

Workgroup size defines the number of threads that are bundled together for cooperative execution on a single Compute Unit (CU) or Streaming Multiprocessor (SM). This grouping is the fundamental unit of scheduling for the hardware's SIMD (Single Instruction, Multiple Data) or SIMT (Single Instruction, Multiple Thread) engine. The hardware executes threads in groups called warps (NVIDIA) or wavefronts (AMD), and the workgroup size must be a multiple of this hardware warp/wavefront size (typically 32 or 64) to avoid underutilization. The compiler and runtime map each workgroup to the hardware's execution resources, managing register allocation and shared memory per workgroup.

02

Impact on Occupancy and Latency Hiding

Occupancy is the ratio of resident workgroups to the maximum possible on a compute unit. A larger workgroup consumes more registers and shared memory, potentially reducing the number of concurrent workgroups and lowering occupancy. However, sufficient occupancy is critical for latency hiding: when some threads are stalled waiting for memory, the hardware can switch to executing instructions from other ready threads within other resident workgroups. The optimal workgroup size maximizes occupancy while providing enough threads to keep the hardware busy during memory access latencies. Profiling tools report occupancy metrics to guide this tuning.

03

Relationship to Memory Coalescing

Workgroup size and organization directly influence memory coalescing, a critical optimization for bandwidth. For global memory accesses, consecutive threads within a workgroup should access consecutive memory addresses. This pattern allows the memory controller to combine multiple accesses into a single, wide transaction. A poorly chosen workgroup size or thread indexing scheme can result in non-coalesced access, where each thread's request is issued separately, devastating effective bandwidth. The workgroup dimensions (e.g., (16, 16) for a 2D kernel) should align with the data access patterns of the algorithm to promote coalescing.

04

Synchronization and Shared Memory Scope

Threads within a workgroup can synchronize efficiently using barrier instructions (e.g., barrier(CLK_LOCAL_MEM_FENCE)). This allows for cooperative algorithms like parallel reductions or tiled matrix multiplication where threads load data into scratchpad memory (a.k.a. shared memory/LDS), synchronize, and then compute. The workgroup size defines the scope and size of this collaborative workspace. The amount of shared memory required per workgroup is a key constraint; exceeding the per-CU limit will prevent the workgroup from launching. Synchronization is only defined within a workgroup; communication between workgroups requires atomic operations on global memory.

05

Auto-Tuning and Parameter Search

Finding the optimal workgroup size is a prime target for auto-tuning due to complex interactions with hardware. The configuration space includes:

  • Total size (e.g., 64, 128, 256, 512).
  • Multi-dimensional layout (e.g., (8,8), (16,16), (32,4)).

Kernel tuners like CLTune or AutoKernel perform a parameter search, often guided by Bayesian optimization or genetic algorithms, to evaluate performance across this space. A performance model may predict optimal sizes based on kernel characteristics (compute vs. memory bound) and hardware limits (register count, shared memory). The search must respect hardware constraints (max workgroup size, which is often 1024 or higher).

06

Trade-offs and Design Heuristics

Choosing workgroup size involves balancing competing factors:

  • Large Workgroups: Improve latency hiding within the group and can reduce global synchronization overhead. Risk higher register pressure, lowering occupancy.
  • Small Workgroups: Increase potential occupancy and may fit more concurrent groups. Risk insufficient parallelism to hide memory latency and increased global scheduling overhead.

Common heuristics: Start with a size that is a multiple of the warp/wavefront size (e.g., 128 or 256). For memory-bound kernels, prioritize sizes that maximize occupancy. For compute-bound kernels, ensure the size provides enough independent instructions to keep all ALUs busy. The final choice is always validated with a kernel profiler measuring execution time and hardware performance counters.

PERFORMANCE TUNING

How Workgroup Size Impacts Performance

Workgroup size is a fundamental tunable parameter that directly dictates how computational threads are mapped to the parallel hardware of a Neural Processing Unit (NPU) or GPU, with profound implications for latency, throughput, and resource efficiency.

Workgroup size defines the number of threads grouped for cooperative execution on a single compute unit. An optimal size maximizes hardware occupancy—the utilization of parallel execution units—and enables efficient intra-group synchronization and shared memory access. If too small, it underutilizes the processor, leaving arithmetic logic units (ALUs) idle. If too large, it can cause resource contention for registers or local memory, leading to pipeline stalls and reduced throughput. The ideal value is discovered through auto-tuning against hardware-specific constraints.

Performance is dictated by the interplay between workgroup size and the underlying memory hierarchy. Efficient sizes promote memory coalescing, where consecutive threads access consecutive addresses, maximizing memory bandwidth. Poorly chosen sizes can create memory access patterns that cause cache thrashing and high latency. Therefore, tuning is a critical step in bottleneck analysis, shifting a kernel from being memory-bound to compute-bound. Tools like a kernel profiler measure execution traces and performance counters to guide this optimization.

PERFORMANCE TRADEOFFS

Workgroup Size Optimization Considerations

Key factors to evaluate when selecting the optimal workgroup size for a computational kernel on an NPU or GPU.

Optimization FactorSmall Workgroup (e.g., 32-64 threads)Medium Workgroup (e.g., 128-256 threads)Large Workgroup (e.g., 512-1024 threads)

Occupancy Potential

Low to Medium

High

High (but can be limited by register pressure)

Thread Divergence Impact

High (significant serialization)

Medium

Low (cost amortized across many threads)

Memory Coalescing Efficiency

Often Poor

Good

Excellent (enables wide, aligned transactions)

Synchronization Overhead (barriers)

< 5 ns

10-20 ns

30-50 ns

Register Pressure per Thread

Low

Medium

High (can force register spilling to slower memory)

Shared Memory Usage per Block

Low

Medium

High (may exceed hardware limits)

Latency Hiding Capability

Poor (few threads to mask stalls)

Good

Excellent (many threads to interleave)

Kernel Launch Overhead

High (relative to work)

Medium

Low (amortized over large work)

WORKGROUP SIZE

Practical Examples and Heuristics

Selecting the optimal workgroup size is a hardware-specific tuning problem. These cards provide concrete heuristics and examples for common NPU and GPU architectures.

01

Hardware-Specific Heuristics

Optimal workgroup size is dictated by the underlying hardware's execution units and memory architecture.

  • NVIDIA GPU (CUDA): Aim for a multiple of 32 (the warp size). Common sizes are 128, 256, or 512 threads per block to maximize occupancy and hide latency.
  • AMD GPU (ROCm): Target a multiple of 64 (the wavefront size). Sizes of 64, 128, or 256 are typical.
  • Mobile/Edge NPUs (e.g., Qualcomm Hexagon): Often have smaller, fixed-size SIMD lanes (e.g., 128-bit). Workgroups may be smaller, such as 64 or 128, to fit constrained shared memory.
  • Apple Silicon (GPU): Uses threadgroups aligned with its SIMD width. Sizes like 128 or 256 are efficient, but performance depends heavily on memory coalescing patterns.
02

Memory-Bound vs. Compute-Bound Kernels

The nature of the kernel's bottleneck influences the ideal workgroup size.

  • Memory-Bound Kernels: Performance is limited by memory bandwidth. Use larger workgroups (e.g., 256-512) to increase the number of concurrent memory requests, improving latency hiding and enabling better memory coalescing.
  • Compute-Bound Kernels: Performance is limited by ALU throughput. Use smaller workgroups (e.g., 64-128) that fit more concurrent groups on a core, increasing occupancy and utilization of arithmetic units.
  • Rule of Thumb: Profile with a kernel profiler to identify the bottleneck, then adjust workgroup size accordingly.
03

Shared Memory and Register Pressure

Workgroup size directly impacts the consumption of on-chip, fast memory resources.

  • Shared Memory (Local Data Share): Each workgroup allocates a static block of shared memory. Larger workgroups consume more, potentially limiting the number of concurrent groups that can reside on a compute unit.
  • Register Pressure: Each thread requires architectural registers. Larger workgroups increase total register demand per group, which can reduce occupancy if registers are exhausted.
  • Heuristic: Use the vendor's occupancy calculator or profiler to find the maximum workgroup size before register/spill pressure causes performance degradation.
04

Divergence and Control Flow

Workgroup size impacts the penalty for thread divergence.

  • Within a warp (NVIDIA, 32 threads) or wavefront (AMD, 64 threads), divergent if/else or loop paths cause serialized execution.
  • Smaller workgroups may increase the probability that all threads in a warp follow the same path, reducing divergence.
  • Heuristic: For kernels with complex, data-dependent control flow, experiment with workgroup sizes that are exact multiples of the hardware's warp/wavefront size to pack similar threads together.
05

Auto-Tuning in Practice

Auto-tuning is the definitive method for finding the optimal workgroup size. A typical search involves:

  1. Define the Configuration Space: Parameterize workgroup size (e.g., [32, 64, 128, 256, 512]).
  2. Use a Search Strategy:
    • Exhaustive Search: Test all combinations (feasible for 1-2 parameters).
    • Bayesian Optimization: Models performance to intelligently sample the space.
    • Genetic Algorithms: Evolve populations of configurations.
  3. Evaluate with a Benchmark: Run the kernel with each configuration, measuring execution time or compute throughput.
  4. Select the Optimum: Choose the configuration with the best performance metric.

Tools like CLTune, Kernel Tuner, or Ansor automate this process.

06

Example: Matrix Multiplication Tuning

For a tiled matrix multiplication kernel on an NVIDIA A100 GPU:

  • Key Tunable: BLOCK_SIZE (which defines the workgroup dimensions as BLOCK_SIZE x BLOCK_SIZE).
  • Typical Search Space: BLOCK_SIZE[8, 16, 32, 64].
  • Trade-offs:
    • BLOCK_SIZE=16: 256 threads/block. Good occupancy, but may not fully utilize shared memory bandwidth.
    • BLOCK_SIZE=32: 1024 threads/block (max). Maximizes parallelism per block but increases register pressure, potentially lowering occupancy.
  • Optimal Result: For large matrices, BLOCK_SIZE=32 often wins due to superior memory coalescing within tiles. Auto-tuning validates this against BLOCK_SIZE=16.

This demonstrates that the theoretical maximum workgroup size is not always optimal.

WORKGROUP SIZE

Frequently Asked Questions

Essential questions and answers about workgroup size, a fundamental tunable parameter for optimizing parallel execution on Neural Processing Units (NPUs) and GPUs.

Workgroup size (also known as thread block size in CUDA or workgroup dimensions in OpenCL) defines the number of threads that are grouped together for cooperative execution and synchronization within a single compute unit on an NPU or GPU. It is a critical launch parameter specified by the programmer that determines how a parallel workload is partitioned across the hardware's execution resources. The optimal size balances occupancy (hardware utilization), efficient use of shared memory, and minimizes overhead from thread divergence and synchronization.

  • Key Components: Typically defined as a 1D, 2D, or 3D configuration (e.g., (256, 1, 1)).
  • Hardware Limits: Constrained by the NPU/GPU architecture's maximum threads per compute unit and available registers.
  • Performance Impact: Directly influences memory coalescing, cache behavior, and the ability to hide instruction and memory latency.
Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.