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

[Feature] Select graph from a multi-graph execution plan to launch. #601

Merged
merged 6 commits into from
Dec 11, 2024

Conversation

jjfumero
Copy link
Member

Description

This PR extends the TornadoExecutionPlan API with a new method to select a graph to launch from a multi-graph execution plan configuration. This type of code is useful when we need to share context (e.g., command queues, cuda streams, code cache, etc) for the whole execution plan, but we only need to execute a task-graph at the time.

The two methods added are as follows:

try (TornadoExecutionPlan executionPlan = new TornadoExecutionPlan(tg1.snapshot(), tg2.snapshot())) {

      // Select graph 1 (tg2) to execute
      // Once selected, every time we call the execute method,
      // TornadoVM will launch the passed task-graph.
      executionPlan.withGraph(1).execute();
  
      // Select the graph 0 (tg1) to execute
      executionPlan.withGraph(0).execute();

      // Select all graphs (tg1 and tg2) to execute.
      // Since we selected individual task-graphs, we should be
      // able to reverse this action and invoke all task-graph
      // again. This is achieved with the `withAllGraphs` from the
      // execution plan.
       executionPlan.withAllGraphs().execute();
 }

This allows the following pattern in TornadoVM:

for (numIterations):
   executionPlan.withGraph(1).execute(); 
}

executionPlan.withGraph(2).execute();
...

Problem description

This path expands the capabilities of TornadoVM towards sharing state across different task-graph within a single execution plan.

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

Did you check on FPGAs?

If it is applicable, check your changes on FPGAs.

  • Yes
  • No

How to test the new patch?

tornado-test --printKernel --threadInfo -V uk.ac.manchester.tornado.unittests.executor.TestExecutor#test06

@jjfumero jjfumero added the API label Dec 10, 2024
@jjfumero jjfumero self-assigned this Dec 10, 2024
@mikepapadim
Copy link
Member

is the original .execute() still works or we need to replace all instnaces with executionPlan.withAllGraphs().execute();?

Copy link
Member

@mikepapadim mikepapadim left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @jjfumero

Comment on lines +320 to +321
a.init(1);
b.init(2);
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we please test the outcome when the elements of the arrays are initialised with different values?

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a new test with random values.

Comment on lines +339 to +347
for (int i = 0; i < c.getSize(); i++) {
assertEquals(a.get(i) + b.get(i), c.get(i));
}

// Select the graph 0 (tg1) to execute
executionPlan.withGraph(0).execute();
for (int i = 0; i < c.getSize(); i++) {
assertEquals(a.get(i) + b.get(i), c.get(i));
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

in this case, all elements in c should be 3, right? I think we should include a test that has different graphs, and potentially the second graph to use the outcome of the first graph.

Does this make sense? In my view this would be a good test to assess the consistency of data used across graphs.

Copy link
Member Author

Choose a reason for hiding this comment

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

It depends on how accessor type associated with the data. If it is read only for both graphs, then yes. Otherwise,a dependency is carried for the next graph. I added a unit-test to check this.

Comment on lines +323 to +331
TaskGraph tg1 = new TaskGraph("s0") //
.transferToDevice(DataTransferMode.FIRST_EXECUTION, a, b) //
.task("t0", TestHello::add, a, b, c) //
.transferToHost(DataTransferMode.EVERY_EXECUTION, c);

TaskGraph tg2 = new TaskGraph("s1") //
.transferToDevice(DataTransferMode.FIRST_EXECUTION, a, b) //
.task("t1", TestHello::add, a, b, c) //
.transferToHost(DataTransferMode.EVERY_EXECUTION, c);
Copy link
Collaborator

Choose a reason for hiding this comment

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

is it possible to add a test in which the graphs have different compute method and they do not share the same variables?

@jjfumero
Copy link
Member Author

is the original .execute() still works or we need to replace all instnaces with executionPlan.withAllGraphs().execute();?

No need to use withAllGraphs to execute all graphs. This is the action by default. The method withAllGraphs is only used when a specific graph was selected a a run, and then the developer wants to select all of them in subsequent runs.

@jjfumero
Copy link
Member Author

Comment addressed.

Copy link
Collaborator

@stratika stratika left a comment

Choose a reason for hiding this comment

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

thanks, LGTM

@jjfumero jjfumero merged commit 2228f74 into beehive-lab:develop Dec 11, 2024
2 checks passed
@jjfumero jjfumero deleted the feat/api/multi-graph branch December 11, 2024 12:11
jjfumero added a commit to jjfumero/TornadoVM that referenced this pull request Dec 20, 2024
Improvements
=============

- beehive-lab#573: Enhanced output of unit-tests with a summary  of pass-rates and fail-rates.
- beehive-lab#576: Extended support for 3D matrices.
- beehive-lab#580: Extended debug information for execution plans.
- beehive-lab#584: Added helper menu for the ``tornado`` launcher script when no arguments are passed.
- beehive-lab#589: Enable partial loop unrolling for all backends.
- beehive-lab#594: Added RISC-V 64 CPU port support to run OpenCL with vector instructions RVV 1.0 (using the Codeplay OCK Toolkit).
- beehive-lab#598: OpenCL low-level buffers tagged as read, write and read/write based on the data dependency analysis.
- beehive-lab#601: Feature to select an immutable task graph to execute from a multi-task graph execution plan.

Compatibility
=============

- beehive-lab#570:  Extended timeout for all suite of unit-tests.
- beehive-lab#579: Removed legacy JDK 8 and JDK11 build options from the TornadoVM installer.
- beehive-lab#582: Restored tornado runner scripts for IntellIJ.
- beehive-lab#583: Automatic generation of IDE IntelliJ configuration runner files from the TornadoVM command.
- beehive-lab#597: Updated white-list of unit-test and checkstyle improved.

Bug Fixes
=============

- beehive-lab#571: Fix issues with bracket closing for if/loops conditions.
- beehive-lab#572: Fix for printing default execution plans (execution plans with default parameters).
- beehive-lab#575: Fix the Level Zero version used for building the SPIR-V backend.
- beehive-lab#577: Fix checkstyle.
- beehive-lab#587: Fix thread scheduler for new NVIDIA Drivers.
- beehive-lab#592: Fix ``Float.POSITIVE_INFINITY`` and ``Float.NEGATIVE_INFINITIVE`` constants for the OpenCL, CUDA and SPIR-V backends.
- beehive-lab#596: Fix extra closing bracket during the code-generation for the FPGAs.
- Remove the intermediate CUDA pinned memory regions in the JNI code: [link](beehive-lab@9c3f8ce)
- Fix bitwise negation operations for the PTX backend:  [link](beehive-lab@0db1cd3)
- `GetBackendImpl::getAllDevices` thread-safe: [link](beehive-lab@0d44252)
- Check size elements for memory segments: [link](beehive-lab@4360385)
@jjfumero jjfumero mentioned this pull request Dec 20, 2024
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

Successfully merging this pull request may close these issues.

3 participants