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.
TaskGraph is the central building block of every TornadoVM program. It is a fluent, mutable container that accumulates tasks (Java method references), data-transfer directives, and device hints into a named graph. Once the graph is fully specified, calling snapshot() seals it into an immutable form that can be handed to a TornadoExecutionPlan for execution. Because TaskGraph is itself mutable, you can modify it between snapshot calls — enabling dynamic workloads — without affecting any previously snapshotted graphs that are already in flight.
Every task name within a single
TaskGraph must be unique. Registering two tasks with the same id throws a TornadoTaskRuntimeException at runtime. Prefix task IDs with a short namespace (e.g. "myGraph.add") to avoid collisions when composing multiple graphs.Constructor
Creates a new, empty task graph with the given name. The name is used as an identifier in logging, profiler output, and when addressing individual tasks from an execution plan (e.g.
"graphName.taskId").Adding Tasks
TornadoVM maps each overloadedtask() variant to the number of parameters your kernel method accepts. All variants return this, enabling fluent chaining.
Adds a zero-argument task. Useful for side-effect-free initialization kernels that operate entirely on device-side state.
| Parameter | Type | Description |
|---|---|---|
id | String | Unique task identifier within this graph. |
code | Task | A reference to a Java method with no parameters. |
Adds a task with one typed argument. The generic type
T1 is inferred from the argument.| Parameter | Type | Description |
|---|---|---|
id | String | Unique task identifier. |
code | Task1<T1> | Method reference — e.g. MyKernels::vectorAdd. |
arg | T1 | The single argument passed to the kernel. |
Adds a task with two typed arguments. The pattern extends uniformly through
Task3, Task4, … up to Task20, each accepting the corresponding number of typed positional arguments.Library Tasks
Library tasks invoke functions from external native libraries (e.g., NVIDIA cuBLAS) via a factory interface pattern. The factory lambda receives the typed arguments, calls the native binding, and returns aTornadoNativeFunction that the runtime dispatches.
Adds a single-argument library task. The Variants exist from
LibraryTask1<T1> functional interface is a factory: it receives arg1 and produces the native-function descriptor that TornadoVM schedules.LibraryTask1 through LibraryTask20, matching the arity of the underlying library call.Data Transfer
Data transfers between the JVM heap and device memory are declared explicitly on theTaskGraph. The runtime uses the specified mode to decide when to perform each copy, eliminating redundant transfers across repeated executions.
Tags one or more Java objects for upload to the device. The
mode constant from DataTransferMode controls the transfer schedule.| Parameter | Type | Description |
|---|---|---|
mode | int | A DataTransferMode constant (see table below). |
objects | Object... | Varargs list of arrays or TornadoVM typed arrays to upload. |
Tags one or more Java objects for readback from the device after kernel execution. Typically called with
EVERY_EXECUTION for output buffers or UNDER_DEMAND when you want to control readback timing explicitly via TornadoExecutionResult.transferToHost().| Parameter | Type | Description |
|---|---|---|
mode | int | A DataTransferMode constant. |
objects | Object... | Varargs list of arrays to read back to host memory. |
Tags objects to remain on the device after execution without being copied back to the host. Equivalent to
transferToHost(DataTransferMode.UNDER_DEMAND, objects). Useful for pipeline stages where intermediate buffers feed the next graph without ever touching the CPU.Instructs the runtime to consume input objects directly from device memory belonging to a previous task graph, skipping any host-to-device transfer. The objects must have been produced and persisted by a preceding
TaskGraph execution within the same execution plan.DataTransferMode Constants
DataTransferMode is a utility class (not an enum) in uk.ac.manchester.tornado.api.enums that exposes three static final int constants. Pass these constants directly to transferToDevice() and transferToHost().
Copies data to/from the device only during the very first execution of the task graph. Subsequent executions reuse the on-device buffer as read-only. Use for constant inputs such as model weights or look-up tables.
Copies data to/from the device on every call to
execute(). Use for inputs that change between invocations or for output buffers that must always be read back.Suppresses automatic copy-out. Data remains on the device until the programmer explicitly calls
TornadoExecutionResult.transferToHost(objects). Use to pipeline multi-graph workflows where intermediate results are consumed on-device.Snapshotting
Seals the current state of the
TaskGraph into an ImmutableTaskGraph. The immutable snapshot can be passed to a TornadoExecutionPlan. The original TaskGraph remains mutable and can be modified to produce further snapshots.Pre-built Native Tasks
For advanced use cases, TornadoVM can schedule pre-built native kernels (e.g., OpenCL C source files) without going through the Java JIT path.prebuiltTask(String id, String entryPoint, String filename, AccessorParameters accessorParameters)
TaskGraph
Adds a pre-built native kernel task. TornadoVM loads and compiles the native source at the path specified by
filename and invokes the function named entryPoint.| Parameter | Type | Description |
|---|---|---|
id | String | Unique task identifier within this graph. |
entryPoint | String | Name of the kernel function to invoke (e.g., "vectorAdd"). |
filename | String | Path to the native kernel source file (e.g., an OpenCL C .cl file). |
accessorParameters | AccessorParameters | Describes read/write access mode for each kernel parameter. |
prebuiltTask(String id, String entryPoint, String filename, AccessorParameters accessorParameters, int[] atomics)
TaskGraph
Variant of
prebuiltTask() that additionally supplies an atomics region (int[]) for kernels that use atomic operations on a pre-allocated integer buffer.| Parameter | Type | Description |
|---|---|---|
id | String | Unique task identifier. |
entryPoint | String | Kernel entry-point name. |
filename | String | Path to the native kernel source file. |
accessorParameters | AccessorParameters | Access mode descriptors for each parameter. |
atomics | int[] | Integer array allocated for atomic operations within the kernel. |
Complete Fluent Example
The following example shows the full lifecycle of aTaskGraph: declare inputs, add a task, declare outputs, snapshot, and execute.
Execution Plan
Learn how to wrap
ImmutableTaskGraph in a TornadoExecutionPlan and control execution policy.Annotations
Use
@Parallel and @Reduce to mark loops and accumulators for automatic GPU parallelisation.