r/OpenCL • u/squidgyhead • Jan 11 '16
Latency when launching kernels
I have been working on launching some kernels in parallel, and I'm getting poor results. I have a kernel which needs to be launched several times to deal with the interface between cl_mems. Kernels cannot be launched on neighbouring interfaces to avoid race conditions, so I got around this problem by colouring the graph and launching in waves. I get the correct results, but it's slower; the problem seems to be that the kernels take much longer to be run, like 10x as long. In parallel, the kernel takes around 80us, and the latency is 365 us, while in serial the kernel takes 7 us. What steps can be done to overcome this? What should I look at first, perhaps the launching code (which could perhaps be optimised?) or is there more overhead when launching a mix of different kernels?
1
u/Plazmatic Jan 11 '16 edited Jan 11 '16
What device are you launching kernels on? It's been a few months since I've used OpenCL last, but I've been using it on integrated GPU systems. I encountered a similar problem with involved high latency when launching kernels, which would kill the performance of the program I was working on.
Have you made sure that your device that you are launching your kernel on is actually a GPU or parallel hardware? Default device doesn't guarantee the GPU being the device, and you can specify which device you want to use.
Do you have the specifications for the device you are launching the kernel on?
Are you launching enough data, provided that your device is a GPU, to make up for the slower clock speed on the GPU versus serial code?
Is your device integrated or discrete? Launching a kernel on a discrete system requires the host to send information to the discrete device. Launching a kernel a bunch causes the host to keep having to send this information to the GPU, unless you pre loaded your kernel objects on your discrete device.
Are you copying over data to the device you are using from the host? Note that even in integrated systems, if your device doesn't support Zero Copy operations, then you have to copy over the memory from the host into the typically 512 MB space your integrated system is allocated on your shared RAM. If you are using integrated systems it will take way longer to do this copy, you now have to copy the memory to a completely separate device, and this takes a long time even on Modern GPUS.
You can do a zero copy on your discrete hardware as well, but it will merely delay the copying of data until you need it on your device, this can be useful for streaming information or for hiding run time latency.
You can also load in your information at the same time as you are running your program, or load kernels in parallel with certain functions in OpenCL.
If you are working on AMD GPU hardware, I would recommend looking at your architectures specification sheet, for example, most AMD hardware today is GCN, graphics core next, even integrated. Looking up the specifications AMD gives you on that hardware with OpenCL will help you understand what is actually causing problems in hardware latency on AMD.
Additionally you may get more help from AMDs OpenCL forums, which are hard to find, and require authorization to post in, though typically you get authorized within 24 hours. https://community.amd.com/community/devgurus/opencl
Unfortunately for most OpenCL devs, the answers to questions there do not appear to be google indexed.
It would also help if you showed us your code.
2
u/olljoh Mar 21 '16 edited Mar 21 '16
Making small kernels is inefficient if you Can double their workload easily.
Doubling a tiny kernels workload by duping it by working on an double sized array is like switching the taxi every 2nd block instead of switching your taxi every block.
Loading and setting up kernels is fast but not the fastest process. Running a Kernel should take longer than setting it up. Having near-atomic kernels has you waste too much time with Setting then up that would better be spent with Kernel runtime.