TornadoVM icon indicating copy to clipboard operation
TornadoVM copied to clipboard

Transfer to host in execution result.

Open jjfumero opened this issue 1 year ago • 0 comments

Discussed in https://github.com/beehive-lab/TornadoVM/discussions/476

Originally posted by andrii0lomakin July 2, 2024 Hi guys. I have tried very simple test case:

public static void main(String[] args) {
        var taskGraph = new TaskGraph("SimpleGraph");
        var input = new FloatArray(10);
        for (int i = 0; i < 10; i++) {
            input.set(i, i + 1);
        }


        var output = new FloatArray(10);
        for (int i = 0; i < 10; i++) {
            output.set(i, 1.1f);
        }

        taskGraph.transferToDevice(DataTransferMode.EVERY_EXECUTION, input);
        taskGraph.task("copyVectorForBroadcast", (in, out) ->
                        TvmVectorOperations.copyVector(in, 0, out, 0, 10),
                input, output);
       // taskGraph.transferToHost(DataTransferMode.EVERY_EXECUTION, output);
        ImmutableTaskGraph immutableTaskGraph = taskGraph.snapshot();

        // Create an execution plan from an immutable task-graph
        try (TornadoExecutionPlan executionPlan = new TornadoExecutionPlan(immutableTaskGraph)) {
            // Run the execution plan on the default device
            var result = executionPlan.execute();
            result.transferToHost(output);

            System.out.println("Execution completed " + Arrays.toString(output.toHeapArray()));
        } catch (TornadoExecutionPlanException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

If I uncomment transferToHost line in execution graph everything works as expected. But should not it work even without this line because I call transferToHost in execution result ?

jjfumero avatar Jul 02 '24 08:07 jjfumero