Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[spirv] flag to be able to run with prev. versions of SPIR-V 1.2 #527

Merged
merged 2 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions docs/source/spirv-backend.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ To build the SPIR-V Backend, enable the backend as follows:
.. code:: bash

$ cd <tornadovm-directory>
$ ./scripts/tornadoVMInstaller.sh --jdk17 --spirv
$ . source.sh
$ ./bin/tornadovm-installer --jdk jdk21 --backend=spirv
$ . setvars.sh

Running examples with the SPIR-V backend
------------------------------------------
Expand Down Expand Up @@ -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:
''''''''''''''''''''''''''''''

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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");
Expand Down