79645531

Date: 2025-05-30 13:24:36
Score: 0.5
Natty:
Report link

Seems like you are searching for "parallel reduction". Here is a recent post on this topic Parallel reduction with single wave
The best way is to calculate this sum per workgroup, beacuse you can control synchronization inside of workgroup inside of shader.

It will look like this: compute sum of all pairs and store them to one of elements in each pair, then compute sum of each pair of the results given by previous computation. you repeat like this untill you get the final single value.

Also Gpu sorting algorithm is made in simmilar way, but more complex, may be you would like to take a look. https://developer.nvidia.com/gpugems/gpugems2/part-vi-simulation-and-numerical-algorithms/chapter-46-improved-gpu-sorting

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (0.5):
Posted by: Mitro Juryev