Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Prochaine révision
Révision précédente
perf:matlabgpu [2019/06/27 08:00] – créée adminperf:matlabgpu [2019/07/08 12:30] (Version actuelle) – [Using Matlab compiler] admin
Ligne 1: Ligne 1:
 ====== Using GPU in MATLAB ====== ====== Using GPU in MATLAB ======
 +In this lab, we will use GPUs with MATLAB to run fftw calculations.
 +First of all we use the parallel toolbox directly from matlab. Then we use the Matlab compiler to stop consuming tokens (only one token is available for the parallel toolbox).
 +
 +This simple example will be used:
 +
 +<file matlab fftgpu.m>
 +
 +function fftgpu()
 +
 +Nx=1024; Ny=1024;
 +
 +[x,y]=ndgrid(-Nx/2:Nx/2-1,-Ny/2:Ny/2-1);
 +r=x+1i*y;   ph=angle(r);    r=abs(r);
 +
 +gpu=gpuDevice();
 +
 +tic;
 +% init m in GPU
 +m=gpuArray(double(exp(-(r/64).^2)));
 +% run FFT on GPU
 +m=fftshift(fft(m));
 +% gather m from GPU to CPU
 +
 +toc;
 +
 +m=gather(m);
 +
 +% save matrix
 +save('saveM.mat','m');
 +
 +exit();
 +end
 +
 +</file>
 +
 +<note tip>Notice that the code is enclosed in function to be able to use the matlab compiler later</note>
 +
 +===== Using Matlab directly =====
 +**prerequisites**
 +  * Matlab 2017b
 +  * Cuda 8
 +
 +Here is the SGE script:
 +
 +<file bash fftmatlab1.sge>
 +
 +#!/bin/bash -l
 +
 +#$ -N fft_matlabGPU
 +#$ -o $JOB_NAME.$JOB_ID.out
 +#$ -q tesla.q  ## request tesla
 +#$ -l h_vmem=20G ## we request more because of Java
 + 
 +module load gpu/cuda/8.0    
 +module load matlab/r2017b 
 + 
 +matlab -nodisplay -r "fftgpu"
 +
 +</file>
 +
 +submit the job with:
 +<code bash>
 +$ qsub fftmatlab1.sge
 +</code>
 +===== Using Matlab compiler =====
 +We use compiler to avoid using parallel tokens ( 1 token available!)
 +
 +MATLAB compiler will generate executable and scripts files in the same directory.
 +
 +here is the SGE script:
 +
 +
 +<file bash fftmatlab2.sge>
 +
 +#!/bin/bash -l
 +
 +#$ -N fft_matlabGPUCompiler
 +#$ -o $JOB_NAME.$JOB_ID.out
 +#$ -q tesla.q  ## request tesla
 +#$ -l h_vmem=20G ## we request more because of Java
 + 
 +module load gpu/cuda/8.0    
 +module load matlab/r2017b 
 +mcc -m fftgpu.m
 +./run_fftgpu.sh $MATLAB_HOME
 +
 +</file>
 +
 +submit the job with:
 +<code bash>
 +$ qsub fftmatlab2.sge
 +</code>
 +
 +
  
  • perf/matlabgpu.1561622405.txt.gz
  • Dernière modification : 2019/06/27 08:00
  • de admin