I’m trying to use atomicCAS on pointers meaning that I want to compare and swap where a pointer is pointing to.
I have pointers to a struct type (a, b, and c). I’m converting from myType* to uintptr_t and then convert from uintptr_t to unsigned long long int to use in atomicCAS(). (see example below)
Is this supposed to work corretly in CUDA? I’m currently running into kernel execution failures and I’m trying to diagnose it.
“Cuda error: Kernel execution failed in file ‘kernel.cu’ in line 330 : unspecified launch failure.”
Is there a reason why you operate on a copy of [font=“Courier New”]a[/font]? I would have expected the code to look something like
myType* a;
myType* b,
myType* c;
// some code here
if (atomicCAS(&(unsigned long long int*)a,(unsigned long long int)b,(unsigned long long int)c))
// do something.
One other thing to note is that this only works with pointers to global memory, or unified pointers on compute capability 2.x devices. Pointers to shared memory lose this attribute when being cast to [font=“Courier New”]unsigned long long int[/font] and back, so they access the same address in global memory instead (likely leading to the error message you are seeing). [EDIT: This applies to your original example, not my code]
Can atomic functions operate on dynamically allocated memory in global memory using CUDA in-Kernel malloc?
I’m not exactly sure that if pointers to dynamically allocated memory in global memory using malloc corresponds to “pointers to global memory” or “unified pointers” in your reply? Can these pointers keep this attribute when being cast to [font=“Courier New”]unsigned long long int[/font] and back? I’m working on a compute capability 2.x device.
They can on a 2.x device, but not on a 1.x device.
Casting to [font=“Courier New”]unsigned long long int*[/font] and back (i.e., casting between pointers of different type) however works on all devices, so my sample code is not concerned. I’ve edited my previous post to clear this up.