AcceleratedFunction
Description
An AcceleratedFunction stores traces of the underlying function
Reusing a cached trace depends on the function inputs and outputs:
For any
dlarrayobject or structure ofdlarrayobject inputs, the trace depends on the size, format, and underlying datatype of thedlarray. That is, the accelerated function triggers a new trace fordlarrayinputs with size, format, or underlying datatype not contained in the cache. Anydlarrayinputs differing only by value to a previously cached trace do not trigger a new trace.For any
dlnetworkinputs, the trace depends on the size, format, and underlying datatype of thedlnetworkstate and learnable parameters. That is, the accelerated function triggers a new trace fordlnetworkinputs with learnable parameters or state with size, format, and underlying datatype not contained in the cache. Anydlnetworkinputs differing only by the value of the state and learnable parameters to a previously cached trace do not trigger a new trace.For other types of input, the trace depends on the values of the input. That is, the accelerated function triggers a new trace for other types of input with value not contained in the cache. Any other inputs that have the same value as a previously cached trace do not trigger a new trace.
The trace depends on the number of function outputs. That is, the accelerated function triggers a new trace for function calls with previously unseen numbers of output arguments. Any function calls with the same number of output arguments as a previously cached trace do not trigger a new trace.
When necessary, the software caches any new traces by evaluating the underlying function
and caching the resulting trace in the AcceleratedFunction object.
The returned AcceleratedFunction object caches the
traces of calls to the underlying function and reuses the cached
result when the same input pattern reoccurs.
Try using dlaccelerate for function calls that:
are long-running
have
dlarrayobjects, structures ofdlarrayobjects, ordlnetworkobjects as inputsdo not have side effects like writing to files or displaying output
Invoke the accelerated function as you would invoke the underlying function. Note that the accelerated function is not a function handle.
Note
When using the dlfeval function, the software automatically
accelerates the forward and predict functions for
dlnetwork input. If you accelerate a deep learning function where the
majority of the computation takes place in calls to the forward or
predict functions for dlnetwork input, then you might
not see an improvement in training time.
Caution
An AcceleratedFunction object is not aware of updates to the underlying
function. If you modify the function associated with the accelerated function, then
clear the cache using the clearCache object function or alternatively use the command
clear functions.
Creation
To create an AcceleratedFunction object, use the dlaccelerate
function.
Properties
Object Functions
clearCache | Clear accelerated deep learning function trace cache |
Examples
Version History
Introduced in R2021a