Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Deepak-Sangle/TornadoVM/llms.txt
Use this file to discover all available pages before exploring further.
WorkerGrid objects define the thread launch configuration for tasks that use KernelContext. They specify how many global threads to launch in each dimension (equivalent to the total number of GPU threads) and how those threads are grouped into workgroups — called thread blocks in CUDA or work-groups in OpenCL. A GridScheduler then maps task names to their respective WorkerGrid instances and is attached to a TornadoExecutionPlan via withGridScheduler(). If no GridScheduler is provided, TornadoVM falls back to an automatic thread-count heuristic and the local work size is chosen by the driver.
WorkerGrid objects are required when a task uses KernelContext to read thread indices. Without a GridScheduler, TornadoVM cannot determine the iteration space at compile time, which prevents correct code generation for explicit thread-ID kernels.WorkerGrid1D
WorkerGrid1D describes a one-dimensional thread grid. It is the correct choice for element-wise array kernels where each thread handles a single scalar element along a single axis.
Creates a 1D grid launching
x global threads in the X dimension. The Y and Z global work sizes are implicitly set to 1.| Parameter | Type | Description |
|---|---|---|
x | int | Total number of threads in the X dimension (global work size). |
Sets the workgroup (thread block) size. For a 1D grid, set
y = 1 and z = 1. The number of workgroups launched is globalWork[i] / localWork[i] for each dimension.| Parameter | Type | Description |
|---|---|---|
x | long | Threads per workgroup in the X dimension. |
y | long | Threads per workgroup in the Y dimension. Set to 1 for 1D grids. |
z | long | Threads per workgroup in the Z dimension. Set to 1 for 1D grids. |
Updates the global work size after construction. Useful when the problem size changes between executions without rebuilding the scheduler.
WorkerGrid2D
WorkerGrid2D describes a two-dimensional thread grid. Use it for matrix, image, or any 2D domain decomposition where each thread handles one (row, col) element.
Creates a 2D grid with
x threads in the X dimension and y threads in the Y dimension. The Z global work size is implicitly 1.| Parameter | Type | Description |
|---|---|---|
x | int | Total threads in the X dimension (e.g., number of columns). |
y | int | Total threads in the Y dimension (e.g., number of rows). |
Sets the 2D workgroup dimensions. Typical values are
16×16 or 32×8 depending on the access pattern and the cache structure of the target GPU.Overrides the global work size for both dimensions.
WorkerGrid3D
WorkerGrid3D describes a three-dimensional thread grid. Use it for volumetric computations, 3D stencils, or any problem that maps naturally to a three-axis decomposition.
Creates a 3D grid with independent work sizes along all three axes.
| Parameter | Type | Description |
|---|---|---|
x | int | Total threads in the X dimension. |
y | int | Total threads in the Y dimension. |
z | int | Total threads in the Z dimension. |
Sets the 3D workgroup dimensions. Ensure that
x * y * z does not exceed the device’s maximum threads-per-block limit (typically 1024).Overrides all three global work sizes simultaneously.
Common WorkerGrid Methods (all variants)
All threeWorkerGrid classes inherit from AbstractWorkerGrid, which provides the following shared accessors:
Returns a 3-element array
[x, y, z] of the current global work sizes.Returns a 3-element array
[x, y, z] of the current local workgroup sizes, or null if setLocalWork() has not been called.Returns a 3-element array of the computed workgroup counts:
globalWork[i] / localWork[i] for each dimension.Returns the 3-element global offset array
[x, y, z]. The offset shifts the starting global ID in each dimension. Defaults to [0, 0, 0].Sets the global offset for each dimension. The offset is added to the base global thread ID computed from the workgroup index, enabling sub-range dispatch within a larger iteration space.
Clears the local work size, reverting to driver-chosen workgroup dimensions.
Clears the precomputed workgroup-count array. The count is automatically recomputed the next time
setLocalWork() is called.GridScheduler
GridScheduler maintains a map from fully-qualified task names ("graphName.taskId") to WorkerGrid instances. It is passed to TornadoExecutionPlan.withGridScheduler() to activate explicit thread scheduling.
Creates an empty grid scheduler. Use
addWorkerGrid() to populate it.Creates a grid scheduler pre-populated with a single task-to-grid mapping. This is the most common constructor for single-task workloads.
| Parameter | Type | Description |
|---|---|---|
taskName | String | Fully qualified name: "graphName.taskId". |
workerGrid | WorkerGrid | The WorkerGrid1D, WorkerGrid2D, or WorkerGrid3D to assign. |
Registers an additional task-to-grid mapping after construction.
| Parameter | Type | Description |
|---|---|---|
taskName | String | Fully qualified task name. |
workerGrid | WorkerGrid | Worker grid to assign to this task. |
Retrieves the
WorkerGrid registered for a given task name, or null if none is registered.Returns
true if a grid is registered for the composite key taskScheduleName + "." + taskName.Returns the set of all registered task names.
WorkerGrid Dimension Summary
Global vs. Local Work Size Relationship
The number of workgroups launched in each dimension is derived automatically:globalWork[i] must be a multiple of localWork[i] in every dimension. If you do not call setLocalWork(), the GPU driver selects a default workgroup size (often 64 or 128 for 1D, 16×16 for 2D).
| Scenario | globalWork | localWork | workgroups |
|---|---|---|---|
| 1D, 4096 threads, 256 per block | [4096, 1, 1] | [256, 1, 1] | 16 |
| 2D matrix 512×512, 16×16 tiles | [512, 512, 1] | [16, 16, 1] | 32×32 = 1024 |
| 3D volume 64×64×64, 8×8×4 | [64, 64, 64] | [8, 8, 4] | 8×8×16 = 1024 |
Complete 2D Matrix Multiply Example
Kernel Context
Read thread IDs, allocate local memory, and issue barriers inside your kernel.
Execution Plan
Attach the GridScheduler to the execution plan with
withGridScheduler().