machine learning, ai, cs · slides · talks & lectures

Introduction to GPU Computing

Slide 1 of 71: INTRODUCTION TO GPU COMPUTING Ilya Kuzovkin 13 May 2014, TartuSlide 2 of 71: PART I “TEAPOT”Slide 3 of 71: SIMPLE OPENGL PROGRAM Idea of computing on GPU emerged because GPUs became very good at parallel computations.Slide 4 of 71: SIMPLE OPENGL PROGRAM Idea of computing on GPU emerged because GPUs became very good at parallel computations. ! Let us start from observing an example of parallelism in a simple OpenGL application.Slide 5 of 71: SIMPLE OPENGL PROGRAM You will need CodeBlocks Windows, Linux or XCode Mac to run this example. • Install CodeBlocks bundled with MinGW compiler from http://www.codeblocks.org/downloads/26 ! • Download codebase from https://github.com/kuz/ Introduction-to-GPU-Computing ! • Open…Slide 6 of 71: SHADER PROGRAM Program which is executed on GPU . Has to be written using shading language . In OpenGL this language is GLSL , which is based on C. http://www.opengl.org/wiki/ShaderSlide 7 of 71: SHADER PROGRAM Program which is executed on GPU . Has to be written using shading language . In OpenGL this language is GLSL , which is based on C. OpenGL has 5 main shader stages: • Vertex Shader • Tessellation Control • Geometry Shader • Fragment Shader • Compute Shader (since…Slide 8 of 71: SHADER PROGRAM Program which is executed on GPU . Has to be written using shading language . In OpenGL this language is GLSL , which is based on C. OpenGL has 5 main shader stages: • Vertex Shader • Tessellation Control • Geometry Shader • Fragment Shader • Compute Shader (since…Slide 9 of 71: LIGHTING Is it a cube or not? We will find out as soon as we add lighting to the scene.Slide 10 of 71: LIGHTING Is it a cube or not? We will find out as soon as we add lighting to the scene. https://github.com/konstantint/ComputerGraphics2013/blob/master/Lectures/07%20-%20Color%20and%20Lighting/slides07_colorandlighting.pdfSlide 11 of 71: LIGHTING Is it a cube or not? We will find out as soon as we add lighting to the scene. https://github.com/konstantint/ComputerGraphics2013/blob/master/Lectures/07%20-%20Color%20and%20Lighting/slides07_colorandlighting.pdf Exercise: code that equation into fragment shader of the…Slide 12 of 71: LIGHTINGSlide 13 of 71: • Run the program with lighting enabled and look at FPS values COMPARE FPSSlide 14 of 71: • Run the program with lighting enabled and look at FPS values ! • In cube.cpp idle() function uncomment dummy code which simulates approximately same amount of computations as Phong lighting model requires. COMPARE FPSSlide 15 of 71: • Run the program with lighting enabled and look at FPS values ! • In cube.cpp idle() function uncomment dummy code which simulates approximately same amount of computations as Phong lighting model requires. ! • Note that these computations are performed on CPU COMPARE FPSSlide 16 of 71: • Run the program with lighting enabled and look at FPS values ! • In cube.cpp idle() function uncomment dummy code which simulates approximately same amount of computations as Phong lighting model requires. ! • Note that these computations are performed on CPU ! • Observe how…Slide 17 of 71: • Run the program with lighting enabled and look at FPS values ! • In cube.cpp idle() function uncomment dummy code which simulates approximately same amount of computations as Phong lighting model requires. ! • Note that these computations are performed on CPU ! • Observe how…Slide 18 of 71: PART II “OLD SCHOOL”Slide 19 of 71: OPENGL PIPELINE + GLSL http://www.opengl.org/wiki/Framebuffer Take the input data from the CPU memory and put it as an image into the GPU memorySlide 20 of 71: http://www.opengl.org/wiki/Framebuffer In the fragment shader perform a computation on each of the pixels of that image Take the input data from the CPU memory and put it as an image into the GPU memory OPENGL PIPELINE + GLSLSlide 21 of 71: http://www.opengl.org/wiki/Framebuffer In the fragment shader perform a computation on each of the pixels of that image Store the resulting image to the Render Buffer inside the GPU memory Take the input data from the CPU memory and put it as an image into the GPU memory OPENGL…Slide 22 of 71: http://www.opengl.org/wiki/Framebuffer Read output from the GPU memory back to the CPU memory Store the resulting image to the Render Buffer inside the GPU memory In the fragment shader perform a computation on each of the pixels of that image Take the input data from the CPU…Slide 23 of 71: • Create texture where will store the input data http://www.opengl.org/wiki/Framebuffer OPENGL PIPELINE + GLSLSlide 24 of 71: • Create texture where will store the input data ! ! ! ! ! • Create FrameBuffer Object (FBO) to “render” to http://www.opengl.org/wiki/Framebuffer OPENGL PIPELINE + GLSLSlide 25 of 71: • Run OpenGL pipeline http://www.opengl.org/wiki/Framebuffer OPENGL PIPELINE + GLSLSlide 26 of 71: • Run OpenGL pipeline • Render GL_QUADS of same size as the texture matrix http://www.opengl.org/wiki/Framebuffer OPENGL PIPELINE + GLSLSlide 27 of 71: • Run OpenGL pipeline • Render GL_QUADS of same size as the texture matrix • Use fragment shader to perform per-fragment computations using data from the texture http://www.opengl.org/wiki/Framebuffer OPENGL PIPELINE + GLSLSlide 28 of 71: • Run OpenGL pipeline • Render GL_QUADS of same size as the texture matrix • Use fragment shader to perform per-fragment computations using data from the texture • OpenGL will store result in the texture given to the Render Buffer (within Framebuffer Object)…Slide 29 of 71: • Run OpenGL pipeline • Render GL_QUADS of same size as the texture matrix • Use fragment shader to perform per-fragment computations using data from the texture • OpenGL will store result in the texture given to the Render Buffer (within Framebuffer Object) ! • Read the data…Slide 30 of 71: • Run OpenGL pipeline • Render GL_QUADS of same size as the texture matrix • Use fragment shader to perform per-fragment computations using data from the texture • OpenGL will store result in the texture given to the Render Buffer (within Framebuffer Object) ! • Read the data…Slide 31 of 71: Run the project from the code/FBO DEMOSlide 32 of 71: PART III “MODERN TIMES”Slide 33 of 71: COMPUTE SHADER • Since OpenGL 4.3 • Used to compute things not related to rendering directlySlide 34 of 71: COMPUTE SHADER • Since OpenGL 4.3 • Used to compute things not related to rendering directlySlide 35 of 71: COMPUTE SHADER http://web.engr.oregonstate.edu/~mjb/cs557/Handouts/compute.shader.1pp.pdf • Since OpenGL 4.3 • Used to compute things not related to rendering directly Will not talk about itSlide 36 of 71: http://wiki.tiker.net/CudaVsOpenCLSlide 37 of 71: Supported only by nVidia hardware Supported by nVidia, AMD, Intel, Qualcomm https://developer.nvidia.com/cuda-gpus http://www.khronos.org/conformance/adopters/conformant-products#opencl http://wiki.tiker.net/CudaVsOpenCLSlide 38 of 71: Supported only by nVidia hardware Supported by nVidia, AMD, Intel, Qualcomm https://developer.nvidia.com/cuda-gpus http://www.khronos.org/conformance/adopters/conformant-products#opencl Implementations only by nVidia Open CL http://wiki.tiker.net/CudaVsOpenCLSlide 39 of 71: Supported only by nVidia hardware Supported by nVidia, AMD, Intel, Qualcomm https://developer.nvidia.com/cuda-gpus http://www.khronos.org/conformance/adopters/conformant-products#opencl Implementations only by nVidia Open CL http://wiki.tiker.net/CudaVsOpenCL ~same performance…Slide 40 of 71: Supported only by nVidia hardware Supported by nVidia, AMD, Intel, Qualcomm https://developer.nvidia.com/cuda-gpus http://www.khronos.org/conformance/adopters/conformant-products#opencl Implementations only by nVidia Open CL http://wiki.tiker.net/CudaVsOpenCL ~same performance…Slide 41 of 71: PART III CHAPTER 1Slide 42 of 71Slide 43 of 71Slide 44 of 71Slide 45 of 71Slide 46 of 71Slide 47 of 71: KERNELSlide 48 of 71: KERNELSlide 49 of 71: KERNELSlide 50 of 71: WRITE AND READ DATA ON GPUSlide 51 of 71: WRITE AND READ DATA ON GPU … run computations here …Slide 52 of 71: WRITE AND READ DATA ON GPU … run computations here …Slide 53 of 71: THE COMPUTATIONSlide 54 of 71: THE COMPUTATIONSlide 55 of 71: THE COMPUTATIONSlide 56 of 71: THE COMPUTATIONSlide 57 of 71: THE COMPUTATIONSlide 58 of 71: DEMO Open, study and run the project from the code/OpenCLSlide 59 of 71: PART III CHAPTER 2Slide 60 of 71: CUDA PROGRAMMING MODEL • CPU is called “ host ” • Move data CPU <-> GPU memory cudaMemcopy • Allocate memory cudaMalloc • Launch kernels on GPU • GPU is called “ device ”Slide 61 of 71: CUDA PROGRAMMING MODEL • CPU is called “ host ” • Move data CPU <-> GPU memory cudaMemcopy • Allocate memory cudaMalloc • Launch kernels on GPU • GPU is called “ device ” 1. CPU allocates memory on GPU 2. CPU copies data to GPU memory 3. CPU launches kernels on GPU (process the…Slide 62 of 71: CUDA PROGRAMMING MODEL • CPU is called “ host ” • Move data CPU <-> GPU memory cudaMemcopy • Allocate memory cudaMalloc • Launch kernels on GPU • GPU is called “ device ” 1. CPU allocates memory on GPU 2. CPU copies data to GPU memory 3. CPU launches kernels on GPU (process the…Slide 63 of 71: EXAMPLE Introduction to Parallel Programming @ Udacity https://www.udacity.com/course/cs344Slide 64 of 71: EXAMPLE Introduction to Parallel Programming @ Udacity https://www.udacity.com/course/cs344Slide 65 of 71: EXAMPLE Introduction to Parallel Programming @ Udacity https://www.udacity.com/course/cs344Slide 66 of 71: EXAMPLE Introduction to Parallel Programming @ Udacity https://www.udacity.com/course/cs344Slide 67 of 71: EXAMPLE Introduction to Parallel Programming @ Udacity https://www.udacity.com/course/cs344Slide 68 of 71: EXAMPLE Introduction to Parallel Programming @ Udacity https://www.udacity.com/course/cs344Slide 69 of 71: EXAMPLE Introduction to Parallel Programming @ Udacity https://www.udacity.com/course/cs344Slide 70 of 71: PART IV “DISCUSSION”Slide 71 of 71: LINKS • Code repository for this presentation • https://github.com/kuz/Introduction-to-GPU-Computing • Feel free to leave feature requests there, ask questions, etc. ! • OpenCL tutorials & presentations • http://streamcomputing.eu/knowledge/for-developers/tutorials/ •…
1 / 71

The presentation was given during the Computer Graphics seminar at the University of Tartu. It is an introductory overview of the GPGPU idea in general and gives “hello world” examples using old-school shader computing, OpenCL and CUDA.

The code is available in my Github repository.
Download PDF