beehive-lab / TornadoVM

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

Issue with multi-device bytecode generation #249

Closed mikepapadim closed 1 year ago

mikepapadim commented 1 year ago

There is an inconsistency in bytecode generation when launching tasks with dependencies on multiple devices.

For the following TaskGraph :

    TaskGraph taskGraph = new TaskGraph("s0")//
                .transferToDevice(DataTransferMode.EVERY_EXECUTION, b) //
                .task("t0", TestMultipleTasksSingleDevice::task0Initialization, b) //
                .task("t1", TestMultipleTasksSingleDevice::task1Multiplication, b, 12) //
                .transferToHost(DataTransferMode.EVERY_EXECUTION, b); //

1) task0Initialization writes a new value in all the elements of the array 2) task1Multiplication scales the array b that the previous device allocates by a factor of 12

So, b should be copied out from the first device. However, the bytecodes are the following:

bc:  ALLOC [I@563f38c4 on   [Intel(R) OpenCL] -- 13th Gen Intel(R) Core(TM) i7-13700 , size=0
bc:  LAUNCH  task s0.t0 - task0Initialization on  [Intel(R) OpenCL] -- 13th Gen Intel(R) Core(TM) i7-13700, size=0, offset=0 [event list=0]
bc:  ALLOC [I@563f38c4 on   [NVIDIA CUDA] -- NVIDIA GeForce RTX 3070 , size=0
bc:  TRANSFER_HOST_TO_DEVICE_ONCE  [Object Hash Code=0x563f38c4] [I@563f38c4 on   [NVIDIA CUDA] -- NVIDIA GeForce RTX 3070 , size=0, offset=0 [event list=-1]
bc:  LAUNCH  task s0.t1 - task1Multiplication on  [NVIDIA CUDA] -- NVIDIA GeForce RTX 3070, size=0, offset=0 [event list=1]
bc:  TRANSFER_DEVICE_TO_HOST_ALWAYS [0x563f38c4] [I@563f38c4 on   [NVIDIA CUDA] -- NVIDIA GeForce RTX 3070 , size=0, offset=0 [event list=2]
bc:  DEALLOC [0x563f38c4] [I@563f38c4 on   [Intel(R) OpenCL] -- 13th Gen Intel(R) Core(TM) i7-13700 
bc:  DEALLOC [0x563f38c4] [I@563f38c4 on   [NVIDIA CUDA] -- NVIDIA GeForce RTX 3070 
bc:  BARRIER  event-list 7
bc:  END

On the above, there is a missing TRANSFER_DEVICE_TO_HOST_ALWAYS after LAUNCH task s0.t0 - task0Initialization.

jjfumero commented 1 year ago

@mikepapadim , I think this is fixed from TornadoVM 0.15.2. Can you confirm?

jjfumero commented 1 year ago

@mikepapadim , I think this is solved. Can you please confirm?

mikepapadim commented 1 year ago

let me check and I need to add also a test for this case

mikepapadim commented 1 year ago

I can verity that this now working after merging the MTMD with master.

mikepapadim commented 1 year ago

I added a test to validate read-only objects shared between tasks are now copied in to all devices runing concurently.

mikepapadim commented 1 year ago

This is now fixed

it can be tested with:

tornado-test -V --fullDebug --debug --printBytecodes --jvm="-Dtornado.concurrent.devices=true -Ds0.t0.device=0:0 -Ds0.t1.device=0:1 " uk.ac.manchester.tornado.unittests.tasks.TestMultipleTasksMultipleDevices#testTwoTasksTwoDevicesSharedReadOnlyRead