make handles bold.

This commit is contained in:
ed committed 2026-08-25 16:26:52 -04:00
1 parent f577242432
commit 69b87777e5
728 files changed
+3291 -3087

No files matched your search

@@ -26,291 +26,291 @@ parent_post_id: "1869436199884222515"
## Branch
**1/** @NOTimothyLottes
**1/** **@NOTimothyLottes** ^1869436525869724013
@AgileJebrim @SebAaltonen @munohikari
**@AgileJebrim** **@SebAaltonen** **@munohikari**
(3.) If you had multiple line stores collecting on a given line with ECC, you'd have the same bottleneck as fire-and-forget atomics. A throughput of one line modification per clock.
**2/** @NOTimothyLottes
**2/** **@NOTimothyLottes** ^1869436940334014771
@AgileJebrim @SebAaltonen @munohikari
**@AgileJebrim** **@SebAaltonen** **@munohikari**
(4.) Note the prior assumes a read hit!
So at the point you get anti-atomic, you are also anti-store and anti-ECC, and anti-etc. It's the same pipelines with the same variability due to on-chip networking, different clock domain crossing, etc.
**3/** @NOTimothyLottes
**3/** **@NOTimothyLottes** ^1869437450399170852
@AgileJebrim @SebAaltonen @munohikari
**@AgileJebrim** **@SebAaltonen** **@munohikari**
(5.) Good GPUs have multiple ALUs doing the atomic by the last level cache. So it scales very well as a function of line collisions. Meaning if all lanes access separate addresses on a cacheline, those go in parallel.
**4/** @NOTimothyLottes
**4/** **@NOTimothyLottes** ^1869437815936979150
@AgileJebrim @SebAaltonen @munohikari
**@AgileJebrim** **@SebAaltonen** **@munohikari**
(6.) Atomics and regular stores have the same memory controller base-camping behavior. If all SIMDs store to addresses that hash to the same last level cache partition, they will drop efficiency just like doing all atomics to the same address.
**5/** @NOTimothyLottes
**5/** **@NOTimothyLottes** ^1869438257983062074
@AgileJebrim @SebAaltonen @munohikari
**@AgileJebrim** **@SebAaltonen** **@munohikari**
(7.) Anyway, while CPU atomics are serious design fail, GPU atomics on good GPUs are your best friend. They are actually a fantastic tool for getting more regular performance in many parallel algorithms.
**6/** @SebAaltonen
**6/** **@SebAaltonen** ^1869438915679338644
@NOTimothyLottes @AgileJebrim @munohikari
**@NOTimothyLottes** **@AgileJebrim** **@munohikari**
Indeed. Many CPU programmers have the wrong belief that GPU atomics are slow and unusable. They are fantastic. Bump allocator is your best friend on CPU side. On GPU you do atomic add to implement a bump allocator. As simple as that. It's super fast.
**7/** @AgileJebrim
**7/** **@AgileJebrim** ^1869455007025946954
@SebAaltonen @NOTimothyLottes @munohikari
**@SebAaltonen** **@NOTimothyLottes** **@munohikari**
I know NVIDIA did a really good atomicAdd, especially if you don’t use the result of the atomicAdd(). If you use it, then it forces it down a significantly slower path. But it’s all implementation-specific and different vendors will do different things yes?
**8/** @NOTimothyLottes
**8/** **@NOTimothyLottes** ^1869461633267032141
@AgileJebrim @SebAaltonen @munohikari
**@AgileJebrim** **@SebAaltonen** **@munohikari**
Atomics come in two forms
(1.) fire-and-forget (aka you don't use the return) - the compiler will flag it for no-return, so it behaves like a store
(2.) read the return - it behaves like a {store, and read} simultaneously with layout "coherent"
**9/** @NOTimothyLottes
**9/** **@NOTimothyLottes** ^1869462116689981465
@AgileJebrim @SebAaltonen @munohikari
**@AgileJebrim** **@SebAaltonen** **@munohikari**
Good GPUs have address coalescing on writes and atomics. So a wave wide store is reduced to a cost that scales with the number of total cachelines all waves touch, with byte-write-mask so there is no read-modify-write
**10/** @NOTimothyLottes
**10/** **@NOTimothyLottes** ^1869462778270085478
@AgileJebrim @SebAaltonen @munohikari
**@AgileJebrim** **@SebAaltonen** **@munohikari**
... atomics have the same but if any wave lane's addresses collide it will bump those to another request (for the same cacheline). Possible that some HW implements a HW reduction for collisions of some kinds of atomics locally before the requests go out, but don't assume that
**11/** @NOTimothyLottes
**11/** **@NOTimothyLottes** ^1869463101361504275
@AgileJebrim @SebAaltonen @munohikari
**@AgileJebrim** **@SebAaltonen** **@munohikari**
... it's more likely that some compilers try to fix stupid behavior by doing a wave-reduction in software, and that causes hell for those of us who already write good code
**12/** @AgileJebrim
**12/** **@AgileJebrim** ^1869463390944629143
@NOTimothyLottes @SebAaltonen @munohikari
**@NOTimothyLottes** **@SebAaltonen** **@munohikari**
Thoughts on atomic compare exchange? I use similar functionality on CPUs to globally synchronize threads and I figured I’d give it a shot attempting to do that on GPUs.
**13/** @NOTimothyLottes
**13/** **@NOTimothyLottes** ^1869464512191238438
@AgileJebrim @SebAaltonen @munohikari
**@AgileJebrim** **@SebAaltonen** **@munohikari**
Compare and exchange since it takes 2 values, it could have half the peak rate through on-chip network. Personally I have always used algorithms that do better things without the cmpswap atomic. You always can get the return (value pre-atomic), so cmpswap utility is less
**14/** @AgileJebrim
**14/** **@AgileJebrim** ^1869465848211230840
@NOTimothyLottes @SebAaltonen
**@NOTimothyLottes** **@SebAaltonen**
My CPU sync mechanism works by stalling each thread until it reaches a multiple of the total number of threads to be synced, only incrementing an integer (swapping) when it reaches its specific thread index.
**15/** @NOTimothyLottes
**15/** **@NOTimothyLottes** ^1869467172495655049
@AgileJebrim @SebAaltonen
**@AgileJebrim** **@SebAaltonen**
I assume you are using a futex then on Linux to block? But the GPU doesn't have such a thing exposed in software. Instead you'd be effectively polling using serial global memory atomic latency as your rate limiter and 'blocking'
**16/** @NOTimothyLottes
**16/** **@NOTimothyLottes** ^1869467614407541225
@AgileJebrim @SebAaltonen
**@AgileJebrim** **@SebAaltonen**
Serializing workgroups on the GPU in this way has a very high latency granularity. There is also the issue of preemption on PCs, there is no guarantee of forward progress due to no guarantee all workgroups get restored
**17/** @NOTimothyLottes
**17/** **@NOTimothyLottes** ^1869467785010762160
@AgileJebrim @SebAaltonen
**@AgileJebrim** **@SebAaltonen**
So you can deadlock post preemption if the workgroup that needs to do the atomic to unblock those spinning cannot get back on the machine
**18/** @NOTimothyLottes
**18/** **@NOTimothyLottes** ^1869468049176506634
@AgileJebrim @SebAaltonen
**@AgileJebrim** **@SebAaltonen**
Now, the important part, there is one compromise rule that has the highest chance of being possible, that is an ask that if there is a partial restore, that it restores the oldest launched workgroups first ...
**19/** @NOTimothyLottes
**19/** **@NOTimothyLottes** ^1869468322003317098
@AgileJebrim @SebAaltonen
**@AgileJebrim** **@SebAaltonen**
And with that you can have some forward progress if an algorithm only has dependencies on workgroups launched before it (like lower kernel global workgroup index), food for thought for algorithm design
**20/** @NOTimothyLottes
**20/** **@NOTimothyLottes** ^1869469045357158663
@AgileJebrim @SebAaltonen
**@AgileJebrim** **@SebAaltonen**
on the CPU side, you'd futex block to get the thread off being scheduled so the dependent one could get on the machine to avoid deadlock, it isn't efficient by any means but works, the GPU's exposed only voluntary method to get off the machine is to exit the workgroup ...
**21/** @NOTimothyLottes
**21/** **@NOTimothyLottes** ^1869469471892795511
@AgileJebrim @SebAaltonen
**@AgileJebrim** **@SebAaltonen**
So if you uber-task, meaning just keep launching the same dispatch, and the workgroup finds what it needs to do (instead of working off kernel global index), then you can workaround preemption that way too ...
**22/** @NOTimothyLottes
**22/** **@NOTimothyLottes** ^1869469740726734946
@AgileJebrim @SebAaltonen
**@AgileJebrim** **@SebAaltonen**
Blocking becomes just workgroup exit. And the next workgroup gets lower schedule priority than existing active workgroups which helps solve of the scheduling issues
**23/** @AgileJebrim
**23/** **@AgileJebrim** ^1869470170613461399
@NOTimothyLottes @SebAaltonen
**@NOTimothyLottes** **@SebAaltonen**
I’m not using a Linux futex. Could you look over my code here?
**24/** @simplex_fx
**24/** **@simplex_fx** ^1869471291973214394
@AgileJebrim @NOTimothyLottes @SebAaltonen
**@AgileJebrim** **@NOTimothyLottes** **@SebAaltonen**
Hey Jeb, have you considered hitting the funny L shaped button on the right of your keyboard more frequently? 😅
**25/** @AgileJebrim
**25/** **@AgileJebrim** ^1869472284156834117
@simplex_fx @NOTimothyLottes @SebAaltonen
**@simplex_fx** **@NOTimothyLottes** **@SebAaltonen**
Enter? Nah
**26/** @simplex_fx
**26/** **@simplex_fx** ^1869474818384670790
@AgileJebrim @NOTimothyLottes @SebAaltonen
**@AgileJebrim** **@NOTimothyLottes** **@SebAaltonen**
![](https://pbs.twimg.com/media/GfG1cCJW8AAXcDg?format=jpg&name=orig)
**27/** @AgileJebrim
**27/** **@AgileJebrim** ^1869479130993234191
@simplex_fx @NOTimothyLottes @SebAaltonen
**@simplex_fx** **@NOTimothyLottes** **@SebAaltonen**
If I don’t have to scroll right…
**28/** @simplex_fx
**28/** **@simplex_fx** ^1869486350074020173
@AgileJebrim @NOTimothyLottes @SebAaltonen
**@AgileJebrim** **@NOTimothyLottes** **@SebAaltonen**
Dude, stop with that WQHD bullshit, buy a proper tv and limit yourself to 80-120
**29/** @AgileJebrim
**29/** **@AgileJebrim** ^1869486638877004115
@simplex_fx @NOTimothyLottes @SebAaltonen
**@simplex_fx** **@NOTimothyLottes** **@SebAaltonen**
Nty. The hell do I need a tv for? I have several monitors.
**30/** @simplex_fx
**30/** **@simplex_fx** ^1869486998249185767
@AgileJebrim @NOTimothyLottes @SebAaltonen
**@AgileJebrim** **@NOTimothyLottes** **@SebAaltonen**
How big?
**31/** @AgileJebrim
**31/** **@AgileJebrim** ^1869487741052023113
@simplex_fx @NOTimothyLottes @SebAaltonen
**@simplex_fx** **@NOTimothyLottes** **@SebAaltonen**
Big enough to maximize a window on each.
**32/** @simplex_fx
**32/** **@simplex_fx** ^1869518005237112922
@AgileJebrim @NOTimothyLottes @SebAaltonen
**@AgileJebrim** **@NOTimothyLottes** **@SebAaltonen**
If you go too wide, you will just kill your neck on the long run
**33/** @AgileJebrim
**33/** **@AgileJebrim** ^1869523900687864185
@simplex_fx @NOTimothyLottes @SebAaltonen
**@simplex_fx** **@NOTimothyLottes** **@SebAaltonen**
I have 4 monitors
**34/** @simplex_fx
**34/** **@simplex_fx** ^1869529828082541035
@AgileJebrim @NOTimothyLottes @SebAaltonen
**@AgileJebrim** **@NOTimothyLottes** **@SebAaltonen**
How big?
**35/** @NOTimothyLottes
**35/** **@NOTimothyLottes** ^1869530109096669269
@simplex_fx @AgileJebrim @SebAaltonen
**@simplex_fx** **@AgileJebrim** **@SebAaltonen**
Ideally one of these
![](https://pbs.twimg.com/media/GfHntpaWYAAGnOk?format=png&name=orig)
**36/** @AgileJebrim
**36/** **@AgileJebrim** ^1869530951480717429
@NOTimothyLottes @simplex_fx @SebAaltonen
**@NOTimothyLottes** **@simplex_fx** **@SebAaltonen**
Not big enough. Evans & Sutherland still makes planetariums. We have smaller scale 360 degree domes. I think they’re about 14ft high.
**37/** @SebAaltonen
**37/** **@SebAaltonen** ^1869808696366379155
@AgileJebrim @NOTimothyLottes
**@AgileJebrim** **@NOTimothyLottes**
Same is true for everything. All memory loads on GPUs are highly vendor specific. On GTX 1080 (Pascal) your memory load goes through sampler, which is around 85 cycles of latency. While on Turing your raw load is only 28 cycles of latency (CUDA benchmarks).
**38/** @AgileJebrim
**38/** **@AgileJebrim** ^1869809446437957837
@SebAaltonen @NOTimothyLottes
**@SebAaltonen** **@NOTimothyLottes**
For sure, but my focus is more on how deterministic and predictable these are. I’ll take 85 if it’s always 85 over something that might vary unpredictably between 28 and 100.
**39/** @SebAaltonen
**39/** **@SebAaltonen** ^1869810947512250536
@AgileJebrim @NOTimothyLottes
**@AgileJebrim** **@NOTimothyLottes**
Nvidia has big L1$, so they are more predictable. Texture samplers are shared with all waves running on the same compute unit. They are not really predictable. You wait until the unit is ready. There's quite a lot of fluctuation. That's why you have 8x-10x hyperthreading per CU.
**40/** @SebAaltonen
**40/** **@SebAaltonen** ^1869811242954830281
@AgileJebrim @NOTimothyLottes
**@AgileJebrim** **@NOTimothyLottes**
The idea is to keep the SIMD running all the time. Wave execution time variance hasn't been a big optimization goal. There's always more work coming, so it's not a problem if some wave takes 10x time to execute compared to others.
**41/** @SebAaltonen
**41/** **@SebAaltonen** ^1869811536547721585
@AgileJebrim @NOTimothyLottes
**@AgileJebrim** **@NOTimothyLottes**
Basically if the SIMD is executing instructions all the time, then your workload runs at predictable amount of instructions per cycle. The problem is barriers. You wait for longest wave to finish. You can't to batch barriers to avoid turning latency into real lost SIMD cycles.
**42/** @AgileJebrim
**42/** **@AgileJebrim** ^1869811840433496316
@SebAaltonen @NOTimothyLottes
**@SebAaltonen** **@NOTimothyLottes**
If they all take the same amount of time then there shouldn’t be much idling of hardware for waiting on the longest wave.
**43/** @SebAaltonen
**43/** **@SebAaltonen** ^1870002011753578827
@AgileJebrim @NOTimothyLottes
**@AgileJebrim** **@NOTimothyLottes**
That's true. But they don't take the same amount of time due to caches. That's where the 10x hyper-threading kicks in. As long as the SIMD is fed all the time, there's no visible issue with fluctuating wave lengths. Barriers make that visible. Minimal amount of barriers = good.
**44/** @AgileJebrim
**44/** **@AgileJebrim** ^1869454583191494967
@NOTimothyLottes @SebAaltonen @munohikari
**@NOTimothyLottes** **@SebAaltonen** **@munohikari**
Would you implement a prefix sum compaction algorithm using atomicAdd?
**45/** @NOTimothyLottes
**45/** **@NOTimothyLottes** ^1869460449194037720
@AgileJebrim @SebAaltonen @munohikari
**@AgileJebrim** **@SebAaltonen** **@munohikari**
Standard optimizations apply, like doing wave-reductions first.
**46/** @AgileJebrim
**46/** **@AgileJebrim** ^1869460608246239720
@NOTimothyLottes @SebAaltonen @munohikari
**@NOTimothyLottes** **@SebAaltonen** **@munohikari**
Okay so you don’t just blanket throw an atomicAdd on it then.
**47/** @NOTimothyLottes
**47/** **@NOTimothyLottes** ^1869463962322149607
@AgileJebrim @SebAaltonen @munohikari
**@AgileJebrim** **@SebAaltonen** **@munohikari**
No. For things like scanning a 1-bit value, it's a wave masked bit count op in software, followed by predicating the atomic to just lane 0 of the wave. For scanning uint32s it's a log2 wave reduction, then predicating the add to lane 0. And so on
@@ -26,17 +26,17 @@ parent_post_id: "1869424048607993895"
## Branch
**1/** @SebAaltonen
**1/** **@SebAaltonen** ^1869425726128304359
@AgileJebrim @NOTimothyLottes @munohikari
**@AgileJebrim** **@NOTimothyLottes** **@munohikari**
Yes, but it's going to be MUCH slower. You can do sums and reductions in groupshared memory, but if that mobile GPU doesn't have real groupshared memory, it's going to be very slow. For example GMEM based groupshared is this slow on Qualcomm (and 730 is much better than 610):
![](https://pbs.twimg.com/media/GfGISwfWgAI6UuY?format=jpg&name=orig)
**2/** @SebAaltonen
**2/** **@SebAaltonen** ^1869426053002997774
@AgileJebrim @NOTimothyLottes @munohikari
**@AgileJebrim** **@NOTimothyLottes** **@munohikari**
X1 is the brand new laptop chip. This architecture is only on latest mobile phones. Low end is Adreno 610 and similar.
@@ -25,80 +25,80 @@ in_reply_to: ""
## Thread
**1/** @AgileJebrim
**1/** **@AgileJebrim** ^1869397269956673662
@munohikari @SebAaltonen
**@munohikari** **@SebAaltonen**
You left out the bit where I also said no graphics pipeline. :P
**2/** @SebAaltonen
**2/** **@SebAaltonen** ^1869401190653730862
@AgileJebrim @munohikari
**@AgileJebrim** **@munohikari**
Computer shaders are a can of worms for old mobile GPUs too. Some have fast groupshared memory (could be tiny), some emulate it. Some have wave intrinsics, some don't. 64-bit atomic support is nonexistent (for MM Dreams / Native style Z+payload packing).
**3/** @SebAaltonen
**3/** **@SebAaltonen** ^1869401541570179083
@AgileJebrim @munohikari
**@AgileJebrim** **@munohikari**
Also compute shader writes are not compressed (pixel shader framebuffer writes have HW lossless compressor). You pay full memory bandwidth cost, which causes phone to heat (drain battery) and eventually throttle.
**4/** @AgileJebrim
**4/** **@AgileJebrim** ^1869402067724615899
@SebAaltonen @munohikari
**@SebAaltonen** **@munohikari**
Alternative approach is to do all rendering in screen space in a fragment shader.
**5/** @SebAaltonen
**5/** **@SebAaltonen** ^1869403157530550660
@AgileJebrim @munohikari
**@AgileJebrim** **@munohikari**
If you intend to do distance field ray-tracing using volume textures, worth noting that most mobile GPUs don't do proper 3d tiling layout for volume textures. Instead they use legacy 2d sliced layout, which results in significantly more L1$ trashing. Can 5x your mem BW use.
**6/** @AgileJebrim
**6/** **@AgileJebrim** ^1869406913676660898
@SebAaltonen @munohikari
**@SebAaltonen** **@munohikari**
Raycasting, no bouncing, using cubic textured bricks that emulate voxel surfaces via a parallax occlusion map approach measuring distances to each voxel surface.
If I’m writing something for an avionics cockpit, I’d be either using an Arm Mali-G78AE or NVIDIA DRIVE AGX Thor GPU.
**7/** @AgileJebrim
**7/** **@AgileJebrim** ^1869408574910423473
@SebAaltonen @munohikari
**@SebAaltonen** **@munohikari**
I’d also be using Vulkan SC, which I believe disables atomics entirely. :P
**8/** @NOTimothyLottes
**8/** **@NOTimothyLottes** ^1869423853761614046
@AgileJebrim @SebAaltonen @munohikari
**@AgileJebrim** **@SebAaltonen** **@munohikari**
Disabling atomics is like chopping off both legs because someone thinks one tow has a blister when it actually doesn't.
**9/** @AgileJebrim
**9/** **@AgileJebrim** ^1869424048607993895
@NOTimothyLottes @SebAaltonen @munohikari
**@NOTimothyLottes** **@SebAaltonen** **@munohikari**
You can still implement a comparable feature yourself.
Branches: [[archive/threads/AgileJebrim/2024-12-18-you-left-out-the-bit-where-i-also-said-no/2024-12-18-SebAaltonen-yes-but-its-going-to-be-much-slower-you-can-do]]
**10/** @NOTimothyLottes
**10/** **@NOTimothyLottes** ^1869434807228461111
@AgileJebrim @SebAaltonen @munohikari
**@AgileJebrim** **@SebAaltonen** **@munohikari**
No actually you cannot. No method of software (or even HW) implemented lock-line algorithm survives the kind of latency in the GPU memory system. There is a big reason atomics on GPUs are done right by the last level of cache (the coherent memory domain)
**11/** @NOTimothyLottes
**11/** **@NOTimothyLottes** ^1869435419244527644
@AgileJebrim @SebAaltonen @munohikari
**@AgileJebrim** **@SebAaltonen** **@munohikari**
Something you really need to understand for your own benefit:
(1.) There are a lot of more expensive things happening in the GPU memory system than atomics. For instance DCC compression. It requires metadata access (to get the state of memory just to do the compression on store).
**12/** @NOTimothyLottes
**12/** **@NOTimothyLottes** ^1869436199884222515
@AgileJebrim @SebAaltonen @munohikari
**@AgileJebrim** **@SebAaltonen** **@munohikari**
(2.) Think of GPU atomics as a read-modify-write op. It's effectively the same behavior as a partial cacheline write-through STORE operation on HW using ECC. Because ECC eats the bits used for byte-write-mask.