-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #384 from jjfumero/fix/memory/fill
Autoclosable Execution Plans for automatic memory management (free resources)
- Loading branch information
Showing
13 changed files
with
278 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
.../src/main/java/uk/ac/manchester/tornado/api/exceptions/TornadoExecutionPlanException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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.exceptions; | ||
|
||
public class TornadoExecutionPlanException extends Exception { | ||
|
||
private String reason; | ||
|
||
public TornadoExecutionPlanException() { | ||
|
||
} | ||
|
||
public TornadoExecutionPlanException(String reason) { | ||
this.reason = reason; | ||
} | ||
|
||
public String getReason() { | ||
return reason; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
tornado-examples/src/main/java/uk/ac/manchester/tornado/examples/memory/TestMemory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package uk.ac.manchester.tornado.examples.memory; | ||
|
||
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.annotations.Parallel; | ||
import uk.ac.manchester.tornado.api.enums.DataTransferMode; | ||
import uk.ac.manchester.tornado.api.exceptions.TornadoExecutionPlanException; | ||
import uk.ac.manchester.tornado.api.types.arrays.FloatArray; | ||
|
||
/** | ||
* Full example to show to matrix addition with non vector types | ||
* <p> | ||
* How to run? | ||
* </p> | ||
* <code> | ||
* tornado --jvm="-Dtornado.device.memory=4GB" -m tornado.examples/uk.ac.manchester.tornado.examples.memory.TestMemory | ||
* </code> | ||
* | ||
*/ | ||
public class TestMemory { | ||
|
||
public static void moveData(FloatArray inputArray, FloatArray outputArray) { | ||
for (@Parallel int i = 0; i < inputArray.getSize(); i++) { | ||
outputArray.set(i, inputArray.get(i)); | ||
} | ||
} | ||
|
||
public static void stressDataAllocationTest(int dataSizeFactor) throws TornadoExecutionPlanException { | ||
System.out.println("Allocating size: " + (dataSizeFactor * 4) + " (bytes)"); | ||
FloatArray inputArray = new FloatArray(dataSizeFactor); | ||
FloatArray outputArray = new FloatArray(dataSizeFactor); | ||
inputArray.init(0.1f); | ||
TaskGraph taskGraph = new TaskGraph("memory" + dataSizeFactor) // | ||
.transferToDevice(DataTransferMode.EVERY_EXECUTION, inputArray) // | ||
.task("stress", TestMemory::moveData, inputArray, outputArray) // | ||
.transferToHost(DataTransferMode.EVERY_EXECUTION, outputArray); | ||
|
||
ImmutableTaskGraph immutableTaskGraph = taskGraph.snapshot(); | ||
try (TornadoExecutionPlan executionPlan = new TornadoExecutionPlan(immutableTaskGraph)) { | ||
executionPlan.execute(); | ||
} | ||
} | ||
|
||
/** | ||
* Depending on the device, this test is expected to fail when using the | ||
* OpenCL backend. | ||
*/ | ||
|
||
public static void main(String[] args) { | ||
// Starting in ~1.5GB and move up to ~2GB | ||
for (int i = 400; i < 500; i += 10) { | ||
int size = 1024 * 1024 * i; | ||
try { | ||
stressDataAllocationTest(size); | ||
} catch (TornadoExecutionPlanException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.