Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application of Project Sumatra to other JVM languages

Tags:

java

jvm

gpu

I have just recently discovered Project Sumatra, which aims to bring the JVM to the graphics card. From their webpage this includes a custom compiler (called Rootbeer) for Java.

This is all good news, however, I would like to hear from someone with more knowledge about the project internals if this means that project Sumatra applies to other JVM languages as well? Will it be possible to make Aparapi calls from Scala or Clojure directly? Or will you have to develop some core functionality in Java and then access that via other JVM languages?

like image 685
Frank Avatar asked Feb 19 '23 23:02

Frank


2 Answers

I only just came across this question. Apologies for taking so long. Full disclosure I am the Aparapi inventor/lead and co sponsor of Sumatra.

Unlike Aparapi Sumatra has the advantage of working from the IR (Intermediate Representation) of Java methods from inside the JVM. This means that ultimately it will detect opportunities for GPU offload based on patterns found at this abstract level. Aparapi had to reverse engineer opportunities from bytecode.

It is likely that Sumatra will initially key off user hints, rather than trying to auto-parallelize code. The main focus at present is the new 'lambda' feature of Java 8 and it's companion 'stream API'. So where Aparapi required the user to inherit from a Kernel base class. Sumatr a will likely use the 'explicit' hint of parallelism suggested by:-

IntRange.range(1024).parallel().forEach(gid->{out[gid]=a[gid]+b[gid];});

Although for obvious cases, such as

for (int id=0; i< 1024; i++){ out[gid]=a[gid]+b[gid]; }

It should be entirely possible to offload this loop. So support for other JVM based languages will depend on how ambitious we are looking for opportunities to auto-parallelize. I suspect that many patterns from other languages (JavaScript (Nashorn), JRuby, Scala, JPython etc) will be detectable.

like image 200
gfrost Avatar answered Feb 21 '23 13:02

gfrost


AFAIK Rootbeer (a university project) and Aparapi (an AMD based project) are unrelated, so you may haved missed something here.

Regarding Aparapi itself it states in its Wiki that it won't work with Scale/Closure etc. or in fact with anything except pure Java, since it depends on patterns used by JDK's javac to properly analyse bytecode. It also requires you to extend its Kernel class to be able to convert the bytecode into OpenCL and execute it in GPU. So it looks like you would use one or another.

Back to your question: based on all this you would have to develop in Java and call it from other JVM languages.

like image 20
Tomasz Stanczak Avatar answered Feb 21 '23 13:02

Tomasz Stanczak