سؤال

I'm experiencing strange bug with my OpenCL kernel. Basically it's bitonic sort upgraded to N != pow of 2. What I do is that I check back on host if the sequence is ordered correctly and what brought me here was the answer NOT.

Now the bug is very difficult to trace because it happens randomly. I sort many different sequences that I generate each time the same way and it just occurs that one sequence is not sorted, then the other.. However high percentage of outputs is correct and also my host implementation in for cycle sorts the same input correctly. What's the funniest thing is that when I keep input and run it once more on device, it is suddenly sorted correctly.

I came up with idea that this might be race condition, because it acts just like that. However I don't have place for such thing in device code so only possibility is host. I have in-order queue and my reads and writes are blocking so there shouldn't be a problem with that, however I don't have synchronization points after executing kernels.

Is such synchronization needed? What OpenCL guarantees for in-order queue? Am I possibly reading before kernel finished all of its operations on the same memory piece?

The only other idea for this random occurrence is faulty memory in device, but that's last option I would accept, so I'll also welcome some other ideas of when one gets random results/bugs with OpenCL.

هل كانت مفيدة؟

المحلول

According to the spec, if you have an in-order queue, your kernels and memory reads/writes will complete in the order in which they were queued: see clCreateCommandQueue here http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/.

If you want to make 100% sure that that's the case, you can enqueue a barrier before the memory read.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top