200 likes | 327 Views
general Purpose GPU computing. Image Processing & CUDA Programming. Jared Barnes Chris Jackson. Graphics Processing Unit. Originally created to calculate pixel values Each core executes the same set of instructions. Mario projected onto several 2D planes. Graphics Processing Unit.
E N D
general Purpose GPU computing Image Processing & CUDA Programming Jared Barnes Chris Jackson
Graphics Processing Unit • Originally created to calculate pixel values • Each core executes the same set of instructions Mario projected onto several 2D planes
Graphics Processing Unit • Chip is designed and manufactured by NVIDIA and AMD • Card bought by consumer is manufactured by various other companies
Image Processing • What does image processing try to accomplish? • Edit an image • Detect faces in an image • Find object edges in an image • Anything you can imagine • Too computationally intensive for a CPU? • Use a GPU!
Image Processing • Simple changes • Crop an image • Recolor an image • Move an image • Harder changes • Scale an image • Compress an image • Filter an image
Image Processing Serial Example // Iterate over all pixels in the image for( int x = 0; x < image.width; x++ ) { for( int y = 0; y < image.height; y++ ) { // Get the value of the current pixel Pixel pixel = image.getPixel(x, y); // Check that Red is more intense than Green if( pixel.red > pixel.green ) { // Check that Red is more intense than Blue if( pixel.red > pixel.blue ) { pixel.red = 0; pixel.green = 0; pixel.blue = 255; } } } }
Image Processing Parallel Example // Use the ID of this thread to calculate which // pixel to operate on intx = thread.Id % image.width; inty = thread.Id/ image.height; // Get the value of this thread’s pixel Pixel pixel = image.getPixel(x, y); // Check that Red is more intense than Green if( pixel.red > pixel.green ) { // Check that Red is more intense than Blue if( pixel.red > pixel.blue ) { pixel.red = 0; pixel.green= 0; pixel.blue= 255; } }
CUDA • Compute Unified Device Architecture • GPU programming language developed by NVIDIA • GPUs have CUDA cores • more cores = more parallel performance
How to write a CUDA program • Have a graphics card with an NVIDIA GPU capable of running CUDA programs • Install CUDA tools and compiler for Visual Studio 2008, 2010, or 2012 • Create a new CUDA project in Visual Studio
3 Steps for Parallelization • Parallelize VectorAdd() • Allocate GPU memory & copy data to it • Modify call to VectorAdd() to launch on GPU