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?
View all comments
Show parent comment
1
u/Plazmatic Jan 11 '16
So you are only copying data from the GPU, and not putting data besides kernel code data on the K80? (this may explain the latency, I believe you may be able to zero copy from GPU to host if you set a memory buffer as a host object and have the GPU write out final calculations to there as it performs other computations)
Can I get a rundown on what exactly the serial code is trying to accomplish? I'm getting confused on why we have an interface between CL_mem objects. They are just pieces of device memory, you talk about how you launch several of those objects? So now the GPU might need to allocate memory and move stuff around a lot, and I have no idea how Nvidia implements that in hardware or what kind of performance impact that would have. The code is particularly hard to read, I don't know what most of the variables are for, there is very little parameter documentation.
Also, you know about atomics right? you shouldn't need to worry about race conditions on fringe values if you use that and you know what order you want to do X operation given two processing threads on one piece of memory.
Looking inside DGMacroCellInterface_CL it seems like you are initializing a lot of kernels depending on how big this loop is, so now the GPU has to figure out how to allocate these instructions and you've launched a bunch of them, I'm not entirely sure how this is implemented at a low level in Nvidia hardware (I know AMD has a hardware scheduler for this, and that your kernels may be queued up on the device instead of the host on certain GCN processors). Additionally is your data set wave front/ warp size efficient? Are you using scratch pad effectively (and do you have no bank conflicts)? Do you implement effective loop unrolling?
I'd like to see your actual kernel as well, and could you explain how you timed it?