{"id":20789687,"url":"https://github.com/jjfumero/tornadovm-examples","last_synced_at":"2025-10-07T20:40:02.939Z","repository":{"id":41288577,"uuid":"428322984","full_name":"jjfumero/tornadovm-examples","owner":"jjfumero","description":"Set of examples written for hardware acceleration via TornadoVM ","archived":false,"fork":false,"pushed_at":"2025-02-26T07:54:08.000Z","size":21074,"stargazers_count":16,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T23:11:34.075Z","etag":null,"topics":["fpga","fpga-programming","gpu","gpuprogramming","java","jvm","opencl","parallel-computing","ptx","spirv","tornadovm"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jjfumero.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-15T15:41:12.000Z","updated_at":"2025-02-26T07:54:12.000Z","dependencies_parsed_at":"2023-02-15T07:46:32.613Z","dependency_job_id":"f93c378a-f0e9-478b-80f6-029fefcaefea","html_url":"https://github.com/jjfumero/tornadovm-examples","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jjfumero%2Ftornadovm-examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jjfumero%2Ftornadovm-examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jjfumero%2Ftornadovm-examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jjfumero%2Ftornadovm-examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jjfumero","download_url":"https://codeload.github.com/jjfumero/tornadovm-examples/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252566006,"owners_count":21768964,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fpga","fpga-programming","gpu","gpuprogramming","java","jvm","opencl","parallel-computing","ptx","spirv","tornadovm"],"created_at":"2024-11-17T15:25:58.049Z","updated_at":"2025-10-07T20:39:57.919Z","avatar_url":"https://github.com/jjfumero.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"## TornadoVM Examples\n\n[TornadoVM](https://github.com/beehive-lab/TornadoVM) is a Java library for hardware acceleration of Java and JVM applications. It has a JIT compiler, a runtime system, and several backends that offload, manage memory and handle execution on GPUs, FPGAs, and multicore CPUs transparently. \n\nThis repository contains a few examples for demonstration purposes. \n\nNote: Examples using TornadoVM [v1.0.9-dev](https://github.com/beehive-lab/TornadoVM/tree/develop)\n\n\nOutline:\n\n| Topic                       | Link                                                                                                            |\n|:----------------------------|:---------------------------------------------------------------------------------------------------------------:|\n| Install TornadoVM           | [link](https://github.com/jjfumero/tornadovm-examples?tab=readme-ov-file#1-build-tornadovm)                     |\n| Setup the examples          | [link](https://github.com/jjfumero/tornadovm-examples?tab=readme-ov-file#2-setup-the-examples)                  |\n| Mandelbrot demo             | [link](https://github.com/jjfumero/tornadovm-examples?tab=readme-ov-file#mandelbrot)                            |\n| Blur Filter demo            | [link](https://github.com/jjfumero/tornadovm-examples?tab=readme-ov-file#blur-filter)                           |\n| Multi-Image Processing demo | [link](https://github.com/jjfumero/tornadovm-examples?tab=readme-ov-file#multi-image-processing)                |\n| KMeans Clustering demo      | [link](https://github.com/jjfumero/tornadovm-examples?tab=readme-ov-file#kmeans-clustering)                     |\n| Live Task Migration demo    | [link](https://github.com/jjfumero/tornadovm-examples?tab=readme-ov-file#live-task-migration-client-server-app) |\n| Matrix Multiplication       | [link](https://github.com/jjfumero/tornadovm-examples?tab=readme-ov-file#matrix-multiplication)                 |\n\n\n## 1. Build TornadoVM\n\nTo run the examples, first build TornadoVM with any backend (OpenCL, PTX and/or SPIR-V).\n\n**Important:** If you do not have an NVIDIA GPU and the CUDA SDK installed, do not use the flag `--ptx` in the following command. \nSimilarly, if your device/system does not support [SPIR-V](https://www.khronos.org/spir/), do not use the `--spirv` flag. \n\nTo install TornadoVM, it requires as prerequisite:\n1. The driver installed (e.g., NVIDIA + CUDA Driver for NVIDIA GPUs, or oneAPI for Intel platforms). \n2. [Maven](https://maven.apache.org/download.cgi?Preferred=ftp://ftp.osuosl.org/pub/apache/)\n\nTornadoVM includes an easy installer script for Linux and OSx: \n\n```bash\n$ git clone https://github.com/beehive-lab/TornadoVM\n$ cd TornadoVM\n## Choose the backend/s that applies to your system. You can install multiple ones\n$ ./bin/tornadovm-installer --jdk jdk21 --backend=opencl,ptx,spirv  \n$ source setvars.sh\n```\n\n### Check installation:\n\n```bash\ntornado --devices\n\nNumber of Tornado drivers: 2\nTotal number of PTX devices  : 1\nTornado device=0:0\n\tPTX -- NVIDIA GeForce RTX 2060 with Max-Q Design\n\t\tGlobal Memory Size: 5.8 GB\n\t\tLocal Memory Size: 48.0 KB\n\t\tWorkgroup Dimensions: 3\n\t\tMax WorkGroup Configuration: [1024, 1024, 64]\n\t\tDevice OpenCL C version: N/A\n\nTotal number of OpenCL devices  : 3\nTornado device=1:0\n\tNVIDIA CUDA -- NVIDIA GeForce RTX 2060 with Max-Q Design\n\t\tGlobal Memory Size: 5.8 GB\n\t\tLocal Memory Size: 48.0 KB\n\t\tWorkgroup Dimensions: 3\n\t\tMax WorkGroup Configuration: [1024, 1024, 64]\n\t\tDevice OpenCL C version: OpenCL C 1.2\n\nTornado device=1:1\n\tIntel(R) OpenCL HD Graphics -- Intel(R) UHD Graphics [0x9bc4]\n\t\tGlobal Memory Size: 24.9 GB\n\t\tLocal Memory Size: 64.0 KB\n\t\tWorkgroup Dimensions: 3\n\t\tMax WorkGroup Configuration: [256, 256, 256]\n\t\tDevice OpenCL C version: OpenCL C 3.0\n\nTornado device=1:2\n\tIntel(R) CPU Runtime for OpenCL(TM) Applications -- Intel(R) Core(TM) i9-10885H CPU @ 2.40GHz\n\t\tGlobal Memory Size: 31.1 GB\n\t\tLocal Memory Size: 32.0 KB\n\t\tWorkgroup Dimensions: 3\n\t\tMax WorkGroup Configuration: [8192, 8192, 8192]\n\t\tDevice OpenCL C version: OpenCL C 2.0\n```\n\n\nNote that, depending on the devices you have and the drivers installed (e.g., NVIDIA CUDA, OpenCL, SPIR-V), you will see different implementations. \n\n\n\n## 2. Setup the examples\n\n```bash\ngit clone https://github.com/jjfumero/tornadovm-examples\ncd tornadovm-examples\nsource /path-to-your-Tornado-DIR/source.sh\nexport TORNADO_SDK=/path-to-your-Tornado-DIR/bin/sdk\nmvn clean package\n```\n\n## Running demos\n\n### Mandelbrot\n\n\n```bash\n## List all devices and backends available \ntornado --devices \n\n## Run the multi-thread version for reference \ntornado -cp target/tornadovm-examples-1.0-SNAPSHOT.jar io.github.jjfumero.Mandelbrot mt\n\n## Run the TornadoVM Version (it will select the device 0:0 by default)\ntornado -cp target/tornadovm-examples-1.0-SNAPSHOT.jar io.github.jjfumero.Mandelbrot tornado\n\n## Print the device and thread information in which the application is running\ntornado --threadInfo -cp target/tornadovm-examples-1.0-SNAPSHOT.jar io.github.jjfumero.Mandelbrot tornado\n\n## Get the SPIRV code (assuming the SPIRV backend is installed in the device 0:0)\ntornado --debug --threadInfo -cp target/tornadovm-examples-1.0-SNAPSHOT.jar io.github.jjfumero.Mandelbrot tornado\nspirv-dis \u003cspirv-binary\u003e \n\n## Change the device\ntornado --threadInfo --jvm=\"-Dfractal.mandelbrot.device=1:1\" -cp target/tornadovm-examples-1.0-SNAPSHOT.jar io.github.jjfumero.Mandelbrot tornado\n\n## Run with the tornadoVM profiler\ntornado --enableProfiler console --threadInfo --jvm=\"-Dfractal.mandelbrot.device=0:0\" -cp target/tornadovm-examples-1.0-SNAPSHOT.jar io.github.jjfumero.Mandelbrot tornado\n```\n\n\n### Blur Filter\n\nThis examples shows a blur effect in a photo. Example of computational photography. \nPlace an JPEG image in `./image.jpg` or feel free to change the path your images. \n\n\n```bash\n## List all devices and backends available \ntornado --devices \n\n## Run the Java Parallel Stream Version on CPU for reference \ntornado -cp target/tornadovm-examples-1.0-SNAPSHOT.jar io.github.jjfumero.BlurFilter mt\n\n## Run the Accelerated Version on the default device \ntornado -cp target/tornadovm-examples-1.0-SNAPSHOT.jar io.github.jjfumero.BlurFilter tornado\n\n## Run the Accelerated Version on the default device with info about the accelerator \ntornado --threadInfo -cp target/tornadovm-examples-1.0-SNAPSHOT.jar io.github.jjfumero.BlurFilter tornado\n\n## Print the generated kernel\ntornado --printKernel --threadInfo -cp target/tornadovm-examples-1.0-SNAPSHOT.jar io.github.jjfumero.BlurFilter tornado\n\n## Run in another device\ntornado --threadInfo -cp target/tornadovm-examples-1.0-SNAPSHOT.jar io.github.jjfumero.BlurFilter tornado device=1:1\n\n## Run with concurrent multi-devices\ntornado --threadInfo --enableConcurrentDevices --jvm=\" -Dblur.red.device=1:0 -Dblur.green.device=2:0 -Dblur.blue.device=1:2\" -cp target/tornadovm-examples-1.0-SNAPSHOT.jar io.github.jjfumero.BlurFilter tornado\n```\n\n### Multi-Image Processing\n\nDemonstration of a Task-Graph to compute:\n  - Black and White filter\n  - Blur Filer \n\nusing multiple GPUs (or accelerators) at the same time for each task.\n\n```bash\n## Run the Java Parallel Stream Version on CPU for reference \ntornado -cp target/tornadovm-examples-1.0-SNAPSHOT.jar io.github.jjfumero.MultiImageProcessor mt\n\n## Run the Accelerated Version on the default device \ntornado -cp target/tornadovm-examples-1.0-SNAPSHOT.jar io.github.jjfumero.MultiImageProcessor tornado\n```\n\nThe examples is created based on the following device setup:\n\n\n```bash\n## List all devices and backends available \n$ tornado --devices \n\nNumber of Tornado drivers: 3\nDriver: SPIRV\n  Total number of SPIRV devices  : 1\n  Tornado device=0:0  (DEFAULT)\n\tSPIRV -- SPIRV LevelZero - Intel(R) UHD Graphics 770\n\t\tGlobal Memory Size: 24.9 GB\n\t\tLocal Memory Size: 64.0 KB\n\t\tWorkgroup Dimensions: 3\n\t\tTotal Number of Block Threads: [512]\n\t\tMax WorkGroup Configuration: [512, 512, 512]\n\t\tDevice OpenCL C version:  (LEVEL ZERO) 1.3\n\nDriver: OpenCL\n  Total number of OpenCL devices  : 4\n  Tornado device=1:0\n\tOPENCL --  [NVIDIA CUDA] -- NVIDIA GeForce RTX 3070\n\t\tGlobal Memory Size: 7.8 GB\n\t\tLocal Memory Size: 48.0 KB\n\t\tWorkgroup Dimensions: 3\n\t\tTotal Number of Block Threads: [1024]\n\t\tMax WorkGroup Configuration: [1024, 1024, 64]\n\t\tDevice OpenCL C version: OpenCL C 1.2\n\n  Tornado device=1:1\n\tOPENCL --  [Intel(R) OpenCL Graphics] -- Intel(R) UHD Graphics 770\n\t\tGlobal Memory Size: 24.9 GB\n\t\tLocal Memory Size: 64.0 KB\n\t\tWorkgroup Dimensions: 3\n\t\tTotal Number of Block Threads: [512]\n\t\tMax WorkGroup Configuration: [512, 512, 512]\n\t\tDevice OpenCL C version: OpenCL C 1.2\n\n  Tornado device=1:2\n\tOPENCL --  [Intel(R) OpenCL] -- 12th Gen Intel(R) Core(TM) i7-12700K\n\t\tGlobal Memory Size: 31.1 GB\n\t\tLocal Memory Size: 32.0 KB\n\t\tWorkgroup Dimensions: 3\n\t\tTotal Number of Block Threads: [8192]\n\t\tMax WorkGroup Configuration: [8192, 8192, 8192]\n\t\tDevice OpenCL C version: OpenCL C 3.0\n\n  Tornado device=1:3\n\tOPENCL --  [Intel(R) FPGA Emulation Platform for OpenCL(TM)] -- Intel(R) FPGA Emulation Device\n\t\tGlobal Memory Size: 31.1 GB\n\t\tLocal Memory Size: 256.0 KB\n\t\tWorkgroup Dimensions: 3\n\t\tTotal Number of Block Threads: [67108864]\n\t\tMax WorkGroup Configuration: [67108864, 67108864, 67108864]\n\t\tDevice OpenCL C version: OpenCL C 1.2\n\nDriver: PTX\n  Total number of PTX devices  : 1\n  Tornado device=2:0\n\tPTX -- PTX -- NVIDIA GeForce RTX 3070\n\t\tGlobal Memory Size: 7.8 GB\n\t\tLocal Memory Size: 48.0 KB\n\t\tWorkgroup Dimensions: 3\n\t\tTotal Number of Block Threads: [2147483647, 65535, 65535]\n\t\tMax WorkGroup Configuration: [1024, 1024, 64]\n\t\tDevice OpenCL C version: N/A\n```\n\nTo change the accelerator, use the following instructions:\n\n\n```java\nTornadoDevice device0 = TornadoExecutionPlan.getDevice(0, 0);\nTornadoDevice device1 = TornadoExecutionPlan.getDevice(1, 0);\nTornadoDevice device2 = TornadoExecutionPlan.getDevice(1, 1);\nTornadoDevice device3 = TornadoExecutionPlan.getDevice(1, 2);\nTornadoDevice device4 = TornadoExecutionPlan.getDevice(2, 0);\n\nexecutionPlan.withConcurrentDevices() //\n\t.withDevice(\"imageProcessor.blackAndWhite\", device0) //\n\t.withDevice(\"imageProcessor.blurRed\", device1) //\n\t.withDevice(\"imageProcessor.blurGreen\", device2) //\n\t.withDevice(\"imageProcessor.blurBlue\", device4);\n```\n\n\n### KMeans Clustering\n\nFull KMeans in which the assign-cluster function is expressed with TornadoVM. \n\n```bash\n# For example use 1000000 data points and classify them into 10 clusters.\n# Points are selected randomly. This is just for quick experiments \n\n## Sequential\ntornado -cp target/tornadovm-examples-1.0-SNAPSHOT.jar io.github.jjfumero.KMeans seq 1000000 10\n\n\n# TornadoVM version \ntornado -cp target/tornadovm-examples-1.0-SNAPSHOT.jar io.github.jjfumero.KMeans tornado 1000000 10\n```\n\n\n### Live Task Migration (Client-Server App)\n\n\n```bash\n## Run Server in one terminal\n./runServer.sh\n\n## Client in another terminal\n./runClient.sh  ## Change device during runtime \n\n## Note: the application selects the backend 0:0 (default backend)\n\n# type different \u003cbackend:deviceNumber\u003e version from the client. \n# Examples:\n# 0:1 \n# 1:0 \n## etc\n```\n\n\n### Matrix Multiplication\n\nThis application shows different implementation for Matrix Multiplications for:\n\n1. Single-core Sequential Implementation using Panama Segments\n2. Multi-core Parallel Streams Using Panama Segments\n3. Multi-core Java Threads using Panama Segments \n4. Single-core Sequential implementation using Panama Vector Types for the reduction part (dotProduct)\n5. Multi-core Parallel Stream implementation using Panama Vector Types for the reduction part (dotProduct)\n6. TornadoVM to run on the default device (usually a GPU if a GPU backends is available and installed)\n\nHow to run? \n\n```bash\nmvn clean install\n\n## Run Java Sequential only\ntornado -cp target/tornadovm-examples-1.0-SNAPSHOT.jar io.github.jjfumero.MatrixMultiplication onlyJavaSeq\n\n## Run all Java implementations\ntornado -cp target/tornadovm-examples-1.0-SNAPSHOT.jar io.github.jjfumero.MatrixMultiplication onlyJava\n\n## Run only TornadoVM. It also runs 1 iteration of the sequential implementation to check results\ntornado -cp target/tornadovm-examples-1.0-SNAPSHOT.jar io.github.jjfumero.MatrixMultiplication onlyTornadoVM\n\n## Run all implementations, including TornadoVM\ntornado -cp target/tornadovm-examples-1.0-SNAPSHOT.jar io.github.jjfumero.MatrixMultiplication \n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjjfumero%2Ftornadovm-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjjfumero%2Ftornadovm-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjjfumero%2Ftornadovm-examples/lists"}