Code Monkey home page Code Monkey logo

levelzero-jni's Introduction

Beehive LevelZero JNI

Baremetal GPU and FPGA programming for Java using Intel's Level Zero API. 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++. Subset of Level Zero 1.4.0 supported (Level Zero May 2022 version)

Compilation & configuration of the JNI Level Zero API

1) Compile Native Library: Level Zero API

Linux

git clone https://github.com/oneapi-src/level-zero.git
cd level-zero
mkdir build
cd build
cmake ..
cmake --build . --config Release
cmake --build . --config Release --target package

Windows 10/11

Tested Configurations:

  • Lenovo IdeaPad Gaming 3 15IHU6
  • Dell XPS 8950
  • Windows 11
  • VS Community 2022
    • components: C++, Git, Spectre mitigated libraries
  • CMake 3.26.3, Maven 3.9.1, JDK 21+

Run commands in x64 Native Tools Command Prompt for VS 2022.

git clone https://github.com/oneapi-src/level-zero
cd level-zero
md build
cd build
cmake ..
cmake --build . --config Release

rem check
.\bin\Release\zello_world.exe

Note: 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.

2) Compile Level Zero Java JNI native code

Set the paths to the directory of Level Zero installation. Here are examples:

Linux

scl enable devtoolset-9 bash # << Only for CentOS
git clone https://github.com/beehive-lab/levelzero-jni
export ZE_SHARED_LOADER="<path-to-levelzero>/build/lib/libze_loader.so"
export CPLUS_INCLUDE_PATH=<path-to-levelzero>/include:$CPLUS_INCLUDE_PATH
export C_INCLUDE_PATH=<path-to-levelzero>/include:$CPLUS_INCLUDE_PATH
cd levelzero-jni/levelZeroLib
mkdir build
cd build
cmake ..
make

Windows 10/11

Note: Run commands in x64 Native Tools Command Prompt for VS 2022.

git clone https://github.com/beehive-lab/levelzero-jni
set ZE_SHARED_LOADER=%USERPROFILE%\lab\level-zero\build\lib\release\ze_loader.lib
set CPLUS_INCLUDE_PATH=%USERPROFILE%\lab\level-zero\include
set C_INCLUDE_PATH=%USERPROFILE%\lab\level-zero\include

rem add the folder with Intel's Level Zero API DLLs to PATH
set PATH=%USERPROFILE%\lab\level-zero\build\bin\release;%PATH%

cd levelzero-jni\levelZeroLib
md build
cd build
cmake ..
cmake --build . --config Release

Obtain a SPIR-V compiler (Linux and Windwos)

In 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.

3) Compile and run a Java test

Linux

mvn clean package
./scripts/run.sh   ## < This script compiles an OpenCL C program to SPIR-V using the llvm-spirv compiler (see 2.1)

The OpenCL C kernel provided for this example is as follows:

__kernel void copyData(__global int* input, __global int* output) {
	uint idx = get_global_id(0);
	output[idx] = input[idx];
}

To compile from OpenCL C to SPIR-V:

clang -cc1 -triple spir copyData.cl -O0 -finclude-default-header -emit-llvm-bc -o copyData.bc
llvm-spirv copyData.bc -o copyData.spv

Windows

Note: 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.

mvn clean package

rem add the folder with Intel's Level Zero API DLLs to PATH
set PATH=%USERPROFILE%\lab\level-zero\build\bin\release;%PATH%

rem copyData.spv file expected in CWD
.\scripts\run.cmd

# more tests
.\scripts\copies.cmd
.\scripts\events.cmd
.\scripts\fences.cmd
.\scripts\kernelTimers.cmd
.\scripts\transferTimers.cmd
.\scripts\largeBuffers.cmd

License

This project is developed at The University of Manchester, and it is fully open source under the MIT license.

Acknowledgments

The work was partially funded by the EU Horizon 2020 Elegant 957286 project, and Intel Coorporation.

levelzero-jni's People

Contributors

jjfumero avatar otabuzzman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

levelzero-jni's Issues

Possible typos in readme

Not sure, but there may be a couple of typos in the readme.

  • in the "To compile to SPIR-V" section, the command line refers to a kernel file 'opencl-copy.cl' but the sample kernel in the repository is called 'copy_data.cl'

  • the command line in the "To run" section looks like it has omitted the package path to the TestLevelZero class

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.