Tutorial / classes / training for developing asynchronous CUDA and MEX code?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Nathan Zechar
le 3 Mar 2022
Commenté : Nathan Zechar
le 12 Mar 2022
Hello, I'm trying to improve the performance of my code which makes use of a GPU for calculations that primarily use MTimes. I have several lines of code I would like performed asynchronously. A rough sample of the code is shown below with the asynchronous portion identified.
N = 128; % Simulation Size
[Nx,Ny,Nz] = deal(N,N,N); % Simulation Cube
Hxey = gpuArray(ones(Nx+1,Ny,Nz)); % Represents Constant
Hxez = gpuArray(ones(Nx+1,Ny,Nz)); % Represents Constant
Hyez = gpuArray(ones(Nx,Ny+1,Nz)); % Represents Constant
Hyex = gpuArray(ones(Nx,Ny+1,Nz)); % Represents Constant
Hzex = gpuArray(ones(Nx,Ny,Nz+1)); % Represents Constant
Hzey = gpuArray(ones(Nx,Ny,Nz+1)); % Represents Constant
Ex = gpuArray(zeros(Nx,Ny+1,Nz+1)); % Ex cells
Ey = gpuArray(zeros(Nx+1,Ny,Nz+1)); % Ey cells
Ez = gpuArray(zeros(Nx+1,Ny+1,Nz)); % Ez cells
Hx = gpuArray(zeros(Nx+1,Ny,Nz)); % Hx cells
Hy = gpuArray(zeros(Nx,Ny+1,Nz)); % Hy cells
Hz = gpuArray(zeros(Nx,Ny,Nz+1)); % Hz cells
%% Representation of code I want to perform asynchronously using CUDA / MEX
%% Begin asynchronous portion
Hx = Hx+Hxey.*diff(Ey,1,3)+Hxez.*diff(Ez,1,2); % Central Difference
Hy = Hy+Hyez.*diff(Ez,1,1)+Hyex.*diff(Ex,1,3); % Central Difference
Hz = Hz+Hzex.*diff(Ex,1,2)+Hzey.*diff(Ey,1,1); % Central Difference
%% End asynchronous portion
Are there any classes or training offered by Matlab or tutorials available online that can teach me how to implement this?
Thank you!
0 commentaires
Réponse acceptée
Joss Knight
le 9 Mar 2022
Make all the variables involved gpuArray objects and those lines of code will run as asynchronously as the GPU allows. This means that the last line of code will exit before Hz has finished being computed.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur GPU Computing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!