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

Reverse usage of String Templates in preparation for JDK23 #525

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ void withDefaultScheduler() {

TornadoDevice getDevice(int immutableTaskGraphIndex) {
if (immutableTaskGraphList.size() < immutableTaskGraphIndex) {
throw new TornadoRuntimeException(STR."TaskGraph index #\{immutableTaskGraphIndex} does not exist in current executor");
throw new TornadoRuntimeException("TaskGraph index #" + immutableTaskGraphIndex + " does not exist in current executor");
}
return immutableTaskGraphList.get(immutableTaskGraphIndex).getDevice();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public int hashCode() {

@Override
public String toString() {
return STR."Shape{dimensions=\{Arrays.toString(dimensions)}}";
return "Shape{dimensions=" + Arrays.toString(dimensions) + "}";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public TornadoXPUDevice getDevice(int index) {
if (index < flatBackends.length) {
return flatBackends[index].getDeviceContext().asMapping();
} else {
throw new TornadoDeviceNotFound(STR."[ERROR] device required not found: \{index} - Max: \{flatBackends.length}");
throw new TornadoDeviceNotFound("[ERROR] device required not found: " + index + " - Max: " + flatBackends.length);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,16 +547,16 @@ private boolean isInputSourceSPIRVBinary(byte[] source) {

private void dumpKernelSource(String id, String entryPoint, String log, byte[] source) {
final Path outDir = resolveLogDirectory();
final String identifier = STR."\{id}-\{entryPoint}";
final String identifier = id + "-" + entryPoint;
logger.error("Unable to compile task %s: check logs at %s/%s.log", identifier, outDir.toAbsolutePath(), identifier);

File file = new File(STR."\{outDir}/\{identifier}.log");
File file = new File(outDir + "/" + identifier + ".log");
try (FileOutputStream fos = new FileOutputStream(file)) {
fos.write(log.getBytes());
} catch (IOException e) {
logger.error("unable to write error log: ", e.getMessage());
}
file = new File(STR."\{outDir}/\{identifier}\{OPENCL_SOURCE_SUFFIX}");
file = new File(outDir + "/" + identifier + OPENCL_SOURCE_SUFFIX);
try (FileOutputStream fos = new FileOutputStream(file)) {
fos.write(source);
} catch (IOException e) {
Expand All @@ -567,13 +567,13 @@ private void dumpKernelSource(String id, String entryPoint, String log, byte[] s

private void installCodeInCodeCache(OCLProgram program, TaskMetaData meta, String id, String entryPoint, OCLInstalledCode code) {

cache.put(STR."\{id}-\{entryPoint}", code);
cache.put(id + "-" + entryPoint, code);

// BUG Apple does not seem to like implementing the OpenCL spec
// properly, this causes a SIGFAULT.
if ((OPENCL_CACHE_ENABLE || OPENCL_DUMP_BINS) && !deviceContext.getPlatformContext().getPlatform().getVendor().equalsIgnoreCase("Apple")) {
final Path outDir = resolveCacheDirectory();
program.dumpBinaries(STR."\{outDir.toAbsolutePath()}/\{entryPoint}");
program.dumpBinaries(outDir.toAbsolutePath() + "/" + entryPoint);
}
}

Expand Down Expand Up @@ -662,11 +662,11 @@ private OCLInstalledCode installBinary(String id, String entryPoint, byte[] bina
long afterLoad = (TornadoOptions.TIME_IN_NANOSECONDS) ? System.nanoTime() : System.currentTimeMillis();

if (PRINT_LOAD_TIME) {
System.out.println(STR."Binary load time: \{afterLoad - beforeLoad}\{TornadoOptions.TIME_IN_NANOSECONDS ? " ns" : " ms"} \n");
System.out.println("Binary load time: " + (afterLoad - beforeLoad) + (TornadoOptions.TIME_IN_NANOSECONDS ? " ns" : " ms") + "\n");
}

if (program == null) {
throw new OCLException(STR."unable to load binary for \{entryPoint}");
throw new OCLException("unable to load binary for " + entryPoint);
}

program.build("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,13 +643,13 @@ public OCLInstalledCode installCode(String id, String entryPoint, byte[] code, b
@Override
public boolean isCached(String id, String entryPoint) {
entryPoint = checkKernelName(entryPoint);
return codeCache.isCached(STR."\{id}-\{entryPoint}");
return codeCache.isCached(id + "-" + entryPoint);
}

@Override
public boolean isCached(String methodName, SchedulableTask task) {
methodName = checkKernelName(methodName);
return codeCache.isCached(STR."\{task.getId()}-\{methodName}");
return codeCache.isCached(task.getId() + "-" + methodName);
}

public OCLInstalledCode getInstalledCode(String id, String entryPoint) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public OCLStamp getStampInt() {
return switch (operation) {
case ADD -> new OCLStamp(OCLKind.ATOMIC_ADD_INT);
case MUL -> new OCLStamp(OCLKind.ATOMIC_MUL_INT);
default -> throw new RuntimeException(STR."Operation for reduction not supported yet: \{operation}");
default -> throw new RuntimeException("Operation for reduction not supported yet: " + operation);
};
}

Expand All @@ -112,7 +112,7 @@ public OCLStamp getStampFloat() {
oclStamp = new OCLStamp(OCLKind.ATOMIC_ADD_FLOAT);
break;
default:
throw new RuntimeException(STR."Operation for reduction not supported yet: \{operation}");
throw new RuntimeException("Operation for reduction not supported yet: " + operation);
}
return oclStamp;
}
Expand All @@ -127,7 +127,7 @@ public void generate(NodeLIRBuilderTool gen) {
// DUE TO UNSUPPORTED FEATURE IN INTEL OpenCL PLATFORM
new OCLStamp(OCLKind.ATOMIC_ADD_INT);
case Float -> getStampFloat();
default -> throw new RuntimeException(STR."Data type for reduction not supported yet: \{elementKind}");
default -> throw new RuntimeException("Data type for reduction not supported yet: " + elementKind);
};

LIRKind writeKind = gen.getLIRGeneratorTool().getLIRKind(oclStamp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected void run(StructuredGraph graph) {

for (ReadNode readNode : graph.getNodes().filter(ReadNode.class)) {
if (readNode.getLocationIdentity().toString().contains("VectorHalf") && !fp16Support) {
throw new TornadoDeviceFP16NotSupported(STR."The current OpenCL device (\{deviceContext.getDeviceName()}) does not support FP64");
throw new TornadoDeviceFP16NotSupported("The current OpenCL device (" + deviceContext.getDeviceName() + ") does not support FP64");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private boolean isStampFP64Type(Stamp stamp) {
private void checkStampForFP64Support(Stamp stamp) {
boolean isStampFP64Type = isStampFP64Type(stamp);
if (isStampFP64Type && !deviceContext.isFP64Supported()) {
throw new TornadoDeviceFP64NotSupported(STR."The current OpenCL device (\{deviceContext.getDeviceName()}) does not support FP64");
throw new TornadoDeviceFP64NotSupported("The current OpenCL device (" + deviceContext.getDeviceName() + ") does not support FP64");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ private JavaKind getJavaKindFromConstantNode(ConstantNode signatureNode) {
case "Class:double", "Class:uk.ac.manchester.tornado.api.types.arrays.DoubleArray":
return JavaKind.Double;
default:
unimplemented(STR."Other types not supported yet: \{signatureNode.getValue().toValueString()}");
unimplemented("Other types not supported yet: " + signatureNode.getValue().toValueString());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ protected void run(StructuredGraph graph, TornadoHighTierContext context) {

deadCodeElimination.run(graph);

getDebugContext().dump(DebugContext.INFO_LEVEL, graph, STR."After TaskSpecialisation iteration = \{iterations}");
getDebugContext().dump(DebugContext.INFO_LEVEL, graph, "After TaskSpecialisation iteration = " + iterations);

hasWork = (lastNodeCount != graph.getNodeCount() || graph.getNewNodes(mark).isNotEmpty() || hasPanamaArraySizeNode(graph)) && (iterations < MAX_ITERATIONS);
lastNodeCount = graph.getNodeCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private MemorySegment getSegmentWithHeader(final Object reference) {
case TornadoImagesInterface<?> imagesInterface -> imagesInterface.getSegmentWithHeader();
case TornadoMatrixInterface<?> matrixInterface -> matrixInterface.getSegmentWithHeader();
case TornadoVolumesInterface<?> volumesInterface -> volumesInterface.getSegmentWithHeader();
default -> throw new TornadoMemoryException(STR."Memory Segment not supported: \{reference.getClass()}");
default -> throw new TornadoMemoryException("Memory Segment not supported: " + reference.getClass());
};
}

Expand Down Expand Up @@ -188,7 +188,7 @@ public void allocate(Object reference, long batchSize) throws TornadoOutOfMemory
}

if (bufferSize <= 0) {
throw new TornadoMemoryException(STR."[ERROR] Bytes Allocated <= 0: \{bufferSize}");
throw new TornadoMemoryException("[ERROR] Bytes Allocated <= 0: " + bufferSize);
}

if (TornadoOptions.FULL_DEBUG) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class OCLVectorWrapper implements XPUBuffer {
private long setSubRegionSize;

public OCLVectorWrapper(final OCLDeviceContext device, final Object object, long batchSize) {
TornadoInternalError.guarantee(object instanceof PrimitiveStorage, STR."Expecting a PrimitiveStorage type, but found: \{object.getClass()}");
TornadoInternalError.guarantee(object instanceof PrimitiveStorage, "Expecting a PrimitiveStorage type, but found: " + object.getClass());
this.deviceContext = device;
this.batchSize = batchSize;
this.bufferId = INIT_VALUE;
Expand All @@ -89,7 +89,7 @@ public void allocate(Object value, long batchSize) {
}

if (bufferSize <= 0) {
throw new TornadoMemoryException(STR."[ERROR] Bytes Allocated <= 0: \{bufferSize}");
throw new TornadoMemoryException("[ERROR] Bytes Allocated <= 0: " + bufferSize);
}

this.bufferId = deviceContext.getBufferProvider().getOrAllocateBufferWithSize(bufferSize);
Expand Down Expand Up @@ -167,7 +167,7 @@ private int enqueueReadArrayData(long executionPlanId, long bufferId, long offse
if (value instanceof TornadoNativeArray nativeArray) {
return deviceContext.enqueueReadBuffer(executionPlanId, bufferId, offset, bytes, nativeArray.getSegmentWithHeader().address(), hostOffset, waitEvents);
} else {
throw new TornadoRuntimeException(STR."Type not supported: \{value.getClass()}");
throw new TornadoRuntimeException("Type not supported: " + value.getClass());
}
} else {
TornadoInternalError.shouldNotReachHere("Expecting an array type");
Expand Down Expand Up @@ -206,7 +206,7 @@ private int enqueueWriteArrayData(long executionPlanId, long bufferId, long offs
if (value instanceof TornadoNativeArray nativeArray) {
return deviceContext.enqueueWriteBuffer(executionPlanId, bufferId, offset, bytes, nativeArray.getSegmentWithHeader().address(), hostOffset, waitEvents);
} else {
throw new TornadoRuntimeException(STR."Type not supported: \{value.getClass()}");
throw new TornadoRuntimeException("Type not supported: " + value.getClass());
}
} else {
TornadoInternalError.shouldNotReachHere("Expecting an array type");
Expand Down Expand Up @@ -247,7 +247,7 @@ private int readArrayData(long executionPlanId, long bufferId, long offset, long
if (value instanceof TornadoNativeArray nativeArray) {
return deviceContext.readBuffer(executionPlanId, bufferId, offset, bytes, nativeArray.getSegmentWithHeader().address(), hostOffset, waitEvents);
} else {
throw new TornadoRuntimeException(STR."Type not supported: \{value.getClass()}");
throw new TornadoRuntimeException("Type not supported: " + value.getClass());
}
} else {
TornadoInternalError.shouldNotReachHere("Expecting an array type");
Expand Down Expand Up @@ -318,7 +318,7 @@ private void writeArrayData(long executionPlanId, long bufferId, long offset, lo
if (value instanceof TornadoNativeArray nativeArray) {
deviceContext.writeBuffer(executionPlanId, bufferId, offset, bytes, nativeArray.getSegmentWithHeader().address(), hostOffset, waitEvents);
} else {
throw new TornadoRuntimeException(STR."Data type not supported: \{value.getClass()}");
throw new TornadoRuntimeException("Data not supported: " + value.getClass());
}
} else {
TornadoInternalError.shouldNotReachHere("Expecting an array type");
Expand Down Expand Up @@ -347,7 +347,7 @@ private JavaKind getJavaKind(Class<?> type) {
} else if (type == FloatArray.class || type == IntArray.class || type == DoubleArray.class || type == LongArray.class || type == ShortArray.class || type == CharArray.class || type == ByteArray.class || type == HalfFloatArray.class) {
return JavaKind.Object;
} else {
TornadoInternalError.shouldNotReachHere(STR."The type should be an array, but found: \{type}");
TornadoInternalError.shouldNotReachHere("The type should be an array, but found: " + type);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
public final class PTXBackendImpl implements TornadoAcceleratorBackend {

private final PTXBackend[] backends;
private List<TornadoDevice> devices;
private final TornadoLogger logger;
private List<TornadoDevice> devices;

public PTXBackendImpl(final OptionValues options, final HotSpotJVMCIRuntime vmRuntime, TornadoVMConfigAccess vmConfig) {

Expand Down Expand Up @@ -125,7 +125,7 @@ public TornadoXPUDevice getDevice(int index) {
if (index < backends.length) {
return backends[index].getDeviceContext().asMapping();
} else {
throw new TornadoDeviceNotFound(STR."[ERROR]-[PTX-DRIVER] Device required not found: \{index} - Max: \{backends.length}");
throw new TornadoDeviceNotFound("[ERROR]-[PTX-DRIVER] Device required not found: " + index + " - Max: " + backends.length);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,9 @@ public class PTXDeviceContext implements TornadoDeviceContext {
private final PTXCodeCache codeCache;
private final PTXScheduler scheduler;
private final TornadoBufferProvider bufferProvider;
private boolean wasReset;
private final PowerMetric powerMetric;

private final Map<Long, PTXStreamTable> streamTable;

private boolean wasReset;
private Set<Long> executionIDs;

public PTXDeviceContext(PTXDevice device) {
Expand Down Expand Up @@ -551,7 +549,8 @@ public void dumpEvents(long executionPlanId) {
PTXStream stream = getStream(executionPlanId);
List<PTXEvent> events = stream.getEventPool().getEvents();

final String deviceName = STR."PTX-\{device.getDeviceName()}";
final String deviceName = "PTX-" + device.getDeviceName();

System.out.printf("Found %d events on device %s:\n", events.size(), deviceName);
if (events.isEmpty()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ public void emit(PTXCompilationResultBuilder crb, Value x, Variable dest) {
if (((PTXKind) x.getPlatformKind()).is64Bit()) {
instructionKind = PTXKind.B64;
}
asm.emit(STR.".\{instructionKind}" );
asm.emit("."+instructionKind );

asm.emitSymbol(TAB);
asm.emitValues(new Value[] { dest, x });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ public class PTXMemorySegmentWrapper implements XPUBuffer {
private static final int INIT_VALUE = -1;
private final PTXDeviceContext deviceContext;
private final long batchSize;
private final TornadoLogger logger;
private long bufferId;
private long bufferOffset;
private long bufferSize;
private long setSubRegionSize;
private final TornadoLogger logger;

public PTXMemorySegmentWrapper(PTXDeviceContext deviceContext, long batchSize) {
this.deviceContext = deviceContext;
Expand Down Expand Up @@ -100,7 +100,7 @@ private MemorySegment getSegmentWithHeader(final Object reference) {
case TornadoImagesInterface<?> imagesInterface -> imagesInterface.getSegmentWithHeader();
case TornadoMatrixInterface<?> matrixInterface -> matrixInterface.getSegmentWithHeader();
case TornadoVolumesInterface<?> volumesInterface -> volumesInterface.getSegmentWithHeader();
default -> throw new TornadoMemoryException(STR."Memory Segment not supported: \{reference.getClass()}");
default -> throw new TornadoMemoryException("Memory Segment not supported: " + reference.getClass());
};
}

Expand Down Expand Up @@ -183,7 +183,7 @@ public void allocate(Object reference, long batchSize) throws TornadoOutOfMemory
}

if (bufferSize <= 0) {
throw new TornadoMemoryException(STR."[ERROR] Bytes Allocated <= 0: \{bufferSize}");
throw new TornadoMemoryException("[ERROR] Bytes Allocated <= 0: " + bufferSize);
}

if (TornadoOptions.FULL_DEBUG) {
Expand Down
Loading