You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Why does TornadoVM not share the same device buffer between them, so that the idea of manipulating the same object is preserved?
I deliberately avoided transferring the output to the device for each graph to prevent values from being overwritten. However, it seems that the initially zeroed output is still being transferred or initialized twice on the device.
Context: I’m trying to implement double buffering on TornadoVM without copying input arrays, so I create two TaskGraph (one per input buffer) because I cannot reassign a different input array to a built TaskGraph. In practice my input buffer would be >= 1GB, so avoiding copies is critical.
publicstaticvoidop(LongArrayinput, LongArrayoutput) {
for (@Parallelinti = 0; i < output.getSize(); i++) {
output.set(i, input.get(i) + output.get(i));
}
}
publicstaticvoidmain(String[] args) throwsException {
finalintN = 8;
finalintNUM_BATCHES = 10; // exampleLongArray[] input = newLongArray[] { newLongArray(N), newLongArray(N) };
LongArrayoutput = newLongArray(N);
TaskGraphA = newTaskGraph("A")
.transferToHost(DataTransferMode.EVERY_EXECUTION, input[0])
.task("A0", Test::op, input[0], output)
.transferToHost(DataTransferMode.UNDER_DEMAND, output);
TaskGraphB = newTaskGraph("B")
.transferToHost(DataTransferMode.EVERY_EXECUTION, input[1])
.task("B0", Test::op, input[1], output)
.transferToHost(DataTransferMode.UNDER_DEMAND, output);
TornadoExecutionPlanpa = newTornadoExecutionPlan(A.snapshot());
TornadoExecutionPlanpb = newTornadoExecutionPlan(B.snapshot());
for (intbatch = 0; batch < NUM_BATCHES; batch++) {
intcurrent = batch % 2; // which input buffer we fill this iterationfillInput(input[current], batch);//load data into the current inputif (batch == NUM_BATCHES - 1) {
// last batch: execute and transfer final output back to hostif (current == 0) pa.execute().transferToHost(output);
elsepb.execute().transferToHost(output);
} else {
// non-final batch: fire execution only so that output accumulates across executionsif (current == 0) pa.execute();
elsepb.execute();
}
// Next loop iteration will fill the other buffer while the previous execution runs. in practise execution would be scheduled to run on another thread so no execution blocks this loop
}
System.out.println("ACCUMULATION: " + Arrays.toString(output.toHeapArray()));
}
How can I do double buffering with no copying of data?
N.B. I am aware I could make input a ×2 capacity array in which I toggle which section is the current buffer so a single TaskGraph i.e. keep one device allocation and either pass an offset parameter to the kernel (or use two logical “views” / slices of the same LongArray) so the kernel reads input[offset + i]. I’m looking for a better approach because I don’t want the device to take up so much memory and I want transfers to host to be faster (smaller arrays); every cost counts since I will be doing multiple executions.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Why is the output here
[0, 0, 0, 0, 0, 0, 0, 0]instead of[0, 2, 4, 6, 8, 10, 12, 14]?Both graphs reference the same
LongArrayobject on the host.Why does TornadoVM not share the same device buffer between them, so that the idea of manipulating the same object is preserved?
Context: I’m trying to implement double buffering on TornadoVM without copying input arrays, so I create two
TaskGraph(one per input buffer) because I cannot reassign a different input array to a builtTaskGraph. In practice my input buffer would be >= 1GB, so avoiding copies is critical.How can I do double buffering with no copying of data?
Beta Was this translation helpful? Give feedback.
All reactions