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

Implement memory limit functionality per ExecutionPlan in the TornadoVM API #323

Merged
merged 16 commits into from
Feb 6, 2024

Conversation

mikepapadim
Copy link
Member

@mikepapadim mikepapadim commented Feb 1, 2024

Description

This PR introduces withMemoryLimit() option in TornadoVM's execution plan. With this feature, the API provides the means to execute a TaskGraph only if fullfil specific memory constraints.

The use of the withMemoryLimit() will cause TornadoVM to throw an OutOfMemoryException in order to resize its buffers or increase the device memory limit or use the batch processing utilities.

 executionPlan.withMemoryLimit("1GB").execute();

Backend/s tested

Mark the backends affected by this PR.

  • OpenCL
  • PTX
  • SPIRV

OS tested

Mark the OS where this PR is tested.

  • Linux
  • OSx
  • Windows

How to test the new patch?

tornado-test -V uk.ac.manchester.tornado.unittests.memoryplan.TestWithMemoryLimit

Implemented a new method to handle specification of memory limit for tasks in the Tornado execution pipeline. The method parses the value and unit from a string input, calculates the size in bytes, and throws an exception for unsupported units. Ensure units "MB" and "GB" are supported. Also added related changes to the `TornadoExecutionContext` and `TornadoExecutionPlan` classes.
Integrate memory limit specification into the Tornado task graph. The update includes a parser to extract value and units from a string input, and computes the memory limit size in bytes. The parser throws exceptions for unsupported units; currently, "MB" and "GB" are supported. The changes affect the `TornadoExecutionContext` and `TornadoExecutionPlan` classes as well.
A new class named TestWithMemoryLimit has been introduced in the tornado-unittests module. This class is an extension of the TornadoTestBase class and is a part of the uk.ac.manchester.tornado.unittests.memoryplan package. This addition is part of work to integrate tests related to memory limitation in Tornado.
This commit introduces the TestWithMemoryLimit class in the tornado-unittests module. The class extends TornadoTestBase and tests the memory limit functionality using two new methods, `testWithMemoryLimitOver` and `testWithMemoryLimitUnder`. These
This commit brings more readability to TornadoVM code by using string interpolation instead of string concatenation. Additionally, it updates the way devices are added to the list in `mapAllTasksToSingleDevice` method making the insertion order clearer.
This update adds a method in TornadoTaskGraph to check if memory limit is exceeded and alters the checkMaxHeapAllocation method in TestBatches to checkMaxHeapAllocationOnDevice for clarity. It also refactors exception handling and debug print statements for improved readability.
The update introduces a new method that checks if a memory limit has been exceeded in the TornadoTaskGraph. It also includes exception handling related to this new feature. Lastly, the test cases in the TestBatches class have been refactored, with the checkMaxHeapAllocation method being altered for clearer understanding and readability.
The code difference shows the reactivation of a test case in the TornadoTaskGraph. This test is focused on checking if the system correctly throws a TornadoMemoryException when the memory limit is exceeded. The previously commented test has been updated to recursively check if the memory limit is under the allotted limit.
@mikepapadim mikepapadim added the API label Feb 1, 2024
@mikepapadim mikepapadim self-assigned this Feb 1, 2024
@mikepapadim
Copy link
Member Author

I need to pass the formatter properly.

The updated code reintroduces a check in the TornadoExecutionContext to ensure it doesn't exceed the execution plan memory limit. This additional check will only run if the memory limit is not -1, which signifies there's a defined limit, and only then it will verify if the total size surpasses the memory limit. This change improves the system's exception handling for memory limit related issues.
The NUM_ELEMENTS value in TestWithMemoryLimit class has been increased. Additionally, changes have been made to increase totalSize incrementally in TornadoExecutionContext to ensure that it does not exceed the execution plan memory limit.
a = new IntArray(NUM_ELEMENTS);
b = new IntArray(NUM_ELEMENTS);
c = new IntArray(NUM_ELEMENTS);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apply the code formatter

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the test in the tornado-test.py script.

@jjfumero
Copy link
Member

jjfumero commented Feb 5, 2024

Is this PR ready?

* </code>
* </p>
*/
public class TestWithMemoryLimit extends TornadoTestBase {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public class TestWithMemoryLimit extends TornadoTestBase {
public class TestMemoryLimits extends TornadoTestBase {

a = new IntArray(NUM_ELEMENTS);
b = new IntArray(NUM_ELEMENTS);
c = new IntArray(NUM_ELEMENTS);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the test in the tornado-test.py script.

@mikepapadim
Copy link
Member Author

This is ready now

Copy link
Collaborator

@mairooni mairooni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jjfumero jjfumero merged commit 191c129 into beehive-lab:develop Feb 6, 2024
2 checks passed
jjfumero added a commit that referenced this pull request Feb 29, 2024
Improvements
~~~~~~~~~~~~~~~~~~

- `#323 <https://github.com/beehive-lab/TornadoVM/pull/323>`_: Set Accelerator Memory Limit per Execution Plan at the API level
- `#328 <https://github.com/beehive-lab/TornadoVM/pull/328>`_: Javadoc API to run with concurrent devices and memory limits
- `#340 <https://github.com/beehive-lab/TornadoVM/pull/340>`_: New API calls to enable ``threadInfo`` and ``printKernel`` from the Execution Plan API.
- `#334 <https://github.com/beehive-lab/TornadoVM/pull/334>`_: Dynamically enable/disable profiler after first run

Compatibility
~~~~~~~~~~~~~~~~~~

- `#337 <https://github.com/beehive-lab/TornadoVM/pull/337>`_ : Initial support for Graal and JDK 21.0.2

Bug Fixes
~~~~~~~~~~~~~~~~~~

- `#322 <https://github.com/beehive-lab/TornadoVM/pull/322>`_: Fix duplicate thread-info debug message when the debug option is also enabled.
- `#325 <https://github.com/beehive-lab/TornadoVM/pull/325>`_: Set/Get accesses for the ``MatrixVectorFloat4`` type fixed
- `#326 <https://github.com/beehive-lab/TornadoVM/pull/326>`_: Fix installation script for running with Python >= 3.12
- `#327 <https://github.com/beehive-lab/TornadoVM/pull/327>`_: Fix Memory Limits for all supported Panama off-heap types.
- `#329 <https://github.com/beehive-lab/TornadoVM/pull/329>`_: Fix timers for the dynamic reconfiguration policies
- `#330 <https://github.com/beehive-lab/TornadoVM/pull/330>`_: Fix the profiler logs when silent mode is enabled
- `#332 <https://github.com/beehive-lab/TornadoVM/pull/332>`_: Fix Batch processing when having multiple task-graphs in a single execution plan.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants