beehive-lab / TornadoVM

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

Add test to trigger unsupported input when user try to offload directly `MemorySegments` #494

Closed mikepapadim closed 1 month ago

mikepapadim commented 1 month ago

Description

Following the discussion in #491, currently there is no proper error and exception handling when the user tries to run TornadoVM with a MemorySegment directly without using any of the TornadoNativeTypes.

This PR adds a test to trigger this behaviour, so we can discuss at which level we should throw the appropriate exception to prevent end-users to try to use MemorySegments directly.

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 -V --debug uk.ac.manchester.tornado.unittests.api.TestMemorySegmentsAsType 

andrii0lomakin commented 1 month ago

@mikepapadim I do not use MemorySegments directly. I used them over the Float/Native arrays.

stratika commented 1 month ago

thanks, I am testing it on Linux and macOS and got this:

tornado-test -V uk.ac.manchester.tornado.unittests.api.TestMemorySegmentsAsType
WARNING: Using incubator modules: jdk.incubator.vector

WARNING: Code Bailout to Java sequential. Use --debug to see the reason
Test: class uk.ac.manchester.tornado.unittests.api.TestMemorySegmentsAsType
    Running test: testMemorySegmentAsInput   ................  [FAILED] 
        \_[REASON] Unable to build sketch for method: getMemorySegment(Cannot invoke "jdk.vm.ci.meta.ResolvedJavaType.getAnnotation(java.lang.Class)" because the return value of "org.graalvm.compiler.core.common.type.ObjectStamp.type()" is null)
Test ran: 1, Failed: 1, Unsupported: 0
mikepapadim commented 1 month ago

thanks, I am testing it on Linux and macOS and got this:

tornado-test -V uk.ac.manchester.tornado.unittests.api.TestMemorySegmentsAsType
WARNING: Using incubator modules: jdk.incubator.vector

WARNING: Code Bailout to Java sequential. Use --debug to see the reason
Test: class uk.ac.manchester.tornado.unittests.api.TestMemorySegmentsAsType
  Running test: testMemorySegmentAsInput   ................  [FAILED] 
      \_[REASON] Unable to build sketch for method: getMemorySegment(Cannot invoke "jdk.vm.ci.meta.ResolvedJavaType.getAnnotation(java.lang.Class)" because the return value of "org.graalvm.compiler.core.common.type.ObjectStamp.type()" is null)
Test ran: 1, Failed: 1, Unsupported: 0

Thats expected. Lets wait for @jjfumero to discuss at which level we should throw an appropriate exception if someone tries to use directly a MemorySegment and not the wrapped types.

jjfumero commented 1 month ago

We can't use a segment directly due to the internal object header, which is custom for the GPU/FPGA. Also, with JDK22+, we can't invoke it directly. So the way to go is to throw an exception during the Task-Graph built, since we get all input/output objects to create the internal GPU buffers.

mikepapadim commented 1 month ago

This is fixed now, it throws a TornadoRuntimeException when user passes a MemorySegment as Task parameter