ATOM_CMPXCHG(3clc)
π 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 π
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 π
- 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
- ubuntu jammy: opencl-1.2-man-doc 1.0~svn33624-5 Β· other
- ubuntu noble: opencl-1.2-man-doc 1.0~svn33624-5 Β· other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms