{"id":13575002,"url":"https://github.com/beehive-lab/levelzero-jni","last_synced_at":"2025-12-30T03:02:44.402Z","repository":{"id":40262921,"uuid":"340364585","full_name":"beehive-lab/levelzero-jni","owner":"beehive-lab","description":"Intel LevelZero JNI library for TornadoVM ","archived":false,"fork":false,"pushed_at":"2024-09-17T07:20:25.000Z","size":341,"stargazers_count":12,"open_issues_count":0,"forks_count":6,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-11-05T10:45:22.702Z","etag":null,"topics":["gpu-library","heterogeneous-parallel-programming","intel-gpu","java","jni-library","level-zero","oneapi","spirv"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/beehive-lab.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-02-19T12:36:12.000Z","updated_at":"2024-09-20T16:39:13.000Z","dependencies_parsed_at":"2024-09-17T09:42:35.659Z","dependency_job_id":null,"html_url":"https://github.com/beehive-lab/levelzero-jni","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beehive-lab%2Flevelzero-jni","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beehive-lab%2Flevelzero-jni/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beehive-lab%2Flevelzero-jni/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beehive-lab%2Flevelzero-jni/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/beehive-lab","download_url":"https://codeload.github.com/beehive-lab/levelzero-jni/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247237606,"owners_count":20906314,"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":["gpu-library","heterogeneous-parallel-programming","intel-gpu","java","jni-library","level-zero","oneapi","spirv"],"created_at":"2024-08-01T15:00:57.395Z","updated_at":"2025-12-30T03:02:44.327Z","avatar_url":"https://github.com/beehive-lab.png","language":"Java","readme":"# Beehive LevelZero JNI\n\nBaremetal GPU and FPGA programming for Java using Intel's [Level Zero API](https://spec.oneapi.io/level-zero/latest/index.html). This project is a Java Native Interface (JNI) binding for Intel's Level Zero. This library is designed to be as closed as possible to the Level Zero API for C++ API, and it supports a subset of the Level Zero 1.4.0 API (Level Zero as in May 2022).\nThis library is used by [TornadoVM](https://github.com/beehive-lab/TornadoVM/), and the subset of the Level Zero API 1.4.0 is the minimum required to dispatch SPIR-V kernels on Intel ARC and Intel integrated GPUs under the TornadoVM Runtime. It is, by no means, a complete port of the Level Zero API, but external contributions are very welcome.\n\n## Compilation \u0026 configuration of the JNI Level Zero API\n\n### 1) Compile Native Library: Level Zero API\n\n#### Linux (Tested for Fedora 35-39 and Ubuntu 22.X-24.X)\n\n```bash\ngit clone https://github.com/oneapi-src/level-zero.git\ncd level-zero\nmkdir build\ncd build\ncmake ..\ncmake --build . --config Release\ncmake --build . --config Release --target package\n```\n\n#### Windows 10/11\n\nTested Configurations:\n- Lenovo IdeaPad Gaming 3 15IHU6\n- Dell XPS 8950\n- Windows 11\n- VS Community 2022\n  + components: C++, Git, Spectre mitigated libraries\n- CMake 3.26.3, Maven 3.9.1, JDK 21+\n\nRun commands in _x64 Native Tools Command Prompt for VS 2022_.\n\n```cmd\ngit clone https://github.com/oneapi-src/level-zero\ncd level-zero\nmd build\ncd build\ncmake ..\ncmake --build . --config Release\n\nrem check\n.\\bin\\Release\\zello_world.exe\n```\n\nNote: If `zello_world.exe` fails, search for existing Level Zero API DLLs (file names start with `ze_`, e.g. `ze_tracing_layer.dll`) in `c:\\windows\\system32` and move them to another folder.\n\n### 2) Compile Level Zero Java JNI native code\n\nSet the paths to the directory of Level Zero installation. Here are examples:\n\n#### Linux\n\n```bash\nscl enable devtoolset-9 bash # \u003c\u003c Only for CentOS/RHEL\ngit clone https://github.com/beehive-lab/levelzero-jni\nexport ZE_SHARED_LOADER=\"\u003cpath-to-levelzero\u003e/build/lib/libze_loader.so\"\nexport CPLUS_INCLUDE_PATH=\u003cpath-to-levelzero\u003e/include:$CPLUS_INCLUDE_PATH\nexport C_INCLUDE_PATH=\u003cpath-to-levelzero\u003e/include:$CPLUS_INCLUDE_PATH\ncd levelzero-jni/levelZeroLib\nmkdir build\ncd build\ncmake ..\nmake\n```\n\n#### Windows 10/11\n\nNote: Run commands in _x64 Native Tools Command Prompt for VS 2022_.\n\n```cmd\ngit clone https://github.com/beehive-lab/levelzero-jni\nset ZE_SHARED_LOADER=%USERPROFILE%\\lab\\level-zero\\build\\lib\\release\\ze_loader.lib\nset CPLUS_INCLUDE_PATH=%USERPROFILE%\\lab\\level-zero\\include\nset C_INCLUDE_PATH=%USERPROFILE%\\lab\\level-zero\\include\n\nrem add the folder with Intel's Level Zero API DLLs to PATH\nset PATH=%USERPROFILE%\\lab\\level-zero\\build\\bin\\release;%PATH%\n\ncd levelzero-jni\\levelZeroLib\nmd build\ncd build\ncmake ..\ncmake --build . --config Release\n```\n\n#### Obtain a SPIR-V compiler (Linux and Windows)\n\nIn case you want to compile kernels from OpenCL C to SPIR-V and use the Level Zero API, you need to download the `llvm-spirv` compiler. The implementation we are currently using is [Intel LLVM](https://github.com/intel/llvm).\n\n### 3) Compile the Java Library and Run Tests\n\n#### Linux\n\n```bash\nmvn clean package\n./scripts/run.sh   ## \u003c This script compiles an OpenCL C program to SPIR-V using the llvm-spirv compiler (see 2.1)\n```\n\nThe OpenCL C kernel provided for this example is as follows:\n\n```c\n__kernel void copyData(__global int* input, __global int* output) {\n\tuint idx = get_global_id(0);\n\toutput[idx] = input[idx];\n}\n```\n\nTo compile from OpenCL C to SPIR-V:\n\n```bash\nclang -cc1 -triple spir copyData.cl -O0 -finclude-default-header -emit-llvm-bc -o copyData.bc\nllvm-spirv copyData.bc -o copyData.spv\n```\n\n#### Windows\n\nNote: Java programs that use `levelzero-jni` are based on DLLs, which are provided by Intel's Level Zero API. For these programs to find these DLLs, the PATH environment variable must contain the folder that contains the DLLs.\n\n```cmd\nmvn clean package\n\nrem add the folder with Intel's Level Zero API DLLs to PATH\nset PATH=%USERPROFILE%\\lab\\level-zero\\build\\bin\\release;%PATH%\n\nrem copyData.spv file expected in CWD\n.\\scripts\\run.cmd\n\n# more tests\n.\\scripts\\copies.cmd\n.\\scripts\\events.cmd\n.\\scripts\\fences.cmd\n.\\scripts\\kernelTimers.cmd\n.\\scripts\\transferTimers.cmd\n.\\scripts\\largeBuffers.cmd\n.\\scripts\\testZelloWorld.cmd\n```\n\n## Some Examples\n\n\n### Instance Driver Pointer \n\n\n```java\n // Obtain the Level Zero Driver\nLevelZeroDriver driver = new LevelZeroDriver();\nint result = driver.zeInit(ZeInitFlag.ZE_INIT_FLAG_GPU_ONLY);\nLevelZeroUtils.errorLog(\"zeInit\", result);\n\nint[] numDrivers = new int[1];\nresult = driver.zeDriverGet(numDrivers, null);\nLevelZeroUtils.errorLog(\"zeDriverGet\", result);\n\nZeDriverHandle driverHandler = new ZeDriverHandle(numDrivers[0]);\nresult = driver.zeDriverGet(numDrivers, driverHandler);\nLevelZeroUtils.errorLog(\"zeDriverGet\", result);\n```\n\n### Create Level Zero Context\n\n```java\nZeContextDescriptor contextDescription = new ZeContextDescriptor();\nLevelZeroContext context = new LevelZeroContext(driverHandler, contextDescription);\nresult = context.zeContextCreate(driverHandler.getZe_driver_handle_t_ptr()[0]);\nLevelZeroUtils.errorLog(\"zeContextCreate\", result);\n```\n\n\n### Allocate Shared Memory:\n\n```java\nZeDeviceMemAllocDescriptor deviceMemAllocDesc = new ZeDeviceMemAllocDescriptor();\ndeviceMemAllocDesc.setFlags(ZeDeviceMemAllocFlags.ZE_DEVICE_MEM_ALLOC_FLAG_BIAS_UNCACHED);\n\n\nZeHostMemAllocDescriptor hostMemAllocDesc = new ZeHostMemAllocDescriptor();\nhostMemAllocDesc.setFlags(ZeHostMemAllocFlags.ZE_HOST_MEM_ALLOC_FLAG_BIAS_UNCACHED);\n\n\nLevelZeroBufferInteger bufferA = new LevelZeroBufferInteger();\nresult = context.zeMemAllocShared(context.getContextHandle().getContextPtr()[0], deviceMemAllocDesc, hostMemAllocDesc, bufferSize, 1, device.getDeviceHandlerPtr(), bufferA);\nLevelZeroUtils.errorLog(\"zeMemAllocShared\", result);\n```\n\nSee the full list of examples [here](https://github.com/beehive-lab/levelzero-jni/tree/master/src/main/java/uk/ac/manchester/tornado/drivers/spirv/levelzero/samples).\n\n\n## License\n\nThis project is developed at [The University of Manchester](https://www.manchester.ac.uk/), and it is fully open source under the [MIT](https://github.com/beehive-lab/levelzero-jni/blob/master/LICENSE) license.\n\n\n## Acknowledgments\n\nThe work was partially funded by the EU Horizon 2020 [Elegant 957286](https://www.elegant-h2020.eu/) project, and [Intel Coorporation](https://www.intel.it/content/www/it/it/homepage.html).\n","funding_links":[],"categories":["Table of Contents"],"sub_categories":["Tools and Development"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeehive-lab%2Flevelzero-jni","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeehive-lab%2Flevelzero-jni","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeehive-lab%2Flevelzero-jni/lists"}