ATOMIC_XCHG(3clc)

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

πŸ’– 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 Β© 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 πŸ“

  1. 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