cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

mattscar
Journeyman III

Aparapi and Work-Groups

Having a problem with getLocalId()

I'm trying to code an Aparapi kernel with 8 work-items and 4 work-groups. I call setSizes(8, 4) and kernel.execute(8), but when I call getLocalId, the numbers vary from 0 to 7 instead of 0 to 4.

 

My code is attached. If I'm doing something wrong, please let me know.

package aparapiTest; import com.amd.aparapi.Kernel; public class AparapiItems { public static void main(String[] args) { final int numItems = 8; final int numGroups = 4; final float[] itemInfo = new float[numItems]; Kernel kernel = new Kernel(){ public void setSizes(int gSize, int lSize) { super.setSizes(numItems, numGroups); } public void run() { itemInfo[getGlobalId()] = getGlobalId() * 10.0f + getGlobalSize() + getLocalId() * 0.1f + getLocalSize() * 0.01f; } }; kernel.execute(numItems); for(int i=0; i<numItems; i++) System.out.println(itemInfo); } }

0 Likes
6 Replies
Marco13
Journeyman III

At least in the given code there seems to be no call to setSizes... Are you sure you are calling it in your real application?

0 Likes

setSizes is a protected method, so you can't just call kernel.setSizes. You have to add code to the method yourself. I've done this inside my class definition.

 

Oddly, getLocalSize() returns the proper work-group size. But getLocalId() doesn't return the right local IDs.

0 Likes
gfrostamd
Staff

I think the Aparapi doc may have been misleading.

setSizes(...) is actually a callback to your Kernel to indicate the 'chosen' values for global/local size.  The intent is that if you needed to allocate a buffer of some data that was global/locals size dependant, you would use this notification.  You should not use this opportunity to change these values.

The idea is that we ask OpenCL (under the covers) for the ideal global local size and then just before execution we allow the Kernel to adjust (if desired) to use this information.

I think we will need to update the Java doc here.

Apologies for the confusion, and for not answering this earlier. 

 

 

0 Likes

No problem at all. I'm grateful for the reply.

 

I'd still like to know how I can recode my anonymous Kernel class to execute with 8 work-items and 4 work-groups. My code is attached.

Kernel kernel = new Kernel(){ public void setSizes(int gSize, int lSize) { super.setSizes(8, 4); } public void run() { itemInfo[getGlobalId()] = getGlobalId() * 10.0f + getGlobalSize() + getLocalId() * 0.1f + getLocalSize() * 0.01f; } };

0 Likes

Aparapi does not let you decide the local size.  You do get to choose the globalsize when you call kernel.execute(n).

Aparapi will work with the underlyig GPU device to choose the appropriate local size. 

You will be 'told' the chosen values via the setSizes() callback just prior to execution.

I am curious as to why you wish to control the value of localsize. 

 

0 Likes

I see. Thank you.

The Aparapi JavaDoc entry for setSizes states that "When kernel.execute(globalsSize) is invoked, Aparapi will determine the localSize based on the execution mode and the globalSize. If you override setSizes( int _globalSize, int _localSize) your overridden method will be called. Your method must call super.setSize(_globalSize, _localSize) to ensure that the kernel receives the correct value for localSize."

If setSize is supposed to give the local size instead of receiving it, then the JavaDoc needs to be changed.

To answer your question, I like to set the local size in regular OpenCL apps because work-items in a work-group can be synchronized.

 

 

 

 

0 Likes