Altera_Forum
Honored Contributor
7 years agochannel deadlock
The below source code is used in opencl programming guide. It is told that without using "mem_fence(CLK_CHANNEL_MEM_FENCE)", the consumer module might end up with deadlock.
1) Consider a case where producer has written in channel c0 first and consumer has read from channel c1. Consumer is currently reading from empty channel. It would stall for couple of cycles but why would there be a deadlock? 2) Cant producer write in channel c0 and c1 in parallel? __kernel void producer (__global const uint * src, const uint iterations) { for (int i = 0; i < iterations; i++) { write_channel_intel(c0, src[2*i]); write_channel_intel(c1, src[2*i+1]); } } __kernel void consumer (__global uint * dst, const uint iterations) { for (int i = 0; i < iterations; i++) { /*During compilation, the AOC might reorder the way the consumer kernel writes to memory to optimize memory access. Therefore, c1 might be read before c0, which is the reverse of what appears in code.*/ dst[2*i+1] = read_channel_intel(c0); dst[2*i] = read_channel_intel(c1); } }