javastringgpujava-8aparapi

Can Aparapi handle string processing with Java 8?


I'm learning to use Aparapi with Java 8 so GPU can be used to speed up my apps, but I wonder if Aparapi can handle string processing.

For instance, if I have 10,000 files to go through and my app needs to read in the text and go through each line to extract and parse float numbers and then do some computation and store the result in some place like a hashmap or list or array, my CPU is running at near 100% when I use multiple threads, and it runs for nearly an hour to get the job done.

Can my app benefit from Aparapi with Java 8 to allocate some computing to the GPU ? I know it can do [ + - * / ], but can Aparapi do things like :

String lines[]=text.split("\n");
for (int i=0;i<lines.length;i++)
{
  float number=Float.parseFloat(lines[i]);
  number*=2000;
}

Solution

  • Aparapi based on OpenCL can't do this because it can't deal directly with Objects on the heap. The best we could do would be to move all the String state to the GPU by marshalling the objects into a single area of contiguous heap (ala Rootbeer), then perform your parallel operation on all strings. Most of the time it is hard to 'win back' the marshall+transfer time.

    The HSA enabled lambda branch of Aparapi (still being worked on!) will enable you to do this on a HSA enabled platform. HSA allows access to Java heap Objects directly from the GPU (shared virtual memory). This means that we no longer have to copy data to and from the GPU. The GPU can follow object references directly.

    Still can't allocate on the GPU (this requires some support for GC, safepoints and deopt handling) which is beyond Aparapi. Sumatra, on the the other hand, is an OpenJDK project and will be able to handle the use case you suggest AND will allow allocations. It has the advantage of being able to hook into the JVM ;)