ATOM_SUB(3clc)
π ATOM_SUB π
okay bestie, welcome to the OpenCL Manual β this little cutie right here is the page for atom_sub, specifically the 64-bit era of her life. she's an atomic function, she's doing math on your memory, and she's doing it in one (1) transaction. main character energy fr fr β¨
β¨ NAME β¨
atom_sub β the 64-bit atom_sub functions. that's the whole name, she's not doing too much, she's just doing her job π
and here's the squad, look at them, four of them, all gorgeous:
long atom_sub(volatile global(3clc) long *p, long val);
long atom_sub(volatile global(3clc) long *p, long val);
ulong atom_sub(volatile local(3clc) ulong *p, ulong val);
ulong atom_sub(volatile local(3clc) ulong *p, ulong val);
(yes bestie, they're listed twice each. no, i'm not gonna "fix" it. i don't make the rules, i just report them faithfully π«Ά)
πΈ DESCRIPTION πΈ
so what is she actually doing? okay so:
she reads the 64-bit value at the location pointed to by p β and we're gonna call that value old, that's its name now, it's been christened β then she computes (old - val) and stores that result at the location pointed to by p. and what does she return? she returns old. the ORIGINAL value. not the new one. not the difference. old. π
if you were expecting the new value back, bestie... no. she gives you the old one. that's the vibe check and she passed it.
about the extension tho β if you actually wanna use this, your application needs to include this in the OpenCL program source:
#pragma OPENCL EXTENSION cl_khr_int64_base_atomics : enable
like, you can't just roll up without it, that's the entry fee π
the atomicity tea β β this function is performed in one atomic transaction. and these transactions are atomic for the device executing these atomic functions. and here's the part where you gotta pay attention:
There is no guarantee of atomicity if the atomic operations to the same memory location are being performed by kernels executing on multiple devices.
one device? slay, we love her. multiple devices hitting the same memory location? you are on your own, no promises, nothing guaranteed π
one more thing β atomic operations on 64-bit integers and 32-bit integers (and float) are also atomic with regard to each other. so the 64-bit girlies, the 32-bit girlies, and even the float girlies are all atomic with respect to each other. everyone's in the group chat, everyone's atomic, we love a cohesive unit β¨
π SPECIFICATION π
the OpenCL Specification[1] β she's citing her sources, academic queen π
π SEE ALSO π
go read these next, bestie, they're all connected, it's a whole cinematic universe:
π«Ά 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.
(translation: do whatever, just keep the notice. it's giving generous, it's giving open, it's giving free π)
π NOTES π
- OpenCL Specification β page 279, section 6.12.11 - Atomic Functions for 32-bit integers. (iykyk, go look it up, page 279, section 6.12.11, i said what i said π¦)
and that's the whole page bestie!! π she was brought to you by The Khronos Group, dated 01/14/2021, and you can find her filed under ATOM_SUB(3clc) whenever you need her. go forth and atomically subtract, you absolute icon π§πΈ
π¦ 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