Skip to content

Commit

Permalink
[spirv] Simplify runtime selection
Browse files Browse the repository at this point in the history
  • Loading branch information
jjfumero committed Jan 8, 2025
1 parent b70bba0 commit 14fc48a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
*/
public class SPIRVRuntimeImpl {

private final String ERROR_PLATFORM_NOT_IMPLEMENTED = "SPIR-V Runtime Implementation not supported: " + TornadoOptions.SPIRV_DEFAULT_RUNTIME + " \nUse \"opencl\" or \"levelzero\"";

private List<SPIRVPlatform> platforms;
private static SPIRVRuntimeImpl instance;

Expand All @@ -59,29 +57,28 @@ private SPIRVRuntimeImpl() {
init();
}

private String printErrorPlatformNotImplemented(String spirvPlatform) {
return "SPIR-V Runtime Implementation not supported: " + spirvPlatform + " \nUse \"opencl\" or \"levelzero\"";
}

private SPIRVDispatcher instantiateDispatcher(String runtimeName) {
if (runtimeName.equalsIgnoreCase("opencl")) {
return new SPIRVOpenCLDriver();
} else if (runtimeName.equalsIgnoreCase("levelzero")) {
return new SPIRVLevelZeroDriver();
} else {
throw new TornadoRuntimeException(ERROR_PLATFORM_NOT_IMPLEMENTED);
throw new TornadoRuntimeException(printErrorPlatformNotImplemented(runtimeName));
}
}

private synchronized void init() {
if (platforms == null) {
List<SPIRVDispatcher> dispatchers = new ArrayList<>();
dispatchers.add(instantiateDispatcher(TornadoOptions.SPIRV_DEFAULT_RUNTIME));

String[] listOfRuntimes = TornadoOptions.SPIRV_INSTALLED_RUNTIMES.split(",");
if (listOfRuntimes.length > 1) {
// We need to install the second runtime
for (String runtime : listOfRuntimes) {
if (!runtime.equals(TornadoOptions.SPIRV_DEFAULT_RUNTIME)) {
dispatchers.add( instantiateDispatcher(runtime));
}
}

// We need to install the second runtime
for (String runtime : listOfRuntimes) {
dispatchers.add(instantiateDispatcher(runtime));
}

platforms = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,19 +217,17 @@ public class TornadoOptions {
* It enables inlining during Java bytecode parsing. Default is False.
*/
public static final boolean INLINE_DURING_BYTECODE_PARSING = getBooleanValue("tornado.compiler.bytecodeInlining", FALSE);
/**
* Use Level Zero or OpenCL as the SPIR-V Code runtime and code dispatcher. Allowed values: "opencl", "levelzero". The default option is "opencl".
*/
public static final String SPIRV_DEFAULT_RUNTIME = getProperty("tornado.spirv.default.dispatcher", "opencl");

/**
* List of installed SPIR-V runtimes. Allowed values : "opencl,levelzero".
* List of installed SPIR-V runtimes. Allowed values : "opencl,levelzero". The first in the list is set to the
* default one.
*
* <p>
* <ul>
* <il>Use <code>-Dtornado.spirv.runtimes=opencl</code> for OpenCL only.
* <il>Use <code>-Dtornado.spirv.runtimes=levelzero</code> for LevelZero only.
* <il>Use <code>-Dtornado.spirv.runtimes=opencl,levelzero</code> for both OpenCL and Level Zero runtimes.
* <il>Use <code>-Dtornado.spirv.runtimes=opencl,levelzero</code> for both OpenCL and Level Zero runtimes, being
* OpenCL the first in the list (default).
* *</ul>
* </p>
*/
Expand Down

0 comments on commit 14fc48a

Please sign in to comment.