### Install TornadoVM with SDKMAN!, verify devices, and run an example Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/faq.rst Three shell commands to install TornadoVM via SDKMAN!, list available devices, and run a matrix-vector example. Requires SDKMAN! and a compatible JDK (e.g., JDK 21). The example JAR path includes version 5.0.0 and the jdk21 profile. ```bash # 1. Install with SDKMAN! $ sdk install tornadovm # 2. Verify devices $ tornado --devices # 3. Run an example $ java @$TORNADOVM_HOME/tornado-argfile -cp $TORNADOVM_HOME/share/java/tornado/tornado-examples-5.0.0-jdk21.jar uk.ac.manchester.tornado.examples.compute.MatrixVectorRowMajor ``` -------------------------------- ### Windows: Setup environment and show installer help Source: https://github.com/beehive-lab/tornadovm/blob/master/INSTALL_FROM_SOURCE.md Creates a Python virtual environment, activates it, runs the Windows tools script, and then shows the installer help. The output lists the same options as on Linux/macOS. ```bash python -m venv .venv .venv\Scripts\activate.bat .\bin\windowsMicrosoftStudioTools2022.cmd python bin\tornadovm-installer --help usage: tornadovm-installer [-h] [--jdk JDK] [--backend BACKEND] [--version] [--listJDKs] [--mvn_single_threaded] [--auto-deps] TornadoVM Installer Tool. It will install all software dependencies except the GPU drivers options: -h, --help show this help message and exit --jdk JDK Specify a JDK to install by its keyword (e.g., 'jdk21', 'graal-jdk-21'). Run with --listJDKs to view all available JDK keywords. --backend BACKEND Select the backend to install: { opencl, cuda, metal } --version Print version --listJDKs List supported JDKs --mvn_single_threaded Run Maven in single-threaded mode --auto-deps Automatic download and use any missing dependencies ``` -------------------------------- ### Example output of tornado --printJavaFlags Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/ide-integration.rst Example output when building with all backends. Copy the flags starting from -server to the end for use in IntelliJ VM options. ```bash /bin/java -server --enable-preview -Djava.library.path=/bin/sdk/lib --module-path .:/bin/sdk/share/java/tornado -Dtornado.load.api.implementation=uk.ac.manchester.tornado.runtime.tasks.TornadoTaskGraph -Dtornado.load.runtime.implementation=uk.ac.manchester.tornado.runtime.TornadoCoreRuntime -Dtornado.load.tornado.implementation=uk.ac.manchester.tornado.runtime.common.Tornado @/bin/sdk/etc/exportLists/common-exports --enable-native-access=tornado.runtime @/bin/sdk/etc/exportLists/opencl-exports @/bin/sdk/etc/exportLists/cuda-exports --add-modules jdk.unsupported,java.management,java.logging,jdk.jfr,java.naming,jdk.management,tornado.runtime,tornado.drivers.common,tornado.drivers.opencl,tornado.drivers.cuda ``` -------------------------------- ### Verify TornadoVM installation Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/developer-guidelines.rst Commands to verify the installation: list accelerator devices, run the unit test suite, and run a specific example (NBody). ```bash # list the accelerator devices reachable from TornadoVM tornado --devices # run the unit test suite tornado-test -V # run a specific example (e.g., NBody) tornado -m tornado.examples/uk.ac.manchester.tornado.examples.compute.NBody ``` -------------------------------- ### Install pre-commit hooks Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/developer-guidelines.rst Install the pre-commit package and set up the hooks in the repository. Run these commands in the project root. ```bash pip install pre-commit pre-commit install ``` -------------------------------- ### Linux/macOS: Show installer help Source: https://github.com/beehive-lab/tornadovm/blob/master/INSTALL_FROM_SOURCE.md Run the installer with --help to display available options and usage. The output lists flags for selecting a JDK, backend, and other options. ```bash $ ./bin/tornadovm-installer --help usage: tornadovm-installer [-h] [--jdk JDK] [--backend BACKEND] [--version] [--listJDKs] [--mvn_single_threaded] [--auto-deps] TornadoVM Installer Tool. It will install all software dependencies except the GPU drivers options: -h, --help show this help message and exit --jdk JDK Specify a JDK to install by its keyword (e.g., 'jdk21', 'graal-jdk-21'). Run with --listJDKs to view all available JDK keywords. --backend BACKEND Select the backend to install: { opencl, cuda, metal } --version Print version --listJDKs List supported JDKs --mvn_single_threaded Run Maven in single-threaded mode --auto-deps Automatic download and use any missing dependencies ``` -------------------------------- ### Windows build setup commands Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/developer-guidelines.rst Commands for setting up the build environment on Windows, including running the Visual Studio tools script, creating a Python virtual environment, activating it, running the installer, and setting environment variables. ```bash .\bin\windowsMicrosoftStudioTools2022.cmd python -m venv .venv .venv\Scripts\activate.bat python bin\tornadovm-installer setvars.cmd ``` -------------------------------- ### Run TornadoVM example with Java and argfile Source: https://github.com/beehive-lab/tornadovm/blob/master/BUILD_AND_RUN.md Example invocation of the java command with the tornado-argfile, specifying the example jar and main class. ```bash java @tornado-argfile \ -cp tornado-examples/target/tornado-examples-1.1.2-SNAPSHOT.jar \ uk.ac.manchester.tornado.examples.compute.MatrixMultiplication ``` -------------------------------- ### Install and run TornadoViz Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/dev-tools.rst Clone the TornadoViz repository, install its Python dependencies, and launch the Streamlit app. Feed it the bytecode log produced by running with --printBytecodes. ```bash git clone https://github.com/beehive-lab/tornadoviz.git cd tornadoviz pip install -r requirements.txt streamlit run tornado-visualizer-fixed.py ``` -------------------------------- ### Windows: Install OpenCL backend with JDK 21 Source: https://github.com/beehive-lab/tornadovm/blob/master/INSTALL_FROM_SOURCE.md Installs the OpenCL backend with OpenJDK 21 on Windows. The second command shows how to combine multiple backends (OpenCL and CUDA). ```bash # Install the OpenCL backend with OpenJDK 21 $ python bin\tornadovm-installer --jdk jdk21 --backend opencl # It is also possible to combine different backends: $ python bin\tornadovm-installer --jdk jdk21 --backend opencl,cuda ``` -------------------------------- ### TornadoExecutionPlan.withWarmUp() Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/programming.rst Performs a warmup, compiling the code and installing it in a code-cache. ```APIDOC ## Method: withWarmUp() ### Description Performs a warmup, compiling the code and installing it in a code-cache. ### Returns - `TornadoExecutionPlan` - The current execution plan for chaining. ### Example ```java executionPlan.withWarmUp() ``` ``` -------------------------------- ### Run cuFFT examples Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/hybrid-api.rst Commands to run the cuFFT hybrid API examples from the tornado-cufft module. Includes the frequency filter example and a benchmark. ```bash tornado -m tornado.cufft/uk.ac.manchester.tornado.cufft.tests.FrequencyFilterExample tornado -m tornado.cufft/uk.ac.manchester.tornado.cufft.tests.BenchmarkFft ``` -------------------------------- ### Run hybrid GEMV example with make and tornado Source: https://github.com/beehive-lab/tornadovm/blob/master/tornado-native-libs/HYBRID_API_GUIDE.md Builds the backend with CUDA and runs the hybrid GEMV test class. Assumes the tornado-cublas module is installed and the test class is on the classpath. ```bash make BACKEND=cuda tornado -m tornado.cublas/uk.ac.manchester.tornado.cublas.tests.TestCuBlasSgemvWithTornadoVMTasksPOST ``` -------------------------------- ### Run TornadoVM example with debug flag Source: https://github.com/beehive-lab/tornadovm/blob/master/BUILD_AND_RUN.md Example invocation of the tornado command with the -Dtornado.debug=true JVM option. ```bash tornado --jvm="-Dtornado.debug=true" -cp target/examples.jar examples.MatrixMultiplication ``` -------------------------------- ### Enable TornadoVM Profiler from Command Line with --enableProfiler console Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/dev-tools.rst Run a TornadoVM example with the profiler enabled in console mode, printing a JSON report to STDOUT. The example uses the VectorAddInt example with a parameter of 100000. All timers are printed in nanoseconds. ```bash $ tornado --enableProfiler console -m tornado.examples/uk.ac.manchester.tornado.examples.VectorAddInt --params="100000" { "s0": { "TOTAL_BYTE_CODE_GENERATION": "10465146", "COPY_OUT_TIME": "24153", "COPY_IN_TIME": "72044", "TOTAL_DRIVER_COMPILE_TIME": "63298322", "TOTAL_DISPATCH_DATA_TRANSFERS_TIME": "0", "TOTAL_CODE_GENERATION_TIME": "16564279", "TOTAL_TASK_GRAPH_TIME": "285317518", "TOTAL_GRAAL_COMPILE_TIME": "109520628", "TOTAL_KERNEL_TIME": "47974", "TOTAL_COPY_OUT_SIZE_BYTES": "400024", "TOTAL_COPY_IN_SIZE_BYTES": "1600096", "s0.t0": { "BACKEND": "OPENCL", "METHOD": "VectorAddInt.vectorAdd", "DEVICE_ID": "0:0", "DEVICE": "Intel(R) UHD Graphics [0x9bc4]", "TASK_COMPILE_GRAAL_TIME": "109520628", "TASK_CODE_GENERATION_TIME": "16564279", "TASK_COMPILE_DRIVER_TIME": "63298322", "POWER_USAGE_mW": "n/a", "TASK_KERNEL_TIME": "47974" } } } ``` -------------------------------- ### Run NcclMultiProcessWorker example (rank 0 and other ranks) Source: https://github.com/beehive-lab/tornadovm/blob/master/tornado-native-libs/tornado-nccl/README.md Commands to launch the NcclMultiProcessWorker example. Rank 0 uses `new` and prints the NCCL-ID; other ranks use that id. The example is runnable via the TornadoVM launcher. ```bash tornado -m tornado.nccl/uk.ac.manchester.tornado.nccl.tests.NcclMultiProcessWorker new 2 0 0 # prints NCCL-ID ``` ```bash tornado -m tornado.nccl/uk.ac.manchester.tornado.nccl.tests.NcclMultiProcessWorker 2 1 1 ``` -------------------------------- ### Example jdk22plus argfile contents Source: https://github.com/beehive-lab/tornadovm/blob/master/LEYDEN_GRAALVM_NATIVE_IMAGE.md The argfile has 11 flag lines and is the same on every JDK the SDK supports. This example is for a jdk22plus SDK with OpenCL and CUDA. The jdk21 argfile also has --enable-preview. No -XX:+EnableJVMCI, --patch-module, or --upgrade-module-path is needed on any JDK. ```text -server -Djava.library.path=$TORNADOVM_HOME/lib --module-path .:$TORNADOVM_HOME/share/java/tornado -Dtornado.load.api.implementation=uk.ac.manchester.tornado.runtime.tasks.TornadoTaskGraph -Dtornado.load.runtime.implementation=uk.ac.manchester.tornado.runtime.TornadoCoreRuntime -Dtornado.load.tornado.implementation=uk.ac.manchester.tornado.runtime.common.Tornado --add-opens java.base/java.lang=tornado.runtime --enable-native-access=tornado.runtime --add-opens java.base/java.lang=tornado.drivers.opencl --add-opens java.base/java.lang=tornado.drivers.cuda --add-modules jdk.unsupported,java.management,java.logging,jdk.jfr,java.naming,jdk.management,tornado.runtime,tornado.drivers.common,tornado.drivers.opencl,tornado.drivers.cuda,tornado.cublas,... ``` -------------------------------- ### Install Sphinx Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/build-documentation.rst Install Sphinx using pip3. ```bash pip3 install -U sphinx ``` -------------------------------- ### Off-heap example using IntArray Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/offheap-types.rst Shows the transformed version using the off-heap IntArray type. The array is created with a size, initialized to 10, and used in the same TaskGraph pattern. The add method is renamed to acc and uses getSize, get, and set methods to access data. ```java public static void main(String[] args) { IntArray input = new IntArray(numElements); // create a new off heap segment of int values input.init(10); // initialize all the values of the input to be 10 TaskGraph taskGraph = new TaskGraph("s0") .transferToDevice(DataTransferMode.FIRST_EXECUTION, input) .task("t", Example::add, input, 1) .transferToHost(DataTransferMode.EVERY_EXECUTION, input); ImmutableTaskGraph immutableTaskGraph = taskGraph.snapshot(); TornadoExecutionPlan executor = new TornadoExecutor(immutableTaskGraph); executor.execute(); } public static void acc(IntArray input, int value) { // Pass the IntArray as a parameter for (@Parallel int i = 0; i < input.getSize(); i++) { input.set(i, input.get(i) + value); // Use the set and get functions access data } } ``` -------------------------------- ### Linux/macOS: Install OpenCL backend with JDK 21 Source: https://github.com/beehive-lab/tornadovm/blob/master/INSTALL_FROM_SOURCE.md Installs the OpenCL backend with OpenJDK 21. The second command shows how to combine multiple backends (OpenCL and CUDA) in a single installation. ```bash # Install the OpenCL backend with OpenJDK 21 $ ./bin/tornadovm-installer --jdk jdk21 --backend opencl # It is also possible to combine different backends: $ ./bin/tornadovm-installer --jdk jdk21 --backend opencl,cuda ``` -------------------------------- ### Load only the backend you use with -Dtornado.enabled.backends Source: https://github.com/beehive-lab/tornadovm/blob/master/LEYDEN_GRAALVM_NATIVE_IMAGE.md Name the backends to load at start-up to avoid initialising unused ones. Values are `opencl`, `cuda`, or `metal`, or a comma-separated list; an empty value (the default) loads all installed backends. Backend indices count only the loaded backends, and a name that matches no installed backend fails at start-up with `TornadoBackendNotFound`. ```bash java @$TORNADOVM_HOME/tornado-argfile -Dtornado.enabled.backends=cuda -cp app.jar com.example.Main ``` ```bash tornado --jvm="-Dtornado.enabled.backends=cuda" --classpath app.jar com.example.Main ``` ```bash ./app -Dtornado.enabled.backends=cuda # a native image reads it at run time ``` -------------------------------- ### Example ~/.bashrc TornadoVM configuration Source: https://github.com/beehive-lab/tornadovm/blob/master/tornado-assembly/src/etc/README.md Example configuration for ~/.bashrc with a GraalVM JDK 21 and a user-local SDK path. Use this to automatically configure the environment in every new terminal session. ```bash # TornadoVM Configuration export JAVA_HOME=/usr/lib/jvm/graalvm-jdk-21 export TORNADOVM_HOME=$HOME/opt/tornadovm-sdk export PATH=$TORNADOVM_HOME/bin:$PATH ``` -------------------------------- ### Run first TornadoVM program (Windows) Source: https://github.com/beehive-lab/tornadovm/blob/master/README.md Runs the MatrixVectorRowMajor example on Windows 10+. Requires TORNADOVM_HOME to be set. ```bash # Windows 10+ java @%TORNADOVM_HOME%\tornado-argfile ^ -cp %TORNADOVM_HOME%\share\java\tornado\tornado-examples-8.0.0.jar ^ uk.ac.manchester.tornado.examples.compute.MatrixVectorRowMajor ``` -------------------------------- ### Install Required Module Dependencies Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/build-documentation.rst Install the required Sphinx theme and jQuery extension. ```bash pip3 install sphinx_rtd_theme pip3 install sphinxcontrib-jquery ``` -------------------------------- ### Install TornadoVM via SDKMAN! Source: https://github.com/beehive-lab/tornadovm/blob/master/README.md Installs the default TornadoVM build via SDKMAN!. Requires JDK 21 or later and a compatible backend driver (OpenCL, CUDA, or Metal). ```bash sdk install tornadovm ``` -------------------------------- ### Verify TornadoVM installation with tornado --version Source: https://github.com/beehive-lab/tornadovm/blob/master/tornado-assembly/src/etc/README.md Displays the TornadoVM version information to confirm the environment is correctly configured. ```bash tornado --version ``` -------------------------------- ### Run TornadoVM example with Java modules Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/simple-start.rst Runs the MatrixMultiplication1D example using the `-m` option for Java modules. The module path is `tornado.examples` and the main class is `uk.ac.manchester.tornado.examples.compute.MatrixMultiplication1D`. ```bash $ tornado -m tornado.examples/uk.ac.manchester.tornado.examples.compute.MatrixMultiplication1D ``` -------------------------------- ### Install TornadoVM SDK with SDKMAN! and list devices Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/benchmarking.rst Install a TornadoVM SDK with SDKMAN! for the chosen backend (metal, opencl, cuda, or full) and verify device detection with the tornado command. ```bash $ sdk install tornadovm 7.2.0-jdk21-opencl $ tornado --devices ``` -------------------------------- ### Run MatrixMultiplication1D on Specific Device Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/simple-start.rst Example command to run the MatrixMultiplication1D example on a specific device (driver:device 1:1, e.g., Intel HD Graphics). The -jvm flag passes the device selection option to the JVM. ```bash $ tornado --jvm="-Ds0.t0.device=1:1" -m tornado.examples/uk.ac.manchester.tornado.examples.compute.MatrixMultiplication1D ``` -------------------------------- ### Run standalone CuBLAS examples Source: https://github.com/beehive-lab/tornadovm/blob/master/tornado-native-libs/tornado-cublas/README.md Runs main()-runnable examples with validation against sequential Java. Each command launches a specific test (SGEMV, SGEMM, TF32, FP16, workspace, mixed graphs). ```bash # Standalone SGEMV (y = A * x) tornado -m tornado.cublas/uk.ac.manchester.tornado.cublas.tests.TestCuBlasSgemv 512 # SGEMV with beta != 0 (y = A * x + beta * y, output is READ_WRITE) tornado -m tornado.cublas/uk.ac.manchester.tornado.cublas.tests.TestCuBlasSgemvBeta 512 # Standalone SGEMM (C = A * B) tornado -m tornado.cublas/uk.ac.manchester.tornado.cublas.tests.TestCuBlasSgemm 256 # TF32 Tensor Core SGEMM vs FP32 (accuracy + speed) tornado -m tornado.cublas/uk.ac.manchester.tornado.cublas.tests.TestCuBlasSgemmTF32 2048 # FP16 GemmEx (FP16 and FP32 outputs) tornado -m tornado.cublas/uk.ac.manchester.tornado.cublas.tests.TestCuBlasGemmExFP16 512 # User-owned cuBLAS workspace tornado -m tornado.cublas/uk.ac.manchester.tornado.cublas.tests.TestCuBlasWorkspace 256 # Mixed graph: JIT task -> cublasSgemv -> JIT task, 10 iterations tornado -m tornado.cublas/uk.ac.manchester.tornado.cublas.tests.TestCuBlasSgemvWithTornadoVMTasksPOST # Same mixed pre/post graph under CUDA Graph capture/replay tornado -m tornado.cublas/uk.ac.manchester.tornado.cublas.tests.TestCuBlasSgemvWithTasksCudaGraph ``` -------------------------------- ### Run first TornadoVM program (Unix) Source: https://github.com/beehive-lab/tornadovm/blob/master/README.md Runs the MatrixVectorRowMajor example on Unix (Linux/macOS). Requires TORNADOVM_HOME to be set. ```bash # Unix (Linux/macOS) java @$TORNADOVM_HOME/tornado-argfile \ -cp $TORNADOVM_HOME/share/java/tornado/tornado-examples-8.0.0.jar \ uk.ac.manchester.tornado.examples.compute.MatrixVectorRowMajor ``` -------------------------------- ### Run tile examples with tornado command Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/tile-api.rst Commands to run seven runnable tile examples from tornado-examples. Each rewrites a known algorithm with TileContext beside thread-level versions, checks results against a sequential Java reference, and prints a table of times. Wall-clock times include JVM-side dispatch, which dominates at small sizes. ```bash # smallest useful tile kernel tornado -m tornado.examples/uk.ac.manchester.tornado.examples.tile.TileVectorAdd # matrix multiply: @Parallel, KernelContext shared-memory tiles, TileContext tornado -m tornado.examples/uk.ac.manchester.tornado.examples.tile.TileMatrixMultiply 512 20 # row softmax: the reductions and the broadcast back across the row tornado -m tornado.examples/uk.ac.manchester.tornado.examples.tile.TileSoftmax 4096 50 # attention: thread-per-query against fused flash attention tornado -m tornado.examples/uk.ac.manchester.tornado.examples.tile.TileAttention 1024 1024 20 # a transformer block built twice: all JIT, then JIT + CUDA Tile + cuBLAS tornado -m tornado.examples/uk.ac.manchester.tornado.examples.tile.TileTransformerBlock # a Q4_0 quantised projection, dequantised inside the tile kernel tornado -m tornado.examples/uk.ac.manchester.tornado.examples.tile.TileQuantizedProjection 1024 1024 2048 20 # three Qwen3 kernels from jitllm#150, thread-level against tiles tornado -m tornado.examples/uk.ac.manchester.tornado.examples.tile.TileQwenNormKernels 4096 50 ``` -------------------------------- ### tc emit command usage and example Source: https://github.com/beehive-lab/tornadovm/blob/master/tornado-compiler/README.md Headless compiler command-line usage. Requires no GPU. The example compiles the saxpy method from com.example.Kernels with the OpenCL target and a class path. ```bash tc emit [--target cuda|opencl|metal] [--cp ] [--stats] tc emit --target opencl --cp my-kernels.jar com.example.Kernels saxpy ``` -------------------------------- ### Example output of tornado --devices Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/simple-start.rst Example output from `tornado --devices` showing two drivers (CUDA and OpenCL) and the discovered devices with their properties such as memory sizes, workgroup dimensions, and OpenCL C versions. ```bash Number of Tornado drivers: 2 Total number of CUDA devices : 1 Tornado device=0:0 CUDA -- GeForce GTX 1650 Global Memory Size: 3.8 GB Local Memory Size: 48.0 KB Workgroup Dimensions: 3 Max WorkGroup Configuration: [1024, 1024, 64] Device OpenCL C version: N/A Total number of OpenCL devices : 4 Tornado device=1:0 NVIDIA CUDA -- GeForce GTX 1650 Global Memory Size: 3.8 GB Local Memory Size: 48.0 KB Workgroup Dimensions: 3 Max WorkGroup Configuration: [1024, 1024, 64] Device OpenCL C version: OpenCL C 1.2 Tornado device=1:1 Intel(R) OpenCL HD Graphics -- Intel(R) Gen9 HD Graphics NEO Global Memory Size: 24.8 GB Local Memory Size: 64.0 KB Workgroup Dimensions: 3 Max WorkGroup Configuration: [256, 256, 256] Device OpenCL C version: OpenCL C 2.0 Tornado device=1:2 Intel(R) OpenCL -- Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz Global Memory Size: 31.0 GB Local Memory Size: 32.0 KB Workgroup Dimensions: 3 Max WorkGroup Configuration: [8192, 8192, 8192] Device OpenCL C version: OpenCL C 1.2 Tornado device=1:3 AMD Accelerated Parallel Processing -- Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz Global Memory Size: 31.0 GB Local Memory Size: 32.0 KB Workgroup Dimensions: 3 Max WorkGroup Configuration: [1024, 1024, 1024] Device OpenCL C version: OpenCL C 1.2 ``` -------------------------------- ### Build TornadoVM with make Source: https://github.com/beehive-lab/tornadovm/blob/master/BUILD_AND_RUN.md Builds the entire TornadoVM SDK in bin/sdk/ using the traditional make build system. ```bash make ``` -------------------------------- ### Static TaskGraph and Task Example Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/unsupported.rst Shows an invalid example of static TaskGraph and Task usage, which TornadoVM does not support due to potential deadlocks during class initialization and JIT compilation. ```java public static void testMethod(IntArray in) { // ... some code ... } static IntArray inTor = IntArray.fromElements(0); static TaskGraph taskGraph = new TaskGraph("g0"); static { taskGraph.task("t0", Main::testMethod, inTor); } ``` -------------------------------- ### Enable feature extraction and run NBody example Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/dev-tools.rst Run the NBody example with feature extraction enabled using the flag `-Dtornado.feature.extraction=True`. The output is a JSON object with feature counts for the generated code. ```bash $ tornado --jvm="-Dtornado.feature.extraction=True" -m tornado.examples/uk.ac.manchester.tornado.examples.compute.NBody --params "1024 1" ``` ```json { "nBody": { "BACKEND" : "CUDA", "DEVICE_ID": "0:2", "DEVICE": "GeForce GTX 1650", "Global Memory Loads": "15", "Global Memory Stores": "6", "Constant Memory Loads": "0", "Constant Memory Stores": "0", "Local Memory Loads": "0", "Local Memory Stores": "0", "Private Memory Loads": "20", "Private Memory Stores": "20", "Total Loops": "2", "Parallel Loops": "1", "If Statements": "2", "Integer Comparison": "2", "Float Comparison": "0", "Switch Statements": "0", "Switch Cases": "0", "Vector Operations": "0", "Integer & Float Operations": "57", "Boolean Operations": "9", "Cast Operations": "2", "Float Math Functions": "1", "Integer Math Functions": "0" } } ``` -------------------------------- ### Build GraalVM native image using tornado-native-image Source: https://github.com/beehive-lab/tornadovm/blob/master/README.md Use this command to build a TornadoVM application into a GraalVM native image (GraalVM for JDK 25+). The output is an executable named 'app' (./app) that starts faster, e.g., Saxpy on an RTX 4090 starts in about 0.3 s with only the CUDA backend loaded. ```bash tornado-native-image -cp app.jar -o app com.example.Main # GraalVM native image: ./app ``` -------------------------------- ### Verify TornadoVM devices Source: https://github.com/beehive-lab/tornadovm/blob/master/README.md Lists available devices (GPUs, CPUs, FPGAs) for the installed TornadoVM backend. ```bash tornado --devices ``` -------------------------------- ### Build TornadoInsight IntelliJ plugin from source Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/dev-tools.rst Commands to clone the tornado-insight repository with submodules and build the plugin using Gradle. The generated zip is installed via IntelliJ's 'Install plugin from disk' action. Requires TornadoVM >= 1.0 and JDK >= 21. ```bash git clone --recurse-submodules https://github.com/beehive-lab/tornado-insight.git cd tornado-insight ./gradlew clean build # Install the generated zip from build/distributions via # IntelliJ > Help > Find Action > "Install plugin from disk" ``` -------------------------------- ### Open local server to test socket streaming Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/dev-tools.rst Start a local server on port 2000 using `ncat` to verify that the socket streams logs correctly. ```bash $ ncat -k -l 2000 ``` -------------------------------- ### Run BlurFilter with device assignments Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/multi-device.rst Command to execute the BlurFilter example, assigning each task to a specific device using JVM properties. The -Dblur.red.device, -Dblur.green.device, and -Dblur.blue.device properties set the device for each task. ```bash $ tornado --threadInfo \ --jvm=" -Dblur.red.device=0:0 -Dblur.green.device=0:1 -Dblur.blue.device=0:0" \ -m tornado.examples/uk.ac.manchester.tornado.examples.compute.BlurFilter ``` -------------------------------- ### Example benchmark output Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/benchmarking.rst Sample output from a benchmark run, showing one line for Java and one per device with performance metrics and speedup. ```bash Performance: bm=sgemm-20-512-512, id=java-reference, average(ns)=1.091877e+08, median(ns)=1.055532e+08, firstIteration(ns)=1.458769e+08, best(ns)=1.021011e+08 Performance: bm=sgemm-20-512-512, device=0:0, average(ns)=2.596025e+06, median(ns)=1.605209e+06, firstIteration(ns)=1.960350e+07, best(ns)=1.243667e+06 , speedupAvg=..., speedupMedian=..., speedupFirstIteration=..., CV=..., deviceName= [Apple Metal] -- Apple M3 Pro ``` -------------------------------- ### Build and View Documentation Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/build-documentation.rst Build the documentation with make docs and optionally open it in Firefox. ```bash make docs ## visualize the documentation (E.g., with Firefox) firefox docs/build/html/index.html ``` -------------------------------- ### Check Available Devices (Option 2: java with argfile) Source: https://github.com/beehive-lab/tornadovm/blob/master/BUILD_AND_RUN.md Lists available OpenCL devices by running the OCLDeviceQuery class with the tornado-argfile. ```bash java @tornado-argfile -cp bin/sdk/share/java/tornado/tornado-drivers-opencl-1.1.2-SNAPSHOT.jar \ uk.ac.manchester.tornado.drivers.opencl.OCLDeviceQuery ``` -------------------------------- ### Show Generated OpenCL/CUDA Kernel for Unittest Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/simple-start.rst Use the -pk flag to print the generated OpenCL/CUDA kernel for a specific unittest method. ```bash $ tornado-test --verbose -pk uk.ac.manchester.tornado.unittests.TestHello#testHello ``` -------------------------------- ### Install Temurin JDK 21 and 25 via sdkman Source: https://github.com/beehive-lab/tornadovm/blob/master/scripts/HOW_TO_BUILD_SDK.md Installs Temurin JDK 21 and 25 using sdkman. The script automatically picks the newest installed patch version for each major, so the exact identifiers are examples only. ```bash sdk install java 21.0.10-tem # or whatever the latest 21.x patch is sdk install java 25.0.2-tem # or whatever the latest 25.x patch is ``` -------------------------------- ### Show tornadovm-installer help Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/developer-guidelines.rst Displays the usage and options for the tornadovm-installer script, including --jdk, --backend, --listJDKs, --mvn_single_threaded, and --auto-deps. ```bash $ ./bin/tornadovm-installer --help usage: tornadovm-installer [-h] [--jdk JDK] [--backend BACKEND] [--version] [--listJDKs] [--mvn_single_threaded] [--auto-deps] options: --jdk JDK Specify a JDK to install (e.g., 'jdk21', 'graal-jdk-21'). Use --listJDKs to see all options. --backend BACKEND Select the backend(s) to install: { opencl, cuda, metal } --listJDKs List supported JDKs --mvn_single_threaded Run Maven in single-threaded mode --auto-deps Automatically download any missing dependencies ``` -------------------------------- ### Enable TornadoVM Profiler in Console Mode via TornadoExecutionPlan Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/dev-tools.rst Enable the profiler and print the report to STDOUT using the TornadoExecutionPlan API. The example chains withProfiler(ProfilerMode.CONSOLE), withDevice, and withDefaultScheduler before calling execute(). ```java // Enable the profiler and print report in STDOUT executionPlan.withProfiler(ProfilerMode.CONSOLE) // .withDevice(device) // .withDefaultScheduler() .execute(); ``` -------------------------------- ### Install CUDA Tile C++ surface with pip Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/tile-api.rst Install the CUDA Tile C++ surface via pip. A userspace install is sufficient; if the system CUDA is older, point -Dtornado.cuda.nvcc at the installed package. ```bash pip install --user 'cuda-tile[tileiras]' ``` -------------------------------- ### Map/Reduce example with two tasks Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/programming.rst Shows a complete map/reduce workflow: a map task adds two arrays element-wise, and a reduce task sums the result. Both tasks are chained in a TaskGraph and executed with TornadoExecutionPlan. ```java public class ReduceExample { public static void map01(IntArray a, IntArray b, IntArray c) { for (@Parallel int i = 0; i < a.length; i++) { c.set(i, a.get(i) + b.get(i)); } } public static void reduce01(IntArray c, @Reduce IntArray result) { result.set(0, 0); for (@Parallel int i = 0; i < c.length; i++) { result.set(0, result.get(0) + c.get(i)); } } public void testMapReduce() { IntArray a = new IntArray(BIG_SIZE); IntArray b = new IntArray(BIG_SIZE); IntArray c = new IntArray(BIG_SIZE); IntArray result = IntArray.fromElements(0); IntStream.range(0, BIG_SIZE).parallel().forEach(i -> { a[i] = 10; b[i] = 2; }); TaskGraph taskGraph = new TaskGraph("s0") // .transferToDevice(DataTransferMode.EVERY_EXECUTION, a, b, c) // .task("t0", TestReductionsIntegers::map01, a, b, c) // .task("t1", TestReductionsIntegers::reduce01, c, result) // .transferToHost(DataTransferMode.EVERY_EXECUTION, result); ImmutableTaskGraph immutableTaskGraph = taskGraph.snapshot(); TornadoExecutionPlan executionPlan = new TornadoExecutionPlan(immutableTaskGraph); TornadoExecutionResult executionResult = executionPlan.execute(); } } ``` -------------------------------- ### Install sdkman Source: https://github.com/beehive-lab/tornadovm/blob/master/scripts/HOW_TO_BUILD_SDK.md Installs sdkman on macOS or Linux. Required before installing Temurin JDKs for the TornadoVM SDK build script. ```bash curl -s "https://get.sdkman.io" | bash source ~/.sdkman/bin/sdkman-init.sh ``` -------------------------------- ### Add TornadoVM Maven Dependencies Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/installation.rst Add TornadoVM to a Java project via Maven Central. Include tornado-runtime and at least one backend driver (opencl, metal, or cuda). The artifact version suffix must match your JDK family: -jdk21 for JDK 21 only, -jdk22plus for JDK 22 and newer. The example shows both JDK 21 and JDK 22+ configurations. ```xml io.github.beehive-lab tornado-runtime 8.0.0-jdk21 io.github.beehive-lab tornado-drivers-opencl 8.0.0-jdk21 io.github.beehive-lab tornado-runtime 8.0.0-jdk22plus io.github.beehive-lab tornado-drivers-opencl 8.0.0-jdk22plus ``` -------------------------------- ### Set up Eclipse auto-formatter with python3 scripts/eclipseSetup.py Source: https://github.com/beehive-lab/tornadovm/blob/master/CONTRIBUTING.md Run this script to set up the Eclipse auto-formatter for the TornadoVM project. It is executed from the project root. ```bash ## For Eclipse, use the following script $ python3 scripts/eclipseSetup.py ``` -------------------------------- ### Run BlurFilter with --printBytecodes Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/multi-device.rst Command to run the BlurFilter example with thread info, bytecode printing, concurrent devices, and device selection via JVM properties. The output shows bytecode execution per device and thread. ```bash $ tornado --threadInfo \ --printBytecodes \ --enableConcurrentDevices \ --jvm=" -Dblur.red.device=0:0 -Dblur.green.device=0:1 -Dblur.blue.device=0:0" \ -m tornado.examples/uk.ac.manchester.tornado.examples.compute.BlurFilter ``` -------------------------------- ### Use Project Leyden AOT cache with the launcher (JDK 25+) Source: https://github.com/beehive-lab/tornadovm/blob/master/LEYDEN_GRAALVM_NATIVE_IMAGE.md The launcher passes `-XX:AOTCacheOutput=app.aot` when the file does not exist and `-XX:AOTCache=app.aot` when it does. It also leaves `.` off the module path but keeps the test modules on it (Step 0), so for the full gain use the argfile. Same JDK build, same module and class paths, and application on the class path as jars are required. ```bash tornado --aotCache app.aot --classpath app.jar com.example.Main # first run: trains and writes app.aot ``` ```bash tornado --aotCache app.aot --classpath app.jar com.example.Main # later runs start from it ``` -------------------------------- ### tornado --help output Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/simple-start.rst Shows the usage and all optional arguments for the `tornado` launcher. It lists flags for version, debug, thread info, kernel printing, profiler, devices, classpath, JVM options, and more. ```bash $ tornado --help usage: tornado [-h] [--version] [-version] [--debug] [--threadInfo] [--printKernel] [--printBytecodes] [--enableProfiler ENABLE_PROFILER] [--dumpProfiler DUMP_PROFILER] [--printJavaFlags] [--devices] [--ea] [--module-path MODULE_PATH] [--classpath CLASSPATH] [--jvm JVM_OPTIONS] [-m MODULE_APPLICATION] [-jar JAR_FILE] [--params APPLICATION_PARAMETERS] [application] Tool for running TornadoVM Applications. This tool sets all Java options for enabling TornadoVM. positional arguments: application optional arguments: -h, --help show this help message and exit --version Print version of TornadoVM -version Print JVM Version --debug Enable debug mode --threadInfo Print thread deploy information per task on the accelerator --printKernel, -pk Print generated kernel (OpenCL or CUDA) --printBytecodes, -pc Print the generated TornadoVM bytecodes --enableProfiler ENABLE_PROFILER Enable the profiler {silent|console} --dumpProfiler DUMP_PROFILER Dump the profiler to a file --printJavaFlags Print all the Java flags to enable the execution with TornadoVM --devices Print information about the accelerators available --ea, -ea Enable assertions --module-path MODULE_PATH Module path option for the JVM --classpath CLASSPATH, -cp CLASSPATH, --cp CLASSPATH Set class-path --jvm JVM_OPTIONS, -J JVM_OPTIONS Pass Java options to the JVM. Use without spaces: e.g., --jvm="-Xms10g" or -J"-Xms10g" -m MODULE_APPLICATION Application using Java modules -jar JAR_FILE Main Java application in a JAR File --params APPLICATION_PARAMETERS Command-line parameters for the host-application. Example: --params="param1 param2..." ``` -------------------------------- ### Compile with --enable-preview --release 21 for jdk21 SDK Source: https://github.com/beehive-lab/tornadovm/blob/master/LEYDEN_GRAALVM_NATIVE_IMAGE.md Required when using the jdk21 SDK because the SDK's classes use the FFM API, still a preview feature in Java 21. ```bash javac --enable-preview --release 21 -cp $TORNADOVM_HOME/share/java/tornado/tornado-api-*.jar -d classes ... ``` -------------------------------- ### Initialize IntelliJ project files for TornadoVM Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/ide-integration.rst Run these commands after building TornadoVM and loading environment variables to generate IntelliJ run configurations in the .build/ directory. The BACKEND can be opencl, cuda, or a comma-separated combination. ```bash # Build TornadoVM first (with your desired backend) $ make BACKEND=opencl # or cuda, opencl,cuda, etc. # Load the environment variables $ source setvars.sh # Linux/macOS $ setvars.cmd # Windows # Generate IntelliJ project files $ make intellijinit ``` -------------------------------- ### Build native image with tornado-native-image (GraalVM JDK 25+) Source: https://github.com/beehive-lab/tornadovm/blob/master/LEYDEN_GRAALVM_NATIVE_IMAGE.md Builds the whole application, including TornadoVM runtime, drivers (via FFM) and TC, into one executable needing no JVM. Requires a jdk22plus SDK and GraalVM JDK 25+. The build takes about 16 s (2.5 GB peak memory) and runs tracing then building. ```bash source setvars.sh # a jdk22plus SDK export GRAALVM_HOME=/path/to/graalvm-jdk-25 # GraalVM CE or Oracle GraalVM, JDK 25+ tornado-native-image -cp app.jar -o app com.example.Main [args for the tracing runs] ./app # the default backend ./app -Dtornado.backend=1 # another backend ./app -Dtornado.enabled.backends=cuda # load only CUDA ./app -Dtornado.tc.verbose=true # TornadoVM and TC options work as on the JVM ``` -------------------------------- ### Run TornadoVM program with java and generated arg-file Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/simple-start.rst Use this command to run a TornadoVM program without the tornado launcher by generating an arg-file once with `tornado --generate-argfile` and then invoking `java` directly with it. The example runs the MatrixVectorRowMajor example from the tornado-examples JAR. ```bash $ java @$TORNADOVM_HOME/tornado-argfile -cp $TORNADOVM_HOME/share/java/tornado/tornado-examples-5.0.0-jdk21.jar uk.ac.manchester.tornado.examples.compute.MatrixVectorRowMajor ``` -------------------------------- ### Example cmake and pyInstaller PATH entries (Windows) Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/ide-integration.rst Example paths to add to your PATH on Windows for cmake and pyInstaller. The pyInstaller path should point to the .venv Scripts directory. ```bash C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\ ``` ```bash \.venv\Scripts ``` -------------------------------- ### Manual native-image build commands (tracing and building) Source: https://github.com/beehive-lab/tornadovm/blob/master/LEYDEN_GRAALVM_NATIVE_IMAGE.md Equivalent manual commands for a build system. Tracing runs once per backend (0, 1, ...) with the native-image agent, then native-image builds with FFM support. Requires the listed JVM flags and module setup. ```bash J=$TORNADOVM_HOME/share/java/tornado MODS=tornado.runtime,tornado.drivers.common,tornado.drivers.opencl,tornado.drivers.cuda JVM="--enable-native-access=ALL-UNNAMED,$MODS -p $J --add-modules jdk.unsupported,java.management,jdk.management,$MODS \ --add-opens java.base/java.lang=tornado.runtime" ``` ```bash $GRAALVM_HOME/bin/java -agentlib:native-image-agent=config-merge-dir=app.native-config $JVM \ -Djava.library.path=$TORNADOVM_HOME/lib -Dtornado.backend=0 -cp app.jar com.example.Main ``` ```bash $GRAALVM_HOME/bin/java -agentlib:native-image-agent=config-merge-dir=app.native-config $JVM \ -Djava.library.path=$TORNADOVM_HOME/lib -Dtornado.backend=1 -cp app.jar com.example.Main ``` ```bash $GRAALVM_HOME/bin/native-image --no-fallback -H:+UnlockExperimentalVMOptions \ -H:+ForeignAPISupport -H:+SharedArenaSupport -H:ConfigurationFileDirectories=app.native-config \ $JVM -cp app.jar -o app com.example.Main ``` -------------------------------- ### Initialize Device Asynchronously and Execute Source: https://github.com/beehive-lab/tornadovm/blob/master/docs/source/programming.rst Initializes a device on a background thread while preparing data, then executes the plan on that device. The initializeDeviceAsync call returns immediately with a CompletableFuture, and an execution that reaches the device first waits for it. ```java TornadoExecutionPlan.initializeDeviceAsync(1, 0); // returns at once (a CompletableFuture) FloatArray input = loadData(); // overlaps the device's initialisation ... executionPlan.withDevice(TornadoExecutionPlan.getDevice(1, 0)).execute(); ```