From 53bb54e66a81f456fe9921925414a49de2204ca9 Mon Sep 17 00:00:00 2001 From: Juan Fumero Date: Fri, 9 Aug 2024 11:09:31 +0200 Subject: [PATCH 1/2] [spirv] flag to be able to run with prev. versions of SPIR-V 1.2 --- docs/source/spirv-backend.rst | 16 ++++++++++++++-- .../tornado/drivers/opencl/OCLDevice.java | 5 +++-- .../tornado/drivers/spirv/SPIRVBackendImpl.java | 11 +++++++++++ .../tornado/runtime/common/TornadoOptions.java | 9 +++++++++ 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/docs/source/spirv-backend.rst b/docs/source/spirv-backend.rst index 28c044f793..32dd5dcfac 100644 --- a/docs/source/spirv-backend.rst +++ b/docs/source/spirv-backend.rst @@ -23,8 +23,8 @@ To build the SPIR-V Backend, enable the backend as follows: .. code:: bash $ cd - $ ./scripts/tornadoVMInstaller.sh --jdk17 --spirv - $ . source.sh + $ ./scripts/tornadovm-installer --jdk jdk21 --backend=spirv + $ . setvars.sh Running examples with the SPIR-V backend ------------------------------------------ @@ -63,6 +63,18 @@ Note: Usually, ``spirv-dis`` can be installed from the common OS repositories (e ## Ubuntu OS: sudo apt-get install spirv-tools + +TornadoVM/Java Options for SPIR-V: +'''''''''''''''''''''''''''''' + +- ``-Dtornado.spirv.version=1.2``: Modify the minimum version supported. By default is 1.2. However, developers can change this value. Note that the generated code might not work, as TornadoVM requires at least 1.2. + +- ``-Dtornado.spirv.dispatcher=opencl``: It sets the runtime to dispatch SPIR-V kernels. Allowed values are: ``opencl`` and ``levelzero``. + +- ``-Dtornado.spirv.levelzero.extended.memory=True``: It uses Level Zero extended memory mode. It is set to ``true`` by default. + + + Disassemble the SPIR-V binary: '''''''''''''''''''''''''''''' diff --git a/tornado-drivers/opencl/src/main/java/uk/ac/manchester/tornado/drivers/opencl/OCLDevice.java b/tornado-drivers/opencl/src/main/java/uk/ac/manchester/tornado/drivers/opencl/OCLDevice.java index 3317397478..b1e34c0be8 100644 --- a/tornado-drivers/opencl/src/main/java/uk/ac/manchester/tornado/drivers/opencl/OCLDevice.java +++ b/tornado-drivers/opencl/src/main/java/uk/ac/manchester/tornado/drivers/opencl/OCLDevice.java @@ -39,6 +39,7 @@ import uk.ac.manchester.tornado.drivers.opencl.enums.OCLDeviceType; import uk.ac.manchester.tornado.drivers.opencl.enums.OCLLocalMemType; import uk.ac.manchester.tornado.runtime.common.RuntimeUtilities; +import uk.ac.manchester.tornado.runtime.common.TornadoOptions; public class OCLDevice implements OCLTargetDevice { @@ -79,7 +80,7 @@ public class OCLDevice implements OCLTargetDevice { private static final int SPIRV_VERSION_INIT = -1; private static final int SPIRV_NOT_SUPPORTED = -2; - private static final float SPIRV_SUPPPORTED = 1.2f; + private static final float SPIRV_SUPPPORTED = TornadoOptions.SPIRV_VERSION_SUPPORTED; public OCLDevice(int index, long devicePointer) { this.index = index; @@ -470,7 +471,7 @@ public boolean isSPIRVSupported() { String v = version.split("_")[1]; try { spirvVersion = Float.parseFloat(v); - return spirvVersion >= 1.2; + return spirvVersion >= SPIRV_SUPPPORTED; } catch (NumberFormatException e) { } } diff --git a/tornado-drivers/spirv/src/main/java/uk/ac/manchester/tornado/drivers/spirv/SPIRVBackendImpl.java b/tornado-drivers/spirv/src/main/java/uk/ac/manchester/tornado/drivers/spirv/SPIRVBackendImpl.java index 00371a1ec6..5a3639cbc9 100644 --- a/tornado-drivers/spirv/src/main/java/uk/ac/manchester/tornado/drivers/spirv/SPIRVBackendImpl.java +++ b/tornado-drivers/spirv/src/main/java/uk/ac/manchester/tornado/drivers/spirv/SPIRVBackendImpl.java @@ -146,6 +146,17 @@ public TornadoDevice getDefaultDevice() { @Override public void setDefaultDevice(int index) { + swapDefaultDevice(index); + } + + private void swapDefaultDevice(final int device) { + SPIRVBackend tmp = flatBackends[0]; + flatBackends[0] = flatBackends[device]; + flatBackends[device] = tmp; + SPIRVBackend backend = flatBackends[0]; + if (!backend.isInitialised()) { + backend.init(); + } } private int getNumDevicesForPlatform(int platform) { diff --git a/tornado-runtime/src/main/java/uk/ac/manchester/tornado/runtime/common/TornadoOptions.java b/tornado-runtime/src/main/java/uk/ac/manchester/tornado/runtime/common/TornadoOptions.java index 350f238ef0..dbc528661a 100644 --- a/tornado-runtime/src/main/java/uk/ac/manchester/tornado/runtime/common/TornadoOptions.java +++ b/tornado-runtime/src/main/java/uk/ac/manchester/tornado/runtime/common/TornadoOptions.java @@ -217,6 +217,11 @@ public class TornadoOptions { * generated SPIRV kernel. */ public static final boolean SPIRV_DIRECT_CALL_WITH_LOAD_HEAP = getBooleanValue("tornado.spirv.directcall.heap", FALSE); + + /** + * Set the SPIR-V Version Supported. It is set to 1.2 by default. + */ + public static final float SPIRV_VERSION_SUPPORTED = getFloatValue("tornado.spirv.version", "1.2"); /** * Trace code generation. */ @@ -405,6 +410,10 @@ private static int getIntValue(String property, String defaultValue) { return Integer.parseInt(System.getProperty(property, defaultValue)); } + private static float getFloatValue(String property, String defaultValue) { + return Float.parseFloat(System.getProperty(property, defaultValue)); + } + private static boolean isFPGAEmulation() { String contextEmulatorIntelFPGA = System.getenv("CL_CONTEXT_EMULATOR_DEVICE_INTELFPGA"); String contextEmulatorXilinxFPGA = System.getenv("XCL_EMULATION_MODE"); From 61ab86a4b335ecc65dbce78213f4320a509dd6f0 Mon Sep 17 00:00:00 2001 From: Thanos Stratikopoulos <34061419+stratika@users.noreply.github.com> Date: Fri, 9 Aug 2024 16:57:38 +0300 Subject: [PATCH 2/2] Update docs/source/spirv-backend.rst --- docs/source/spirv-backend.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/spirv-backend.rst b/docs/source/spirv-backend.rst index 32dd5dcfac..d5223fec66 100644 --- a/docs/source/spirv-backend.rst +++ b/docs/source/spirv-backend.rst @@ -23,7 +23,7 @@ To build the SPIR-V Backend, enable the backend as follows: .. code:: bash $ cd - $ ./scripts/tornadovm-installer --jdk jdk21 --backend=spirv + $ ./bin/tornadovm-installer --jdk jdk21 --backend=spirv $ . setvars.sh Running examples with the SPIR-V backend