Code covered by the BSD License  

Highlights from
A CUDA accelerated Beam Propagation Method [BPM] Solver using the Parallel Computing Toolbox

image thumbnail

A CUDA accelerated Beam Propagation Method [BPM] Solver using the Parallel Computing Toolbox

by

 

21 Oct 2010 (Updated )

A beam propagation method solver using the CUDA capabilities in the parallel computing toolbox.

ScrTimeBPM.m
%SCR_TIME_BPM A script to time the BPM code with and without CUDA
%Author: Patrick Kano, Applied Energetics, Inc.
% Modification Dates [M/D/Y]: 10/21/10 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

format compact;
diary('CompareRunTimes.txt');

%%Parameters
%CUDAswitch = 0 %0-CPU fft2, 1-GPU fft2
PLOTswitch = 0; %0-No plots, 1-With plots
%BetaSwitch = 0; %0-Constant beta, 1-Update beta
 
LengthX = 4*10^(-3);  %m
LengthY = 4*10^(-3);  %m
LengthZ = 5*10^(-3);     %m
deltaZ = LengthZ/1000; %m

Lambda = 1000*10^(-6); %m

%Nx = 2^6; %Must be 2^N
%Ny = 2^6; %Must be 2^N
 
%%Simulations 
%Note: The BPM code is [-Lx,Lx]x[-Ly,Ly] and (2Nx,2Ny) points.
ExpVec = 2:11

disp('Constant Beta');
BetaSwitch = 0; %0-Constant beta, 1-Update beta
for expidx=ExpVec
 Nx = 2^expidx; %Must be 2^N
 Ny = 2^expidx; %Must be 2^N
 disp(['Nx = Ny = ',num2str(Nx)]);
 
 disp('GPU');
 RunTimeCUDAConst(expidx-1) = CUDAparaxbpm(1, PLOTswitch, BetaSwitch, Nx, Ny, LengthX, LengthY, LengthZ, deltaZ, Lambda);
 
 disp('CPU');
 RunTimeMATLABConst(expidx-1) =  CUDAparaxbpm(0, PLOTswitch, BetaSwitch, Nx, Ny, LengthX, LengthY, LengthZ, deltaZ, Lambda);
end %for loop

disp('Updated Beta');
BetaSwitch = 1; %0-Constant beta, 1-Update beta
for expidx=ExpVec
 Nx = 2^expidx; %Must be 2^N
 Ny = 2^expidx; %Must be 2^N
 disp(['Nx = Ny = ',num2str(Nx)]);
 
 disp('GPU');
 RunTimeCUDAUpdate(expidx-1) = CUDAparaxbpm(1, PLOTswitch, BetaSwitch, Nx, Ny, LengthX, LengthY, LengthZ, deltaZ, Lambda);
 
 disp('CPU');
 RunTimeMATLABUpdate(expidx-1) =  CUDAparaxbpm(0, PLOTswitch, BetaSwitch, Nx, Ny, LengthX, LengthY, LengthZ, deltaZ, Lambda);
end %for loop

RunTimeCUDAConst = RunTimeCUDAConst
RunTimeMATLABConst = RunTimeMATLABConst
RunTimeCUDAUpdate = RunTimeCUDAUpdate
RunTimeMATLABUpdate = RunTimeMATLABUpdate

%%Plots
figure(2001);
plot(ExpVec+1,RunTimeCUDAConst,'-bo',ExpVec+1,RunTimeMATLABConst,'-rx');
xlabel('Matrix Size 2^{N}');
ylabel('Run Time [sec]');
legend('GPU','CPU');

figure(2002);
plot(ExpVec+1,RunTimeCUDAConst./RunTimeMATLABConst,'-ko');
xlabel('Matrix Size 2^{N}');
ylabel('Ratio [sec]');

figure(2003);
plot(ExpVec+1,RunTimeCUDAUpdate,'-bo',ExpVec+1,RunTimeMATLABUpdate,'-rx');
xlabel('Matrix Size 2^{N}');
ylabel('Run Time [sec]');
legend('GPU','CPU');

figure(2004);
plot(ExpVec+1,RunTimeCUDAUpdate./RunTimeMATLABUpdate,'-ko');
xlabel('Matrix Size 2^{N}');
ylabel('Ratio [sec]');

diary off;
%end of script
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Contact us