<MPSImageAllocator >(3) | MetalPerformanceShaders.framework | <MPSImageAllocator >(3) |
<MPSImageAllocator >
#import <MPSImage.h>
Inherits <NSObject>, and <NSSecureCoding>.
(MPSImage *__nonnull) -
imageForCommandBuffer:imageDescriptor:kernel:
(MPSImageBatch *__nonnull) -
imageBatchForCommandBuffer:imageDescriptor:kernel:count:
A class that allocates new MPSImage or MPSTemporaryImage Sometimes it is prohibitively costly for MPS to figure out how big an image should be in advance. In addition, you may want to have some say over whether the image is a temporary image or not. In such circumstances, the MPSImageAllocator is used to provide the developer with an opportunity for just in time feedback about how the image should be allocated.
Two standard MPSImageAllocators are provided: MPSImageDefaultAllocator and MPSTemporaryImageDefaultAllocator. You may of course provide your own allocator instead.
Example:
// Note: MPSImageDefaultAllocator is already provided // by the framework under that name. It is provided here // as sample code for writing your own variant. -(MPSImage * __nonnull) imageForCommandBuffer: (__nonnull id <MTLCommandBuffer>) cmdBuf imageDescriptor: (MPSImageDescriptor * __nonnull) descriptor kernel: (MPSKernel * __nonnull) kernel { MPSImage * result = [[MPSImage alloc] initWithDevice: cmdBuf.device imageDescriptor: descriptor ]; // make sure the object sticks around at least as lomg as the command buffer [result retain]; [cmdBuf addCompletedHandler: ^(id <MTLCommandBuffer> c){[result release];}]; // return autoreleased result return [result autorelease]; }; -(BOOL) supportsSecureCoding{ return YES; } -(void)encodeWithCoder:(NSCoder * __nonnull)aCoder { [super encodeWithCoder: aCoder]; // encode any data owned by the class at this level } -(nullable instancetype) initWithCoder: (NSCoder*__nonnull) aDecoder { self = [super initWithCoder: aDecoder ]; if( nil == self ) return self; // use coder to load any extra data kept by this object here return self; }
Please see [MPSImage defaultAllocator] and [MPSTemporaryImage defaultAllocator] for implentations of the protocol already provided by MPS.
When considering whether to write your own MPSImageAllocator, you should know the existing MPSImage and MPSTemporaryImage default allocators are optimized to make image batch allocation much faster than one MPSImage at a time in a loop. When possible, it can be better to use the MPS provided allocators and override the behavior in a padding policy instead, if the changes can be contained in the MPSImageDescriptor. This will help reduce CPU encode time. However, custom padding policies can inhibit optimizations in the MPSNNGraph, particularly node fusion, resulting in more work for the GPU. In cases where the custom padding method does not change filter properties but only adjusts the result image (e.g. adjust result feature channel format) then MPSNNPaddingMethodCustomWhitelistForNodeFusion may be used to signal that node fusion is acceptable.
Efficiently create an array of MPSImages with a common descriptor See class description for sample implementation
Parameters:
Returns:
Create a new MPSImage See class description for sample implementation
Parameters:
Returns:
Generated automatically by Doxygen for MetalPerformanceShaders.framework from the source code.
Mon Jul 9 2018 | Version MetalPerformanceShaders-119.3 |