ATOMICMIN(3G)

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

πŸ’– NAME πŸ’–

atomicMin β€” perform an atomic min operation to a variable.

Bestie, you're reading the 3G manual page for her. (Yes the header really does say ATOMICMIN(3G), and yes there's a little [FIXME: manual] placeholder hanging out up there too β€” we love a work in progress. πŸ™ˆ)


✨ DECLARATION ✨

Two whole flavors, both iconic:

int atomicMin(inout int mem, int data);

uint atomicMin(inout uint mem, uint data);

πŸŽ€ PARAMETERS πŸŽ€

  • mem β€” the variable that's being used as the target of the operation. She's the main character here, the one getting written to.
  • data β€” the data that gets compared against mem.

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so here's the whole plot: atomicMin does an atomic comparison of data against whatever's currently sitting inside mem. Then she writes the minimum value into mem β€” and she returns the original contents of mem from before the comparison happened. So you get the old value back, and mem walks away holding the smaller one. Queen behavior. πŸ‘‘

And here's the part that's genuinely the best: the contents of the memory being updated by the atomic operation are guaranteed not to be modified by any other assignment or atomic memory function in any shader invocation between the time the original value is read and the time the new value is written. Translation: nobody gets to cut in line mid-operation. No cap. πŸ’…

⚠️ Okay so this next bit matters a LOT. Atomic memory functions are supported only for a limited set of variables. A shader will fail to compile if the value you pass to the mem argument of an atomic memory function does not correspond to a buffer or shared variable. So like, double check that before you come crying to me. 😭

Now the good news: it is totally acceptable to pass an element of an array or a single component of a vector to the mem argument of an atomic memory function β€” as long as the underlying array or vector is a buffer or shared variable. Slay. ✨


🌈 VERSION SUPPORT 🌈

Here's the vibe check on which OpenGL Shading Language Versions actually support atomicMin (βœ” = she's here, - = not yet, babe):

  • 1.10 β€” -
  • 1.20 β€” -
  • 1.30 β€” -
  • 1.40 β€” -
  • 1.50 β€” -
  • 3.30 β€” -
  • 4.00 β€” -
  • 4.10 β€” -
  • 4.20 β€” -
  • 4.30 β€” βœ”
  • 4.40 β€” βœ”
  • 4.50 β€” βœ”

So basically she showed up in 4.30 and has been booked and busy ever since. 🫢


πŸ’… SEE ALSO πŸ’…

Her whole friend group, go say hi:

  • atomicAdd()
  • atomicAnd()
  • atomicOr()
  • atomicXor()
  • atomicMax()
  • atomicExchange()
  • atomicCompSwap()

Copyright Β© 2011-2014 Khronos Group. This material may be distributed subject to the terms and conditions set forth in the Open Publication License, v 1.0, 8 June 1999. http://opencontent.org/openpub/.

Copyright Β© 2012-2014 Khronos Group


Okay that's the whole page, you're officially educated. πŸ’– This one came out of [FIXME: source], dated 01/03/2018, and it's filed under ATOMICMIN(3G). Go forth and min atomically, bestie. 🌸

πŸ“¦ where this page comes from