Quantcast
Channel: Altera Forums
Viewing all articles
Browse latest Browse all 19390

mem_fence() not working for channels

$
0
0
Hi all,

I am testing the function of the feed-forward model(ping-pong buffer) mentioned in the programming guide. And I found the mem_fence function is not working. Here's the code I used for testing:

channel int c_id __attribute__((depth(100)));

__attribute__((reqd_work_group_size(10,1,1)))
__kernel void producer (__global int *restrict x, __global volatile int *restrict producer_data){
int global_x = get_global_id(0);
producer_data[global_x] = global_x;
mem_fence(CLK_CHANNEL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
write_channel_altera(c_id, global_x);
}
__attribute__((reqd_work_group_size(10,1,1)))
__kernel void consumer (__global int *restrict y, __global volatile int *restrict producer_data, __global int *restrict output) {
int global_x = read_channel_altera(c_id);
int sum2 = producer_data[global_x] + global_x;
output[global_x] = sum2;
}


The producer_data[] is initialized to zero. The producer kernel writes it's global id to the producer_data[global_x] and channel. After the consumer kernel reads from the channel, it writes producer_data[global_x] + global_x to output[global_x]. The value of output[global_x] should always be global_x * 2.

However in my experiment, the output array is not always global_x * 2, sometimes output[global_x] = global_x. The consumer kernel reads the data before producer writes to global memory. mem_fence() here is not working.

I guess the problem lies with the way to create a shared buffer. I put the producer and consumer kernels in different command queues for the concurrent execution and use clCreateBuffer(...,CL_MEM_READ_WRITE,...) to create a shared buffer. The programming guide mentioned clCreateBuffer(...,CL_MEM_READ_WRITE,...) allocates memory to nonshared DDR memory banks and shared memory should be allocated by using clCreateBuffer(...,CL_MEM_ALLOC_HOST_PTR,...). However, when I am using the clCreateBuffer(...,CL_MEM_ALLOC_HOST_PTR,...) function, these two kernels cannot execute concurrently. Consumer kernel will wait until producer kernel finishes.

How to allocate the shared buffer for two concurrent kernels? Any example host code for the feed-forward model(ping-pong buffer) will greatly help.

Thanks in advance.

Viewing all articles
Browse latest Browse all 19390

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>