public class MPSCNNMultiaryKernel extends MPSKernel
Describes a neural network kernel with multiple image sources.
A MPSCNNKernel consumes multiple MPSImages, possibly a MPSState, and produces one MPSImage.
NSObject.Function_instanceMethodForSelector_ret, NSObject.Function_methodForSelector_ret| Modifier | Constructor and Description |
|---|---|
protected |
MPSCNNMultiaryKernel(org.moe.natj.general.Pointer peer) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
_supportsSecureCoding()
This property must return YES on all classes that allow secure coding.
|
static boolean |
accessInstanceVariablesDirectly() |
static MPSCNNMultiaryKernel |
alloc() |
static MPSCNNMultiaryKernel |
allocWithZone(org.moe.natj.general.ptr.VoidPtr zone) |
boolean |
appendBatchBarrier()
Returns YES if the filter must be run over the entire batch before its
results may be used
|
static boolean |
automaticallyNotifiesObserversForKey(java.lang.String key) |
static void |
cancelPreviousPerformRequestsWithTarget(java.lang.Object aTarget) |
static void |
cancelPreviousPerformRequestsWithTargetSelectorObject(java.lang.Object aTarget,
org.moe.natj.objc.SEL aSelector,
java.lang.Object anArgument) |
static NSArray<java.lang.String> |
classFallbacksForKeyedArchiver() |
static org.moe.natj.objc.Class |
classForKeyedUnarchiver() |
MTLRegion |
clipRect()
[@property] clipRect
|
static java.lang.String |
debugDescription_static() |
static java.lang.String |
description_static() |
long |
destinationFeatureChannelOffset()
[@property] destinationFeatureChannelOffset
|
MPSImageAllocator |
destinationImageAllocator()
Method to allocate the result image for -encodeToCommandBuffer:sourceImage:
|
MPSImageDescriptor |
destinationImageDescriptorForSourceImagesSourceStates(NSArray<? extends MPSImage> sourceImages,
NSArray<? extends MPSState> sourceStates)
Get a suggested destination image descriptor for a source image
|
long |
dilationRateXatIndex(long index)
Stride in source coordinates from one kernel tap to the next in the X dimension.
|
long |
dilationRateYatIndex(long index)
Stride in source coordinates from one kernel tap to the next in the Y dimension.
|
long |
edgeModeAtIndex(long index)
The MPSImageEdgeMode to use when texture reads stray off the edge of the primary source image
|
MPSImage |
encodeToCommandBufferSourceImages(MTLCommandBuffer commandBuffer,
NSArray<? extends MPSImage> sourceImages)
Encode a MPSCNNKernel into a command Buffer.
|
void |
encodeToCommandBufferSourceImagesDestinationImage(MTLCommandBuffer commandBuffer,
NSArray<? extends MPSImage> sourceImages,
MPSImage destinationImage)
Encode a MPSCNNKernel into a command Buffer.
|
MPSImage |
encodeToCommandBufferSourceImagesDestinationStateDestinationStateIsTemporary(MTLCommandBuffer commandBuffer,
NSArray<? extends MPSImage> sourceImages,
org.moe.natj.general.ptr.Ptr<MPSState> outState,
boolean isTemporary)
Encode a MPSCNNKernel into a command Buffer.
|
static long |
hash_static() |
MPSCNNMultiaryKernel |
init() |
MPSCNNMultiaryKernel |
initWithCoder(NSCoder aDecoder)
NS_DESIGNATED_INITIALIZER
|
MPSCNNMultiaryKernel |
initWithCoderDevice(NSCoder aDecoder,
java.lang.Object device)
NSSecureCoding compatability
|
MPSCNNMultiaryKernel |
initWithDevice(java.lang.Object device)
Standard init with default properties per filter type
|
MPSCNNMultiaryKernel |
initWithDeviceSourceCount(MTLDevice device,
long sourceCount)
Standard init with default properties per filter type
|
static NSObject.Function_instanceMethodForSelector_ret |
instanceMethodForSelector(org.moe.natj.objc.SEL aSelector) |
static NSMethodSignature |
instanceMethodSignatureForSelector(org.moe.natj.objc.SEL aSelector) |
static boolean |
instancesRespondToSelector(org.moe.natj.objc.SEL aSelector) |
boolean |
isBackwards()
[@property] isBackwards
|
boolean |
isResultStateReusedAcrossBatch()
Returns YES if the same state is used for every operation in a batch
|
boolean |
isStateModified()
Returns true if the -encode call modifies the state object it accepts.
|
static boolean |
isSubclassOfClass(org.moe.natj.objc.Class aClass) |
long |
kernelHeightAtIndex(long index)
The height of the kernel filter window
|
long |
kernelWidthAtIndex(long index)
The width of the kernel filter window
|
static NSSet<java.lang.String> |
keyPathsForValuesAffectingValueForKey(java.lang.String key) |
static MPSCNNMultiaryKernel |
new_objc() |
MPSOffset |
offsetAtIndex(long index)
The positon of the destination clip rectangle origin relative to each source buffer
|
MPSNNPadding |
padding()
[@property] padding
|
static boolean |
resolveClassMethod(org.moe.natj.objc.SEL sel) |
static boolean |
resolveInstanceMethod(org.moe.natj.objc.SEL sel) |
MPSState |
resultStateForSourceImagesSourceStatesDestinationImage(NSArray<? extends MPSImage> sourceImages,
NSArray<? extends MPSState> sourceStates,
MPSImage destinationImage)
Allocate a MPSState (subclass) to hold the results from a -encodeBatchToCommandBuffer...
|
void |
setClipRect(MTLRegion value)
[@property] clipRect
|
void |
setDestinationFeatureChannelOffset(long value)
[@property] destinationFeatureChannelOffset
|
void |
setDestinationImageAllocator(MPSImageAllocator value)
Method to allocate the result image for -encodeToCommandBuffer:sourceImage:
|
void |
setDilationRateXAtIndex(long dilationRate,
long index)
Set the stride in source coordinates from one kernel tap to the next in the X dimension.
|
void |
setDilationRateYAtIndex(long dilationRate,
long index)
Set the stride in source coordinates from one kernel tap to the next in the Y dimension.
|
void |
setEdgeModeAtIndex(long edgeMode,
long index)
Set the MPSImageEdgeMode to use when texture reads stray off the edge of the primary source image
|
void |
setKernelHeightAtIndex(long height,
long index)
Set the height of the kernel filter window
|
void |
setKernelWidthAtIndex(long width,
long index)
Set the width of the kernel filter window
|
void |
setOffsetAtIndex(MPSOffset offset,
long index)
Set the positon of the destination clip rectangle origin relative to each source buffer
|
void |
setPadding(MPSNNPadding value)
[@property] padding
|
void |
setSourceFeatureChannelMaxCountAtIndex(long count,
long index)
Set the maximum number of channels in the source MPSImage to use
|
void |
setSourceFeatureChannelOffsetAtIndex(long offset,
long index)
Set the number of channels in the source MPSImage to skip before reading the input.
|
void |
setStrideInPixelsXAtIndex(long stride,
long index)
The downsampling factor in the horizontal dimension for the source image
|
void |
setStrideInPixelsYAtIndex(long stride,
long index)
The downsampling factor in the vertical dimension for the source image
|
static void |
setVersion_static(long aVersion) |
long |
sourceCount()
The number of source images accepted by the kernel
|
long |
sourceFeatureChannelMaxCountAtIndex(long index)
The maximum number of channels in the source MPSImage to use
|
long |
sourceFeatureChannelOffsetAtIndex(long index)
The number of channels in the source MPSImage to skip before reading the input.
|
long |
strideInPixelsXatIndex(long index)
The downsampling factor in the horizontal dimension for the source image
|
long |
strideInPixelsYatIndex(long index)
The downsampling factor in the vertical dimension for the source image
|
static org.moe.natj.objc.Class |
superclass_static() |
static boolean |
supportsSecureCoding() |
MPSState |
temporaryResultStateForCommandBufferSourceImagesSourceStatesDestinationImage(MTLCommandBuffer commandBuffer,
NSArray<? extends MPSImage> sourceImage,
NSArray<? extends MPSState> sourceStates,
MPSImage destinationImage)
Allocate a temporary MPSState (subclass) to hold the results from a -encodeBatchToCommandBuffer...
|
static long |
version_static() |
copyWithZone, copyWithZoneDevice, device, encodeWithCoder, label, options, setLabel, setOptionsaccessibilityActivate, accessibilityActivationPoint, accessibilityAssistiveTechnologyFocusedIdentifiers, accessibilityAttributedHint, accessibilityAttributedLabel, accessibilityAttributedUserInputLabels, accessibilityAttributedValue, accessibilityContainerType, accessibilityCustomActions, accessibilityCustomRotors, accessibilityDecrement, accessibilityDragSourceDescriptors, accessibilityDropPointDescriptors, accessibilityElementAtIndex, accessibilityElementCount, accessibilityElementDidBecomeFocused, accessibilityElementDidLoseFocus, accessibilityElementIsFocused, accessibilityElements, accessibilityElementsHidden, accessibilityFrame, accessibilityHint, accessibilityIncrement, accessibilityLabel, accessibilityLanguage, accessibilityNavigationStyle, accessibilityPath, accessibilityPerformEscape, accessibilityPerformMagicTap, accessibilityRespondsToUserInteraction, accessibilityScroll, accessibilityTextualContext, accessibilityTraits, accessibilityUserInputLabels, accessibilityValue, accessibilityViewIsModal, addObserverForKeyPathOptionsContext, attemptRecoveryFromErrorOptionIndex, attemptRecoveryFromErrorOptionIndexDelegateDidRecoverSelectorContextInfo, autoContentAccessingProxy, awakeAfterUsingCoder, awakeFromNib, class_objc, classForCoder, classForKeyedArchiver, copy, dealloc, debugDescription, description, dictionaryWithValuesForKeys, didChangeValueForKey, didChangeValueForKeyWithSetMutationUsingObjects, didChangeValuesAtIndexesForKey, doesNotRecognizeSelector, fileManagerShouldProceedAfterError, fileManagerWillProcessPath, finalize_objc, forwardingTargetForSelector, forwardInvocation, hash, indexOfAccessibilityElement, isAccessibilityElement, isEqual, isKindOfClass, isMemberOfClass, isProxy, methodForSelector, methodSignatureForSelector, mutableArrayValueForKey, mutableArrayValueForKeyPath, mutableCopy, mutableOrderedSetValueForKey, mutableOrderedSetValueForKeyPath, mutableSetValueForKey, mutableSetValueForKeyPath, observationInfo, observeValueForKeyPathOfObjectChangeContext, performSelector, performSelectorInBackgroundWithObject, performSelectorOnMainThreadWithObjectWaitUntilDone, performSelectorOnMainThreadWithObjectWaitUntilDoneModes, performSelectorOnThreadWithObjectWaitUntilDone, performSelectorOnThreadWithObjectWaitUntilDoneModes, performSelectorWithObject, performSelectorWithObjectAfterDelay, performSelectorWithObjectAfterDelayInModes, performSelectorWithObjectWithObject, prepareForInterfaceBuilder, provideImageDataBytesPerRowOrigin_Size_UserInfo, removeObserverForKeyPath, removeObserverForKeyPathContext, replacementObjectForCoder, replacementObjectForKeyedArchiver, respondsToSelector, self, setAccessibilityActivationPoint, setAccessibilityAttributedHint, setAccessibilityAttributedLabel, setAccessibilityAttributedUserInputLabels, setAccessibilityAttributedValue, setAccessibilityContainerType, setAccessibilityCustomActions, setAccessibilityCustomRotors, setAccessibilityDragSourceDescriptors, setAccessibilityDropPointDescriptors, setAccessibilityElements, setAccessibilityElementsHidden, setAccessibilityFrame, setAccessibilityHint, setAccessibilityLabel, setAccessibilityLanguage, setAccessibilityNavigationStyle, setAccessibilityPath, setAccessibilityRespondsToUserInteraction, setAccessibilityTextualContext, setAccessibilityTraits, setAccessibilityUserInputLabels, setAccessibilityValue, setAccessibilityViewIsModal, setIsAccessibilityElement, setNilValueForKey, setObservationInfo, setShouldGroupAccessibilityChildren, setValueForKey, setValueForKeyPath, setValueForUndefinedKey, setValuesForKeysWithDictionary, shouldGroupAccessibilityChildren, superclass, validateValueForKeyError, validateValueForKeyPathError, valueForKey, valueForKeyPath, valueForUndefinedKey, willChangeValueForKey, willChangeValueForKeyWithSetMutationUsingObjects, willChangeValuesAtIndexesForKeyprotected MPSCNNMultiaryKernel(org.moe.natj.general.Pointer peer)
public static boolean accessInstanceVariablesDirectly()
public static MPSCNNMultiaryKernel alloc()
public static MPSCNNMultiaryKernel allocWithZone(org.moe.natj.general.ptr.VoidPtr zone)
public boolean appendBatchBarrier()
Nearly all filters do not need to see the entire batch all at once and can operate correctly with partial batches. This allows the graph to strip-mine the problem, processing the graph top to bottom on a subset of the batch at a time, dramatically reducing memory usage. As the full nominal working set for a graph is often so large that it may not fit in memory, sub-batching may be required forward progress.
Batch normalization statistics on the other hand must complete the batch before the statistics may be used to normalize the images in the batch in the ensuing normalization filter. Consequently, batch normalization statistics requests the graph insert a batch barrier following it by returning YES from -appendBatchBarrier. This tells the graph to complete the batch before any dependent filters can start. Note that the filter itself may still be subject to sub-batching in its operation. All filters must be able to function without seeing the entire batch in a single -encode call. Carry over state that is accumulated across sub-batches is commonly carried in a shared MPSState containing a MTLBuffer. See -isResultStateReusedAcrossBatch.
Caution: on most supported devices, the working set may be so large that the graph may be forced to throw away and recalculate most intermediate images in cases where strip-mining can not occur because -appendBatchBarrier returns YES. A single batch barrier can commonly cause a memory size increase and/or performance reduction by many fold over the entire graph. Filters of this variety should be avoided.
Default: NO
public static boolean automaticallyNotifiesObserversForKey(java.lang.String key)
public static void cancelPreviousPerformRequestsWithTarget(java.lang.Object aTarget)
public static void cancelPreviousPerformRequestsWithTargetSelectorObject(java.lang.Object aTarget,
org.moe.natj.objc.SEL aSelector,
java.lang.Object anArgument)
public static NSArray<java.lang.String> classFallbacksForKeyedArchiver()
public static org.moe.natj.objc.Class classForKeyedUnarchiver()
public MTLRegion clipRect()
An optional clip rectangle to use when writing data. Only the pixels in the rectangle will be overwritten.
A MTLRegion that indicates which part of the destination to overwrite. If the clipRect does not lie completely within the destination image, the intersection between clip rectangle and destination bounds is used. Default: MPSRectNoClip (MPSKernel::MPSRectNoClip) indicating the entire image. clipRect.origin.z is the index of starting destination image in batch processing mode. clipRect.size.depth is the number of images to process in batch processing mode.
See Also: @ref subsubsection_clipRect
public static java.lang.String debugDescription_static()
public static java.lang.String description_static()
public long destinationFeatureChannelOffset()
The number of channels in the destination MPSImage to skip before writing output.
This is the starting offset into the destination image in the feature channel dimension at which destination data is written. This allows an application to pass a subset of all the channels in MPSImage as output of MPSKernel. E.g. Suppose MPSImage has 24 channels and a MPSKernel outputs 8 channels. If we want channels 8 to 15 of this MPSImage to be used as output, we can set destinationFeatureChannelOffset = 8. Note that this offset applies independently to each image when the MPSImage is a container for multiple images and the MPSCNNKernel is processing multiple images (clipRect.size.depth > 1). The default value is 0 and any value specifed shall be a multiple of 4. If MPSKernel outputs N channels, destination image MUST have at least destinationFeatureChannelOffset + N channels. Using a destination image with insufficient number of feature channels result in an error. E.g. if the MPSCNNConvolution outputs 32 channels, and destination has 64 channels, then it is an error to set destinationFeatureChannelOffset > 32.
public MPSImageAllocator destinationImageAllocator()
Default: MPSTemporaryImage.defaultAllocator
public MPSImageDescriptor destinationImageDescriptorForSourceImagesSourceStates(NSArray<? extends MPSImage> sourceImages, NSArray<? extends MPSState> sourceStates)
Your application is certainly free to pass in any destinationImage it likes to encodeToCommandBuffer:sourceImage:destinationImage, within reason. This is the basic design for iOS 10. This method is therefore not required.
However, calculating the MPSImage size and MPSCNNKernel properties for each filter can be tedious and complicated work, so this method is made available to automate the process. The application may modify the properties of the descriptor before a MPSImage is made from it, so long as the choice is sensible for the kernel in question. Please see individual kernel descriptions for restrictions.
The expected timeline for use is as follows:
1) This method is called: a) The default MPS padding calculation is applied. It uses the MPSNNPaddingMethod of the .padding property to provide a consistent addressing scheme over the graph. It creates the MPSImageDescriptor and adjusts the .offset property of the MPSNNKernel. When using a MPSNNGraph, the padding is set using the MPSNNFilterNode as a proxy.
b) This method may be overridden by MPSCNNKernel subclass to achieve any customization appropriate to the object type.
c) Source states are then applied in order. These may modify the descriptor and may update other object properties. See: -destinationImageDescriptorForSourceImages:sourceStates: forKernel:suggestedDescriptor: This is the typical way in which MPS may attempt to influence the operation of its kernels.
d) If the .padding property has a custom padding policy method of the same name, it is called. Similarly, it may also adjust the descriptor and any MPSCNNKernel properties. This is the typical way in which your application may attempt to influence the operation of the MPS kernels.
2) A result is returned from this method and the caller may further adjust the descriptor and kernel properties directly.
3) The caller uses the descriptor to make a new MPSImage to use as the destination image for the -encode call in step 5.
4) The caller calls -resultStateForSourceImage:sourceStates:destinationImage: to make any result states needed for the kernel. If there isn't one, it will return nil. A variant is available to return a temporary state instead.
5) a -encode method is called to encode the kernel.
The entire process 1-5 is more simply achieved by just calling an -encode... method that returns a MPSImage out the left hand sid of the method. Simpler still, use the MPSNNGraph to coordinate the entire process from end to end. Opportunities to influence the process are of course reduced, as (2) is no longer possible with either method. Your application may opt to use the five step method if it requires greater customization as described, or if it would like to estimate storage in advance based on the sum of MPSImageDescriptors before processing a graph. Storage estimation is done by using the MPSImageDescriptor to create a MPSImage (without passing it a texture), and then call -resourceSize. As long as the MPSImage is not used in an encode call and the .texture property is not invoked, the underlying MTLTexture is not created.
No destination state or destination image is provided as an argument to this function because it is expected they will be made / configured after this is called. This method is expected to auto-configure important object properties that may be needed in the ensuing destination image and state creation steps.
sourceImages - A array of source images that will be passed into the -encode call
Since MPSCNNKernel is a unary kernel, it is an array of length 1.sourceStates - An optional array of source states that will be passed into the -encode callpublic long dilationRateXatIndex(long index)
index - The index of the source image to which the dilation rate appliespublic long dilationRateYatIndex(long index)
index - The index of the source image to which the dilation rate appliespublic long edgeModeAtIndex(long index)
Most MPSKernel objects can read off the edge of the source image. This can happen because of a negative offset property, because the offset + clipRect.size is larger than the source image or because the filter looks at neighboring pixels, such as a Convolution filter. Default: MPSImageEdgeModeZero.
See Also: @ref subsubsection_edgemode
index - The index of the source image to which the edge mode referspublic MPSImage encodeToCommandBufferSourceImages(MTLCommandBuffer commandBuffer, NSArray<? extends MPSImage> sourceImages)
In the first iteration on this method, encodeToCommandBuffer:sourceImage:destinationImage: some work was left for the developer to do in the form of correctly setting the offset property and sizing the result buffer. With the introduction of the padding policy (see padding property) the filter can do this work itself. If you would like to have some input into what sort of MPSImage (e.g. temporary vs. regular) or what size it is or where it is allocated, you may set the destinationImageAllocator to allocate the image yourself.
This method uses the MPSNNPadding padding property to figure out how to size the result image and to set the offset property. See discussion in MPSNeuralNetworkTypes.h.
commandBuffer - The command buffersourceImages - An array of MPSImages to use as the source images for the filter.public void encodeToCommandBufferSourceImagesDestinationImage(MTLCommandBuffer commandBuffer, NSArray<? extends MPSImage> sourceImages, MPSImage destinationImage)
This is the older style of encode which reads the offset, doesn't change it, and ignores the padding method.
commandBuffer - A valid MTLCommandBuffer to receive the encoded filtersourceImages - An array containing the source imagesdestinationImage - A valid MPSImage to be overwritten by result image. destinationImage may not alias primarySourceImage or secondarySourceImage.public MPSImage encodeToCommandBufferSourceImagesDestinationStateDestinationStateIsTemporary(MTLCommandBuffer commandBuffer, NSArray<? extends MPSImage> sourceImages, org.moe.natj.general.ptr.Ptr<MPSState> outState, boolean isTemporary)
In the first iteration on this method, encodeToCommandBuffer:sourceImage:destinationState:destinationImage: some work was left for the developer to do in the form of correctly setting the offset property and sizing the result buffer. With the introduction of the padding policy (see padding property) the filter can do this work itself. If you would like to have some input into what sort of MPSImage (e.g. temporary vs. regular) or what size it is or where it is allocated, you may set the destinationImageAllocator to allocate the image yourself.
This method uses the MPSNNPadding padding property to figure out how to size the result image and to set the offset property. See discussion in MPSNeuralNetworkTypes.h. All images in a batch must have MPSImage.numberOfImages = 1.
commandBuffer - The command buffersourceImages - An array of MPSImages to use as the source images for the filter.outState - The address of location to write the pointer to the result state of the operationisTemporary - YES if the outState should be a temporary objectpublic static long hash_static()
public MPSCNNMultiaryKernel init()
public MPSCNNMultiaryKernel initWithCoder(NSCoder aDecoder)
NSCodinginitWithCoder in interface NSCodinginitWithCoder in class MPSKernelpublic MPSCNNMultiaryKernel initWithCoderDevice(NSCoder aDecoder, java.lang.Object device)
While the standard NSSecureCoding/NSCoding method -initWithCoder: should work, since the file can't know which device your data is allocated on, we have to guess and may guess incorrectly. To avoid that problem, use initWithCoder:device instead.
initWithCoderDevice in class MPSKernelaDecoder - The NSCoder subclass with your serialized MPSKerneldevice - The MTLDevice on which to make the MPSKernelpublic MPSCNNMultiaryKernel initWithDevice(java.lang.Object device)
MPSKernelinitWithDevice in class MPSKerneldevice - The device that the filter will be used on. May not be NULL.public MPSCNNMultiaryKernel initWithDeviceSourceCount(MTLDevice device, long sourceCount)
device - The device that the filter will be used on. May not be NULL.sourceCount - The number of source images or MPSImageBatchespublic static NSObject.Function_instanceMethodForSelector_ret instanceMethodForSelector(org.moe.natj.objc.SEL aSelector)
public static NSMethodSignature instanceMethodSignatureForSelector(org.moe.natj.objc.SEL aSelector)
public static boolean instancesRespondToSelector(org.moe.natj.objc.SEL aSelector)
public boolean isBackwards()
YES if the filter operates backwards.
This influences how strideInPixelsX/Y should be interpreted.
public boolean isResultStateReusedAcrossBatch()
If NO, then each image in a MPSImageBatch will need a corresponding (and different) state to go with it. Set to YES to avoid allocating redundant state in the case when the same state is used all the time. Default: NO
public boolean isStateModified()
public static boolean isSubclassOfClass(org.moe.natj.objc.Class aClass)
public long kernelHeightAtIndex(long index)
This is the horizontal diameter of the region read by the filter for each result pixel. If the MPSCNNKernel does not have a filter window, then 1 will be returned.
index - The index of the source image to which the kernel width referspublic long kernelWidthAtIndex(long index)
This is the horizontal diameter of the region read by the filter for each result pixel. If the MPSCNNKernel does not have a filter window, then 1 will be returned.
index - The index of the source image to which the kernel width referspublic static NSSet<java.lang.String> keyPathsForValuesAffectingValueForKey(java.lang.String key)
public static MPSCNNMultiaryKernel new_objc()
public MPSOffset offsetAtIndex(long index)
The offset is defined to be the position of clipRect.origin in source coordinates. Default: {0,0,0}, indicating that the top left corners of the clipRect and source image align. offset.z is the index of starting source image in batch processing mode.
index - The index of the source image described by the offsetpublic MPSNNPadding padding()
The padding method used by the filter
This influences how strideInPixelsX/Y should be interpreted. Default: MPSNNPaddingMethodAlignCentered | MPSNNPaddingMethodAddRemainderToTopLeft | MPSNNPaddingMethodSizeSame Some object types (e.g. MPSCNNFullyConnected) may override this default with something appropriate to its operation.
public static boolean resolveClassMethod(org.moe.natj.objc.SEL sel)
public static boolean resolveInstanceMethod(org.moe.natj.objc.SEL sel)
public MPSState resultStateForSourceImagesSourceStatesDestinationImage(NSArray<? extends MPSImage> sourceImages, NSArray<? extends MPSState> sourceStates, MPSImage destinationImage)
A graph may need to allocate storage up front before executing. This may be necessary to avoid using too much memory and to manage large batches. The function should allocate any MPSState objects that will be produced by an -encode call with the indicated sourceImages and sourceStates inputs. Though the states can be further adjusted in the ensuing -encode call, the states should be initialized with all important data and all MTLResource storage allocated. The data stored in the MTLResource need not be initialized, unless the ensuing -encode call expects it to be.
The MTLDevice used by the result is derived from the source image. The padding policy will be applied to the filter before this is called to give it the chance to configure any properties like MPSCNNKernel.offset.
CAUTION: The kernel must have all properties set to values that will ultimately be passed to the -encode call that writes to the state, before -resultStateForSourceImages:sourceStates:destinationImage: is called or behavior is undefined. Please note that -destinationImageDescriptorForSourceImages:sourceStates: will alter some of these properties automatically based on the padding policy. If you intend to call that to make the destination image, then you should call that before -resultStateForSourceImages:sourceStates:destinationImage:. This will ensure the properties used in the encode call and in the destination image creation match those used to configure the state.
The following order is recommended:
// Configure MPSCNNKernel properties first kernel.edgeMode = MPSImageEdgeModeZero; kernel.destinationFeatureChannelOffset = 128; // concatenation without the copy ...
// ALERT: will change MPSCNNKernel properties MPSImageDescriptor * d = [kernel destinationImageDescriptorForSourceImage: source sourceStates: states]; MPSTemporaryImage * dest = [MPSTemporaryImage temporaryImageWithCommandBuffer: cmdBuf imageDescriptor: d];
// Now that all properties are configured properly, we can make the result state // and call encode. MPSState * __nullable destState = [kernel resultStateForSourceImage: source sourceStates: states destinationImage: dest];
// This form of -encode will be declared by the MPSCNNKernel subclass [kernel encodeToCommandBuffer: cmdBuf sourceImage: source destinationState: destState destinationImage: dest ];
Default: returns nil
sourceImages - The MPSImage consumed by the associated -encode call.sourceStates - The list of MPSStates consumed by the associated -encode call,
for a batch size of 1.destinationImage - The destination image for the encode callpublic void setClipRect(MTLRegion value)
An optional clip rectangle to use when writing data. Only the pixels in the rectangle will be overwritten.
A MTLRegion that indicates which part of the destination to overwrite. If the clipRect does not lie completely within the destination image, the intersection between clip rectangle and destination bounds is used. Default: MPSRectNoClip (MPSKernel::MPSRectNoClip) indicating the entire image. clipRect.origin.z is the index of starting destination image in batch processing mode. clipRect.size.depth is the number of images to process in batch processing mode.
See Also: @ref subsubsection_clipRect
public void setDestinationFeatureChannelOffset(long value)
The number of channels in the destination MPSImage to skip before writing output.
This is the starting offset into the destination image in the feature channel dimension at which destination data is written. This allows an application to pass a subset of all the channels in MPSImage as output of MPSKernel. E.g. Suppose MPSImage has 24 channels and a MPSKernel outputs 8 channels. If we want channels 8 to 15 of this MPSImage to be used as output, we can set destinationFeatureChannelOffset = 8. Note that this offset applies independently to each image when the MPSImage is a container for multiple images and the MPSCNNKernel is processing multiple images (clipRect.size.depth > 1). The default value is 0 and any value specifed shall be a multiple of 4. If MPSKernel outputs N channels, destination image MUST have at least destinationFeatureChannelOffset + N channels. Using a destination image with insufficient number of feature channels result in an error. E.g. if the MPSCNNConvolution outputs 32 channels, and destination has 64 channels, then it is an error to set destinationFeatureChannelOffset > 32.
public void setDestinationImageAllocator(MPSImageAllocator value)
Default: MPSTemporaryImage.defaultAllocator
public void setDilationRateXAtIndex(long dilationRate,
long index)
index - The index of the source image to which the dilation rate appliesdilationRate - The dilation ratepublic void setDilationRateYAtIndex(long dilationRate,
long index)
index - The index of the source image to which the dilation rate appliesdilationRate - The dilation ratepublic void setEdgeModeAtIndex(long edgeMode,
long index)
Most MPSKernel objects can read off the edge of the source image. This can happen because of a negative offset property, because the offset + clipRect.size is larger than the source image or because the filter looks at neighboring pixels, such as a Convolution filter. Default: MPSImageEdgeModeZero.
See Also: @ref subsubsection_edgemode
edgeMode - The new edge mode to useindex - The index of the source image to which the edge mode referspublic void setKernelHeightAtIndex(long height,
long index)
This is the horizontal diameter of the region read by the filter for each result pixel. If the MPSCNNKernel does not have a filter window, then 1 will be returned.
height - The new widthindex - The index of the source image to which the kernel width referspublic void setKernelWidthAtIndex(long width,
long index)
This is the horizontal diameter of the region read by the filter for each result pixel. If the MPSCNNKernel does not have a filter window, then 1 will be returned.
width - The new widthindex - The index of the source image to which the kernel width referspublic void setOffsetAtIndex(MPSOffset offset, long index)
The offset is defined to be the position of clipRect.origin in source coordinates. Default: {0,0,0}, indicating that the top left corners of the clipRect and source image align. offset.z is the index of starting source image in batch processing mode.
offset - The new offsetindex - The index of the source image described by the offsetpublic void setPadding(MPSNNPadding value)
The padding method used by the filter
This influences how strideInPixelsX/Y should be interpreted. Default: MPSNNPaddingMethodAlignCentered | MPSNNPaddingMethodAddRemainderToTopLeft | MPSNNPaddingMethodSizeSame Some object types (e.g. MPSCNNFullyConnected) may override this default with something appropriate to its operation.
public void setSourceFeatureChannelMaxCountAtIndex(long count,
long index)
Most filters can insert a slice operation into the filter for free. Use this to limit the size of the feature channel slice taken from the input image. If the value is too large, it is truncated to be the remaining size in the image after the sourceFeatureChannelOffset is taken into account. Default: ULONG_MAX
count - The new source feature channel max countindex - The index of the source image to which the max count referspublic void setSourceFeatureChannelOffsetAtIndex(long offset,
long index)
This is the starting offset into the source image in the feature channel dimension at which source data is read. Unit: feature channels This allows an application to read a subset of all the channels in MPSImage as input of MPSKernel. E.g. Suppose MPSImage has 24 channels and a MPSKernel needs to read 8 channels. If we want channels 8 to 15 of this MPSImage to be used as input, we can set sourceFeatureChannelOffset[0] = 8. Note that this offset applies independently to each image when the MPSImage is a container for multiple images and the MPSCNNKernel is processing multiple images (clipRect.size.depth > 1). The default value is 0 and any value specifed shall be a multiple of 4. If MPSKernel inputs N channels, the source image MUST have at least primarySourceFeatureChannelOffset + N channels. Using a source image with insufficient number of feature channels will result in an error. E.g. if the MPSCNNConvolution inputs 32 channels, and the source has 64 channels, then it is an error to set primarySourceFeatureChannelOffset > 32.
index - The index of the source image that the feature channel offset describesoffset - The source feature channel offsetpublic void setStrideInPixelsXAtIndex(long stride,
long index)
If the filter does not do up or downsampling, 1 is returned. Default: 1
index - The index of the source Imagestride - The stride for the source imagepublic void setStrideInPixelsYAtIndex(long stride,
long index)
If the filter does not do up or downsampling, 1 is returned. Default: 1
index - The index of the source Imagestride - The stride for the source imagepublic static void setVersion_static(long aVersion)
public long sourceCount()
public long sourceFeatureChannelMaxCountAtIndex(long index)
Most filters can insert a slice operation into the filter for free. Use this to limit the size of the feature channel slice taken from the input image. If the value is too large, it is truncated to be the remaining size in the image after the sourceFeatureChannelOffset is taken into account. Default: ULONG_MAX
index - The index of the source image to which the max count referspublic long sourceFeatureChannelOffsetAtIndex(long index)
This is the starting offset into the source image in the feature channel dimension at which source data is read. Unit: feature channels This allows an application to read a subset of all the channels in MPSImage as input of MPSKernel. E.g. Suppose MPSImage has 24 channels and a MPSKernel needs to read 8 channels. If we want channels 8 to 15 of this MPSImage to be used as input, we can set sourceFeatureChannelOffset[0] = 8. Note that this offset applies independently to each image when the MPSImage is a container for multiple images and the MPSCNNKernel is processing multiple images (clipRect.size.depth > 1). The default value is 0 and any value specifed shall be a multiple of 4. If MPSKernel inputs N channels, the source image MUST have at least primarySourceFeatureChannelOffset + N channels. Using a source image with insufficient number of feature channels will result in an error. E.g. if the MPSCNNConvolution inputs 32 channels, and the source has 64 channels, then it is an error to set primarySourceFeatureChannelOffset > 32.
index - The index of the source image that the feature channel offset describespublic long strideInPixelsXatIndex(long index)
If the filter does not do up or downsampling, 1 is returned.
index - The index of the source Imagepublic long strideInPixelsYatIndex(long index)
If the filter does not do up or downsampling, 1 is returned.
index - The index of the source Imagepublic static org.moe.natj.objc.Class superclass_static()
public static boolean supportsSecureCoding()
public boolean _supportsSecureCoding()
NSSecureCoding_supportsSecureCoding in interface NSSecureCoding_supportsSecureCoding in class MPSKernelpublic MPSState temporaryResultStateForCommandBufferSourceImagesSourceStatesDestinationImage(MTLCommandBuffer commandBuffer, NSArray<? extends MPSImage> sourceImage, NSArray<? extends MPSState> sourceStates, MPSImage destinationImage)
A graph may need to allocate storage up front before executing. This may be necessary to avoid using too much memory and to manage large batches. The function should allocate any MPSState objects that will be produced by an -encode call with the indicated sourceImages and sourceStates inputs. Though the states can be further adjusted in the ensuing -encode call, the states should be initialized with all important data and all MTLResource storage allocated. The data stored in the MTLResource need not be initialized, unless the ensuing -encode call expects it to be.
The MTLDevice used by the result is derived from the command buffer. The padding policy will be applied to the filter before this is called to give it the chance to configure any properties like MPSCNNKernel.offset.
CAUTION: The kernel must have all properties set to values that will ultimately be passed to the -encode call that writes to the state, before -resultStateForSourceImages:sourceStates:destinationImage: is called or behavior is undefined. Please note that -destinationImageDescriptorForSourceImages:sourceStates:destinationImage: will alter some of these properties automatically based on the padding policy. If you intend to call that to make the destination image, then you should call that before -resultStateForSourceImages:sourceStates:destinationImage:. This will ensure the properties used in the encode call and in the destination image creation match those used to configure the state.
The following order is recommended:
// Configure MPSCNNKernel properties first kernel.edgeMode = MPSImageEdgeModeZero; kernel.destinationFeatureChannelOffset = 128; // concatenation without the copy ...
// ALERT: will change MPSCNNKernel properties MPSImageDescriptor * d = [kernel destinationImageDescriptorForSourceImage: source sourceStates: states]; MPSTemporaryImage * dest = [MPSTemporaryImage temporaryImageWithCommandBuffer: cmdBuf imageDescriptor: d];
// Now that all properties are configured properly, we can make the result state // and call encode. MPSState * __nullable destState = [kernel temporaryResultStateForCommandBuffer: cmdBuf sourceImage: source sourceStates: states];
// This form of -encode will be declared by the MPSCNNKernel subclass [kernel encodeToCommandBuffer: cmdBuf sourceImage: source destinationState: destState destinationImage: dest ];
Default: returns nil
commandBuffer - The command buffer to allocate the temporary storage against
The state will only be valid on this command buffer.sourceImage - The MPSImage consumed by the associated -encode call.sourceStates - The list of MPSStates consumed by the associated -encode call,
for a batch size of 1.destinationImage - The destination image for the encode callpublic static long version_static()