Altera_Forum
Honored Contributor
12 years agoAtomic operation on global memory
Atomic operation on global memory do have some problem based on my code.
The value of global_offset[0] is 508 after the fpga computation, it should be 512. __attribute__ ((reqd_work_group_size (128,1,1))) __kernel void global_atomic_loop( __global int *global_offset, int num_elem) // num_elem is 512 in my host code. { const unsigned int local_id = get_local_id(0); if (local_id == 0) { global_offset[0] = 0; } barrier(clk_local_mem_fence); int i; for ( i = local_id; i < num_elem; i += 128 ) { int addr = atomic_add(&global_offset[0], 1); global_offset[addr + 1] = i; } }