how do I gather() a variable in atomicAdd()?

9 Ansichten (letzte 30 Tage)
Nick Tsui
Nick Tsui am 19 Mär. 2012
I am just wondering how to return result from atomicAdd(), since atomicAdd only changes one of its inputs. Here is my kernel (CUDA C):
__global__ void agpuhelloworld( double* c, double ato, double b ) {
*c = ato + b;
atomicAdd(&ato, b);
}
I know how to collect c, but how do I collect value of ato from this kernel with a MATLAB script? I cannot declare that as persistent, because ato is one of the inputs to MATLAB function. Following is my MATLAB code, I think it is something like that. I only show how to gather() c.
function out = gpuhelloworld(ato,b)
persistent gpuadd;
persistent c;
if isempty(gpuadd)
disp 'Initializing GPU drf calculation...';
gpuadd = parallel.gpu.CUDAKernel('agpuhelloworld.ptx','agpuhelloworld.cu','agpuhelloworld');
tmp = gpuDevice;
gpuadd.GridSize = [min(1024,tmp.MaxGridSize(1)) 1]; % min(1024, maxblocks)
gpuadd.ThreadBlockSize = [min(128,tmp.MaxThreadsPerBlock) 1 1]; % min(128, maxthreadsperblock)
c = gpuArray(zeros(1,1));
end;
c= feval(gpuadd, c,ato,b);
out = gather(c);

Akzeptierte Antwort

m4 Chrennikov
m4 Chrennikov am 22 Mär. 2012
Try this:
[c, ato] = feval(gpuadd, c,ato,b);
out = gather(ato);

Weitere Antworten (1)

Nick Tsui
Nick Tsui am 24 Mär. 2012
Thanks it works.

Kategorien

Mehr zu GPU Computing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by