diff --git a/tornado-api/src/main/java/uk/ac/manchester/tornado/api/ExecutionPlanType.java b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/ExecutionPlanType.java new file mode 100644 index 0000000000..c74db148c4 --- /dev/null +++ b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/ExecutionPlanType.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2024, APT Group, Department of Computer Science, + * The University of Manchester. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package uk.ac.manchester.tornado.api; + +import uk.ac.manchester.tornado.api.plan.types.OffConcurrentDevices; +import uk.ac.manchester.tornado.api.plan.types.OffMemoryLimit; +import uk.ac.manchester.tornado.api.plan.types.OffPrintKernel; +import uk.ac.manchester.tornado.api.plan.types.OffProfiler; +import uk.ac.manchester.tornado.api.plan.types.OffThreadInfo; +import uk.ac.manchester.tornado.api.plan.types.WithBatch; +import uk.ac.manchester.tornado.api.plan.types.WithClearProfiles; +import uk.ac.manchester.tornado.api.plan.types.WithCompilerFlags; +import uk.ac.manchester.tornado.api.plan.types.WithConcurrentDevices; +import uk.ac.manchester.tornado.api.plan.types.WithDefaultScheduler; +import uk.ac.manchester.tornado.api.plan.types.WithDevicePlan; +import uk.ac.manchester.tornado.api.plan.types.WithDynamicReconfiguration; +import uk.ac.manchester.tornado.api.plan.types.WithFreeDeviceMemory; +import uk.ac.manchester.tornado.api.plan.types.WithGridScheduler; +import uk.ac.manchester.tornado.api.plan.types.WithMemoryLimit; +import uk.ac.manchester.tornado.api.plan.types.WithPrintKernel; +import uk.ac.manchester.tornado.api.plan.types.WithProfiler; +import uk.ac.manchester.tornado.api.plan.types.WithResetDevice; +import uk.ac.manchester.tornado.api.plan.types.WithThreadInfo; +import uk.ac.manchester.tornado.api.plan.types.WithWarmUp; + +public abstract sealed class ExecutionPlanType extends TornadoExecutionPlan // + permits OffConcurrentDevices, OffMemoryLimit, OffPrintKernel, // + OffProfiler, OffThreadInfo, WithWarmUp, WithBatch, WithClearProfiles, // + WithCompilerFlags, WithConcurrentDevices, WithDefaultScheduler, // + WithDevicePlan, WithDynamicReconfiguration, WithFreeDeviceMemory, // + WithGridScheduler, WithMemoryLimit, WithPrintKernel, WithProfiler, // + WithResetDevice, WithThreadInfo { + + public ExecutionPlanType(TornadoExecutionPlan parentNode) { + + // Set link between the previous action (parent) and the new one + this.parentLink = parentNode; + + // Propagate the root node of the current execution plan + this.rootNode = parentNode.rootNode; + + // Set Link the root node to the leaf + this.rootNode.childLink = this; + + // Copy the reference for the executor + this.tornadoExecutor = parentNode.tornadoExecutor; + + // Copy the reference for the execution frame + this.executionFrame = parentNode.executionFrame; + + // Set child reference to this instance + this.childLink = this; + } +} diff --git a/tornado-api/src/main/java/uk/ac/manchester/tornado/api/ImmutableTaskGraph.java b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/ImmutableTaskGraph.java index bd03d33070..dabd1423d2 100644 --- a/tornado-api/src/main/java/uk/ac/manchester/tornado/api/ImmutableTaskGraph.java +++ b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/ImmutableTaskGraph.java @@ -36,7 +36,7 @@ * affecting the execution of graphs encapsulated in {@link ImmutableTaskGraph}. *

* - * @since TornadoVM-0.15 + * @since 0.15 */ public class ImmutableTaskGraph { @@ -170,10 +170,6 @@ void enableProfiler(ProfilerMode profilerMode) { taskGraph.enableProfiler(profilerMode); } - void disableProfiler(ProfilerMode profilerMode) { - taskGraph.disableProfiler(profilerMode); - } - void withConcurrentDevices() { taskGraph.withConcurrentDevices(); } diff --git a/tornado-api/src/main/java/uk/ac/manchester/tornado/api/TaskGraph.java b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/TaskGraph.java index 95b3b48b5e..ead6cca220 100644 --- a/tornado-api/src/main/java/uk/ac/manchester/tornado/api/TaskGraph.java +++ b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/TaskGraph.java @@ -862,10 +862,6 @@ void enableProfiler(ProfilerMode profilerMode) { taskGraphImpl.enableProfiler(profilerMode); } - void disableProfiler(ProfilerMode profilerMode) { - taskGraphImpl.disableProfiler(profilerMode); - } - void withConcurrentDevices() { taskGraphImpl.withConcurrentDevices(); } diff --git a/tornado-api/src/main/java/uk/ac/manchester/tornado/api/TornadoExecutionPlan.java b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/TornadoExecutionPlan.java index c7871ede15..c4231acd79 100644 --- a/tornado-api/src/main/java/uk/ac/manchester/tornado/api/TornadoExecutionPlan.java +++ b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/TornadoExecutionPlan.java @@ -17,17 +17,32 @@ */ package uk.ac.manchester.tornado.api; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; import java.util.concurrent.atomic.AtomicLong; -import java.util.stream.Collectors; import uk.ac.manchester.tornado.api.common.TornadoDevice; import uk.ac.manchester.tornado.api.enums.ProfilerMode; import uk.ac.manchester.tornado.api.enums.TornadoVMBackendType; import uk.ac.manchester.tornado.api.exceptions.TornadoExecutionPlanException; -import uk.ac.manchester.tornado.api.exceptions.TornadoRuntimeException; +import uk.ac.manchester.tornado.api.plan.types.OffConcurrentDevices; +import uk.ac.manchester.tornado.api.plan.types.OffMemoryLimit; +import uk.ac.manchester.tornado.api.plan.types.OffPrintKernel; +import uk.ac.manchester.tornado.api.plan.types.OffProfiler; +import uk.ac.manchester.tornado.api.plan.types.OffThreadInfo; +import uk.ac.manchester.tornado.api.plan.types.WithWarmUp; +import uk.ac.manchester.tornado.api.plan.types.WithBatch; +import uk.ac.manchester.tornado.api.plan.types.WithClearProfiles; +import uk.ac.manchester.tornado.api.plan.types.WithCompilerFlags; +import uk.ac.manchester.tornado.api.plan.types.WithConcurrentDevices; +import uk.ac.manchester.tornado.api.plan.types.WithDefaultScheduler; +import uk.ac.manchester.tornado.api.plan.types.WithDevicePlan; +import uk.ac.manchester.tornado.api.plan.types.WithDynamicReconfiguration; +import uk.ac.manchester.tornado.api.plan.types.WithFreeDeviceMemory; +import uk.ac.manchester.tornado.api.plan.types.WithGridScheduler; +import uk.ac.manchester.tornado.api.plan.types.WithMemoryLimit; +import uk.ac.manchester.tornado.api.plan.types.WithPrintKernel; +import uk.ac.manchester.tornado.api.plan.types.WithProfiler; +import uk.ac.manchester.tornado.api.plan.types.WithResetDevice; +import uk.ac.manchester.tornado.api.plan.types.WithThreadInfo; import uk.ac.manchester.tornado.api.runtime.ExecutorFrame; import uk.ac.manchester.tornado.api.runtime.TornadoRuntimeProvider; @@ -40,7 +55,7 @@ * * @since v0.15 */ -public class TornadoExecutionPlan implements AutoCloseable { +public sealed class TornadoExecutionPlan implements AutoCloseable permits ExecutionPlanType { /** * Method to obtain the default device in TornadoVM. The default one corresponds @@ -48,11 +63,32 @@ public class TornadoExecutionPlan implements AutoCloseable { */ public static TornadoDevice DEFAULT_DEVICE = TornadoRuntimeProvider.getTornadoRuntime().getDefaultDevice(); - private final TornadoExecutor tornadoExecutor; - private ProfilerMode profilerMode; - private boolean disableProfiler; private static final AtomicLong globalExecutionPlanCounter = new AtomicLong(0); - private final ExecutorFrame executionPackage; + + /** + * The TornadoVM executor is a list of chain of actions to be performed. + * Each action can enable/disable runtime features, influence the compiler, + * influence the code optimization, adapt runtime parameters, etc. + */ + protected TornadoExecutor tornadoExecutor; + + protected ExecutorFrame executionFrame; + + // Pointers + /** + * Pointer to the Root of the List + */ + protected TornadoExecutionPlan rootNode; + + /** + * Pointer to the next node in the list + */ + protected TornadoExecutionPlan childLink; + + /** + * Pointer to the previous node in the list + */ + protected TornadoExecutionPlan parentLink; /** * Create an Execution Plan: Object to create and optimize an execution plan for @@ -65,9 +101,10 @@ public class TornadoExecutionPlan implements AutoCloseable { * {@link ImmutableTaskGraph} */ public TornadoExecutionPlan(ImmutableTaskGraph... immutableTaskGraphs) { - this.tornadoExecutor = new TornadoExecutor(immutableTaskGraphs); + tornadoExecutor = new TornadoExecutor(immutableTaskGraphs); final long id = globalExecutionPlanCounter.incrementAndGet(); - executionPackage = new ExecutorFrame(id); + executionFrame = new ExecutorFrame(id); + rootNode = this; } /** @@ -114,17 +151,9 @@ public static TornadoDeviceMap getTornadoDeviceMap() { * @return {@link TornadoExecutionPlan} */ public TornadoExecutionResult execute() { - checkProfilerEnabled(); - tornadoExecutor.execute(executionPackage); - return new TornadoExecutionResult(new TornadoProfilerResult(tornadoExecutor)); - } - - private void checkProfilerEnabled() { - if (this.profilerMode != null && !this.disableProfiler) { - tornadoExecutor.enableProfiler(profilerMode); - } else if (this.profilerMode != null) { - tornadoExecutor.disableProfiler(profilerMode); - } + tornadoExecutor.execute(executionFrame); + TornadoProfilerResult profilerResult = new TornadoProfilerResult(tornadoExecutor); + return new TornadoExecutionResult(profilerResult); } /** @@ -134,9 +163,8 @@ private void checkProfilerEnabled() { * @return {@link TornadoExecutionPlan} */ public TornadoExecutionPlan withWarmUp() { - checkProfilerEnabled(); - tornadoExecutor.warmup(executionPackage); - return this; + tornadoExecutor.warmup(executionFrame); + return new WithWarmUp(this); } /** @@ -147,7 +175,31 @@ public TornadoExecutionPlan withWarmUp() { */ public TornadoExecutionPlan withDevice(TornadoDevice device) { tornadoExecutor.setDevice(device); - return this; + return new WithDevicePlan(this); + } + + /** + * Print all operations enabled/disabled from the Execution Plan. + * + * @since 1.0.8 + */ + public void printTraceExecutionPlan() { + System.out.println(childLink); + } + + /** + * Returns a string with all the operations enabled/disabled from the + * Execution Plan. + * + * @since 1.0.8 + */ + public String getTraceExecutionPlan() { + return childLink.toString(); + } + + @Override + public String toString() { + return "Root"; } /** @@ -163,7 +215,7 @@ public TornadoExecutionPlan withDevice(TornadoDevice device) { */ public TornadoExecutionPlan withDevice(String taskName, TornadoDevice device) { tornadoExecutor.setDevice(taskName, device); - return this; + return new WithDevicePlan(this); } /** @@ -177,7 +229,7 @@ public TornadoExecutionPlan withDevice(String taskName, TornadoDevice device) { */ public TornadoExecutionPlan withConcurrentDevices() { tornadoExecutor.withConcurrentDevices(); - return this; + return new WithConcurrentDevices(this); } /** @@ -188,7 +240,7 @@ public TornadoExecutionPlan withConcurrentDevices() { */ public TornadoExecutionPlan withoutConcurrentDevices() { tornadoExecutor.withoutConcurrentDevices(); - return this; + return new OffConcurrentDevices(this); } /** @@ -219,7 +271,7 @@ public TornadoDevice getDevice(int immutableTaskGraphIndex) { */ public TornadoExecutionPlan freeDeviceMemory() { tornadoExecutor.freeDeviceMemory(); - return this; + return new WithFreeDeviceMemory(this); } /** @@ -233,7 +285,7 @@ public TornadoExecutionPlan freeDeviceMemory() { */ public TornadoExecutionPlan withGridScheduler(GridScheduler gridScheduler) { tornadoExecutor.withGridScheduler(gridScheduler); - return this; + return new WithGridScheduler(this); } /** @@ -243,7 +295,7 @@ public TornadoExecutionPlan withGridScheduler(GridScheduler gridScheduler) { */ public TornadoExecutionPlan withDefaultScheduler() { tornadoExecutor.withDefaultScheduler(); - return this; + return new WithDefaultScheduler(this); } /** @@ -257,8 +309,8 @@ public TornadoExecutionPlan withDefaultScheduler() { * @return {@link TornadoExecutionPlan} */ public TornadoExecutionPlan withDynamicReconfiguration(Policy policy, DRMode mode) { - executionPackage.withPolicy(policy).withMode(mode); - return this; + executionFrame.withPolicy(policy).withMode(mode); + return new WithDynamicReconfiguration(this); } /** @@ -273,7 +325,7 @@ public TornadoExecutionPlan withDynamicReconfiguration(Policy policy, DRMode mod */ public TornadoExecutionPlan withBatch(String batchSize) { tornadoExecutor.withBatch(batchSize); - return this; + return new WithBatch(this); } /** @@ -286,9 +338,8 @@ public TornadoExecutionPlan withBatch(String batchSize) { * @return {@link TornadoExecutionPlan} */ public TornadoExecutionPlan withProfiler(ProfilerMode profilerMode) { - this.profilerMode = profilerMode; - disableProfiler = false; - return this; + executionFrame.withProfilerOn(profilerMode); + return new WithProfiler(this); } /** @@ -297,8 +348,8 @@ public TornadoExecutionPlan withProfiler(ProfilerMode profilerMode) { * @return {@link TornadoExecutionPlan} */ public TornadoExecutionPlan withoutProfiler() { - this.disableProfiler = true; - return this; + executionFrame.withProfilerOff(); + return new OffProfiler(this); } /** @@ -314,7 +365,7 @@ public TornadoExecutionPlan withoutProfiler() { */ public TornadoExecutionPlan withMemoryLimit(String memoryLimit) { tornadoExecutor.withMemoryLimit(memoryLimit); - return this; + return new WithMemoryLimit(this); } /** @@ -329,7 +380,7 @@ public TornadoExecutionPlan withMemoryLimit(String memoryLimit) { */ public TornadoExecutionPlan withoutMemoryLimit() { tornadoExecutor.withoutMemoryLimit(); - return this; + return new OffMemoryLimit(this); } /** @@ -342,14 +393,14 @@ public TornadoExecutionPlan withoutMemoryLimit() { */ public TornadoExecutionPlan resetDevice() { tornadoExecutor.resetDevice(); - return this; + return new WithResetDevice(this); } /** * Obtains the ID that was assigned to the execution plan. */ public long getId() { - return executionPackage.getExecutionPlanId(); + return executionFrame.getExecutionPlanId(); } /** @@ -366,7 +417,7 @@ public long getGlobalExecutionPlansCounter() { */ public TornadoExecutionPlan clearProfiles() { tornadoExecutor.clearProfiles(); - return this; + return new WithClearProfiles(this); } /** @@ -378,7 +429,7 @@ public TornadoExecutionPlan clearProfiles() { */ public TornadoExecutionPlan withThreadInfo() { tornadoExecutor.withThreadInfo(); - return this; + return new WithThreadInfo(this); } /** @@ -390,7 +441,7 @@ public TornadoExecutionPlan withThreadInfo() { */ public TornadoExecutionPlan withoutThreadInfo() { tornadoExecutor.withoutThreadInfo(); - return this; + return new OffThreadInfo(this); } /** @@ -400,10 +451,9 @@ public TornadoExecutionPlan withoutThreadInfo() { * * @return {@link TornadoExecutionPlan} */ - public TornadoExecutionPlan withPrintKernel() { tornadoExecutor.withPrintKernel(); - return this; + return new WithPrintKernel(this); } /** @@ -415,7 +465,7 @@ public TornadoExecutionPlan withPrintKernel() { */ public TornadoExecutionPlan withoutPrintKernel() { tornadoExecutor.withoutPrintKernel(); - return this; + return new OffPrintKernel(this); } /** @@ -430,13 +480,14 @@ public TornadoExecutionPlan withoutPrintKernel() { */ public TornadoExecutionPlan withCompilerFlags(TornadoVMBackendType backend, String compilerFlags) { tornadoExecutor.withCompilerFlags(backend, compilerFlags); - return this; + return new WithCompilerFlags(this); } /** * @since 1.0.4 * - * @throws TornadoExecutionPlanException + * @throws {@link + * TornadoExecutionPlanException} */ @Override public void close() throws TornadoExecutionPlanException { @@ -453,202 +504,4 @@ public long getCurrentDeviceMemoryUsage() { return tornadoExecutor.getCurrentDeviceMemoryUsage(); } - static class TornadoExecutor { - - private final List immutableTaskGraphList; - - TornadoExecutor(ImmutableTaskGraph... immutableTaskGraphs) { - immutableTaskGraphList = new ArrayList<>(); - Collections.addAll(immutableTaskGraphList, immutableTaskGraphs); - } - - void execute(ExecutorFrame executionPackage) { - immutableTaskGraphList.forEach(immutableTaskGraph -> immutableTaskGraph.execute(executionPackage)); - } - - void withGridScheduler(GridScheduler gridScheduler) { - immutableTaskGraphList.forEach(immutableTaskGraph -> immutableTaskGraph.withGridScheduler(gridScheduler)); - } - - void warmup(ExecutorFrame executionPackage) { - immutableTaskGraphList.forEach(immutableTaskGraph -> immutableTaskGraph.warmup(executionPackage)); - } - - void withBatch(String batchSize) { - immutableTaskGraphList.forEach(immutableTaskGraph -> immutableTaskGraph.withBatch(batchSize)); - } - - void withMemoryLimit(String memoryLimit) { - immutableTaskGraphList.forEach(immutableTaskGraph -> immutableTaskGraph.withMemoryLimit(memoryLimit)); - } - - public void withoutMemoryLimit() { - immutableTaskGraphList.forEach(ImmutableTaskGraph::withoutMemoryLimit); - } - - /** - * For all task-graphs contained in an Executor, update the device. - * - * @param device - * {@link TornadoDevice} object - */ - void setDevice(TornadoDevice device) { - immutableTaskGraphList.forEach(immutableTaskGraph -> immutableTaskGraph.withDevice(device)); - } - - void setDevice(String taskName, TornadoDevice device) { - immutableTaskGraphList.forEach(immutableTaskGraph -> immutableTaskGraph.withDevice(taskName, device)); - } - - void withConcurrentDevices() { - immutableTaskGraphList.forEach(ImmutableTaskGraph::withConcurrentDevices); - } - - void withoutConcurrentDevices() { - immutableTaskGraphList.forEach(ImmutableTaskGraph::withoutConcurrentDevices); - } - - void freeDeviceMemory() { - immutableTaskGraphList.forEach(ImmutableTaskGraph::freeDeviceMemory); - } - - void transferToHost(Object... objects) { - immutableTaskGraphList.forEach(immutableTaskGraph -> immutableTaskGraph.transferToHost(objects)); - } - - void partialTransferToHost(DataRange dataRange) { - // At this point we compute the offsets and the total size in bytes. - dataRange.materialize(); - immutableTaskGraphList.forEach(immutableTaskGraph -> immutableTaskGraph.transferToHost(dataRange.getArray(), dataRange.getOffset(), dataRange.getPartialSize())); - } - - boolean isFinished() { - boolean result = true; - for (ImmutableTaskGraph immutableTaskGraph : immutableTaskGraphList) { - result &= immutableTaskGraph.isFinished(); - } - return result; - } - - void resetDevice() { - immutableTaskGraphList.forEach(ImmutableTaskGraph::resetDevice); - } - - long getTotalTime() { - return immutableTaskGraphList.stream().map(ImmutableTaskGraph::getTotalTime).mapToLong(Long::longValue).sum(); - } - - long getCompileTime() { - return immutableTaskGraphList.stream().map(ImmutableTaskGraph::getCompileTime).mapToLong(Long::longValue).sum(); - } - - long getTornadoCompilerTime() { - return immutableTaskGraphList.stream().map(ImmutableTaskGraph::getTornadoCompilerTime).mapToLong(Long::longValue).sum(); - } - - long getDriverInstallTime() { - return immutableTaskGraphList.stream().map(ImmutableTaskGraph::getDriverInstallTime).mapToLong(Long::longValue).sum(); - } - - long getDataTransfersTime() { - return immutableTaskGraphList.stream().map(ImmutableTaskGraph::getDataTransfersTime).mapToLong(Long::longValue).sum(); - } - - long getDeviceWriteTime() { - return immutableTaskGraphList.stream().map(ImmutableTaskGraph::getDeviceWriteTime).mapToLong(Long::longValue).sum(); - } - - long getDeviceReadTime() { - return immutableTaskGraphList.stream().map(ImmutableTaskGraph::getDeviceReadTime).mapToLong(Long::longValue).sum(); - } - - long getDataTransferDispatchTime() { - return immutableTaskGraphList.stream().map(ImmutableTaskGraph::getDataTransferDispatchTime).mapToLong(Long::longValue).sum(); - } - - long getKernelDispatchTime() { - return immutableTaskGraphList.stream().map(ImmutableTaskGraph::getKernelDispatchTime).mapToLong(Long::longValue).sum(); - } - - long getDeviceKernelTime() { - return immutableTaskGraphList.stream().map(ImmutableTaskGraph::getDeviceKernelTime).mapToLong(Long::longValue).sum(); - } - - long getTotalBytesCopyIn() { - return immutableTaskGraphList.stream().map(ImmutableTaskGraph::getTotalBytesCopyIn).mapToLong(Long::longValue).sum(); - } - - long getTotalBytesCopyOut() { - return immutableTaskGraphList.stream().map(ImmutableTaskGraph::getTotalBytesCopyOut).mapToLong(Long::longValue).sum(); - } - - String getProfileLog() { - return immutableTaskGraphList.stream().map(ImmutableTaskGraph::getProfileLog).collect(Collectors.joining()); - } - - void dumpProfiles() { - immutableTaskGraphList.forEach(ImmutableTaskGraph::dumpProfiles); - } - - void clearProfiles() { - immutableTaskGraphList.forEach(ImmutableTaskGraph::clearProfiles); - } - - void withDefaultScheduler() { - immutableTaskGraphList.forEach(immutableTaskGraph -> immutableTaskGraph.withDefaultScheduler(true)); - } - - TornadoDevice getDevice(int immutableTaskGraphIndex) { - if (immutableTaskGraphList.size() < immutableTaskGraphIndex) { - throw new TornadoRuntimeException("TaskGraph index #" + immutableTaskGraphIndex + " does not exist in current executor"); - } - return immutableTaskGraphList.get(immutableTaskGraphIndex).getDevice(); - } - - List getOutputs() { - List outputs = new ArrayList<>(); - immutableTaskGraphList.forEach(immutableTaskGraph -> outputs.addAll(immutableTaskGraph.getOutputs())); - return outputs; - } - - void enableProfiler(ProfilerMode profilerMode) { - immutableTaskGraphList.forEach(immutableTaskGraph -> immutableTaskGraph.enableProfiler(profilerMode)); - } - - void disableProfiler(ProfilerMode profilerMode) { - immutableTaskGraphList.forEach(immutableTaskGraph -> immutableTaskGraph.disableProfiler(profilerMode)); - } - - void withThreadInfo() { - immutableTaskGraphList.forEach(ImmutableTaskGraph::withThreadInfo); - } - - void withoutThreadInfo() { - immutableTaskGraphList.forEach(ImmutableTaskGraph::withoutThreadInfo); - } - - void withPrintKernel() { - immutableTaskGraphList.forEach(ImmutableTaskGraph::withPrintKernel); - } - - void withoutPrintKernel() { - immutableTaskGraphList.forEach(ImmutableTaskGraph::withoutPrintKernel); - } - - void withCompilerFlags(TornadoVMBackendType backendType, String compilerFlags) { - immutableTaskGraphList.forEach(immutableTaskGraph -> immutableTaskGraph.withCompilerFlags(backendType, compilerFlags)); - } - - long getTotalBytesTransferred() { - return immutableTaskGraphList.stream().mapToLong(ImmutableTaskGraph::getTotalBytesTransferred).sum(); - } - - long getTotalDeviceMemoryUsage() { - return immutableTaskGraphList.stream().mapToLong(ImmutableTaskGraph::getTotalDeviceMemoryUsage).sum(); - } - - long getCurrentDeviceMemoryUsage() { - return immutableTaskGraphList.stream().mapToLong(ImmutableTaskGraph::getCurrentDeviceMemoryUsage).sum(); - } - } } diff --git a/tornado-api/src/main/java/uk/ac/manchester/tornado/api/TornadoExecutor.java b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/TornadoExecutor.java new file mode 100644 index 0000000000..a20ed5eb6a --- /dev/null +++ b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/TornadoExecutor.java @@ -0,0 +1,225 @@ +/* + * Copyright (c) 2024, APT Group, Department of Computer Science, + * The University of Manchester. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package uk.ac.manchester.tornado.api; + +import uk.ac.manchester.tornado.api.common.TornadoDevice; +import uk.ac.manchester.tornado.api.enums.TornadoVMBackendType; +import uk.ac.manchester.tornado.api.exceptions.TornadoRuntimeException; +import uk.ac.manchester.tornado.api.runtime.ExecutorFrame; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +/** + * Executor Class to dispatch Tornado Task-Graphs. An executor plan + * {@link TornadoExecutionPlan} contains an executor object, which in turn, + * contains a set of immutable task-graphs. All actions applied to the + * execution plan affect to all the immutable graphs associated with it. + */ +class TornadoExecutor { + + private final List immutableTaskGraphList; + + TornadoExecutor(ImmutableTaskGraph... immutableTaskGraphs) { + immutableTaskGraphList = new ArrayList<>(); + Collections.addAll(immutableTaskGraphList, immutableTaskGraphs); + } + + void execute(ExecutorFrame executionPackage) { + immutableTaskGraphList.forEach(immutableTaskGraph -> immutableTaskGraph.execute(executionPackage)); + } + + void withGridScheduler(GridScheduler gridScheduler) { + immutableTaskGraphList.forEach(immutableTaskGraph -> immutableTaskGraph.withGridScheduler(gridScheduler)); + } + + void warmup(ExecutorFrame executorFrame) { + immutableTaskGraphList.forEach(immutableTaskGraph -> immutableTaskGraph.warmup(executorFrame)); + } + + void withBatch(String batchSize) { + immutableTaskGraphList.forEach(immutableTaskGraph -> immutableTaskGraph.withBatch(batchSize)); + } + + void withMemoryLimit(String memoryLimit) { + immutableTaskGraphList.forEach(immutableTaskGraph -> immutableTaskGraph.withMemoryLimit(memoryLimit)); + } + + public void withoutMemoryLimit() { + immutableTaskGraphList.forEach(ImmutableTaskGraph::withoutMemoryLimit); + } + + /** + * For all task-graphs contained in an Executor, update the device. + * + * @param device + * {@link TornadoDevice} object + */ + void setDevice(TornadoDevice device) { + immutableTaskGraphList.forEach(immutableTaskGraph -> immutableTaskGraph.withDevice(device)); + } + + void setDevice(String taskName, TornadoDevice device) { + immutableTaskGraphList.forEach(immutableTaskGraph -> immutableTaskGraph.withDevice(taskName, device)); + } + + void withConcurrentDevices() { + immutableTaskGraphList.forEach(ImmutableTaskGraph::withConcurrentDevices); + } + + void withoutConcurrentDevices() { + immutableTaskGraphList.forEach(ImmutableTaskGraph::withoutConcurrentDevices); + } + + void freeDeviceMemory() { + immutableTaskGraphList.forEach(ImmutableTaskGraph::freeDeviceMemory); + } + + void transferToHost(Object... objects) { + immutableTaskGraphList.forEach(immutableTaskGraph -> immutableTaskGraph.transferToHost(objects)); + } + + void partialTransferToHost(DataRange dataRange) { + // At this point we compute the offsets and the total size in bytes. + dataRange.materialize(); + immutableTaskGraphList.forEach(immutableTaskGraph -> immutableTaskGraph.transferToHost(dataRange.getArray(), dataRange.getOffset(), dataRange.getPartialSize())); + } + + boolean isFinished() { + boolean result = true; + for (ImmutableTaskGraph immutableTaskGraph : immutableTaskGraphList) { + result &= immutableTaskGraph.isFinished(); + } + return result; + } + + void resetDevice() { + immutableTaskGraphList.forEach(ImmutableTaskGraph::resetDevice); + } + + long getTotalTime() { + return immutableTaskGraphList.stream().map(ImmutableTaskGraph::getTotalTime).mapToLong(Long::longValue).sum(); + } + + long getCompileTime() { + return immutableTaskGraphList.stream().map(ImmutableTaskGraph::getCompileTime).mapToLong(Long::longValue).sum(); + } + + long getTornadoCompilerTime() { + return immutableTaskGraphList.stream().map(ImmutableTaskGraph::getTornadoCompilerTime).mapToLong(Long::longValue).sum(); + } + + long getDriverInstallTime() { + return immutableTaskGraphList.stream().map(ImmutableTaskGraph::getDriverInstallTime).mapToLong(Long::longValue).sum(); + } + + long getDataTransfersTime() { + return immutableTaskGraphList.stream().map(ImmutableTaskGraph::getDataTransfersTime).mapToLong(Long::longValue).sum(); + } + + long getDeviceWriteTime() { + return immutableTaskGraphList.stream().map(ImmutableTaskGraph::getDeviceWriteTime).mapToLong(Long::longValue).sum(); + } + + long getDeviceReadTime() { + return immutableTaskGraphList.stream().map(ImmutableTaskGraph::getDeviceReadTime).mapToLong(Long::longValue).sum(); + } + + long getDataTransferDispatchTime() { + return immutableTaskGraphList.stream().map(ImmutableTaskGraph::getDataTransferDispatchTime).mapToLong(Long::longValue).sum(); + } + + long getKernelDispatchTime() { + return immutableTaskGraphList.stream().map(ImmutableTaskGraph::getKernelDispatchTime).mapToLong(Long::longValue).sum(); + } + + long getDeviceKernelTime() { + return immutableTaskGraphList.stream().map(ImmutableTaskGraph::getDeviceKernelTime).mapToLong(Long::longValue).sum(); + } + + long getTotalBytesCopyIn() { + return immutableTaskGraphList.stream().map(ImmutableTaskGraph::getTotalBytesCopyIn).mapToLong(Long::longValue).sum(); + } + + long getTotalBytesCopyOut() { + return immutableTaskGraphList.stream().map(ImmutableTaskGraph::getTotalBytesCopyOut).mapToLong(Long::longValue).sum(); + } + + String getProfileLog() { + return immutableTaskGraphList.stream().map(ImmutableTaskGraph::getProfileLog).collect(Collectors.joining()); + } + + void dumpProfiles() { + immutableTaskGraphList.forEach(ImmutableTaskGraph::dumpProfiles); + } + + void clearProfiles() { + immutableTaskGraphList.forEach(ImmutableTaskGraph::clearProfiles); + } + + void withDefaultScheduler() { + immutableTaskGraphList.forEach(immutableTaskGraph -> immutableTaskGraph.withDefaultScheduler(true)); + } + + TornadoDevice getDevice(int immutableTaskGraphIndex) { + if (immutableTaskGraphList.size() < immutableTaskGraphIndex) { + throw new TornadoRuntimeException("TaskGraph index #" + immutableTaskGraphIndex + " does not exist in current executor"); + } + return immutableTaskGraphList.get(immutableTaskGraphIndex).getDevice(); + } + + List getOutputs() { + List outputs = new ArrayList<>(); + immutableTaskGraphList.forEach(immutableTaskGraph -> outputs.addAll(immutableTaskGraph.getOutputs())); + return outputs; + } + + void withThreadInfo() { + immutableTaskGraphList.forEach(ImmutableTaskGraph::withThreadInfo); + } + + void withoutThreadInfo() { + immutableTaskGraphList.forEach(ImmutableTaskGraph::withoutThreadInfo); + } + + void withPrintKernel() { + immutableTaskGraphList.forEach(ImmutableTaskGraph::withPrintKernel); + } + + void withoutPrintKernel() { + immutableTaskGraphList.forEach(ImmutableTaskGraph::withoutPrintKernel); + } + + void withCompilerFlags(TornadoVMBackendType backendType, String compilerFlags) { + immutableTaskGraphList.forEach(immutableTaskGraph -> immutableTaskGraph.withCompilerFlags(backendType, compilerFlags)); + } + + long getTotalBytesTransferred() { + return immutableTaskGraphList.stream().mapToLong(ImmutableTaskGraph::getTotalBytesTransferred).sum(); + } + + long getTotalDeviceMemoryUsage() { + return immutableTaskGraphList.stream().mapToLong(ImmutableTaskGraph::getTotalDeviceMemoryUsage).sum(); + } + + long getCurrentDeviceMemoryUsage() { + return immutableTaskGraphList.stream().mapToLong(ImmutableTaskGraph::getCurrentDeviceMemoryUsage).sum(); + } +} \ No newline at end of file diff --git a/tornado-api/src/main/java/uk/ac/manchester/tornado/api/TornadoProfilerResult.java b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/TornadoProfilerResult.java index 39f8443476..ca62a9a70b 100644 --- a/tornado-api/src/main/java/uk/ac/manchester/tornado/api/TornadoProfilerResult.java +++ b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/TornadoProfilerResult.java @@ -17,7 +17,6 @@ */ package uk.ac.manchester.tornado.api; -import uk.ac.manchester.tornado.api.TornadoExecutionPlan.TornadoExecutor; import uk.ac.manchester.tornado.api.enums.ProfilerMode; import uk.ac.manchester.tornado.api.profiler.ProfilerInterface; @@ -37,7 +36,7 @@ * {@link TornadoExecutionPlan#withProfiler(ProfilerMode)}. *

* - * @since TornadoVM-0.15 + * @since 0.15 */ public class TornadoProfilerResult implements ProfilerInterface { diff --git a/tornado-api/src/main/java/uk/ac/manchester/tornado/api/TornadoTaskGraphInterface.java b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/TornadoTaskGraphInterface.java index 1f530e2a9a..2565777ff3 100644 --- a/tornado-api/src/main/java/uk/ac/manchester/tornado/api/TornadoTaskGraphInterface.java +++ b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/TornadoTaskGraphInterface.java @@ -106,7 +106,7 @@ public interface TornadoTaskGraphInterface extends ProfilerInterface { void enableProfiler(ProfilerMode profilerMode); - void disableProfiler(ProfilerMode profilerMode); + void disableProfiler(); void withConcurrentDevices(); diff --git a/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/OffConcurrentDevices.java b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/OffConcurrentDevices.java new file mode 100644 index 0000000000..5831d1e218 --- /dev/null +++ b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/OffConcurrentDevices.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024, APT Group, Department of Computer Science, + * The University of Manchester. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package uk.ac.manchester.tornado.api.plan.types; + +import uk.ac.manchester.tornado.api.ExecutionPlanType; +import uk.ac.manchester.tornado.api.TornadoExecutionPlan; + +public final class OffConcurrentDevices extends ExecutionPlanType { + + public OffConcurrentDevices(TornadoExecutionPlan parent) { + super(parent); + } + + @Override + public String toString() { + return parentLink.toString() + "\n -> withoutConcurrentDevices "; + } + +} diff --git a/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/OffMemoryLimit.java b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/OffMemoryLimit.java new file mode 100644 index 0000000000..cec34910dc --- /dev/null +++ b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/OffMemoryLimit.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024, APT Group, Department of Computer Science, + * The University of Manchester. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package uk.ac.manchester.tornado.api.plan.types; + +import uk.ac.manchester.tornado.api.ExecutionPlanType; +import uk.ac.manchester.tornado.api.TornadoExecutionPlan; + +public final class OffMemoryLimit extends ExecutionPlanType { + + public OffMemoryLimit(TornadoExecutionPlan parent) { + super(parent); + } + + @Override + public String toString() { + return parentLink.toString() + "\n -> withoutMemoryLimit "; + } + +} diff --git a/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/OffPrintKernel.java b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/OffPrintKernel.java new file mode 100644 index 0000000000..298f8ca46c --- /dev/null +++ b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/OffPrintKernel.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024, APT Group, Department of Computer Science, + * The University of Manchester. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package uk.ac.manchester.tornado.api.plan.types; + +import uk.ac.manchester.tornado.api.ExecutionPlanType; +import uk.ac.manchester.tornado.api.TornadoExecutionPlan; + +public final class OffPrintKernel extends ExecutionPlanType { + public OffPrintKernel(TornadoExecutionPlan parent) { + super(parent); + } + + @Override + public String toString() { + return parentLink.toString() + "\n -> withoutPrintKernel "; + } +} diff --git a/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/OffProfiler.java b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/OffProfiler.java new file mode 100644 index 0000000000..d9462c4fe8 --- /dev/null +++ b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/OffProfiler.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024, APT Group, Department of Computer Science, + * The University of Manchester. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package uk.ac.manchester.tornado.api.plan.types; + +import uk.ac.manchester.tornado.api.ExecutionPlanType; +import uk.ac.manchester.tornado.api.TornadoExecutionPlan; + +public final class OffProfiler extends ExecutionPlanType { + + public OffProfiler(TornadoExecutionPlan parent) { + super(parent); + } + + @Override + public String toString() { + return parentLink.toString() + "\n -> withoutProfiler "; + } + +} diff --git a/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/OffThreadInfo.java b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/OffThreadInfo.java new file mode 100644 index 0000000000..11d6961075 --- /dev/null +++ b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/OffThreadInfo.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024, APT Group, Department of Computer Science, + * The University of Manchester. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package uk.ac.manchester.tornado.api.plan.types; + +import uk.ac.manchester.tornado.api.ExecutionPlanType; +import uk.ac.manchester.tornado.api.TornadoExecutionPlan; + +public final class OffThreadInfo extends ExecutionPlanType { + public OffThreadInfo(TornadoExecutionPlan parent) { + super(parent); + } + + @Override + public String toString() { + return parentLink.toString() + "\n -> withoutThreadInfo "; + } +} diff --git a/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithBatch.java b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithBatch.java new file mode 100644 index 0000000000..69ac675756 --- /dev/null +++ b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithBatch.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024, APT Group, Department of Computer Science, + * The University of Manchester. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package uk.ac.manchester.tornado.api.plan.types; + +import uk.ac.manchester.tornado.api.ExecutionPlanType; +import uk.ac.manchester.tornado.api.TornadoExecutionPlan; + +public final class WithBatch extends ExecutionPlanType { + + public WithBatch(TornadoExecutionPlan parent) { + super(parent); + } + + @Override + public String toString() { + return parentLink.toString() + "\n -> withBatch "; + } +} diff --git a/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithClearProfiles.java b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithClearProfiles.java new file mode 100644 index 0000000000..a66bfd2aa8 --- /dev/null +++ b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithClearProfiles.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024, APT Group, Department of Computer Science, + * The University of Manchester. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package uk.ac.manchester.tornado.api.plan.types; + +import uk.ac.manchester.tornado.api.ExecutionPlanType; +import uk.ac.manchester.tornado.api.TornadoExecutionPlan; + +public final class WithClearProfiles extends ExecutionPlanType { + public WithClearProfiles(TornadoExecutionPlan parent) { + super(parent); + } + + @Override + public String toString() { + return parentLink.toString() + "\n -> withClearProfiles "; + } +} diff --git a/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithCompilerFlags.java b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithCompilerFlags.java new file mode 100644 index 0000000000..d5d719a3cc --- /dev/null +++ b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithCompilerFlags.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024, APT Group, Department of Computer Science, + * The University of Manchester. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package uk.ac.manchester.tornado.api.plan.types; + +import uk.ac.manchester.tornado.api.ExecutionPlanType; +import uk.ac.manchester.tornado.api.TornadoExecutionPlan; + +public final class WithCompilerFlags extends ExecutionPlanType { + public WithCompilerFlags(TornadoExecutionPlan parent) { + super(parent); + } + + @Override + public String toString() { + return parentLink.toString() + "\n -> withCompilerFlags "; + } +} diff --git a/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithConcurrentDevices.java b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithConcurrentDevices.java new file mode 100644 index 0000000000..d3eafdda3b --- /dev/null +++ b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithConcurrentDevices.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024, APT Group, Department of Computer Science, + * The University of Manchester. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package uk.ac.manchester.tornado.api.plan.types; + +import uk.ac.manchester.tornado.api.ExecutionPlanType; +import uk.ac.manchester.tornado.api.TornadoExecutionPlan; + +public final class WithConcurrentDevices extends ExecutionPlanType { + + public WithConcurrentDevices(TornadoExecutionPlan parent) { + super(parent); + } + + @Override + public String toString() { + return parentLink.toString() + "\n -> withConcurrentDevices "; + } + +} diff --git a/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithDefaultScheduler.java b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithDefaultScheduler.java new file mode 100644 index 0000000000..bbf636304d --- /dev/null +++ b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithDefaultScheduler.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024, APT Group, Department of Computer Science, + * The University of Manchester. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package uk.ac.manchester.tornado.api.plan.types; + +import uk.ac.manchester.tornado.api.ExecutionPlanType; +import uk.ac.manchester.tornado.api.TornadoExecutionPlan; + +public final class WithDefaultScheduler extends ExecutionPlanType { + + public WithDefaultScheduler(TornadoExecutionPlan parent) { + super(parent); + } + + @Override + public String toString() { + return parentLink.toString() + "\n -> withDefaultGridScheduler "; + } +} diff --git a/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithDevicePlan.java b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithDevicePlan.java new file mode 100644 index 0000000000..c9b110faf3 --- /dev/null +++ b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithDevicePlan.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024, APT Group, Department of Computer Science, + * The University of Manchester. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package uk.ac.manchester.tornado.api.plan.types; + +import uk.ac.manchester.tornado.api.ExecutionPlanType; +import uk.ac.manchester.tornado.api.TornadoExecutionPlan; + +public final class WithDevicePlan extends ExecutionPlanType { + + public WithDevicePlan(TornadoExecutionPlan parent) { + super(parent); + } + + @Override + public String toString() { + return parentLink.toString() + "\n -> withDevice "; + } +} diff --git a/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithDynamicReconfiguration.java b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithDynamicReconfiguration.java new file mode 100644 index 0000000000..90bf3a820c --- /dev/null +++ b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithDynamicReconfiguration.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024, APT Group, Department of Computer Science, + * The University of Manchester. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package uk.ac.manchester.tornado.api.plan.types; + +import uk.ac.manchester.tornado.api.ExecutionPlanType; +import uk.ac.manchester.tornado.api.TornadoExecutionPlan; + +public final class WithDynamicReconfiguration extends ExecutionPlanType { + + public WithDynamicReconfiguration(TornadoExecutionPlan parent) { + super(parent); + } + + @Override + public String toString() { + return parentLink.toString() + "\n -> withDynamicReconfiguration "; + } +} diff --git a/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithFreeDeviceMemory.java b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithFreeDeviceMemory.java new file mode 100644 index 0000000000..bb481dc3d8 --- /dev/null +++ b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithFreeDeviceMemory.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024, APT Group, Department of Computer Science, + * The University of Manchester. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package uk.ac.manchester.tornado.api.plan.types; + +import uk.ac.manchester.tornado.api.ExecutionPlanType; +import uk.ac.manchester.tornado.api.TornadoExecutionPlan; + +public final class WithFreeDeviceMemory extends ExecutionPlanType { + + public WithFreeDeviceMemory(TornadoExecutionPlan parent) { + super(parent); + } + + @Override + public String toString() { + return parentLink.toString() + "\n -> withFreeDeviceMemory "; + } +} diff --git a/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithGridScheduler.java b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithGridScheduler.java new file mode 100644 index 0000000000..d280acaddd --- /dev/null +++ b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithGridScheduler.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024, APT Group, Department of Computer Science, + * The University of Manchester. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package uk.ac.manchester.tornado.api.plan.types; + +import uk.ac.manchester.tornado.api.ExecutionPlanType; +import uk.ac.manchester.tornado.api.TornadoExecutionPlan; + +public final class WithGridScheduler extends ExecutionPlanType { + + public WithGridScheduler(TornadoExecutionPlan parent) { + super(parent); + } + + @Override + public String toString() { + return parentLink.toString() + "\n -> withGridScheduler "; + } +} diff --git a/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithMemoryLimit.java b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithMemoryLimit.java new file mode 100644 index 0000000000..ce4fe92865 --- /dev/null +++ b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithMemoryLimit.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024, APT Group, Department of Computer Science, + * The University of Manchester. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package uk.ac.manchester.tornado.api.plan.types; + +import uk.ac.manchester.tornado.api.ExecutionPlanType; +import uk.ac.manchester.tornado.api.TornadoExecutionPlan; + +public final class WithMemoryLimit extends ExecutionPlanType { + + public WithMemoryLimit(TornadoExecutionPlan parent) { + super(parent); + } + + @Override + public String toString() { + return parentLink.toString() + "\n -> withMemoryLimit "; + } + +} diff --git a/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithPrintKernel.java b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithPrintKernel.java new file mode 100644 index 0000000000..b239bafa2e --- /dev/null +++ b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithPrintKernel.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024, APT Group, Department of Computer Science, + * The University of Manchester. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package uk.ac.manchester.tornado.api.plan.types; + +import uk.ac.manchester.tornado.api.ExecutionPlanType; +import uk.ac.manchester.tornado.api.TornadoExecutionPlan; + +public final class WithPrintKernel extends ExecutionPlanType { + public WithPrintKernel(TornadoExecutionPlan parent) { + super(parent); + } + + @Override + public String toString() { + return parentLink.toString() + "\n -> withPrintKernel "; + } +} diff --git a/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithProfiler.java b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithProfiler.java new file mode 100644 index 0000000000..5d8c370ed9 --- /dev/null +++ b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithProfiler.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024, APT Group, Department of Computer Science, + * The University of Manchester. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package uk.ac.manchester.tornado.api.plan.types; + +import uk.ac.manchester.tornado.api.ExecutionPlanType; +import uk.ac.manchester.tornado.api.TornadoExecutionPlan; + +public final class WithProfiler extends ExecutionPlanType { + + public WithProfiler(TornadoExecutionPlan parent) { + super(parent); + } + + @Override + public String toString() { + return parentLink.toString() + "\n -> withProfiler "; + } +} diff --git a/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithResetDevice.java b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithResetDevice.java new file mode 100644 index 0000000000..9a6d944e3f --- /dev/null +++ b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithResetDevice.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024, APT Group, Department of Computer Science, + * The University of Manchester. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package uk.ac.manchester.tornado.api.plan.types; + +import uk.ac.manchester.tornado.api.ExecutionPlanType; +import uk.ac.manchester.tornado.api.TornadoExecutionPlan; + +public final class WithResetDevice extends ExecutionPlanType { + + public WithResetDevice(TornadoExecutionPlan parent) { + super(parent); + } + + @Override + public String toString() { + return parentLink.toString() + "\n -> withResetDevice "; + } +} diff --git a/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithThreadInfo.java b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithThreadInfo.java new file mode 100644 index 0000000000..3052fa94f6 --- /dev/null +++ b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithThreadInfo.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024, APT Group, Department of Computer Science, + * The University of Manchester. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package uk.ac.manchester.tornado.api.plan.types; + +import uk.ac.manchester.tornado.api.ExecutionPlanType; +import uk.ac.manchester.tornado.api.TornadoExecutionPlan; + +public final class WithThreadInfo extends ExecutionPlanType { + public WithThreadInfo(TornadoExecutionPlan parent) { + super(parent); + } + + @Override + public String toString() { + return parentLink.toString() + "\n -> withThreadInfo "; + } +} diff --git a/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithWarmUp.java b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithWarmUp.java new file mode 100644 index 0000000000..5df39627a9 --- /dev/null +++ b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/plan/types/WithWarmUp.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024, APT Group, Department of Computer Science, + * The University of Manchester. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package uk.ac.manchester.tornado.api.plan.types; + +import uk.ac.manchester.tornado.api.ExecutionPlanType; +import uk.ac.manchester.tornado.api.TornadoExecutionPlan; + +public final class WithWarmUp extends ExecutionPlanType { + + public WithWarmUp(TornadoExecutionPlan parent) { + super(parent); + } + + @Override + public String toString() { + return super.toString() + "\n -> withWarmUp "; + } +} diff --git a/tornado-api/src/main/java/uk/ac/manchester/tornado/api/runtime/ExecutorFrame.java b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/runtime/ExecutorFrame.java index 4301b96de3..256700b8e9 100644 --- a/tornado-api/src/main/java/uk/ac/manchester/tornado/api/runtime/ExecutorFrame.java +++ b/tornado-api/src/main/java/uk/ac/manchester/tornado/api/runtime/ExecutorFrame.java @@ -20,6 +20,7 @@ import uk.ac.manchester.tornado.api.DRMode; import uk.ac.manchester.tornado.api.GridScheduler; import uk.ac.manchester.tornado.api.Policy; +import uk.ac.manchester.tornado.api.enums.ProfilerMode; /** * Class to store all objects and parameters related to the dispatch of an execution plan. @@ -30,6 +31,7 @@ public class ExecutorFrame { private DRMode dynamicReconfigurationMode; private Policy dynamicReconfigurationPolicy; private GridScheduler gridScheduler; + private ProfilerMode profilerMode; public ExecutorFrame(long id) { this.executionPlanId = id; @@ -65,4 +67,16 @@ public GridScheduler getGridScheduler() { public long getExecutionPlanId() { return this.executionPlanId; } + + public void withProfilerOn(ProfilerMode profilerMode) { + this.profilerMode = profilerMode; + } + + public void withProfilerOff() { + this.profilerMode = null; + } + + public ProfilerMode getProfilerMode() { + return profilerMode; + } } diff --git a/tornado-runtime/src/main/java/uk/ac/manchester/tornado/runtime/graal/compiler/TornadoSketchTier.java b/tornado-runtime/src/main/java/uk/ac/manchester/tornado/runtime/graal/compiler/TornadoSketchTier.java index d28b067e00..7215d7b05a 100644 --- a/tornado-runtime/src/main/java/uk/ac/manchester/tornado/runtime/graal/compiler/TornadoSketchTier.java +++ b/tornado-runtime/src/main/java/uk/ac/manchester/tornado/runtime/graal/compiler/TornadoSketchTier.java @@ -62,7 +62,7 @@ public TornadoSketchTier(OptionValues options, CanonicalizerPhase.CustomSimplifi InliningPolicy inliningPolicy = (TornadoOptions.FULL_INLINING) ? new TornadoFullInliningPolicy() : new TornadoPartialInliningPolicy(); - CanonicalizerPhase canonicalizer = createCanonicalizerPhase(options, customCanonicalizer); + CanonicalizerPhase canonicalizer = CanonicalizerPhase.create(); appendPhase(canonicalizer); if (Inline.getValue(options)) { @@ -87,7 +87,4 @@ public TornadoSketchTier(OptionValues options, CanonicalizerPhase.CustomSimplifi appendPhase(new TornadoBatchFunctionAnalysis()); } - private CanonicalizerPhase createCanonicalizerPhase(OptionValues options, CanonicalizerPhase.CustomSimplification customCanonicalizer) { - return CanonicalizerPhase.create(); - } } diff --git a/tornado-runtime/src/main/java/uk/ac/manchester/tornado/runtime/graal/phases/sketcher/TornadoDataflowAnalysis.java b/tornado-runtime/src/main/java/uk/ac/manchester/tornado/runtime/graal/phases/sketcher/TornadoDataflowAnalysis.java index f7f31e36b8..5668c9dfa1 100644 --- a/tornado-runtime/src/main/java/uk/ac/manchester/tornado/runtime/graal/phases/sketcher/TornadoDataflowAnalysis.java +++ b/tornado-runtime/src/main/java/uk/ac/manchester/tornado/runtime/graal/phases/sketcher/TornadoDataflowAnalysis.java @@ -70,6 +70,7 @@ public class TornadoDataflowAnalysis extends BasePhase @Override protected void run(StructuredGraph graph, TornadoSketchTierContext context) { Access[] accesses = context.getAccesses(); + TornadoLogger logger = new TornadoLogger(this.getClass()); for (int i = 0; i < accesses.length; i++) { accesses[i] = Access.NONE; @@ -79,8 +80,9 @@ protected void run(StructuredGraph graph, TornadoSketchTierContext context) { if (param != null && param.stamp(NodeView.DEFAULT) instanceof ObjectStamp) { accesses[i] = processUsages(param, context.getMetaAccess()); } - new TornadoLogger().debug("access: parameter %d -> %s\n", i, accesses[i]); + logger.debug("access: parameter %d -> %s\n", i, accesses[i]); } + logger.debug("[Compiler Pass] TornadoVM DataFlow Analysis finished"); } @Override diff --git a/tornado-runtime/src/main/java/uk/ac/manchester/tornado/runtime/tasks/TornadoTaskGraph.java b/tornado-runtime/src/main/java/uk/ac/manchester/tornado/runtime/tasks/TornadoTaskGraph.java index b2a1b24374..00e6d653f2 100644 --- a/tornado-runtime/src/main/java/uk/ac/manchester/tornado/runtime/tasks/TornadoTaskGraph.java +++ b/tornado-runtime/src/main/java/uk/ac/manchester/tornado/runtime/tasks/TornadoTaskGraph.java @@ -443,7 +443,7 @@ public void enableProfiler(ProfilerMode profilerMode) { } @Override - public void disableProfiler(ProfilerMode profilerMode) { + public void disableProfiler() { TornadoOptions.TORNADO_PROFILER = false; TornadoOptions.TORNADO_PROFILER_LOG = false; this.timeProfiler = null; @@ -1417,18 +1417,30 @@ private TornadoTaskGraphInterface execute() { return this; } + private void checkProfilerOn(ExecutorFrame executorFrame) { + if (executorFrame.getProfilerMode() != null) { + enableProfiler(executorFrame.getProfilerMode()); + } else { + disableProfiler(); + } + } + + private TornadoTaskGraphInterface executeWithDynamicReconfiguration(ExecutorFrame executorFrame) { + return switch (executorFrame.getDRMode()) { + case SERIAL -> scheduleDynamicReconfigurationSequential(executorFrame.getDynamicReconfigurationPolicy()); + case PARALLEL -> scheduleDynamicReconfigurationParallel(executorFrame.getDynamicReconfigurationPolicy()); + case null, default -> throw new TornadoRuntimeException("[Error] Dynamic Reconfiguration Mode not Implemented: " + executorFrame.getDRMode()); + }; + } + @Override - public TornadoTaskGraphInterface execute(ExecutorFrame executionPackage) { - executionPlanId = executionPackage.getExecutionPlanId(); - if (executionPackage.getDynamicReconfigurationPolicy() == null) { + public TornadoTaskGraphInterface execute(ExecutorFrame executorFrame) { + executionPlanId = executorFrame.getExecutionPlanId(); + checkProfilerOn(executorFrame); + if (executorFrame.getDynamicReconfigurationPolicy() == null) { return execute(); } else { - if (executionPackage.getDRMode() == DRMode.SERIAL) { - return scheduleDynamicReconfigurationSequential(executionPackage.getDynamicReconfigurationPolicy()); - } else if (executionPackage.getDRMode() == DRMode.PARALLEL) { - return scheduleDynamicReconfigurationParallel(executionPackage.getDynamicReconfigurationPolicy()); - } - throw new TornadoRuntimeException(""); + return executeWithDynamicReconfiguration(executorFrame); } } diff --git a/tornado-unittests/src/main/java/uk/ac/manchester/tornado/unittests/executor/TestExecutor.java b/tornado-unittests/src/main/java/uk/ac/manchester/tornado/unittests/executor/TestExecutor.java index be8d6c5fd8..7976fa4c4c 100644 --- a/tornado-unittests/src/main/java/uk/ac/manchester/tornado/unittests/executor/TestExecutor.java +++ b/tornado-unittests/src/main/java/uk/ac/manchester/tornado/unittests/executor/TestExecutor.java @@ -24,11 +24,15 @@ import org.junit.Test; +import uk.ac.manchester.tornado.api.ExecutionPlanType; +import uk.ac.manchester.tornado.api.GridScheduler; import uk.ac.manchester.tornado.api.ImmutableTaskGraph; import uk.ac.manchester.tornado.api.TaskGraph; import uk.ac.manchester.tornado.api.TornadoExecutionPlan; import uk.ac.manchester.tornado.api.TornadoExecutionResult; import uk.ac.manchester.tornado.api.TornadoProfilerResult; +import uk.ac.manchester.tornado.api.WorkerGrid; +import uk.ac.manchester.tornado.api.WorkerGrid1D; import uk.ac.manchester.tornado.api.common.TornadoDevice; import uk.ac.manchester.tornado.api.enums.DataTransferMode; import uk.ac.manchester.tornado.api.enums.ProfilerMode; @@ -241,5 +245,51 @@ public void test04() throws TornadoExecutionPlanException { } } + + @Test + public void test05() throws TornadoExecutionPlanException { + int numElements = 16; + IntArray a = new IntArray(numElements); + IntArray b = new IntArray(numElements); + IntArray c = new IntArray(numElements); + + a.init(1); + b.init(2); + + TaskGraph tg = new TaskGraph("s0") // + .transferToDevice(DataTransferMode.FIRST_EXECUTION, a, b) // + .task("t0", TestHello::add, a, b, c) // + .transferToHost(DataTransferMode.EVERY_EXECUTION, c); + + try (TornadoExecutionPlan executionPlan = new TornadoExecutionPlan(tg.snapshot())) { + + TornadoDevice device = TornadoExecutionPlan.getDevice(0, 0); + + WorkerGrid workerGrid = new WorkerGrid1D(16); + GridScheduler grid = new GridScheduler("s0.t0", workerGrid); + + // Testing multiple functions to invoke the print logic plan later + var trace = executionPlan.withWarmUp() // + .withDevice(device) // + .withGridScheduler(grid) // + .withThreadInfo() // + .withProfiler(ProfilerMode.SILENT); + + // When we call execute(), then it records the path + executionPlan.execute(); + + // Print/dump the execution plan and see all optimizations that were enabled/disabled + trace.printTraceExecutionPlan(); + + // Print the plan. It must be the same as the trace variable + executionPlan.printTraceExecutionPlan(); + + String trace1 = trace.getTraceExecutionPlan(); + String trace2 = executionPlan.getTraceExecutionPlan(); + assertEquals(trace1, trace2); + + } + } + // CHECKSTYLE:ON -} +} \ No newline at end of file diff --git a/tornado-unittests/src/main/java/uk/ac/manchester/tornado/unittests/foundation/TestIntegers.java b/tornado-unittests/src/main/java/uk/ac/manchester/tornado/unittests/foundation/TestIntegers.java index b3c9ea7bba..b8a909bc20 100644 --- a/tornado-unittests/src/main/java/uk/ac/manchester/tornado/unittests/foundation/TestIntegers.java +++ b/tornado-unittests/src/main/java/uk/ac/manchester/tornado/unittests/foundation/TestIntegers.java @@ -170,8 +170,7 @@ public void test06() throws TornadoExecutionPlanException { .task("t0", TestKernels::init, a, b) // .transferToHost(DataTransferMode.EVERY_EXECUTION, a, b); - ImmutableTaskGraph immutableTaskGraph = taskGraph.snapshot(); - try (TornadoExecutionPlan executionPlan = new TornadoExecutionPlan(immutableTaskGraph)) { + try (TornadoExecutionPlan executionPlan = new TornadoExecutionPlan(taskGraph.snapshot())) { executionPlan.withPrintKernel().execute(); } @@ -206,7 +205,5 @@ public void test07() throws TornadoExecutionPlanException { assertEquals(expectedResultA.get(i), a.get(i)); assertEquals(expectedResultB.get(i), b.get(i)); } - } - }