public interface MPSHandle extends NSSecureCoding
MPS resource identification
Most of the time, there is only one image and one or fewer states needed as input to a graph, so the order of the images and states passed to [MPSNNGraph encodeToCommandBuffer:sourceImages:] or [MPSNNGraph encodeToCommandBuffer:sourceImages:sourceStates:intermediateImages:destinationStates:] is clear. There is only one order. However, sometimes graphs have more than one input image or state. What order should they appear in the NSArray passed to these methods?
Each MPSNNImageNode or MPSNNStateNode can be tagged with a MPSHandle. MPSNNGraph keeps track of these. You can request that the MPSNNGraph return them to you in an array in the same order as needed to encode the MPSNNGraph, using MPSNNGraph.sourceImageHandles and MPSNNGraph.sourceStateHandles.
Example:
[@code]
[@interface] MyHandle : NSObject
// required by MPSHandle protocol
-(NSString * __nullable) label;
// MPSHandle implies NSSecureCoding too
+(BOOL) supportsSecureCoding;
- (void)encodeWithCoder:(NSCoder * __nonnull )aCoder;
- (nullable instancetype)initWithCoder:(NSCoder * __nonnull )aDecoder; // NS_DESIGNATED_INITIALIZER
[@end]
// Encode a graph to cmdBuf using handles for images
// Here we assume that the MPSNNImageNodes that are graph inputs (not produced
// by the graph) are tagged with a unique instance of MyHandle that can be used
// to get the appropriate image for that node.
static void MyEncodeGraph( MPSNNGraph * graph, id
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
label()
A label to be attached to associated MTLResources for this node
|
_supportsSecureCodingencodeWithCoder, initWithCoder