OpenCL Continuous Kernel?

Started by
3 comments, last by Bacterius 11 years, 5 months ago
I am just starting to learn how to use opencl and from what I can tell there doesnt seem to be a way to run the kernel and read/write the buffers constantly I only see ways of running the kernel then getting the response and restarting the kernel which to me would seem like a huge waste if say some of the threads take longer than others wouldn’t the done ones have to sit around waiting?
Advertisement
That's quite hard to read because there's no punctuation. Even though I'm reasonably sure where you intended your sentences to end, I'm confused. There's a question mark at the end but the sentences do not seem to form a question of any kind.
It won't matter, if you have lots of work-items, which you should have. The threads that complete the kernel just restart and run it again for another work-item, so if you have a million work-items and a thousand threads it won't even be noticeable if one of those threads takes 100x longer than the others, as the others will run 1000 times anyway. If you only have as many work-items as there are cores, then yes all the others will wait for the slowest one, but if you have such a complex kernel that's run so few times then OpenCL probably isn't the right tool for the job. In that case, either do it on the CPU instead or try to change your kernel into a smaller kernel that runs 10x as many times and does part of the work each time.
Hi Stroppy
your absolutely correct I wrote it on the way out the door and was pretty exhausted sorry about that.

Hi Erik
That does make sense I wasnt thinking about it that way until today and realize that I cant think of it as a function to a program but an entire program it self.

Another thought is what if I want results back as fast as possible then I would have to stop all the threads so the buffer could be read correct?
Then in that scenario it would have to restart the kernel since I had to stop everything to be read. Or is their a way to read the output but continue processing?
You cannot interrupt a kernel in progress except by crashing the driver (and losing all your output buffers in the process). GPU's do not support that kind of execution yet. What I usually do when I need my application to be responsive is to design the kernels to do the absolute minimum amount of work possible in a single kernel enqueue, and just submit them to the card a lot faster, that way I can interrupt it CPU-side whenever and have everything stop quickly.

As for reading back, I suppose you could copy the output buffer to a temporary buffer (still GPU-side), keep launching your kernels and read from that, so that you could still get your card to work while DMA-copying the last execution's results to the CPU, but be wary that if your kernels finish faster than you can actually get your output back to the CPU (for a discrete card, that's generally 4GB/s bandwidth) you will run out of buffer memory, so it's not a great idea.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

This topic is closed to new replies.

Advertisement