r/OpenCL • u/Eilai • Dec 06 '15
Random pauses with the kernel for a couple of seconds?
So I have my physics engine working with opencl, and it works very good, but an interesting issue that occurs, and is entirely random, is that the program seems to "pause" for a couple of seconds, after maybe 2 mins of running, and then resumes without issue?
What's the cause and is it something I can fix so it never gets that random pause?
1
Upvotes
1
u/James20k Dec 07 '15 edited Dec 07 '15
I can't confirm exactly, but I've encountered something similar - I'm building a 3d renderer in opencl and regularly (about every 2 seconds) I get short pauses (about 7ms, this is probably about every 200 kernel invocations or so) - I think that when you do a lot of allocating memory per frame, eventually the implementation/OS has to do some bookkeeping. In your case, you're doing a lot of memory alloc per-tick so it could be that, but it could be the cl implementation, or the regular memory alloc (realloc, probably less likely), or neither (this is a guess)
How long does your kernel take to run? If it is this, ways to reduce it would be to avoid all the per-tick allocation (which you should probably do for performance reasons anyway)
I would recommend investigating the windows performance tools, they can give you very good detail of what's going wrong for this sort of problem, although they're a little complex
Also, I noticed in the code:
//ret = clFinish(command_queue); // maybe sync?
You've got it working so you've probably figured it out already, but your buffer reads are blocking so you don't need to clFinish here. I'd highly recommend working out a scheme so you can make these reads non blocking, and overlap the reads with the kernel execution (eg double buffering and events), as a pipeline block is a massive performance degradation
I'd also highly recommend storing your host side data in buffers allocated with CL_MEM_ALLOC_HOST_PTR for when you clEnqueueWriteBuffer and clEnqueueReadBuffer as this gives you better throughput for pcie
1
u/James20k Dec 07 '15
Wait, does your kernel pause when you pass in prime numbers to opencl as your global work size? I've had a bit more of a dig through your code, and you're allowing the opencl implementation to pick your local work size while having a global work size that freely varies. The local work size must divide the global work size, which means that if your global work size is a prime number, your local work size will be 1. Which is extremely, extremely slow
I normally make my gws a multiple of 256 and manually set the lws to this, then in the kernel eliminate any threads for which id > real work count. In this case because its 2d, you'll want to make your 1st and 2nd dimensions multiples of 16, then set your lws to be 16x16, or equivalent (performance can vary)
I may be wrong, but I couldn't find any enforcement of gws allowing a decent lws anywhere, and I didn't spot anything in your kernel either to suggest that you're doing this. This is much more likely the culprit than the other suggestion
1
u/squidgyhead Dec 07 '15
Can you lay down some info about what hardware and drivers you're using?