From 14fc48a030b4a75c3fbc080d739701c3516d3b9d Mon Sep 17 00:00:00 2001 From: Juan Fumero Date: Wed, 8 Jan 2025 10:45:36 +0100 Subject: [PATCH] [spirv] Simplify runtime selection --- .../drivers/spirv/SPIRVRuntimeImpl.java | 21 ++++++++----------- .../runtime/common/TornadoOptions.java | 10 ++++----- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/tornado-drivers/spirv/src/main/java/uk/ac/manchester/tornado/drivers/spirv/SPIRVRuntimeImpl.java b/tornado-drivers/spirv/src/main/java/uk/ac/manchester/tornado/drivers/spirv/SPIRVRuntimeImpl.java index 7b2f53d3c..013e0136b 100644 --- a/tornado-drivers/spirv/src/main/java/uk/ac/manchester/tornado/drivers/spirv/SPIRVRuntimeImpl.java +++ b/tornado-drivers/spirv/src/main/java/uk/ac/manchester/tornado/drivers/spirv/SPIRVRuntimeImpl.java @@ -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 platforms; private static SPIRVRuntimeImpl instance; @@ -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 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<>(); 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 b49abe680..1e7f078ee 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,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. * *

*

    * Use -Dtornado.spirv.runtimes=opencl for OpenCL only. * Use -Dtornado.spirv.runtimes=levelzero for LevelZero only. - * Use -Dtornado.spirv.runtimes=opencl,levelzero for both OpenCL and Level Zero runtimes. + * Use -Dtornado.spirv.runtimes=opencl,levelzero for both OpenCL and Level Zero runtimes, being + * OpenCL the first in the list (default). * *
*

*/