gputimeit
Time required to run function on GPU
Syntax
t = gputimeit(F)
t = gputimeit(F,N)
Description
t = gputimeit(F)
measures the typical time (in seconds) required to run the function specified by the function handleF
. The function handle accepts no external input arguments, but can be defined with input arguments to its internal function call.
t = gputimeit(F,N)
callsF
to returnN
output arguments. By default,gputimeit
calls the functionF
with one output argument, or no output arguments ifF
does not return any output.
Examples
Measure the time to calculatesum(A.' .* B, 1)
on a GPU, whereA
is a 12000-by-400 matrix andB
is 400-by-12000.
A = rand(12000,400,'gpuArray'); B = rand(400,12000,'gpuArray'); f = @() sum(A.' .* B, 1); t = gputimeit(f)
0.0026
Compare the time to runsvd
on a GPU, with one versus three output arguments.
X = rand(1000,'gpuArray'); f = @() svd(X); t3 = gputimeit(f,3)
1.0622
t1 = gputimeit(f,1)
0.2933
Tips
gputimeit
is preferable totimeit
for functions that use the GPU, because it ensures that all operations on the GPU have finished before recording the time and compensates for the overhead. For operations that do not use a GPU,timeit
offers greater precision.
Note the following limitations:
The function
F
should not calltic
ortoc
.You cannot use
tic
andtoc
to measure the execution time ofgputimeit
itself.