ATOM_XOR(3clc)
π ATOM_XOR(3clc) β the OpenCL Manual, but make it make sense π
okay bestie, welcome to ATOM_XOR, straight out of the OpenCL Manual. yes it's a manual page, no it does not have to be boring. sit down, grab a boba, we're doing 64-bit atomics today and honestly? it's giving β¨ exclusive β¨. π¦
πΈ NAME πΈ
atom_xor β the 64-bit atom_xor functions. that's it, that's the name, she's simple and she's iconic. π
β¨ SYNOPSIS β¨
okay so here's the whole cast, no cuts, no edits, every single one of them:
long atom_xor(volatile global(3clc) long *p, long val);
long atom_xor(volatile global(3clc) long *p, long val);
ulong atom_xor(volatile local(3clc) ulong *p, ulong val);
ulong atom_xor(volatile local(3clc) ulong *p, ulong val);
yep, that's four lines, and yep, they come in pairs. don't come for me, I'm just the messenger, I copy them exactly as they are. π«Ά
π DESCRIPTION π
okay so the actual tea. β
she reads the 64-bit value sitting at the location pointed to by p β we're gonna call that value old, because that's literally what the manpage calls it and we respect her. then she computes (old ^ val) and stores the result right back at the location pointed to by p. and what does she hand back to you? she returns old. the original. the pre-glow-up version. periodt. π
now, plot twist, she's an extension, so you can't just waltz in and use her. if your app wants her, you have to include this exact line in your OpenCL program source:
#pragma OPENCL EXTENSION cl_khr_int64_extended_atomics : enable
that's the β¨ invite β¨. no invite, no party. π
this whole thing happens in one atomic transaction. one. transaction. no halfsies. and here's the important part bestie, listen closely:
these transactions are atomic for the device executing these atomic functions. there is no guarantee of atomicity if the atomic operations to the same memory location are being performed by kernels executing on multiple devices. π
so like... one device, we're slaying. multiple devices, we're on our own. noted.
also, and this is lowkey the cutest detail: atomic operations on 64-bit integers and 32-bit integers (and float) are also atomic with regard to each other. they're a friend group. they move as one. π
π SPECIFICATION π
OpenCL Specification[1] β that's the source of truth, the citation, the receipts. π§Ύ
π SEE ALSO π
go read her sisters, they're all doing numbers:
iykyk π
π AUTHORS π
The Khronos Group β yes, that Khronos Group. the ones who brought you the whole spec. absolute icons, no notes. π
π COPYRIGHT π
okay legal bestie moment, here's the whole thing, word for word, no paraphrasing because I am not getting us sued:
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.
slay, and also: legally binding. π
π NOTES π
- OpenCL Specification β page 279, section 6.12.11 - Atomic Functions for 32-bit integers. that's your footnote, bestie, go look it up. π₯
and that's the whole page!! π one last thing, the vibe check at the very bottom: this little beauty comes from The Khronos Group, dated 01/14/2021, filed under ATOM_XOR(3clc). she's 64-bit, she's atomic, she's that girl. go xor something. π β¨π¦πΈπ
π¦ 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