Forum Discussion
Altera_Forum
Honored Contributor
8 years agoCorrect me if I wrong: you are saying that in the code you have posted, even if you uncomment the fences, the k0_end flag is received and the k1 kernel jumps out of the while loop before all data from the "ch12" channel is processed?
If this is the case, I can think of a case where this could happen. You should remember that channel reads/writes might not happen every clock. Since the pipeline in the "k1" kernel is longer, it is possible that the distance between reading "ch01" and "k0_end" in kernel "k1" could be longer than the delay to write to both "ch01" and "k0_end" in the "k0" kernel. Hence, it is possible that at a specific cycle, when the "ch0" channel is empty, but the write loop in k0 has not finished yet, the read from "ch0" in kernel "k1" fails and hence, "data_valid' becomes false. After that, by the time the pipeline in kernel "k1" reaches the read from "k0_end", kernel "k0" has written the last data to "ch0" and the end flag to "k0_end"; hence, kernel "k1" sees the exit flag, without processing the data that has been written to the "ch0" channel after the last read attempt. This is a concurrency issue and cannot be fixed using fences. However, it is very easy to fix by using only one channel instead of two; i.e. instead of sending your exit flag via a separate channel, send it using the same channel that you use for your data. This way, it is impossible for any data to remain in the channel after the exit flag is received. Though you will need to choose some value for the exit condition that will never exist among your data so that you can differentiate between that and your actual data.