Optimize this program on a GPU
Mostrar comentarios más antiguos
I'm trying to speed up my program on a GPU. But it is much slower than the CPU version, although I use a very powerful GPU. I haven't been able to vectorize my code due to the fact that every element in my main vector has to be compared to all the other elements in my main vector. Therefore i had to use a parfor loop.
This is my program:
%%generate data
num_tst = 5000; % this is the key number. The CPU takes about 10 sek for 65000
binning = num_tst/100;
N = num_tst /binning;
timestamps = gpuArray.randi(num_tst,num_tst,1);
detectors = gpuArray.randi(4,num_tst,1);
T = N*binning;
timestamps = sort(timestamps);
%%to be optimized
tic;
correlations = gpuArray.zeros(1,N);
parfor i = 1:(size(timestamps,1)-1)
a = gpuArray.zeros(1,N);
j = i+1;
dts = timestamps(j) - timestamps(i);
while (dts < T) && (j <= size(timestamps,1))
if dts == 0 && detectors(i) ~= detectors(j)
a(1) = a(1) + 2;
elseif detectors(i) ~= detectors(j)
dts = floor(dts/binning)+1;
a(dts) = a(dts) + 1;
end
j = j + 1;
if j <= size(timestamps,1)
dts = timestamps(j) - timestamps(i);
end
end
correlations = correlations + a;
end
toc;
How can I speed up my program? Is it possible to vectorize a program like this or do I need to implement this program in CUDA code?
2 comentarios
Edric Ellis
el 22 de Abr. de 2013
You have managed only to run the addition on the GPU, which is why you're seeing no benefit. You should profile the code with no parallelism to see which portions might benefit. If you could make the code self-contained so that it is executable, it might be possible to see how to vectorise or parallelise things.
Matthias
el 22 de Abr. de 2013
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Parallel Computing Toolbox en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!