3 ms·
Can you summarize what does this do for you?
by lostmsu 7y ago
Can you summarize what does this do for you?
- dragontamer 7y agoHmmm... perhaps an example would be best? I wrote myself FizzBuzz a few days ago as a proof-of-concept. // AMD cards are 64 SIMD-lanes // Untested, but I think you can understand the concept from this. for(int i=0; i<10000; i+=64){ int myIdx = i + hipThreadIdx_x; bool fizz = myIdx % 3 == 0; bool buzz = myIdx % 5 == 0; if(fizz){ fizzTable[fizzTail + active_lane()] = myIdx; } if(buzz){ buzzTable[buzzTail + active_lane()] = myIdx; } fizzNum = popcnt(ballot(fizz)); buzzNum = popcnt(ballot(buzz)); if(active_lane() == 0){ fizzTail += fizzNum; buzzTail += buzzNum; } __syncthreads(); // Thread barrier, this is the only synchronization needed. } The above implements parallel fizzbuzz with 100% utilization and only one synchronization primitive. The syncthreads(); call is extremely efficient for SIMD programming: if you have a workgroup of size 64 on AMD platforms, it is nearly a no-op (aside from a relatively cheap L1 memory-barrier to ensure all threads are reading the same value). In practice, the above methodology scales to +1024 threads at a time on AMD and NVidia GPUs if you increase the work-item or CUDA-block size to the max. If you tried to write 64-way parallel fizzBuzz, what would it look like? I think the above implementation, using active_lane(), is pretty elegant. --------- I read this pattern off of Github with some high-speed GPU-raytracing code. It seems that a lot of GPU-programmers know this pattern already, and use it to increase utilization of the SIMD-cores.