Professional Documents
Culture Documents
S4421 Gpu Computing With Matlab
S4421 Gpu Computing With Matlab
Andy Th
Product Marketing Manager
Image Processing Applications
2
Agenda
What is MATLAB?
Summary
3
What is MATLAB?
Implementation
5
Running MATLAB code on the GPU
bwmorph imhist
bwlookup imnoise
Ability to launch CUDA kernels corr2
edge
imopen
imresize
histeq imrotate
imadjust imshow
imbothat imtophat
imclose imwarp
Ability to deploy MATLAB GPU applications imdilate mean2
imerode medfilt2
imfilter padarray
imgradient rgb2gray 6
Agenda
What is MATLAB?
Summary
7
Demo: Digital Camera Pipeline
From Sensor Data to Image
Scene Image
8
Stages of the Camera Pipeline
Greater Control
Simple programming constructs:
gpuArray, gather
Ease of Use
http://www.mathworks.com/help/distcomp/run-mex-functions-containing-cuda-code.html
10
Agenda
What is MATLAB?
Summary
11
Demo: Brain Scan
CPU vs GPU
12
Agenda
What is MATLAB?
Summary
13
Stages of the Camera Pipeline
Before After
15
Programming Parallel Applications (GPU)
Greater Control
Simple programming constructs:
gpuArray, gather
Ease of Use
http://www.mathworks.com/help/distcomp/run-mex-functions-containing-cuda-code.html
16
Summary Part 1: Apply Scaling Factors on GPU
% Find average gray value and compute scaling factor. % Load the Kernel
factors = max(mean(avg_rgb), 128)./avg_rgb; kernel =
parallel.gpu.CUDAKernel('applyScaleFactors.ptxw64',
'applyScaleFactors.cu' );
...
% Copy our Image to the GPU
% Adjust the image to the new gray value. imageDataGPU = gpuArray( imageData );
imageData(:,:,1) = uint8(imageData(:,:,1)*factors(1)); ...
imageData(:,:,2) = uint8(imageData(:,:,2)*factors(2)); % Apply kernel to scale the color values
imageData(:,:,3) = uint8(imageData(:,:,3)*factors(3)); adjustedImageGPU = feval( kernel, adjustedImageGPU,
imageDataGPU, factors, nRows, nCols );
% Find average gray value and compute scaling factor. % Compute the factors from the mean.
factors = max(mean(avg_rgb), 128)./avg_rgb; computeFactorsKernel = parallel.gpu.CUDAKernel( ...
'computeScaleFactors.ptxw64','computeScaleFactors.cu'
);
...
18
Summary Part 3: Compute Mean on GPU with NPP
19
Summary Part 4: Integrate C with CUDA
function imageData = whitebalance(imageData) // dllmain.cpp : Defines the entry point for the DLL
% WHITEBALANCE forces average image color to be gray. application.
#include <mex.h>
% Find the average values for each channel. #include <gpu\mxGPUArray.h>
avg_rgb = mean(mean(imageData)); #include "whitebalance.h"
What is MATLAB?
Summary
21
Programming Parallel Applications (GPU)
Greater Control
Simple programming constructs:
gpuArray, gather
Ease of Use
http://www.mathworks.com/help/distcomp/run-mex-functions-containing-cuda-code.html
22
MATLAB Value-add to CUDA Programmers
23
Scaling to Run on Multiple GPUs
24
Running MATLAB code on the GPU
bwmorph imhist
bwlookup imnoise
Ability to launch CUDA kernels corr2
edge
imopen
imresize
histeq imrotate
imadjust imshow
imbothat imtophat
imclose imwarp
Ability to deploy MATLAB GPU applications imdilate mean2
imerode medfilt2
imfilter padarray
imgradient rgb2gray 25
GPU Computing with MATLAB
26
Questions & Answers