HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because...
Transcript of HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because...
![Page 1: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/1.jpg)
HEIGHT MAP GENERATION WITH GPU’s
Ravi Kiran Chilakapati CSE 633: Parallel Algorithms
Fall 2011
![Page 2: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/2.jpg)
FRACTALS
! Self-Similarity
! Fine structure at arbitrarily small scales
! Simple and recursive definition
! Everywhere in nature – snowflakes, clouds, mountain ranges, lightning bolts and even in vegetables!
![Page 3: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/3.jpg)
Source: Wikipedia
![Page 4: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/4.jpg)
SELF SIMILARITY
Source: Wikipedia
![Page 5: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/5.jpg)
FRACTAL GENERATION
! The “simple” part is exaggerated!
! Recursion perfectly captures the self-similarity of fractals
! Usually generated in a complex plane
! Escape-time; Iterated functions; Random fractals; Strange attractors; L-systems
! Julia set, Mandelbrot set, Nova fractal, Sierpinski carpet, Koch snowflake, Brownian Tree
![Page 6: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/6.jpg)
Source: http://www.clarku.edu/~djoyce/complex/plane.html
![Page 7: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/7.jpg)
APPLICATION OF FRACTALS
! Lossy compression (sounds and images)
! Seismology
! Fractal antennas
! Computer network design
! Fractal landscape generation
! Financial analysis
! Computer graphics
! Art
![Page 8: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/8.jpg)
MANDELBROT SET
! A visualization of an iterative function in a complex plane
! y(z) = z2 + c
! c is used as a bounding constant to ensure that y(z) does not exceed that value as we perform an increasing number of iterations
! Fine detail even on infinite magnification
![Page 9: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/9.jpg)
TERRAIN MAPPING
! Used to generate mountainous or futuristic terrain
! Practical use in the entertainment/graphics sector
! Far Cry 2, Left4Dead, .kkrieger, Borderlands, Diablo
Source: Wikipedia
![Page 10: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/10.jpg)
MID POINT DISPLACEMENT ALGORITHM
! Take a line segment on the X-axis
! Calculate the mid-point of the segment
! Add some random noise to generate the y co-ordinate
! Reduce the range of the random noise
! Recursively call the above steps for all the line segments
![Page 11: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/11.jpg)
DIAMOND SQUARE ALGORITHM
Source: http://gameprogrammer.com/fractal.html#diamond
![Page 12: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/12.jpg)
PROBLEMS
! The number of squares increases exponentially after every round
! 2X+2 squares after X iterations
! Large terrains require a huge number of calculations
![Page 13: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/13.jpg)
GOALS
! Write a Mandelbrot set visualization program using CUDA/C ! Generate the elements of a Mandelbrot set ! Visualize them using OpenGL
! Create a random terrain map generation program using CUDA/C ! Generate random height maps using
fractals ! Visualize them using OpenGL/pass height
maps as inputs to existing 3D renderers
![Page 14: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/14.jpg)
APPROACH
! Divide and Conquer!
! Assign a thread/block/processor to each individual pixel value that needs to be calculated
! Run the fractal generation/diamond square algorithm
! Because the number of pixels to be calculated differs in each step for DS, dynamically allocate
! CUDA did not support recursive device calls for < CUDA 3.1 (roughly compute capability 2.0)
![Page 15: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/15.jpg)
CUDA ABSTRACTION FOR DEVELOPERS
Source: CUDA C Programming Guide
![Page 16: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/16.jpg)
! Though GPU’s inherently support multi-threading, there are several hardware constraints
! Eg: CCR
! Name: Tesla M2050
! CUDA Version: 2.0
! Shared memory per block: 49152
! Total constant memory: 65536
! Regs per block: 32768
! Max threads per block: 1024
! Max threads per dim: 1024,1024,64
! Max grid size: 65535,65535,65535
! Multi processor count: 14
![Page 17: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/17.jpg)
MANDELBROT SET
! Straight-forward implementation
! Challenge was in writing the program in CUDA
! Use varying number of threads and blocks
! Number of blocks dependent on the number of threads
! I learnt the hard way about the hardware limitation on the number of threads
! numBlocks*numThreadsPerBlock <= maxThreadsPerDim
! numThreadsPerBlock <= maxThreadsPerBlock
! Based on input number of threads, dynamically allocating number of blocks to be created by the GPU
! Communication time => Time taken to transfer initial array to GPU or to allocate memory on GPU
! Computation time => Time taken by the GPU to finish computation
![Page 18: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/18.jpg)
![Page 19: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/19.jpg)
![Page 20: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/20.jpg)
![Page 21: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/21.jpg)
![Page 22: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/22.jpg)
HEIGHT MAPS WITH GPU’s
! Sample height map available on the internet
![Page 23: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/23.jpg)
! Sample height map from my code
![Page 24: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/24.jpg)
! Flatten the array and pass it to the GPU
! Communication time – Time take to initialize GPU with initial height map with seeded values
! Computation time – Time taken by the GPU to calculate height values for ALL the points in the given 2D array
! Runs
! Sequential run on CPU
! Single thread with multiple blocks
! Single block with multiple threads
! Multiple blocks with multiple threads
![Page 25: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/25.jpg)
SEQUENTIAL CPU RUN
![Page 26: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/26.jpg)
! The previous image did not use random values in the diamond square algorithm
! Grid size: 1025*1025
! Average running time (with random value generation) was 64.9 ms (100 runs)
! Difference in running on integrated graphics memory vs. dedicated GPU (CCR machine)
! For the parallel runs, number of blocks/threads = dimension of image
! If hardware limit is smaller, assign multiple pixel values to each block/thread
![Page 27: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/27.jpg)
SINGLE THREAD WITH MULTIPLE BLOCKS (INTEGRATED GRAPHICS MEMORY)
![Page 28: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/28.jpg)
SINGLE THREAD WITH MULTIPLE BLOCKS (CCR)
![Page 29: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/29.jpg)
SINGLE BLOCK WITH MULTIPLE THREADS (INTEGRATED GRAPHICS MEMORY)
![Page 30: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/30.jpg)
SINGLE BLOCK WITH MULTIPLE THREADS (CCR)
![Page 31: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/31.jpg)
MULTIPLE BLOCKS WITH 4 OR LESS THREADS - (INTEGRATED GRAPHICS MEMORY)
![Page 32: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/32.jpg)
MULTIPLE BLOCKS WITH 4 OR LESS THREADS - (CCR)
![Page 33: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/33.jpg)
COMMENTS
! When we have multiple blocks, assign each square step to a single thread
! Can’t always launch 4 threads (hardware limitation!)
! Based on the maxThreadsPerDim property of the CUDA enabled device
! Dynamic creation of threads and blocks maybe creating considerable overhead
! Computation time involves some communication (random numbers) to the GPU
! Using more advanced features of the GPU – streams, DMA, Shaders, maybe even multiple CUDA enabled devices – might considerably lower the running time
![Page 34: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/34.jpg)
FUTURE WORK
! Make use of 2D CUDA functions like cudaMemcpy2D, cudaMallocPitch etc.
! Utilize advanced features – streams, DMA, Shaders
! Divide into smaller problems of constant size and solve each problem on a separate device in parallel – will help in static assignment of number of threads/blocks
! Use better terrain generation algorithms
! Add rendering code – mesh and full color
![Page 35: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/35.jpg)
QUESTIONS?
![Page 36: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/36.jpg)
SAMPLE HEIGHT MAPS GENERATED
![Page 37: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/37.jpg)
SAMPLE HEIGHT MAPS GENERATED
![Page 38: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/38.jpg)
SAMPLE HEIGHT MAPS GENERATED
![Page 39: HEIGHT MAP GENERATION WITH GPU’s · Run the fractal generation/diamond square algorithm ! Because the number of pixels to be calculated differs in each step for DS, dynamically](https://reader035.fdocuments.in/reader035/viewer/2022070921/5fb9c0d413bda218fe511c8c/html5/thumbnails/39.jpg)
SAMPLE HEIGHT MAPS GENERATED