Time required to run function on GPU
measures the typical time, in seconds, required to run the function specified by the
t = gputimeit(
F. The function handle accepts no external input
arguments, but you can defined it with input arguments to its internal function
This example shows how to measure the time to calculate
sum(A.' .* B, 1) on a GPU, where
A is a
12000-by-400 matrix and
B is 400-by-12000.
A = rand(12000,400,'gpuArray'); B = rand(400,12000,'gpuArray'); f = @() sum(A.' .* B, 1); t = gputimeit(f)
Compare the time to run
svd on a GPU, with one versus three
X = rand(1000,'gpuArray'); f = @() svd(X); t3 = gputimeit(f,3)
t1 = gputimeit(f,1)
F— Function to measure
Function to measure, specified as a function handle.
numOutputs— Number of output arguments
Number of output arguments to use in the function call, specified as a scalar integer.
If the function specified by
F has a variable number of
numOutputs specifies which syntax
uses to call the function. For example, the
returns a single output,
s, or three outputs,
1 to time the
s = svd(X) syntax, or set it to
3 to time the
[U,S,V] = svd(X) syntax.
F must not call
You cannot use
toc to measure the
execution time of
gputimeit is preferable to
timeit 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.