Using atomicCAS(long long) on a pointer to struct type

I saw a post on using atomicCAS() on two fields at once, and it was suggetsed to use atomicCAS(long long) on a structure.
http://forums.nvidia.com/index.php?showtopic=205714

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.”

Thanks much.

//-----------------------------------------

myType* a;
myType* b,
myType* c;

// some code here

uintptr_t a_intptr = (uintptr_t)(a);
uintptr_t b_intptr = (uintptr_t)(b);
uintptr_t c_intptr = (uintptr_t)©;
unsigned long long int a_longlongint = (unsigned long long int)a_intptr;

if (atomicCAS(&a_longlongint,(unsigned long long int)b_intptr,(unsigned long long int)c_intptr))
// do something.

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]

Also make sure your structs are properly aligned.

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.

Thanks much.

Yes.

Yes, they do.

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.