pro test_gpuWhere
gpuinit
A = float(round(randomu(s,1000000)))
st = systime(2)
for i=0,99 do begin
gpuPutArr, A, A_gpu
ind = where(A,count)
endfor
print,count
CPUtime = systime(2)-st
st = systime(2)
_ = temporary(count)
for i=0,99 do begin
gpuPutArr, A, A_gpu
gpuWhere,A_gpu,ind_gpu,count
endfor
print,count
GPUtime = systime(2)-st
print, 'Speedup: ',CPUtime/GPUtime
gpuFree,A_gpu
gpuFree,ind_gpu
end
Several things to notice here:
A is an array of "float flags", i.e. 1.0s and 0.0s. Everything, repeat, everything in GPULIB is float. Also the count parameter in gpuWhere returns the sum of A, not the number of nonzero elements.
Before reusing count in gpuWhere I have to undefine it, because it is returned as longint from where(). GPULIB will report an error otherwise.
In the loop, I have to use putArr,A,A_gpu each time, because gpuWhere overwrites its first argument.
So is all this worth the trouble?
% Compiled module: TEST_GPUWHERE.
500933
500933.
Speedup: 1.3521798
Evidently not.

0 comments:
Post a Comment