Presentation is loading. Please wait.

Presentation is loading. Please wait.

©Wen-mei W. Hwu and David Kirk/NVIDIA Urbana, Illinois, August 2-5, 2010 VSCSE Summer School Proven Algorithmic Techniques for Many-core Processors Lecture.

Similar presentations


Presentation on theme: "©Wen-mei W. Hwu and David Kirk/NVIDIA Urbana, Illinois, August 2-5, 2010 VSCSE Summer School Proven Algorithmic Techniques for Many-core Processors Lecture."— Presentation transcript:

1 ©Wen-mei W. Hwu and David Kirk/NVIDIA Urbana, Illinois, August 2-5, 2010 VSCSE Summer School Proven Algorithmic Techniques for Many-core Processors Lecture 7: Dealing with Non-Uniform Data

2 MRI Reconstruction  MRI scanners increasingly use spiral trajectories in a cylindrical or spherical coordinate system ⟹ The image cannot be reconstructed by directly applying IFFT to the k-space samples  Transform MR data samples from the k-space into the image space using IFFT 2

3 Gridding to Enable IFFT  Instead, map non-Cartesian samples in frequency domain onto a 3D Cartesian grid based on a Kaiser- Bessel function (Gridding)  Next, perform IFFT on grid to transform it to the image domain 3

4 Large Number of Sample Points Each sample contains –Its K-space Coordinates, s.coordinates –Its strength value, s.value Given s.coordinates, it is easy to calculate the range of grid points affected –Cutoff distance ©Wen-mei W. Hwu and David Kirk/NVIDIA Urbana, Illinois, August 2-5, 2010

5 An Input Oriented Sequential Code  Uses a window function for (every sample point s){ for(z in range){ for(y in range){ for(x in range){ weight = kaiser_bessel(| - |) grid[z][y][x] += s.value * weight; } 5

6 Binning of Sample Points For simplicity, we will use 1D gridding examples Each sample point has –s.x (will be represented with Bin#) –S.value (will be omitted unless necessary) ©Wen-mei W. Hwu and David Kirk/NVIDIA Urbana, Illinois, August 2-5, 2010 01324 5 Bin 1Bin 0Bin 2Bin 3Bin 4 cutoff distance

7 A Scatter Parallelization Use each thread to process N sample points Use Global Memory atomic operation to accumulate into grid points Each sample point affects all grid points with cutoff distance Slow, but not pathologically slow Fermi runs this faster than its predecessors ©Wen-mei W. Hwu and David Kirk/NVIDIA Urbana, Illinois, August 2-5, 2010 01002134 54321076 cutoff distance

8 A Faster Scatter Implementation Algorithm: –Sort input data –Each block processes one section of sample points Each thread processes a smaller section of sample points –Create window of grid points in shared memory and compute into it when possible Quick inspection of the end sample points of sample section determines window –Use atomic operation to coordinate across threads ©Wen-mei W. Hwu and David Kirk/NVIDIA Urbana, Illinois, August 2-5, 2010 00011324 0214350213 Shared Memory Regularization helps scatter too.

9 Limited Space in Shared Memory The sample sections vary in the span of grid points they cover –The algorithms works best in sample points are mostly concentrated in small grid regions Limit the size of grid point window for Share Memory limitation and copy-merge overhead Moderate level of contention ©Wen-mei W. Hwu and David Kirk/NVIDIA Urbana, Illinois, August 2-5, 2010 00011324 0214350213 Shared Memory

10 Accesses to Global Memory A condition test of bin value and widow span determines if an affected grid point is in Shared Memory window –Use atomic operation to accumulate into Global Memory –low contention At the end of block execution, thread collectively merge window back to Global Memory –Use atomic operation –Moderate to low contention ©Wen-mei W. Hwu and David Kirk/NVIDIA Urbana, Illinois, August 2-5, 2010 00011324 0214350213 Shared Memory 45021367

11 How about Scatter Parallelization No contention We know we can bin sample points However, there can be great load imbalance –Some grid points are affected by many more sample points than others ©Wen-mei W. Hwu and David Kirk/NVIDIA Urbana, Illinois, August 2-5, 2010

12 A Binned Gather Parallelization Use each thread to compute the value of N grid points Pre-sort sample points into fixed size bins Each thread reads only the relevant input bins ©Wen-mei W. Hwu and David Kirk/NVIDIA Urbana, Illinois, August 2-5, 2010 000112XX 02163745 Shared Memory X3XX4XX

13 A Tiled Gather Implementation ©Wen-mei W. Hwu and David Kirk/NVIDIA Urbana, Illinois, August 2-5, 2010 k 021 6 3 745 Shared Memory 012 01X 0XX 3 X X 4 X X 5 X X 234 XXX XXX X X X X X X 7 X X X X X 9 X X

14 More on Tiled Gather Threads cooperate to load the relevant bins for all of them from Global Memory to Shared Memory Each thread only access relevant bins from Shared Memory Uniform binning for Non-uniform distribution –Large memory overhead for dummy cells –Reduced benefit of tiling –Many threads spend much time on dummy sample points ©Wen-mei W. Hwu and David Kirk/NVIDIA Urbana, Illinois, August 2-5, 2010

15 Bin 4 Implicit Binning for Gather Parallelization  Don’t use pre-allocated fixed size bins (multi- dimensional array)  Sort samples into bins of varying sizes in input array instead  Bins 5, 6, 8 are implicit, zero-sample 15 00011324 01002134 sort Bin 0Bin 2Bin 1Bin 3 97 79 Bin 7Bin 9

16 Determine Start and End of Bins Use parallel scan operations to generate an array of starting points of all bins (CUDPP) ©Wen-mei W. Hwu and David Kirk/NVIDIA Urbana, Illinois, August 2-5, 2010 00011324 Bin 0Bin 2Bin 1Bin 3Bin 4 0335677 79 0123457689 7889

17 A Tiled Gather Implementation ©Wen-mei W. Hwu and David Kirk/NVIDIA Urbana, Illinois, August 2-5, 2010 k 021 6 3 745 Shared Memory 00011223479 34

18 Controlling Load Balance Limit the size of each bin –Both uniform and variable/implicit bins –CPU places excess sample points into a CPU list –CPU does gridding on the excess sample points in parallel with GPU –Eventually merge ©Wen-mei W. Hwu and David Kirk/NVIDIA Urbana, Illinois, August 2-5, 2010 0123497001 GPU CPU

19 19 Determining the bin-size limit can be tricky. Higher limit creates more load imbalance on GPU Lower limit may cause too much CPU execution time What is the best bin size? Sort-reduce … CPU GPU

20 20 There is a range of good bin sizes for each processor.

21 21 Performance Chart Partitioning achieves 43% speedup over sort- reduce without partitioning AlgorithmTime (sec.)Speedup Sequential23.441X Shared Atomic15.41.52X Sort-Reduce14.251.64X Sort-Reduce + Partitioning (binsize limit=128) 9.922.36X

22 22 Determining Appropriate Algorithm

23 The Answer is depends. No panacea here: best algorithm and optimal bin size depend on input data distribution!

24 ANY FURTHER QUESTIONS? ©Wen-mei W. Hwu and David Kirk/NVIDIA Urbana, Illinois, August 2-5, 2010


Download ppt "©Wen-mei W. Hwu and David Kirk/NVIDIA Urbana, Illinois, August 2-5, 2010 VSCSE Summer School Proven Algorithmic Techniques for Many-core Processors Lecture."

Similar presentations


Ads by Google