TornadoVM’s cuBLAS integration brings NVIDIA’s production-grade dense linear algebra library into the JavaDocumentation 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 model. Rather than calling cuBLAS through a separate JNI layer with manually managed device memory, you express GEMM and GEMV operations as library tasks — first-class TaskGraph nodes that share TornadoVM-managed device buffers with your JIT-compiled kernels on one CUDA stream. The cuBLASLt variant extends this with fused epilogues (BIAS, GELU_BIAS) that collapse a GEMM plus a separate activation kernel into a single highly-optimized dispatch, which is especially valuable in the launch-bound regime of LLM token generation.
Prerequisite: CUDA Toolkit with cuBLAS (
libcublas). cuBLAS ships inside the CUDA Toolkit — no separate package is needed. Build TornadoVM with make BACKEND=cuda.cuBLAS Factory Methods
All factories are static methods onuk.ac.manchester.tornado.cublas.CuBlas. Pass them as the second argument to taskGraph.libraryTask(id, factory, args...).
| Factory | cuBLAS Function | Semantics |
|---|---|---|
cublasSgemv(op, m, n, α, A, lda, x, incx, β, y, incy) | cublasSgemv | y = α·op(A)·x + β·y |
cublasSgemm(opA, opB, m, n, k, α, A, lda, B, ldb, β, C, ldc) | cublasSgemm | C = α·op(A)·op(B) + β·C |
cublasSgemmTF32(...) | cublasSgemm + TF32 math mode | Same as SGEMM, executed on TF32 Tensor Cores (~1e-4 rel. error) |
cublasGemmExFP16(...) | cublasGemmEx | FP16 inputs, FP16 output, FP32 Tensor Core accumulation |
cublasGemmExFP16FP32(...) | cublasGemmEx | FP16 inputs, FP32 output, FP32 Tensor Core accumulation |
cublasGemmExBF16(...) | cublasGemmEx | BF16 inputs and output, FP32 accumulation (BFloat16Array) |
cublasSgemmStridedBatched(...) | cublasSgemmStridedBatched | C[i] = α·op(A[i])·op(B[i]) + β·C[i] over a flat-array batch |
cuBLASLt Factory Methods
Fused-epilogue GEMM is available throughuk.ac.manchester.tornado.cublas.CuBlasLt. Plans (descriptors + heuristic-selected algorithm) are created once per problem shape and cached with a 32 MiB device workspace.
| Factory | Epilogue | Notes |
|---|---|---|
ltMatmulFP32(opA, opB, m, n, k, α, A, lda, B, ldb, β, C, ldc) | None | FP32 matmul with plan caching |
ltMatmulFP16(...) | None | FP16 matmul, FP32 Tensor Core accumulation |
ltMatmulFP8(...) | None | E4M3 operands, FP16 output, TN layout, ld must be multiple of 16 B |
ltMatmulBiasFP16(..., bias) | BIAS | C = op(A)·op(B) + bias, fused |
ltMatmulGeluBiasFP16(..., bias) | GELU_BIAS | C = GELU(op(A)·op(B) + bias), tanh approximation, fully fused |
Column-Major Layout
cuBLAS is column-major. TornadoVM arrays are row-major. The standard tricks used throughout the tests:- SGEMV (row-major W·x)
- SGEMM (row-major C = A·B)
A row-major weight matrix
W of shape (d × n) is the column-major matrix (n × d) with lda = n. Compute y = W·x using the transpose op:Complete SGEMM Example
The following example runs a complete matrix multiply through a cuBLAS library task inside aTaskGraph, cross-validates against a sequential Java result, and measures throughput.
Performance Reference
All numbers below are from an NVIDIA GeForce RTX 4090 with CUDA 12.6.SGEMM Throughput
| Size | JIT Kernel | cuBLAS FP32 | cuBLAS TF32 | cuBLAS FP16 |
|---|---|---|---|---|
| 1024 | 3.9 TFLOP/s | 26.1 TFLOP/s | 28.2 TFLOP/s | 44.1 TFLOP/s |
| 2048 | 6.0 TFLOP/s | 48.3 TFLOP/s | 62.8 TFLOP/s | 120.6 TFLOP/s |
| 4096 | 5.8 TFLOP/s | 57.0 TFLOP/s | 81.1 TFLOP/s | 160.6 TFLOP/s |
Fused Epilogue Speedup (cuBLASLt)
BenchmarkLtFusedMlp: fused GELU_BIAS vs. unfused GemmEx FP16 + JIT kernel.| Size | Unfused | Fused | Speedup |
|---|---|---|---|
| 1024 | 17.5 TFLOP/s | 29.4 TFLOP/s | 1.68× |
| 2048 | 73.8 TFLOP/s | 98.3 TFLOP/s | 1.33× |
| 4096 | 132.1 TFLOP/s | 147.3 TFLOP/s | 1.11× |
TF32 and FP16 Tensor Cores
TornadoVM exposes Tensor Core acceleration through named factory variants — no code restructuring required.- TF32 Tensor Cores
- FP16 Tensor Cores
- FP16 cuBLASLt (fused)
TF32 uses the same
FloatArray inputs as FP32 but routes through Tensor Cores via the CUBLAS_TF32_TENSOR_OP_MATH math mode. Expect ~1e-4 relative error compared to FP32.