beehive-lab / TornadoVM

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

Transfer to host in execution result. #477

Open jjfumero opened 3 months ago

jjfumero commented 3 months ago

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 ?