Fast way to update gpuArray data for mesh(X,Y,Z) in a loop

8 visualizzazioni (ultimi 30 giorni)
Currently Im testing gpu related calculations in matlab out. I searched for efficient ways to update plots with new calculated data / or just updating data out of an gpuarray in a loop. Im made an example for testing this specific topic. For large gridsize >>500 plotting the mesh on cpu is rather slow, so I wanted to try it on gpu. But I didnt find an efficient and working way to update, in this example, the Z-Data without deleting and creating new meshes.
Running this code with gpu = true results in :
Value must be a scalar, vector or array of numeric type.
Error in GPU (line 32)
gpuPlot.ZData = currentZ;
Do I have to gather() the data each time in the loop or is there a faster way?
clear
gpu = false;
if ~gpu
gridsize = (500);
else
gridsize = gpuArray(500);
end
t = 10;
B = 1000;
L = 1000;
dt = t/gridsize;
iterations = t/dt;
[X,Y] = meshgrid(0:B/gridsize:B,0:L/gridsize:L);
if ~gpu
Zstart = zeros(length(X),length(Y));
Z = zeros(iterations,length(X),length(Y));
else
Zstart = zeros(length(X),length(Y),"gpuArray");
Z = zeros(iterations,length(X),length(Y),"gpuArray");
end
figure
gpuPlot = mesh(X,Y,Zstart);
zlim([-9e+09 9e+09])
for t =1: iterations
current_time = dt*t;
currentZ = 100*cos(1/current_time.^0.5)*(X.^2 +Y.^2)*sin(X/(current_time/0.01).^1.1 +Y/(current_time/0.01).^1.1);
gpuPlot.ZData = currentZ;
Z(t,:,:) =currentZ ;
drawnow
if mod(t,10)==0
title(current_time)
end
end

Risposte (1)

Shubham
Shubham il 6 Set 2023
Hey Jonas,
To efficiently plot the mesh for a large dataset you can try using external GPU-accelerated plotting libraries or leverage MATLAB's Parallel Computing Toolbox.
One option is to use the gplot3 function from the GPUmat library from the MATLAB file exchange, which provides GPU-accelerated plotting capabilities.
Another approach is to use MATLAB's Parallel Computing Toolbox and parfor loop to perform the calculations in parallel on the GPU and transfer the data to the CPU using the gather function and then plotting the mesh. 
You can also refer to :
Hope this helps!!

Prodotti


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by