Spinlock functionality?

I can’t seem to find anything standard in CUDA for simple locking functionality?
I need a warp to output non-trivial struct in an atomic manner. I was hoping I wouldn’t have to write spinlock/mutex myself and instead use something already written and tested.

There is cuda::atomic<T, scope> Extended API - libcu++ though I don’t know if this is want you need.

Could you show your current code which requires locking?

atm. various stats reduced to a rather big structure (mostly doubles and int64s) . So I go around using a long chain of atomic operations. But I wonder for general case, like when you need to assemble a linked list or something non-trivial in memory.

I’m not aware of CUDA providing anything beyond atomics for this purpose.

CUDA’s atomicCAS() seems like the appropriate building block for any kind of mechanism like this. Before going down that path, one might ponder whether programming with spinlocks is the most “CUDAic” way of addressing whatever the use case is.

Thank you all for the answers and Merry Christmas everyone!

I’m surprised that you have to roll out some sort of simple lock yourself. It’d be very handy if cuda sdk provided mutual exclusion primitive. Writing it yourself opens possibility of getting memory order wrong and thus introducing hard to catch bugs.
Regarding CUDAic way, I would agree, but sometimes a simple spinlock is just good enough and any more time spent on a re-write is just not worth the prize, and sometimes there’s just no lock-free way of achieving a solution.
If anyone can point me to a well-tested 3rdparty library with a spinlock , please advise.

Consider filing an enhancement request with NVIDIA.