[code-reflection] RFR: Implementation of a HAT Spirv backend
Steve Dohrmann
sdohrmann at openjdk.org
Thu Sep 12 22:52:40 UTC 2024
## A HAT SPIR-V backend
Implements an initial version of a HAT SPIR-V backend. It extends JavaBackend and includes no native code. It is complete enough to run the HAT Mandel example and some other simple examples. It lacks generalized data structure support and so will not yet run, e.g., the BlackScholes or ViolaJones examples.
The backend currently only supports Linux and requires an Intel GPU to run. Examples of compatible Intel GPU hardware are:
* Integrated Intel GPU such as:
* Iris Xe or UHD graphics in 11th generation or later CPUs (Rocket Lake, Alder Lake, Raptor Lake, ...)
* Arc graphics available with the latest CPUs, e.g., Meteor Lake
* Discrete Intel GPU such as Arc 580, 750, 770
* these are available on Amazon, search, e.g., "Intel Arc 580" or "Intel Arc 770"
Linux drivers for the above hardware have been included in some major Linux distros (e.g. Ubuntu) in time corresponding to the release of the hardware. Drivers for the discrete Arc cards are included in, e.g., Ubuntu 23.10. Ubuntu drivers for Arc discrete GPUs can also be downloaded separately. See https://www.intel.com/content/www/us/en/download/747008/intel-arc-graphics-driver-ubuntu.html
## Dependencies
Software-wise, the backend has several dependencies outside of the Babylon repo:
1. The Intel Level Zero library, a low level native library used to access the GPU
2. A Java binding to the Level Zero library, generated using the OpenJDK jextract tool
3. The Beehive Labs Java SPIR-V toolkit, used to construct a SPIR-V binary module
Currently these dependencies are not automatically built. Below is information on how to build and install the three items above.
### Intel Level Zero library
A build-levelzero.sh script is included in the hat/backends/spirv/scripts directory. Superuser privileges may be required when running this script. Execute the script with the scripts directory as the current directory:
cd backends/spirv/scripts
sh build-level-zero.sh
This will build and install the Level Zero ze_loader.so to /usr/local/lib. This path must be include in java.library.path or LD_LIBRARY_PATH when running using the spirv backend.
### OpenJDK jextract tool and generated binding to Level Zero
An early-access binary of the jextract tool can be found at:
https://jdk.java.net/jextract/
- expand the archive
- set a JEXTRACT_DIR environment variable to point at the jextract directory.
A generate-level-zero-binding.sh script is included in the hat/backends/spirv/scripts directory. The script will reference the JEXTRACT_DIR variable set earlier. Execute the script with the scripts directory as the current directory:
cd backends/spirv/scripts
sh generate-level-zero-binding.sh
This will generate a Java FFM-based binding to LevelZero, as levelzero.jar, and install the jar in your local Maven repo to satisfy a Maven dependency in the spirv backend pom file. This jar must be on the Java classpath when running using the spirv backend.
### Beehive Labs Java SPIR-V toolkit
A build-beehive-spirv-toolkit.sh script is included in the hat/backends/spirv/scripts directory. Note that this project will not currently compile with the babylon JDK, please temporarily set your JAVA_HOME to JDK 22. Execute the script with the scripts directory as the current directory:
cd backends/spirv/scripts
export JAVA_HOME = <path to JDK 22>
sh build-beehive-spirv-toolkit.sh
This will build a beehive_spirv_lib.0.0.4.jar and install it in your local maven repo to satisfy a Maven dependency in the spirv backend pom file. This jar must be on the Java classpath when running the spirv backend.
## Note:
These three dependencies (Level Zero library, Level Zero Java binding, Beehive SPIR-V Toolkit) must be built and installed prior to building and using the 'spirv' backend. Because these dependencies are not yet built automatically, the spirv backend is current not built by default. To enable building and use of the spirv backend, after manually running these scripts, change one line of the 'modules' section in hat/backends/pom.xml:
<modules>
<module>opencl</module>
<module>cuda</module>
<module>mock</module>
<module>ptx</module>
</modules>
to:
<modules>
<module>opencl</module>
<module>cuda</module>
<module>mock</module>
<module>ptx</module>
<module>spirv</module>
</modules>
-------------
Commit messages:
- bug fixes, scripts copy jars now
- Implementation of a HAT Spirv backend
Changes: https://git.openjdk.org/babylon/pull/229/files
Webrev: https://webrevs.openjdk.org/?repo=babylon&pr=229&range=00
Stats: 3095 lines in 15 files changed: 3052 ins; 26 del; 17 mod
Patch: https://git.openjdk.org/babylon/pull/229.diff
Fetch: git fetch https://git.openjdk.org/babylon.git pull/229/head:pull/229
PR: https://git.openjdk.org/babylon/pull/229
More information about the babylon-dev
mailing list