MPSCNNArithmetic(3)

NAME
MPSCNNArithmetic

SYNOPSIS

#import <MPSCNNMath.h>

Inherits MPSCNNBinaryKernel.

Inherited by MPSCNNAdd, MPSCNNDivide, MPSCNNMultiply, and MPSCNNSubtract.

  Instance Methods
(nonnull instancetype) - initWithDevice:
(void) - encodeToCommandBuffer:primaryImage:secondaryImage:destinationState:destinationImage:
(void) - encodeBatchToCommandBuffer:primaryImages:secondaryImages:destinationStates:destinationImages:

  Properties
float primaryScale
float secondaryScale
float bias
NSUInteger primaryStrideInFeatureChannels
NSUInteger secondaryStrideInFeatureChannels
float minimumValue
float maximumValue

  Additional Inherited Members

Detailed Description

This depends on Metal.framework The MPSCNNArithmetic filter takes two source images, a primary source image and a secondary source image, and outputs a single destination image. It applies an element-wise arithmetic operator to each pixel in a primary source image and a corresponding pixel in a secondary source image over a specified region.

The supported arithmetic operators are the following:

•   Addition

•   Subtraction

•   Multiplication

•   Division

This filter takes additional parameters: primaryScale, secondaryScale, and bias. The default value for primaryScale and secondaryScale is 1.0f. The default value for bias is 0.0f. This filter applies primaryScale, secondaryScale, and bias to the primary source pixel (x) and secondary source pixel (y) in the following way:

•   Addition: result = ((primaryScale * x) + (secondaryScale * y)) + bias

•   Subtraction: result = ((primaryScale * x) - (secondaryScale * y)) + bias

•   Multiplicaton: result = ((primaryScale * x) * (secondaryScale * y)) + bias

•   Division: result = ((primaryScale * x) / (secondaryScale * y)) + bias

To clamp the result of an arithmetic operation, where result = clamp(result, minimumValue, maximumValue), set the minimumValue and maximumValue appropriately. The default value of minimumValue is -FLT_MAX. The default value of maximumValue is FLT_MAX.

This filter also takes the following additional parameters:

•   primaryStrideInPixelsX, primaryStrideInPixelsY, primaryStrideInFeatureChannels

•   secondaryStrideInPixelsX, secondaryStrideInPixelsY, secondaryStrideInFeatureChannels These parameters can be used to control broadcasting for the data stored in the primary and secondary source images. For example, setting all strides for the primary source image to 0 will result in the primarySource image being treated as a scalar value. The only supported values are 0 or 1. The default value of these parameters is 1.

The number of output feature channels remains the same as the number of input feature channels.

You must use one of the sub-classes of MPSImageArithmetic.

Method Documentation

  - (void) encodeBatchToCommandBuffer: (__nonnull id< MTLCommandBuffer >) commandBuffer(MPSImageBatch *__nonnull) primaryImages(MPSImageBatch *__nonnull) secondaryImages(MPSCNNArithmeticGradientStateBatch *__nonnull) destinationStates(MPSImageBatch *__nonnull) destinationImages
Encode call that operates on a state for later consumption by a gradient kernel in training This is the older style of encode which reads the offset, doesn't change it, and ignores the padding method. Multiple images are processed concurrently. All images must have MPSImage.numberOfImages = 1.

Parameters:
    commandBuffer A valid MTLCommandBuffer to receive the encoded filter
    primaryImages An array of MPSImage objects containing the primary source images.
    secondaryImages An array MPSImage objects containing the secondary source images.
    destinationStates An array of MPSCNNArithmeticGradientStateBatch to be consumed by the gradient layer
    destinationImages An array of MPSImage objects to contain the result images. destinationImages may not alias primarySourceImages or secondarySourceImages in any manner.

  - (void) encodeToCommandBuffer: (__nonnull id< MTLCommandBuffer >) commandBuffer(MPSImage *__nonnull) primaryImage(MPSImage *__nonnull) secondaryImage(MPSCNNArithmeticGradientState *__nonnull) destinationState(MPSImage *__nonnull) destinationImage
Encode call that operates on a state for later consumption by a gradient kernel in training This is the older style of encode which reads the offset, doesn't change it, and ignores the padding method.

Parameters:
    commandBuffer The command buffer
    primaryImage A MPSImage to use as the source images for the filter.
    secondaryImage A MPSImage to use as the source images for the filter.
    destinationState MPSCNNArithmeticGradientState to be consumed by the gradient layer
    destinationImage A valid MPSImage to be overwritten by result image. destinationImage may not alias primarySourceImage or secondarySourceImage.

  - (nonnull instancetype) initWithDevice: (nonnull id< MTLDevice >) device
Standard init with default properties per filter type

Parameters:
    device The device that the filter will be used on. May not be NULL.

Returns:
    A pointer to the newly initialized object. This will fail, returning nil if the device is not supported. Devices must be MTLFeatureSet_iOS_GPUFamily2_v1 or later.

Reimplemented from MPSCNNBinaryKernel.

Reimplemented in MPSCNNAdd, MPSCNNSubtract, MPSCNNMultiply, and MPSCNNDivide.

Property Documentation

  - (float) bias [read], [write], [nonatomic], [assign]

  - maximumValue [read], [write], [nonatomic], [assign]
maximumValue is used to clamp the result of an arithmetic operation: result = clamp(result, minimumValue, maximumValue). The default value of maximumValue is FLT_MAX.

  - minimumValue [read], [write], [nonatomic], [assign]
minimumValue is to clamp the result of an arithmetic operation: result = clamp(result, minimumValue, maximumValue). The default value of minimumValue is -FLT_MAX.

  - (float) primaryScale [read], [write], [nonatomic], [assign]

  - (NSUInteger) primaryStrideInFeatureChannels [read], [write], [nonatomic], [assign]

  - (float) secondaryScale [read], [write], [nonatomic], [assign]

  - (NSUInteger) secondaryStrideInFeatureChannels [read], [write], [nonatomic], [assign]

Author

Generated automatically by Doxygen for MetalPerformanceShaders.framework from the source code.