Tutorial / classes / training for developing asynchronous CUDA and MEX code?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Joss Knight
2022-3-9
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 GPU Computing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!