% This m-file compiles and test
% a MEX file making use of the GPUFFTW
% source to do FFTs on the GPU in matlab
% It assumes a working GPUFFTW installation
% (http://gamma.cs.unc.edu/GPUFFTW/)
% in the same folder than this testGPU_FFT.m
% The gpu_FFT.cpp and fftGPU.m file should also be in this folder.
% Mods required to built the C++ example3:
% LINUX
% 1)
% in /usr/lib64, freeglut (libglut.so.3)
% Was replaced by glut 3.7, see www.opengl.org
% 2)
% in the /lib/Linux folder of the GPUFFTW
% installation we had to make a symlink to
% our /usr/lib64/libglut.so.3
% WINDOWS
% 1) install glut 3.7g, lib named glut32.lib
% there's a glut 64 bit for win64
% Our first system is Fedora Core 5, 64 bits
% NVIDIA linux driver installed.
% You may have to change the /usr/lib64/ path
% depending upon your system.
% Our second system is Windows XP pro, 64 bits
% NVIDIA driver installed.
% You may have to change the glut32.lib path
% depending upon your system.
% Read fftGPU.m for some restrictions for the fft
% Known bugs: on Linux, GPUFFTW is unable to
% retreive the VRAM size and assumes 256 MB.
% You can change the assuming size in GPUFFTW.cpp line (132)
% Simon Potvin and Jerome Genest, July 2006
% Centre d'optique, photonique et laser (COPL)
% Universite Laval
% Quebec, Canada
close all
clear all
clc
%%% LINUX MEX COMPILATION
lib = '/usr/lib64/';
mex('-IGPUFFTW/include', '-IGPUFFTW/src', ... % Headers
'gpu_FFT.cpp', 'GPUFFTW/src/GPUFFTW.cpp', 'GPUFFTW/src/arbfprog.cpp', 'GPUFFTW/src/stopwatch.cpp',... % sources
[lib 'libglut.so.3'], [lib 'libGLU.so'], [lib 'libGL.so'], [lib 'libXi.so.6'], [lib 'libXmu.so']) % Shared libs
%%% WINDOWS MEX COMPILATION
% mex ('-IGPUFFTW/include', '-IGPUFFTW/src', ... % Headers
% 'gpu_FFT.cpp', 'GPUFFTW/src/GPUFFTW.cpp', 'GPUFFTW/src/arbfprog.cpp', 'GPUFFTW/src/stopwatch.cpp',... % sources
% 'C:\Program Files (x86)\Microsoft Visual Studio 8\VC\lib\amd64\glut32.lib') % Shared libs
N=5:20;
t_gpu_c = [];
t_fft_c = [];
t_gpu_r = [];
t_fft_r = [];
Nombre=2^22./2.^N; % assuming VRAM = 256 MB
%Nombre=[1];
for i=1:length(N)
N(i)
%%% COMPLEX TEST
a=rand(2^N(i),Nombre(i));
a=a+sqrt(-1).*rand(2^N(i),Nombre(i));
tic
d1=fftGPU(a,1);
t_gpu_c = [t_gpu_c toc/Nombre(i)];
%%% REAL TEST
b=rand(2^(N(i)+1),Nombre(i));
tic
d2=fftGPU(b,1);
t_gpu_r = [t_gpu_r toc/Nombre(i)];
%%% MATLAB
tic
c1=fft(a);
t_fft_c = [t_fft_c toc/Nombre(i)];
tic
c2=fft(b);
t_fft_r = [t_fft_r toc/Nombre(i)];
end
%%% ERROR
error_real=c2-d2;
error_complex=c1-d1;
%%% PLOT SPEED
plot(2.^N,t_gpu_c,'-*b',2.^N,t_fft_c,'-+g',2.^(N+1),t_gpu_r,'-or',2.^(N+1),t_fft_r,'-xm')
figure
plot(N,t_gpu_c,'-*b' ,N,t_fft_c,'-+g',(N+1),t_gpu_r,'-or',(N+1),t_fft_r,'-xm')