Class

MPSNNGraph

An optimized representation of a graph of neural network image and filter nodes.

Declaration

@interface MPSNNGraph : MPSKernel

Overview

Once you have prepared a graph of MPSNNImageNode, MPSNNFilterNode, and, if needed, MPSNNStateNode objects, you may initialize a MPSNNGraph using the image node that you wish to appear as the result. The graph object will introspect the graph representation and determine which nodes are needed for inputs, and which nodes are produced as output state (if any). Nodes which are not needed to calculate the result image node are ignored. Some nodes may be internally concatenated with other nodes for better performance.

During MPSNNGraph construction, the graph attached to the result node will be parsed and reduced to an optimized representation. This representation may be saved using the NSSecureCoding protocol for later recall.

When decoding a MPSNNGraph using a NSCoder, it will be created against the system default MTLDevice. If you would like to set the device, your NSCoder should conform to the MPSDeviceProvider protocol.

Debugging Tips

In typical usage, some refinement, especially of padding policies, may be required to get the expected answer from Metal Performance Shaders. If the result image is the wrong size, padding is typically the problem. When the answers are incorrect, the offset or other property may be incorrectly configured at some stage. As the graph is generated starting from an output image node, you may create other graphs starting at any image node within the graph. This will give you a view into the result produced from each intermediate layer with a minimum of fuss. In addition, the usual debugDescription method is available to inspect objects to make sure they conform to expectation.

Note that certain operations such as neuron filters that follow convolution filters and image concatenation may be optimized away by the MPSNNGraph when it is constructed. The convolution can do neuron operations as part of its operation. Concatenation is best done by writing the result of earlier filter passes in the right place using destinationFeatureChannelOffset rather than by adding an extra copy. Other optimizations may be added as framework capabilities improve.

Relationships

Inherits From

See Also

Neural Network Graphs

MPSNNImageNode

A placeholder node denoting the position of a neural network image in a graph.

MPSHandle

The protocol that provides resource identification.