beehive-lab / TornadoVM

TornadoVM: A practical and efficient heterogeneous programming framework for managed languages
https://www.tornadovm.org
Apache License 2.0
1.15k stars 109 forks source link

[feat][api] Prebuilt API redesign and simplification #487

Open jjfumero opened 3 days ago

jjfumero commented 3 days ago

Description

Draft PR - > Proposal to simplify the prebuilt-task API.

Since we split Task-Graph into different data structures for definition and execution, we do not need all scheduling arguments in the prebuilt task API. This PR proposes a simplification of the Prebuilt Task API for:

1) Create Accessors to define data and its own accessor to the kernel. This is similar to SYCL and oneAPI. 2) Remove the scheduling parameters from the Prebuilt-Task Graph. This information is stored in a GridScheduler that is passed at a later stage to the execution plan.

As an example:

       // Define accessors for each parameter
        AccessorParameters accessorParameters = new AccessorParameters(3);
        accessorParameters.set(0, a, Access.READ_ONLY);
        accessorParameters.set(1, b, Access.READ_ONLY);
        accessorParameters.set(2, c, Access.WRITE_ONLY);

        // Define the Task-Graph
        TaskGraph taskGraph = new TaskGraph("s0") //
                .transferToDevice(DataTransferMode.FIRST_EXECUTION, a, b) //
                .prebuiltTask("t0",      //task name
                        "add",              // name of the low-level kernel to invoke
                        FILE_PATH,          // file name
                        accessorParameters) // accessors
                .transferToHost(DataTransferMode.EVERY_EXECUTION, c);

        // When using the prebuilt API, we need to define the WorkerGrid, otherwise it will launch 1 thread
        // on the target device
        WorkerGrid workerGrid = new WorkerGrid1D(numElements);
        GridScheduler gridScheduler = new GridScheduler("s0.t0", workerGrid);

        // Launch the application on the target device
        try (TornadoExecutionPlan executionPlan = new TornadoExecutionPlan(taskGraph.snapshot())) {
            executionPlan.withGridScheduler(gridScheduler) //
                    .withDevice(defaultDevice) //
                    .execute();
        }

Problem description

n/ a.

Backend/s tested

Mark the backends affected by this PR.

OS tested

Mark the OS where this PR is tested.

Did you check on FPGAs?

If it is applicable, check your changes on FPGAs.

How to test the new patch?

tornado-test --debug -V uk.ac.manchester.tornado.unittests.prebuilt.PrebuiltTest

tornado-test -pk --threadInfo -V --fast uk.ac.manchester.tornado.unittests.atomics.TestAtomics#testAtomic05_precompiled