TornadoVM’s vector and matrix types are lightweight value-class wrappers that map directly to GPU vector registers. Writing a kernel in terms ofDocumentation 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.
Float4 instead of four separate float variables lets the JIT compiler emit vectorized SIMD instructions on both GPU (OpenCL float4, CUDA float4) and CPU (AVX/NEON) backends without any intrinsic annotations. Every vector type lives in the package uk.ac.manchester.tornado.api.types.vectors, is annotated @Vector, and carries its payload in a small on-heap backing array tagged @Payload—a layout the TornadoVM compiler recognizes and maps to a vector register allocation. Matrix types in uk.ac.manchester.tornado.api.types.matrix follow the same principle but store their elements in a TornadoVM off-heap FloatArray / DoubleArray so the full matrix can be registered with a TaskGraph.
Why use vector types?
Register-width utilization
A single
Float4.add maps to one 128-bit SIMD add instruction. Without vector types, the compiler may or may not auto-vectorize scalar loops.GPU data-type parity
OpenCL and CUDA both define
float2, float4, float8, float16 natively. TornadoVM vector types produce identical code to hand-written OpenCL C kernels.Dot-product and norms
Float4.dot, Float4.length, Float4.normalise map to optimized math paths, avoiding manual intermediate stores.Type safety
Mixing element widths (e.g.
Float4 + Int4) is caught at compile time and handled via explicit overloads rather than implicit casts.Float vector types
Float vectors cover widths 2, 3, 4, 8, and 16 lanes.Float2, Float3, and Float4 use named accessors (.getX(), .getY(), .getZ(), .getW()); Float8 and Float16 use lane indices .getS0() through .getS7() / .getS15().
Float2
Two single-precision floats: x and y.
Zero-initializes both lanes.
Initializes x and y lanes explicitly.
Returns the x (index 0) or y (index 1) lane value.
Sets the x or y lane.
Element-wise arithmetic. Overloads accept
(Float2, Float2), (Float2, float), and mixed (Float2, Int2) / (Int2, Float2).Element-wise minimum or maximum.
Returns the scalar dot product
a.x*b.x + a.y*b.y.Euclidean length:
sqrt(dot(v, v)).Float3
Three single-precision floats: x, y, z. Commonly used in 3D geometry kernels.
Initializes all three lanes.
Accessor for the z (index 2) lane.
Returns the cross product
a × b.Returns
v / length(v).Casts the first two lanes to a
Float2.Float4
Four single-precision floats: x, y, z, w. The most widely used vector type in TornadoVM—maps to a 128-bit register on every supported backend.
Accessor for the w (index 3) lane.
Four-lane dot product.
Element-wise square root.
Element-wise floor.
Element-wise fractional part.
Clamps each lane to
[min, max].Returns the unit vector in the same direction.
Returns the scalar horizontal sum of all four lanes.
Truncating casts to narrower vector types.
Returns the low two lanes
(x, y) or high two lanes (z, w) as a Float2.Float8 and Float16
Eight-lane and sixteen-lane float vectors. Lanes are accessed by index suffix: .getS0() through .getS7() (Float8) or .getS0() through .getS15() (Float16). All arithmetic operations (add, sub, mult, div, min, max, sqrt, dot) are available as static methods with the same signatures as Float4.
Int vector types
Integer vectors follow the same lane-count progression:Int2, Int3, Int4, Int8, Int16. Named accessors .getX() / .getY() / .getZ() / .getW() apply to widths 2–4; lane-index accessors .getS0()–.getSN() apply to 8 and 16. Arithmetic operations match their Float counterparts.
Double vector types
Double-precision vectors:Double2, Double3, Double4, Double8, Double16. They follow the same pattern as float vectors but use double lanes and DoubleBuffer as their NIO buffer type. Use these when FP64 precision is required (e.g. scientific simulations) and the target GPU has adequate FP64 throughput.
Half-precision vector types
TheHalf2, Half3, Half4, Half8, and Half16 types in the vectors package hold HalfFloat lanes for FP16 arithmetic in GPU kernels. Element-wise add, sub, mult, and div are defined, each delegating to the HalfFloat arithmetic helpers.
Half2 is also used by HalfFloatArray.getHalf2(int) for packed 32-bit aligned loads from FP16 buffers.
Matrix types
TornadoVM provides 2D and 3D matrix types backed by off-heapFloatArray / DoubleArray storage in row-major order, making them compatible with TaskGraph data-transfer operations.
Matrix2DFloat
A rectangular float matrix stored in row-major order.
Allocates an off-heap float matrix of the given dimensions.
Wraps an existing
FloatArray as a matrix view; no copy is made.Returns the element at row
i, column j.Sets the element at row
i, column j.Zeros all elements of the underlying
FloatArray.Matrix2DDouble, Matrix2DInt, Matrix3DFloat, Matrix3DDouble, Matrix3DInt, Matrix3DLong, Matrix3DShort, and Matrix2DFloat4 (elements are Float4 vectors).
Using vector types in parallel kernels
Vector types work in both@Parallel index-space kernels and KernelContext kernels. The example below shows a parallel RGBA image desaturation using Float4 to process four channel values per pixel in one SIMD operation.
Vector and matrix type summary
Float family
Float2 · Float3 · Float4 · Float8 · Float16Collections:
VectorFloat2–VectorFloat16Int family
Int2 · Int3 · Int4 · Int8 · Int16Collections:
VectorInt2–VectorInt16Double family
Double2 · Double3 · Double4 · Double8 · Double16Collections:
VectorDouble2–VectorDouble16Half family
Half2 · Half3 · Half4 · Half8 · Half16Collections:
VectorHalf2–VectorHalf16Byte / Short
Byte3 · Byte4 · Short2 · Short3Matrix types
Matrix2DFloat · Matrix2DDouble · Matrix2DIntMatrix3DFloat · Matrix3DDouble · Matrix2DFloat4