diff --git a/docs/source/spirv-backend.rst b/docs/source/spirv-backend.rst index 28c044f793..d5223fec66 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 + $ ./bin/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");