Main Content

gputimeit

Time required to run function on GPU

Description

example

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 you can defined it with input arguments to its internal function call.

example

t= gputimeit(F,numOutputs)callsFwith the desired number of output arguments,numOutputs. By default,gputimeitcalls the functionFwith one output argument, or no output arguments ifFdoes not return any output.

Examples

collapse all

This example shows how to measure the time to calculatesum(A.' .* B, 1)on a GPU, whereAis a 12000-by-400 matrix andBis 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 runsvdon 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

Input Arguments

collapse all

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 byFhas a variable number of outputs,numOutputsspecifies which syntaxgputimeituses to call the function. For example, thesvdfunction returns a single output,s, or three outputs,[U,S,V]. SetnumOutputsto1to time thes = svd(X)syntax, or set it to3to time the[U,S,V] = svd(X)syntax.

Limitations

  • The functionFmust not callticortoc.

  • You cannot useticandtocto measure the execution time ofgputimeititself.

Tips

gputimeitis preferable totimeitfor 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,timeitoffers greater precision.

版本历史

Introduced in R2013b