From 6b18bca7f5daf641b4171aff1150bb8517ecd920 Mon Sep 17 00:00:00 2001 From: Mohamed Ibrahim <mibrahim@mibrahim.net> Date: Sat, 29 Aug 2015 08:08:41 -0400 Subject: [PATCH] AddingLambdasToAparapi.md --- doc/AddingLambdasToAparapi.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/doc/AddingLambdasToAparapi.md b/doc/AddingLambdasToAparapi.md index 4d8878ee..07e9ab9f 100644 --- a/doc/AddingLambdasToAparapi.md +++ b/doc/AddingLambdasToAparapi.md @@ -29,17 +29,19 @@ So you can run the familiar 'squares' kernel using int in[] = ..// int out[] = .../ Device.bestGPU().forEach(in.length, (i)->{ - out[i] = in[i]*in[i]; + out[i] = in[i] * in[i]; }); + Instead of int in[] = ..// int out[] = .../ Device.bestGPU().forEach(in.length, new IntConsumer(){ public void accept(int i){ - out[i] = in[i]*in[i]; + out[i] = in[i] * in[i]; } }); + To accomodate lambda's we created Device.forEach(int range, IntConsumer ic) which converts the bytecode of the ic parameter to OpenCL at runtime. The captured args (in, out and i - in this case) are passed to the GPU and the kernel executed. During our early experiments we encountered an interesting issue. The new 'lambdafied' javac uses Java 7 method handles and invoke dynamic instructions to dispatch the lambda code. It does this by injecting a call to a MethodHandle factory into the call site. At runtime, this factory creates a synthetic class (to capture call-site args) and passes this to our Device.forEach(). @@ -53,6 +55,7 @@ This will mean that in future we will change how Aparapi is launched. Instead of $ java -Djava.library.path=path/to/aparapi -classpath path/to/aparapi/aparapi.jar:your.jar YourClass + We will use $ java -agentlib=path/to/aparapi/aparapi.dll -classpath path/to/aparapi/aparapi.jar:your.jar YourClass @@ -100,4 +103,4 @@ or the range can be a lambda itself, here we specify a start and end value for t Device.bestGPU().forEach(1024, 1, r->{return(r/2);},(pass, r, id)->{lambda}); // or - Device.bestGPU().forEach(1, 1024, r->{return(r*2);},(pass, r, id)->{lambda}); \ No newline at end of file + Device.bestGPU().forEach(1, 1024, r->{return(r*2);},(pass, r, id)->{lambda}); -- GitLab