Comments (8)
Alex
There were various possible targets for @Local, which were you trying to use?
Given this class
public class MyKernel extends Kernel{
@Local int thisField
@Local int thisArrayField[] = new int[100];
public void run(){
@Local int thisLocalVariable;
@Local int thisLocalArray[] = ??;
}
}
We only support the 'thisArrayField[]' from the example above.
'thisField' would be useful if the variable was read-only. We don't allow
writing to fields (not in generated OpenCL at least) because each work item
gets it's own thread so instance fields would cause a race (same in JTP
actually!)
Possibly @Local static int primitive might make sense.
thisLocalVariable would be possible (not supported yet).
thisLocalArray would not be possible (we don't allow array aliasing).
But I would be interested in which of these you were wanting.
Gary
Original comment by [email protected]
on 27 Feb 2012 at 10:45
from aparapi.
[Nice presentation of the concept!]
So, I was referring to thisField and thisArrayField[]. thisArrayField[] works
as expected, but the wiki about @Local gave me the impression that thisField
would work as well, especially considering that a one-element thisArrayField[]
works.
My idea was to have thread 0 of each group write the field so that other work
items in the same group wouldn't have to access it from the global memory.
Something like:
public class MyKernel extends Kernel{
@Local int thisField = 0;
public void run(){
if (getLocalId() == 0){
thisField = anArrayFromTheGlobalMemory(this.getGroupId());
}
localBarrier();
}
}
Original comment by [email protected]
on 27 Feb 2012 at 11:05
from aparapi.
Yes we don't actually support write to fields. In a weird way it is best to
think of fields as args. Actually that is what we do we convert the accessed
fields into OpenCL args. For primitive scalars we use openCL's clSetKernelArg,
for arrays we create buffers and set the buffer as the arg. So because of the
normal copy by value of scalars modifying a scalar field does nothing. For each
work item it does change the arg for a while, but can never be seen by another
work item executing.
Run aparapi with -Dcom.amd.aparapi.enableShowOpenCL=true and take a look at the
args, I think it will help explain why fields are not mutable unless they are
arrays.
However, I think that if the field was a static field. We might be able to
infer that it can be changed and convert it to a one element array (behind the
scenes). This then would also work from Java and OpenCL side.
However, we don't have this yet ;) Sorry about that. I will modify the wiki
page to try to explain this.
Original comment by [email protected]
on 28 Feb 2012 at 12:53
from aparapi.
[deleted comment]
from aparapi.
Well, glad to have sorted it out :-) . I will take look at the generated code
as well.
Original comment by [email protected]
on 28 Feb 2012 at 1:14
from aparapi.
What OpenCL args? What do they have to do with local memory?
Local memory is a little bit (16-48KB) of very fast SRAM that is located inside
a GPU core and can be used as a scratchpad or a manual cache by the
threads/work-items of a block/work-group. It has nothing to do with passing
args (which should go into global mem).
A Local scalar makes perfect sense. "We don't allow writing to fields (not in
generated OpenCL at least) because each work item gets it's own thread so
instance fields would cause a race (same in JTP actually!)" And that's the
reason for having barriers...
Original comment by [email protected]
on 16 Feb 2013 at 12:41
from aparapi.
See
http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/clSetKernelArg.html
Scroll down to the description of arg_value and arg_size.
OpenCL allows you to allocate local memory (on the GPU) by setting an ARG as
local and defining the size. We use this mechanism to allocate local buffers,
because it allows us to vary the local size without recompiling the Kernel.
Gary
Original comment by [email protected]
on 16 Feb 2013 at 12:46
from aparapi.
Oh, I see. You pass a local memory pointer as a way of creating a variable-size
local memory array.
It is also possible to declare constant-size arrays and scalars. In OpenCL
they're method-scoped variables. In fact, I would say they are more common than
variable-sized arrays (since fixed size or scalar is simpler than variable).
I think you should support them, for the sake of consistency. I am not sure how
you are generating the OpenCL or the Java fallback, but I expect you have
enough flexibility. (For Java fallback, I would make @Local variables
non-static fields and @Global variables static. I would then make one object
per work group, rewrite work-items as for() loops in the object's run() method,
and make method-scoped @Local variables into the non-static fields.)
Original comment by [email protected]
on 16 Feb 2013 at 1:38
from aparapi.
Related Issues (20)
- Invoking kernels with single boolean fields in kernel causes NoSuchFieldError in JNI
- Problem when running with NVIDIA GPUs HOT 8
- Generating OpenCL
- Patch for /trunk/samples/add/src/com/amd/aparapi/sample/add/Main.java
- fatal error when disposing a 2D float execution kernel HOT 2
- Failed to load aparapi native library
- 2D arrays management HOT 2
- FFT Extension example fails to run HOT 1
- Add support for Intel Xeon Phi
- Trouble running samples in lambda branch on Kaveri HOT 6
- Release in the downloads section is old and no guide on how to compile on Mac HOT 1
- High total processing/running time on GPU mode w/Aparapi HOT 2
- Aparapi can't find OpenCL HOT 21
- Mandel Works Fine With The GPU But, When I Run My Code From BlueJ It Doesn't Work HOT 1
- Can i Run Aparapi on "Nvidia Gpu" or "Intel Gpu"? HOT 4
- Missing Sync or Volatile with Aparapi HOT 2
- Dump modified Java bytecode HOT 4
- Please update the tutorial about HSA settings
- Adding Vector data type at Aparapi HOT 1
- OpenCL compile fails... sometimes? (w/ Processing)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aparapi.