Giter Club home page Giter Club logo

Comments (8)

GoogleCodeExporter avatar GoogleCodeExporter commented on June 15, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 15, 2024
[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.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 15, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 15, 2024
[deleted comment]

from aparapi.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 15, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 15, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 15, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 15, 2024
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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.