ATOMIC_XCHG(3clc)
π ATOMIC_XCHG π
okay bestie, welcome to ATOMIC_XCHG(3clc) from the OpenCL Manual β¨ this one is short, it's sweet, and it's giving main character energy in the world of atomics π«Ά
πΈ NAME πΈ
atomic_xchg β the atomic_xchg functions. yes that's the whole name. she's humble π
here's the whole squad, literally every single one of them, no cap:
int atomic_xchg(volatile global(3clc) int *p, int val);
unsigned int atomic_xchg(volatile global(3clc) unsigned int *p,
unsigned int val);
float atomic_xchg(volatile global(3clc) float *p, float val);
int atomic_xchg(volatile local(3clc) int *p, int val);
unsigned int atomic_xchg(volatile local(3clc) unsigned int *p,
unsigned int val);
float atomic_xchg(volatile global(3clc) float *p, float val);
look at all those overloads π¦ global and local, int and unsigned int and float β she said "I contain multitudes" and honestly? periodt π
β¨ DESCRIPTION β¨
so what does she DO. okay so basically: she swaps the old value that's chillin at location p with the new value you hand her in val. that's it. that's the whole bit π
and then β and this is the slay part β the function returns the old value. so you get to keep the thing that was there before, like a little souvenir π
not me just casually doing a whole read-and-write in one atomic step, obsessed π
also!! there's a 64-bit version of this function, atom_xchg(3clc), and it's enabled by cl_khr_int64_base_atomics(3clc) β (yes the name is different, yes that's on purpose, don't @ me, that's just how the extension rolls π)
π SPECIFICATION π
OpenCL Specification[1] β that's the source of truth, bestie π
π¦ SEE ALSO π¦
go read these too, they're part of the friend group:
π AUTHORS π
The Khronos Group β icons only π
π 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 following condition:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Materials.
okay so the legal bit: keep the copyright notice and the permission notice in all copies or substantial portions of the Materials. it's giving "you can do whatever but don't erase my name" π
π NOTES π
- OpenCL Specification, page 279, section 6.12.11 - Atomic Functions for 32-bit integers
and that's the whole page, bestie π courtesy of The Khronos Group, dated 01/14/2021 β go forth and swap your values atomically, you absolute legend π«Άβ¨πΈ
π¦ 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