sha256 aparapi example

653 views
Skip to first unread message

James Northrup

unread,
Mar 3, 2013, 5:52:17 AM3/3/13
to aparapi...@googlegroups.com
Hello I have been using aparapi for 15 minutes and have a simple project up and running but don't know how to bridge the Kernel over from the existing benchmark.

I was hoping someone could walk me through a trivial port of my trivial example Kernel.

the main sha256 code I'm hoping to test lives in this function.  
 

after a couple of tries and this exception in a local IDE project I wanted to reach out for help. 

com.amd.aparapi.ClassParseException: Using java objects inside kernels is not supported
at com.amd.aparapi.Entrypoint.getFieldFromClassHierarchy(Entrypoint.java:190)
at com.amd.aparapi.Entrypoint.<init>(Entrypoint.java:698)
at com.amd.aparapi.ClassModel.getEntrypoint(ClassModel.java:2635)
at com.amd.aparapi.ClassModel.getEntrypoint(ClassModel.java:2643)
at com.amd.aparapi.KernelRunner.execute(KernelRunner.java:1380)
at com.amd.aparapi.Kernel.execute(Kernel.java:1774)
at com.amd.aparapi.Kernel.execute(Kernel.java:1705)
at com.amd.aparapi.Kernel.execute(Kernel.java:1675)
at fr.cryptohash.SHA256.processBlock(SHA256.java:246)


what needs be done to make processBlock deliver the "data" byte[] paramater to opencl and process a block?

anyhelp is appreciated!

thanks
Jim

gfrost

unread,
Mar 3, 2013, 9:51:54 AM3/3/13
to aparapi...@googlegroups.com
Hey James. 

So I spent some time looking at your code (via the link), then realized that this code was not using Aparapi ;) 

From the stack trace below it appears you are trying to reference an Object from your Aparapi code. 

Only primitive parallel arrays can be used in Aparapi. 

The reason for this is that we need to move the memory accessed by the 'run' method (and all methods reachable from run() ) to the GPU.  We can easily (well - relatively) do this for parallel arrays of primitives because int[1024] has all ints in consecutive memory locations. Whereas Foo[1024] contains 1024 Foo 'references' in contiguous locations, the actual Objects are scattered over the heap. 

You cannot allocate an array (Ala new int[1024]), inside a Kernel (because all buffers have to be pre allocated). 

If you are prepared to share your Aparapi code, I would be happy to suggest alternatives.

Gary 

james northrup

unread,
Mar 3, 2013, 8:20:11 PM3/3/13
to aparapi...@googlegroups.com
Hi Gary, I did not check in the aparapi Kernel attempt.  I hit the reset button after finding a regression.  

the processBlock method shown is the intended kernel code, I will re-insert the the attempt in a github branch. 

the methodology for now is to use the existing maven project and code, and assign intellij debugging with the -Djava.library.path switch for aparapi and manual jarfile imports per project, so it wouldn't necessarily look like a complete github project, unless there's a maven solution handy.

on the maven tip, I wanted to share that intel's bluecove project is a fully multiplatform java driver layer wrapping jni libraries in a maven build.  I would look at this for inspiration and may contribute some cycles in this direction if aparapi is something i can grasp.  


--
You received this message because you are subscribed to the Google Groups "aparapi-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aparapi-discu...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

james northrup

unread,
Mar 3, 2013, 10:30:52 PM3/3/13
to aparapi...@googlegroups.com
ok repeated the build for aparapi, see https://github.com/jnorthrup/sphlib/commit/bc5192469a6ae8e8a8d5b90608da3749e7e77ccf  and https://github.com/jnorthrup/sphlib/blob/bc5192469a6ae8e8a8d5b90608da3749e7e77ccf/src/main/java/fr/cryptohash/SHA2Core.java

once again, the aparapi dependencies are done in-IDE, specific to this branch, the rest of the library is otherwise pretty buildable standalone.

gfrost

unread,
Mar 4, 2013, 10:11:00 AM3/4/13
to aparapi...@googlegroups.com
James. 

So the error you see here 

Is basically Aparapi's equivalent NullPointerException

One of the buffers (primitive arrays) that Aparapi is asked to process is 'null' when kernel.execute() is invoked. 

To move data from the host (the CPU running Java and you APP) to the GPU Aparapi has to request OpenCL to move the data from the host to the GPU.  If the buffer is null then the code cannot function.  So we catch the fact that the buffer is null and refuse to send it (or the execution request) to the GPU. 

Gary  

james northrup

unread,
Mar 4, 2013, 6:17:02 PM3/4/13
to aparapi...@googlegroups.com

https://github.com/jnorthrup/sphlib/commit/c4466466674f941a7e5729d6b2ddea58a438d448

:)

this branch and commit should work if you add the -D switches to java.

the test I'm using is Speed.main() found in src/main/test directory, where it may or may not belong with unit tests.

the code performs with gpu at about 1000x slower, but it works....

Gary Frost

unread,
Mar 4, 2013, 9:50:39 PM3/4/13
to aparapi...@googlegroups.com
How often is processBlock called?

It looks like the kernel is created each time processBlock is called.  So OpenCL is created each time processBlock is called. 

It takes ~ 150 ms each time to convert byte code to OpenCL.  maybe 50 ms to  compile OpenCL. 

Can't you create the Kernel once then use it (kernel.execute()) each time processBlock is called. 

Maybe store the kernel in a static field?

Gary

james northrup

unread,
Mar 4, 2013, 10:44:51 PM3/4/13
to aparapi...@googlegroups.com
thanks, Gary 

as written, the checked-in benchmark MyKernel is faster than static MyKernel by .3 MB/s on the top end.  this is a 64 byte rotation operation so the main slowdown is in IO.  I presume the benchmark is creating one instance of SHA2Core and then running it, i see only one kernel printed out.  prior experiments using anonymous inline Kernel (){} printed the kernel each iteration.  cards are 2 amd 6970's, fwiw.  I had to symlink the old fglrx opencl driver over top of the one in /AMDAPP in order to see the demos run.  (ubuntu 12.04)
Reply all
Reply to author
Forward
0 new messages