Skip to content

Instantly share code, notes, and snippets.

@rej55
Created December 3, 2017 05:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rej55/a759c1d92f438804fcb79049f2ae96bc to your computer and use it in GitHub Desktop.
Save rej55/a759c1d92f438804fcb79049f2ae96bc to your computer and use it in GitHub Desktop.
%% Initialize
clear
%% Set dimesion
N = 10^6;
%% Set source vectors and scalar values
src1 = ones(N, 1);
src2 = 2*ones(N, 1);
k1 = 2;
k2 = 3;
%% Measure elapsed time with MATLAB
tic;
dst1 = k1*src1 + k2*src2;
Elapsed1 = toc;
%% Measure elapsed time with MEX CUDA
tic;
d_src1 = gpuArray(src1);
d_src2 = gpuArray(src2);
d_dst2 = vec_add(d_src1, d_src2, k1, k2);
dst2 = gather(d_dst2);
Elapsed2 = toc;
%% Display result
disp(['N = ' num2str(N)]);
disp(['Elapsed time with MATLAB : ' num2str(Elapsed1) ' sec.']);
disp(['Elapsed time with MEX CUDA : ' num2str(Elapsed2) ' sec.']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment