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

Extension of the TornadoExecutionPlan API to allow backend and device filters from the API #357

Merged
merged 19 commits into from
Mar 21, 2024

Conversation

jjfumero
Copy link
Member

@jjfumero jjfumero commented Mar 20, 2024

Description

This PR adds an extension to the TornadoExecutionPlan API in TornadoVM to allow developers to query backends and devices by applying filters. This API is designed as a consequence of the inconsistencies when obtaining a device using different APIs (more details in the next Section).

This API fixes this inconsistencies by giving the user a new Data Structure, called TornadoDeviceMap in which developers can query all backends, devices and apply filters.

Examples of use:

// Obtain an instance of the TornadoDeviceMap via the execution plan
TornadoDeviceMap tornadoDeviceMap = TornadoExecutionPlan.getTornadoDeviceMap();

// Obtain the number of backends installed
int numBackends = tornadoDeviceMap.getNumBackends();


// Query all backends installed
List<TornadoBackend> backends = tornadoDeviceMap.getAllBackends();

// Obtain the number of devices for the first backend
int numDevicesBackendZero = backends.getFirst().getDeviceCount();

We can apply more complex queries as follows:

TornadoDeviceMap tornadoDeviceMap = TornadoExecutionPlan.getTornadoDeviceMap();

// Obtain the OpenCL Backend
List<TornadoBackend> openCLBackend = tornadoDeviceMap.getBackendsWithPredicate(backend -> backend.getBackendType() == TornadoVMBackendType.OPENCL);

// Obtain Backends with at least, two devices
List<TornadoBackend> multiDeviceBackends = tornadoDeviceMap.getBackendsWithPredicate(backend -> backend.getDeviceCount() > 1);


// Obtain All backends that can access to an NVIDIA GPU
List<TornadoBackend> backendsWithNVIDIAAccess = tornadoDeviceMap.getBackendsWithDevicePredicate(device -> device.getDeviceName().toLowerCase().contains("nvidia"));

As part of this API, we needed to refactor some internal classes. The concept of Driver is not the same as we have in TornadoVM compared to the OS driver. Thus, all old driver classes became the Backend classes.

Problem description

The main problem is that to query the number of devices, developers need to access through the TornadoRuntime.getRuntime class. However, to select a device or a backend, developers need to the ExecutionPlan.

This PR fixes this inconsistencies by providing a more concise and expressive API to filter devices and backends without the need to instantiate or interact with the TornadoVM Core Runtime (internal class).

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?

$ make 
$ tornado-test  -V uk.ac.manchester.tornado.unittests.api.TestDevices 

$ make BACKEND=spirv
$ tornado-test -V uk.ac.manchester.tornado.unittests.api.TestDevices 

$ make BACKEND-ptx
$ tornado-test -V uk.ac.manchester.tornado.unittests.api.TestDevices

@jjfumero jjfumero added enhancement New feature or request API feature New feature proposal labels Mar 20, 2024
@jjfumero jjfumero requested review from mairooni and stratika March 20, 2024 11:12
@jjfumero jjfumero self-assigned this Mar 20, 2024
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, just have a look at the files that were changed to make sure that the date in the license header is updated to 2024. E.g. in the TornadoBackend.java, TornadoExecutionPlan.java etc.

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.

LGTM, some minor comments:

  1. Regarding the update of the year in the copyright headers for the files that have been altered.
  2. Java doc description for the new methods. Especially to clarify the use of predicate for the methods that use the TornadoBackend and the TornadoDevice as predicates.

@@ -17,11 +17,14 @@
*/
package uk.ac.manchester.tornado.api;

import java.util.List;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Update the year in the copyright header

@@ -31,6 +34,10 @@ public interface TornadoDriver {

TornadoDevice getDevice(int index);

List<TornadoDevice> getAllDevices();

List<TornadoDevice> getDevicesWithPredicate(Predicate<? super TornadoDevice> predicate);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add a java doc for this method. What is the context of the predicate in this case?

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 removed this method. We don't need it in this interface.

private final List<TornadoBackend> backends;

public TornadoDeviceMap() {
numBackends = coreRuntime.getNumDrivers();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shall we refactor the name of that method to coreRuntime.getNumBackends? Or does it break consistency within the runtime class? If it breaks consistency we can do it in a later PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

good point. I think we can apply this refactor now.

@@ -20,7 +20,7 @@

import org.junit.Before;

import uk.ac.manchester.tornado.api.TornadoDriver;
import uk.ac.manchester.tornado.api.TornadoBackend;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Update the year in copyright header.

@@ -22,14 +22,14 @@

import uk.ac.manchester.tornado.api.ImmutableTaskGraph;
import uk.ac.manchester.tornado.api.TaskGraph;
import uk.ac.manchester.tornado.api.TornadoDriver;
import uk.ac.manchester.tornado.api.TornadoBackend;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Update the year in copyright header.

@@ -18,22 +18,23 @@

package uk.ac.manchester.tornado.unittests.loops;

import static org.junit.Assert.assertEquals;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Update the year in copyright header.

@@ -26,12 +26,12 @@

import uk.ac.manchester.tornado.api.ImmutableTaskGraph;
import uk.ac.manchester.tornado.api.TaskGraph;
import uk.ac.manchester.tornado.api.TornadoDriver;
import uk.ac.manchester.tornado.api.TornadoBackend;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Update the year in copyright header.

@@ -18,27 +18,28 @@

package uk.ac.manchester.tornado.unittests.virtualization;

import static org.junit.Assert.assertEquals;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Update the year in copyright header.

jjfumero and others added 6 commits March 21, 2024 12:58
…DeviceMap.java

Co-authored-by: Thanos Stratikopoulos <34061419+stratika@users.noreply.github.com>
…DeviceMap.java

Co-authored-by: Thanos Stratikopoulos <34061419+stratika@users.noreply.github.com>
@jjfumero
Copy link
Member Author

All changes done.

@jjfumero
Copy link
Member Author

PR description updated with the latest API version.

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 @jjfumero, LGTM.

@jjfumero jjfumero merged commit f02e7cb into beehive-lab:develop Mar 21, 2024
2 checks passed
@jjfumero jjfumero deleted the feat/api/device-query branch March 21, 2024 13:09
jjfumero added a commit to jjfumero/TornadoVM that referenced this pull request Mar 27, 2024
Improvements
~~~~~~~~~~~~~~~~~~

- `beehive-lab#344 <https://github.com/beehive-lab/TornadoVM/pull/344>`_: Support for Multi-threaded Execution Plans.
- `beehive-lab#347 <https://github.com/beehive-lab/TornadoVM/pull/347>`_: Enhanced examples.
- `beehive-lab#350 <https://github.com/beehive-lab/TornadoVM/pull/350>`_: Obtain internal memory segment for the Tornado Native Arrays without the object header.
- `beehive-lab#357 <https://github.com/beehive-lab/TornadoVM/pull/357>`_: API extensions to query and apply filters to backends and devices from the ``TornadoExecutionPlan``.
- `beehive-lab#359 <https://github.com/beehive-lab/TornadoVM/pull/359>`_: Support Factory Methods for FFI-based array collections to be used/composed in TornadoVM Task-Graphs.

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

- `beehive-lab#351 <https://github.com/beehive-lab/TornadoVM/pull/351>`_: Compatibility of TornadoVM Native Arrays with the Java Vector API.
- `beehive-lab#352 <https://github.com/beehive-lab/TornadoVM/pull/352>`_: Refactor memory limit to take into account primitive types and wrappers.
- `beehive-lab#354 <https://github.com/beehive-lab/TornadoVM/pull/354>`_: Add DFT-sample benchmark in FP32.
- `beehive-lab#356 <https://github.com/beehive-lab/TornadoVM/pull/356>`_: Initial support for Windows 11 using Visual Studio Development tools.
- `beehive-lab#361 <https://github.com/beehive-lab/TornadoVM/pull/361>`_: Compatibility with the SPIR-V toolkit v0.0.4.
- `beehive-lab#366 <https://github.com/beehive-lab/TornadoVM/pull/363>`_: Level Zero JNI Dependency updated to 0.1.3.

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

- `beehive-lab#346 <https://github.com/beehive-lab/TornadoVM/pull/346>`_: Computation of local-work group sizes for the Level Zero/SPIR-V backend fixed.
- `beehive-lab#360 <https://github.com/beehive-lab/TornadoVM/pull/358>`_: Fix native tests to check the JIT compiler for each backend.
- `beehive-lab#355 <https://github.com/beehive-lab/TornadoVM/pull/355>`_: Fix custom exceptions when a driver/device is not found.
@jjfumero jjfumero mentioned this pull request Mar 27, 2024
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API enhancement New feature or request feature New feature proposal
Projects
Development

Successfully merging this pull request may close these issues.

3 participants