Re: Multi-GPU processing inconsistent.
Posted by The.Scotsman on Mar 27, 2015; 11:49pm
URL: https://forum.jogamp.org/Multi-GPU-processing-inconsistent-tp4031306p4034210.html
Solved.
The problem lies where data is copied to CL, like this:
FloatBuffer localBuff = myObject.getMyData();
localBuff.rewind();
CLBuffer<FloatBuffer> clBuff = clContext.createFloatBuffer(...);
clBuff.getBuffer().put(localBuff);
clBuff.getBuffer().rewind();
...because, in a parallel environment, multiple threads can be accessing this data simultaneously.
Some threads may be on the "put" line, others in the "rewind" line.
The solution is to synchronize this small section of code (I created a separate method, because I do this a lot):
FloatBuffer localBuff = myObject.getMyData();
CLBuffer<FloatBuffer> clBuff = clContext.createFloatBuffer(...);
synchronized(localBuff) {
localBuff.rewind();
clBuff.getBuffer().put(localBuff);
}
clBuff.getBuffer().rewind();
Hope this helps somebody.