OpenCL* for CPU
Ask questions and share information on Intel® SDK for OpenCL™ Applications and OpenCL™ implementations for Intel® CPU
Announcements
This forum covers OpenCL* for CPU only. OpenCL* for GPU questions can be asked in the GPU Compute Software forum. Intel® FPGA SDK for OpenCL™ questions can be ask in the FPGA Intel® High Level Design forum.
1663 Discussions

Weird behaviour of atomic functions

mheimel
Beginner
188 Views
Hi,
I tried implementing a simple lock/mutex using OpenCL atomic functions. The following kernel demonstrates the general idea:
__kernel void lock() {
volatile __local int mutex;
// Every thread waits until it gets the lock.
int done = 0;
while (!done) {
// Try to get the lock
int lock = !atomic_cmpxchg(&(mutex), 0, 1);
if (lock) {
done = 1;
// Release the lock
atomic_xchg(&(mutex), 0);
}
}
return;
}
On my Nvidia GPU, the kernel works fine. However, on the latest Intel OCL SDK (version 2.0.31360.31426 on x64 Linux, running on Xeon CPU) the kernel seems to deadlock. Am I missing something here?
Max
0 Kudos
1 Reply
Evgeny_F_Intel
Employee
188 Views

You made an assumption of parallel execution of work items. However, it's not a always true.
The appropriate way to synchronize inside a work group is barrier() built-in.
Thanks,
Evgeny

Reply