Interface MPSHandle

  • All Superinterfaces:
    NSCoding, NSSecureCoding

    public interface MPSHandle
    extends NSSecureCoding
    [@protocol] MPSHandle 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 // Add a method for my use to get the image needed based on the handle to it. // This isn't part of the MPSHandle protocol, but we need it for MyEncodeGraph // below. Since it is my code calling my object, we can add whatever we want like this. -(MPSImage*__nonnull) image; // return the MPSImage corresponding to the handle // 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 cmdBuf ) {
    • Method Detail

      • label

        java.lang.String label()
        A label to be attached to associated MTLResources for this node
        Returns:
        A human readable string for debugging purposes