Last active
August 29, 2015 13:56
-
-
Save brockpalen/8816376 to your computer and use it in GitHub Desktop.
Example of using Matlab with GPUS and doing all computation on the GPU
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%Brock Palen brockp@umich.edu 1/2014 | |
%To compare against a single core run: | |
% hwloc-bind core:0 matlab -r gen\(1e4\) #first core | |
% hwloc-bind socket:0 matlab -r gen\(1e4\) #first socket all cores | |
function gen(dim) | |
if ischar(dim) | |
dim=str2num(dim); | |
end | |
%preallocate | |
a = zeros(dim); | |
%wakeup the gpu takes ~12 seconds | |
II = gpuArray.eye(10,'int32'); | |
%slow way, ommitted | |
%disp('Time to use loop for allocation') | |
%tic; | |
%for x = 1:dim, | |
% for y = 1:dim, | |
% a(x, y) = sin(6 * pi * (x^2 + y^2)); | |
% end | |
%end | |
%toc | |
disp('Vector Form') | |
tic; | |
x = 1:dim; | |
y = 1:dim; | |
[X, Y] = meshgrid(x,y); | |
a = sin(6 * pi * (X.^2 + Y.^2)); | |
fftn(a); | |
toc | |
disp('GPU Form') | |
tic; | |
Gx = gpuArray(1:dim); | |
Gy = gpuArray(1:dim); | |
[GX, GY] = meshgrid(Gx, Gy); | |
Ga = sin(6 *pi * (GX.^2 + GY.^2)); | |
clear GX GY Gx Gy; | |
fftn(Ga); | |
toc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment