gputimeit - Time required to run function on GPU - MATLAB (original) (raw)
Time required to run function on GPU
Syntax
Description
`t` = gputimeit([F](#bt2teyd-1%5Fsep%5Fmw%5F36bf257a-b3d9-489e-b520-c6940be573f1))
measures the typical time, in seconds, required to run the function specified by the function handle F
. The function handle accepts no external input arguments, but you can define it with input arguments to its internal function call.
`t` = gputimeit([F](#bt2teyd-1%5Fsep%5Fmw%5F36bf257a-b3d9-489e-b520-c6940be573f1),[numOutputs](#mw%5F8e259ce9-4335-466f-b535-33c4681fca4a))
calls F
with the desired number of output arguments,numOutputs
. By default, gputimeit
calls the function F
with one output argument, or no output arguments ifF
does not return any output.
Examples
This example shows how to measure the time to calculatesum(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 output arguments.
X = rand(1000,'gpuArray'); f = @() svd(X); t3 = gputimeit(f,3)
Input Arguments
Function to measure, specified as a function handle.
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 outputs, numOutputs
specifies which syntax gputimeit
uses to call the function. For example, the svd
function returns a single output, s
, or three outputs,[U,S,V]
. Set numOutputs
to1
to time the s = svd(X)
syntax, or set it to3
to time the [U,S,V] = svd(X)
syntax.
Limitations
- The function
F
must not calltic
ortoc
. - You cannot use
tic
andtoc
to measure the execution time ofgputimeit
itself.
Tips
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.
Extended Capabilities
Version History
Introduced in R2013b