ATOM_CMPXCHG(3clc)

πŸ“¦
version 1.0~svn33624 Β· 3 versions
, in ubuntu jammy, ubuntu noble

πŸ’– NAME πŸ’–

atom_cmpxchg β€” the 64-bit atom_cmpxchg functions, bestie. it's giving "compare and swap but make it 64-bit" ✨

long atom_cmpxchg(volatile global(3clc) long *p, long cmp, long val);

long atom_cmpxchg(volatile global(3clc) long *p, long cmp, long val);

ulong atom_cmpxchg(volatile local(3clc) ulong *p, ulong cmp, ulong val);

ulong atom_cmpxchg(volatile local(3clc) ulong *p, ulong cmp, ulong val);

okay and yes, we're in the OpenCL Manual section 3clc, in case you were wondering where you even are rn 🫢


🌸 DESCRIPTION 🌸

okay so here's the whole vibe. you read the 64-bit value (we're calling it old) that's sitting at the location pointed to by p. then you compute (old == cmp) ? val : old and store that result right back at the location pointed to by p. and the function hands you back old. that's it. that's the whole thing. πŸ’…

if your app wants in on this extension, you gotta include this in your OpenCL program source:

#pragma OPENCL EXTENSION cl_khr_int64_base_atomics : enable

no pragma, no party. πŸ™ˆ

this function goes down in one atomic transaction. and like, these transactions are atomic for the device executing these atomic functions β€” so if you're on one device, you're golden πŸ‘‘

but listen. there is no guarantee of atomicity if the atomic operations to the same memory location are being performed by kernels executing on multiple devices. none. zero. don't come for me, that's just the spec. πŸ’€

also, atomic operations on 64-bit integers and 32-bit integers (and float) are also atomic with regard to each other. so they're all in the same little atomic friend group. iconic. 🌈


⭐ SPECIFICATION ⭐

OpenCL Specification[1]


πŸ¦‹ SEE ALSO πŸ¦‹

go read those next, bestie, they're all connected iykyk πŸ’œ


πŸŽ€ AUTHORS πŸŽ€

The Khronos Group πŸ‘‘


Copyright Β© 2007-2011 The Khronos Group Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and/or associated documentation files (the "Materials"), to deal in the Materials without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Materials, and to permit persons to whom the Materials are furnished to do so, subject to the condition that this copyright notice and permission notice shall be included in all copies or substantial portions of the Materials.

like yes the lawyers wrote that part but it slaps fr fr, keep the notice in your copies periodt πŸ“œ


🌟 NOTES 🌟

  1. OpenCL Specification page 279, section 6.12.11 - Atomic Functions for 32-bit integers

okay that's the whole page, you ate it, you understood it, main character energy only πŸ’…βœ¨

little sign-off moment: this came to you from The Khronos Group, dated 01/14/2021, filed under ATOM_CMPXCHG(3clc). mwah, take care of your atomics πŸ«ΆπŸŽ€

πŸ“¦ where this page comes from