-
Notifications
You must be signed in to change notification settings - Fork 516
MetalPerformanceShadersGraph iOS xcode14.0 beta1
Alex Soto edited this page Jun 7, 2022
·
1 revision
#MetalPerformanceShadersGraph.framework
diff -ruN /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraph.h /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraph.h
--- /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraph.h 2022-02-23 07:59:33.000000000 -0500
+++ /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraph.h 2022-05-31 14:52:13.000000000 -0400
@@ -62,6 +62,18 @@
MPSGraphOptimizationProfilePowerEfficiency MPS_ENUM_AVAILABLE_STARTING(macos(12.3), ios(15.4), tvos(15.4)) = 1L,
};
+/*!
+ * @typedef MPSGraphExecutionStage
+ * @abstract Execution events that can be used with shared events
+ *
+ * @constant MPSGraphExecutionStageCompleted execution complete
+ */
+typedef NS_ENUM(uint64_t, MPSGraphExecutionStage)
+{
+ MPSGraphExecutionStageCompleted MPS_ENUM_AVAILABLE_STARTING(macos(13.0), ios(16.0), tvos(16.0)) MPS_SWIFT_NAME(completed) = 0L,
+};
+
+
/*! @abstract A dictionary of tensors and correspondiing tensorData for them
*/
MPS_AVAILABLE_STARTING(macos(11.0), ios(14.0), tvos(14.0))
@@ -73,19 +85,26 @@
typedef NSDictionary<MPSGraphTensor*, MPSGraphShapedType *> MPSGraphTensorShapedTypeDictionary;
/*! @abstract A notification when graph execution: has finished
- * @param resultsDictionary If no error, the image produced by the graph operation.
+ * @param resultsDictionary If no error, the results dictionary produced by the graph operation.
* @param error If an error occurs, more information might be found here.
*/
typedef void (^MPSGraphCompletionHandler)(MPSGraphTensorDataDictionary * resultsDictionary,
NSError * _Nullable error);
/*! @abstract A notification when graph execution: has finished
- * @param resultsDictionary If no error, the image produced by the graph operation.
+ * @param resultsDictionary If no error, the results dictionary produced by the graph operation.
* @param error If an error occurs, more information might be found here.
*/
typedef void (^MPSGraphScheduledHandler)(MPSGraphTensorDataDictionary * resultsDictionary,
NSError * _Nullable error);
+/*! @abstract A notification when compilation: has finished
+ * @param executable If no error, the executable produced by the compilation
+ * @param error If an error occurs, more information might be found here.
+ */
+typedef void (^MPSGraphCompilationCompletionHandler)(MPSGraphExecutable* executable,
+ NSError * _Nullable error);
+
/*! @class MPSGraphCompilationDescriptor
* @abstract A structure which consists of all the levers users can use to compile their graphs
*
@@ -108,6 +127,21 @@
*/
@property (readwrite, nonatomic) MPSGraphOptimizationProfile optimizationProfile MPS_AVAILABLE_STARTING(macos(12.3), ios(15.4), tvos(15.4));
+/*! @property waitForCompilationCompletion
+ * @discussion makes the compile or specialize call blocking till the entire compilation is completed, defaults to NO
+ */
+@property (readwrite, nonatomic) BOOL waitForCompilationCompletion MPS_AVAILABLE_STARTING(macos(13.0), ios(16.0), tvos(16.0));
+
+/*! @property compilationCompletionHandler
+ * @discussion compilationCompletionHandler for the compilation, default value is nil, it is called after compilation is completed
+ */
+@property (readwrite, atomic) MPSGraphCompilationCompletionHandler compilationCompletionHandler MPS_AVAILABLE_STARTING(macos(13.0), ios(16.0), tvos(16.0));
+
+/*! @property dispatchQueue
+ * @discussion dispatchQueue for the compilation, default value is nil
+ */
+@property (readwrite, atomic, retain) dispatch_queue_t dispatchQueue MPS_AVAILABLE_STARTING(macos(13.0), ios(16.0), tvos(16.0));
+
@end
/*! @class MPSGraphExecutionDescriptor
@@ -138,6 +172,28 @@
@property (readwrite, atomic, copy, nullable) MPSGraphCompilationDescriptor *compilationDescriptor
MPS_AVAILABLE_STARTING(macos(12.3), ios(15.4), tvos(15.4));
+/*!
+ * @abstract Executable waits on these shared events before scheduling execution on the HW, this does not include encoding which can still continue.
+ *
+ * @param event shared event to wait on
+ * @param value value for shared event to wait on
+ */
+-(void) waitForEvent:(id<MTLSharedEvent>) event
+ value:(uint64_t) value
+MPS_AVAILABLE_STARTING(macos(13.0), ios(16.0), tvos(16.0));
+
+/*!
+ * @abstract Executable signals these shared events at execution stage and immediately proceeds
+ *
+ * @param event shared event to signal
+ * @param executionStage execution stage to signal event at
+ * @param value value for shared event to wait on
+ */
+-(void) signalEvent:(id<MTLSharedEvent>) event
+ atExecutionEvent:(MPSGraphExecutionStage) executionStage
+ value:(uint64_t) value
+MPS_AVAILABLE_STARTING(macos(13.0), ios(16.0), tvos(16.0));
+
@end
/*! @class MPSGraph
diff -ruN /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphArithmeticOps.h /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphArithmeticOps.h
--- /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphArithmeticOps.h 2022-02-23 07:10:00.000000000 -0500
+++ /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphArithmeticOps.h 2022-05-31 14:52:13.000000000 -0400
@@ -150,6 +150,16 @@
-(MPSGraphTensor *) erfWithTensor:(MPSGraphTensor *) tensor
name:(NSString * _Nullable) name;
+/*!
+ * @abstract Truncate op - floor for positive inputs, ceil for negative.
+ * @param tensor The input
+ * @param name Name for the operation
+ * @return A valid MPSGraphTensor object.
+ */
+-(MPSGraphTensor *) truncateWithTensor:(MPSGraphTensor *) tensor
+ name:(NSString * _Nullable) name
+MPS_SWIFT_NAME( truncate(_:name:) )
+MPS_AVAILABLE_STARTING(macos(13.0), ios(16.0), tvos(16.0));
#pragma mark - BinaryArithmeticOps
diff -ruN /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphCore.h /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphCore.h
--- /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphCore.h 2022-02-23 10:57:12.000000000 -0500
+++ /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphCore.h 2022-06-03 18:07:04.000000000 -0400
@@ -71,10 +71,11 @@
* @typedef MPSGraphPaddingStyle
* @abstract Tensor Layout
*
- * @constant MPSGraphPaddingStyleExplicit Explicit
- * @constant MPSGraphPaddingStyleTF_SAME TF_SAME
- * @constant MPSGraphPaddingStyleTF_VALID TF_VALID
- * @constant MPSGraphPaddingStyleExplicitOffset Explicit offsets
+ * @constant MPSGraphPaddingStyleExplicit Explicit
+ * @constant MPSGraphPaddingStyleONNX_SAME_LOWER ONNX_SAME_LOWER
+ * @constant MPSGraphPaddingStyleTF_SAME TF_SAME
+ * @constant MPSGraphPaddingStyleTF_VALID TF_VALID
+ * @constant MPSGraphPaddingStyleExplicitOffset Explicit offsets
*/
typedef NS_ENUM(NSUInteger, MPSGraphPaddingStyle)
{
@@ -82,6 +83,7 @@
MPSGraphPaddingStyleTF_VALID MPS_ENUM_AVAILABLE_STARTING(macos(11.0), ios(14.0), tvos(14.0)) = 1L,
MPSGraphPaddingStyleTF_SAME MPS_ENUM_AVAILABLE_STARTING(macos(11.0), ios(14.0), tvos(14.0)) = 2L,
MPSGraphPaddingStyleExplicitOffset MPS_ENUM_AVAILABLE_STARTING(macos(12.0), ios(15.0), tvos(15.0)) = 3L,
+ MPSGraphPaddingStyleONNX_SAME_LOWER MPS_ENUM_AVAILABLE_STARTING(macos(13.0), ios(16.0), tvos(16.0)) = 4L,
};
/*!
diff -ruN /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphExecutable.h /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphExecutable.h
--- /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphExecutable.h 2022-02-23 07:56:15.000000000 -0500
+++ /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphExecutable.h 2022-06-03 18:07:04.000000000 -0400
@@ -47,6 +47,28 @@
*/
@property (readwrite, atomic) BOOL waitUntilCompleted;
+/*!
+ * @abstract Executable waits on these shared events before scheduling execution on the HW, this does not include encoding which can still continue.
+ *
+ * @param event shared event to wait on
+ * @param value value for shared event to wait on
+ */
+-(void) waitForEvent:(id<MTLSharedEvent>) event
+ value:(uint64_t) value
+MPS_AVAILABLE_STARTING(macos(13.0), ios(16.0), tvos(16.0));
+
+/*!
+ * @abstract Executable signals these shared events at execution stage and immediately proceeds
+ *
+ * @param event shared event to signal
+ * @param executionStage execution stage to signal event at
+ * @param value value for shared event to wait on
+ */
+-(void) signalEvent:(id<MTLSharedEvent>) event
+ atExecutionEvent:(MPSGraphExecutionStage) executionStage
+ value:(uint64_t) value
+MPS_AVAILABLE_STARTING(macos(13.0), ios(16.0), tvos(16.0));
+
@end
/*! @class MPSGraphExecutable
@@ -73,10 +95,11 @@
@property (readonly, atomic, nullable) NSArray<MPSGraphTensor *> *targetTensors;
/*!
- * @abstract Specialize MLIR module and optimize it
+ * @abstract Specialize the MPSGraphExecutable and optimize it, use this method to choose when specialization happens, else it occurs at encode time automatically
*
- * @param device optional MPSGraph device to compile with
- * @param inputTypes input types
+ * @param device optional MPSGraph device to compile with
+ * @param inputTypes input types
+ * @param compilationDescriptor compilationDescriptor to be used to specialize, since the executable was created with a compilationDescriptor already this one overrides those settings to the extent it can
*
*/
-(void) specializeWithDevice:(MPSGraphDevice * _Nullable) device
diff -ruN /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphGatherNDOps.h /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphGatherNDOps.h
--- /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphGatherNDOps.h 2022-02-06 17:44:48.000000000 -0500
+++ /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphGatherNDOps.h 1969-12-31 19:00:00.000000000 -0500
@@ -1,14 +0,0 @@
-//
-// MPSGraphGatherNDOps.h
-// MPSGraph
-//
-// Created by Chris Bayley on 12/2/20.
-// Copyright © 2020 Dhruv Saksena. All rights reserved.
-//
-
-#ifndef MPSGraphGatherNDOps_h
-#define MPSGraphGatherNDOps_h
-
-#import "MPSGraphGatherOps.h"
-
-#endif /* MPSGraphGatherNDOps_h */
diff -ruN /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphMatrixMultiplicationOps.h /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphMatrixMultiplicationOps.h
--- /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphMatrixMultiplicationOps.h 2022-02-23 07:59:33.000000000 -0500
+++ /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphMatrixMultiplicationOps.h 2022-05-31 14:52:13.000000000 -0400
@@ -34,6 +34,27 @@
name:(NSString * _Nullable) name
MPS_SWIFT_NAME( matrixMultiplication(primary:secondary:name:) );
+/*!
+ * @abstract Create a Hamming Distance op and return the result tensor, it supports broadcasting as well.
+ * @discussion The Hamming Distance is computed between sets of vectors and the last dimension(s) of each
+ * input tensor is considered a vector. If the shape of @ref primaryTensor is `[Na, M, K]` and the shape
+ * of @ref secondaryTensor is `[Nb, N, K]`, with Na, Nb being any batch dimensions,
+ * then the result shape is `[Na/Nb, M, N]`, where `Na/Nb` are the broadcasted batch dimensions.
+ * The result datatype is either MPSDataTypeUInt32 or MPSDataTypeUInt16.
+ *
+ * @param primaryTensor LHS tensor of the binary Op
+ * @param secondaryTensor RHS tensor of the binary Op
+ * @param resultDataType Must be either MPSDataTypeUInt32 or MPSDataTypeUInt16
+ * @param name name for the operation
+ *
+ * @return A valid MPSGraphTensor object.
+ */
+-(MPSGraphTensor *) HammingDistanceWithPrimaryTensor:(MPSGraphTensor *) primaryTensor
+ secondaryTensor:(MPSGraphTensor *) secondaryTensor
+ resultDataType:(MPSDataType) resultDataType
+ name:(NSString * _Nullable) name
+MPS_SWIFT_NAME( HammingDistance(primary:secondary:resultDataType:name:) )
+MPS_AVAILABLE_STARTING(macos(13.0), ios(16.0), tvos(16.0));
@end
diff -ruN /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphOptimizerOps.h /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphOptimizerOps.h
--- /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphOptimizerOps.h 2022-02-23 07:59:31.000000000 -0500
+++ /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphOptimizerOps.h 2022-05-31 14:52:12.000000000 -0400
@@ -38,6 +38,56 @@
name:(NSString * _Nullable) name
MPS_SWIFT_NAME( applyStochasticGradientDescent(learningRate:variable:gradient:name:) );
+/*!
+ * @abstract Adam
+ * @discussion The adam update ops are added
+ *
+ * current learning rate:
+ * lr[t] = learningRate * sqrt(1 - beta2^t) / (1 - beta1^t)
+ *
+ * m[t] = beta1 * m[t-1] + (1 - beta1) * g
+ * v[t] = beta2 * v[t-1] + (1 - beta2) * (g ^ 2)
+ * maxVel[t] = max(maxVel[t-1],v[t])
+ * variable = variable - lr[t] * m[t] / (sqrt(maxVel) + epsilon)
+ * @return if maximumVelocity is nil array of 3 tensors (update, newMomentum, newVelocity) else array of 4 tensors (update, newMomentum, newVelocity, newMaximumVelocity)
+ */
+-(NSArray<MPSGraphTensor *> *) adamWithLearningRateTensor:(MPSGraphTensor *) learningRateTensor
+ beta1Tensor:(MPSGraphTensor *) beta1Tensor
+ beta2Tensor:(MPSGraphTensor *) beta2Tensor
+ epsilonTensor:(MPSGraphTensor *) epsilonTensor
+ beta1PowerTensor:(MPSGraphTensor *) beta1PowerTensor
+ beta2PowerTensor:(MPSGraphTensor *) beta2PowerTensor
+ valuesTensor:(MPSGraphTensor *) valuesTensor
+ momentumTensor:(MPSGraphTensor *) momentumTensor
+ velocityTensor:(MPSGraphTensor *) velocityTensor
+ maximumVelocityTensor:(MPSGraphTensor * _Nullable) maximumVelocityTensor
+ gradientTensor:(MPSGraphTensor *) gradientTensor
+ name:(NSString * _Nullable) name
+MPS_SWIFT_NAME( adam(learningRate:beta1:beta2:epsilon:beta1Power:beta2Power:values:momentum:velocity:maximumVelocity:gradient:name:) );
+
+
+/*!
+ * @abstract Adam
+ * @discussion The adam update ops are added
+ *
+ * m[t] = beta1 * m[t-1] + (1 - beta1) * g
+ * v[t] = beta2 * v[t-1] + (1 - beta2) * (g ^ 2)
+ * maxVel[t] = max(maxVel[t-1],v[t])
+ * variable = variable - lr[t] * m[t] / (sqrt(maxVel) + epsilon)
+ * @return if maximumVelocity is nil array of 3 tensors (update, newMomentum, newVelocity) else array of 4 tensors (update, newMomentum, newVelocity, newMaximumVelocity)
+ */
+-(NSArray<MPSGraphTensor *> *) adamWithCurrentLearningRateTensor:(MPSGraphTensor *) currentLearningRateTensor
+ beta1Tensor:(MPSGraphTensor *) beta1Tensor
+ beta2Tensor:(MPSGraphTensor *) beta2Tensor
+ epsilonTensor:(MPSGraphTensor *) epsilonTensor
+ valuesTensor:(MPSGraphTensor *) valuesTensor
+ momentumTensor:(MPSGraphTensor *) momentumTensor
+ velocityTensor:(MPSGraphTensor *) velocityTensor
+ maximumVelocityTensor:(MPSGraphTensor * _Nullable) maximumVelocityTensor
+ gradientTensor:(MPSGraphTensor *) gradientTensor
+ name:(NSString * _Nullable) name
+MPS_SWIFT_NAME( adam(currentLearningRate:beta1:beta2:epsilon:values:momentum:velocity:maximumVelocity:gradient:name:) );
+
@end
NS_ASSUME_NONNULL_END
diff -ruN /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphPoolingOps.h /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphPoolingOps.h
--- /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphPoolingOps.h 2022-02-23 07:59:31.000000000 -0500
+++ /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphPoolingOps.h 2022-05-31 14:49:41.000000000 -0400
@@ -262,6 +262,42 @@
descriptor:(MPSGraphPooling2DOpDescriptor *) descriptor
name:(NSString * _Nullable) name;
+/*!
+ * @abstract MaxPool2D Gradient API
+ * @param gradient Input gradient tensor
+ * @param indices Indices tensor returned from maxPooling2DReturnIndicesWithSourceTensor API
+ * @param outputShape shape of the destination gradient
+ * @param descriptor See corresponding property above.
+ * @return Destination gradient tensor
+ * @discussion MaxPool2D gradient is computed efficiently by reusing the indices from the forward API instead of recomputing them.
+ * The descriptor must set returnIndicesMode and returnIndicesDataType to the same value as that set by the forward pass
+ */
+-(MPSGraphTensor *) maxPooling2DGradientWithGradientTensor:(MPSGraphTensor *) gradient
+ indicesTensor:(MPSGraphTensor *) indices
+ outputShape:(MPSShape*) outputShape
+ descriptor:(MPSGraphPooling2DOpDescriptor *) descriptor
+ name:(NSString * _Nullable) name;
+MPS_SWIFT_NAME( maxPooling2DGradient(gradient:indices:outputShape:descriptor:name:))
+MPS_AVAILABLE_STARTING(macos(13.0), ios(16.0), tvos(16.0));
+
+/*!
+ * @abstract MaxPool2D Gradient API
+ * @param gradient Input gradient tensor
+ * @param indices Indices tensor returned from maxPooling2DReturnIndicesWithSourceTensor API
+ * @param outputShape shape of the destination gradient
+ * @param descriptor See corresponding property above.
+ * @return Destination gradient tensor
+ * @discussion MaxPool2D gradient is computed efficiently by reusing the indices from the forward API instead of recomputing them.
+ * The descriptor must set returnIndicesMode and returnIndicesDataType to the same value as that set by the forward pass
+ */
+-(MPSGraphTensor *) maxPooling2DGradientWithGradientTensor:(MPSGraphTensor *) gradient
+ indicesTensor:(MPSGraphTensor *) indices
+ outputShapeTensor:(MPSGraphTensor*) outputShape
+ descriptor:(MPSGraphPooling2DOpDescriptor *) descriptor
+ name:(NSString * _Nullable) name;
+MPS_SWIFT_NAME( maxPooling2DGradient(gradient:indices:outputShape:descriptor:name:))
+MPS_AVAILABLE_STARTING(macos(13.0), ios(16.0), tvos(16.0));
+
-(MPSGraphTensor *) avgPooling2DWithSourceTensor:(MPSGraphTensor *) source
descriptor:(MPSGraphPooling2DOpDescriptor *) descriptor
name:(NSString * _Nullable) name;
@@ -300,6 +336,44 @@
MPS_SWIFT_NAME( maxPooling4DGradient(_:source:descriptor:name:))
MPS_AVAILABLE_STARTING(macos(12.0), ios(15.0), tvos(15.0));
+/*!
+ * @abstract MaxPool4D Gradient API
+ * @param gradient Input gradient tensor
+ * @param indices Indices tensor returned from maxPooling4DReturnIndicesWithSourceTensor API
+ * @param outputShape Shape of source tensor
+ * @param descriptor See corresponding property above.
+ * @return Destination gradient tensor
+ * @discussion MaxPool4D gradient is computed efficiently by reusing the indices from the forward API instead of recomputing them.
+ * The descriptor must set returnIndicesMode and returnIndicesDataType to the same value as that set by the forward pass
+ * This API should be used for NCHW and NHWC layouts
+ */
+-(MPSGraphTensor *) maxPooling4DGradientWithGradientTensor:(MPSGraphTensor *) gradient
+ indicesTensor:(MPSGraphTensor *) indices
+ outputShape:(MPSShape*) outputShape
+ descriptor:(MPSGraphPooling4DOpDescriptor *) descriptor
+ name:(NSString * _Nullable) name;
+MPS_SWIFT_NAME( maxPooling4DGradient(gradient:indices:outputShape:descriptor:name:))
+MPS_AVAILABLE_STARTING(macos(13.0), ios(16.0), tvos(16.0));
+
+/*!
+ * @abstract MaxPool4D Gradient API
+ * @param gradient Input gradient tensor
+ * @param indices Indices tensor returned from maxPooling4DReturnIndicesWithSourceTensor API
+ * @param outputShape Shape of source tensor
+ * @param descriptor See corresponding property above.
+ * @return Destination gradient tensor
+ * @discussion MaxPool4D gradient is computed efficiently by reusing the indices from the forward API instead of recomputing them.
+ * The descriptor must set returnIndicesMode and returnIndicesDataType to the same value as that set by the forward pass
+ * This API should be used for NCHW and NHWC layouts
+ */
+-(MPSGraphTensor *) maxPooling4DGradientWithGradientTensor:(MPSGraphTensor *) gradient
+ indicesTensor:(MPSGraphTensor *) indices
+ outputShapeTensor:(MPSGraphTensor*) outputShape
+ descriptor:(MPSGraphPooling4DOpDescriptor *) descriptor
+ name:(NSString * _Nullable) name;
+MPS_SWIFT_NAME( maxPooling4DGradient(gradient:indices:outputShape:descriptor:name:))
+MPS_AVAILABLE_STARTING(macos(13.0), ios(16.0), tvos(16.0));
+
-(MPSGraphTensor *) avgPooling4DWithSourceTensor:(MPSGraphTensor *) source
descriptor:(MPSGraphPooling4DOpDescriptor *) descriptor
name:(NSString * _Nullable) name
diff -ruN /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphRNNOps.h /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphRNNOps.h
--- /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphRNNOps.h 2022-02-23 07:56:16.000000000 -0500
+++ /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphRNNOps.h 2022-06-03 18:07:04.000000000 -0400
@@ -145,6 +145,80 @@
@end
+MPS_CLASS_AVAILABLE_STARTING(macos(13.0), ios(16.0), tvos(16.0))
+@interface MPSGraphGRUDescriptor : NSObject<NSCopying>
+
+/*!
+ * @property reverse
+ * @discussion If set then the input sequence is passed in reverse time order to the layer.
+ * Note: Ignored when @code bidirectional = YES @endcode.
+ * Default value: @code NO @endcode
+ */
+@property (readwrite, nonatomic) BOOL reverse;
+
+/*!
+ * @property bidirectional
+ * @discussion If set then the input sequence is traversed in both directions and the two results
+ * are concatenated together on the channel-axis.
+ * Default value: @code NO @endcode
+ */
+@property (readwrite, nonatomic) BOOL bidirectional;
+
+/*!
+ * @property training
+ * @discussion If set then the layer will produce training state tensor as a secondary or third output.
+ * Default value: @code NO @endcode
+ */
+@property (readwrite, nonatomic) BOOL training;
+
+/*!
+ * @property resetGateFirst
+ * @discussion If set then the layer will use the gate-ordering `[ r, z, o ]` instead of default `[ z, r, o ]`.
+ * Default value: @code NO @endcode
+ */
+@property (readwrite, nonatomic) BOOL resetGateFirst;
+
+/*!
+ * @property resetAfter
+ * @discussion If set then the layer will compute the intermediate value as `c[t] = ( b + (h[t-1] m ) R^T) r[t]`.
+ * Otherwise it's computed as `c[t] = (h[t-1] r[t] m) R^T`.
+ * Default value: @code NO @endcode
+ */
+@property (readwrite, nonatomic) BOOL resetAfter;
+
+/*!
+ * @property flipZ
+ * @discussion If set then the layer will compute the final value as `h[t] = z[t] h[t-1] + (1-z[t]) o[t]`.
+ * Otherwise it's computed as `h[t] = (1-z[t]) h[t-1] + z[t] o[t]`.
+ * Default value: @code NO @endcode
+ */
+@property (readwrite, nonatomic) BOOL flipZ;
+
+/*!
+ * @property updateGateActivation
+ * @discussion Activation function to use with the z-gate of the GRU op.
+ * Default value: @code MPSGraphRNNActivationSigmoid @endcode
+ */
+@property (readwrite, nonatomic) MPSGraphRNNActivation updateGateActivation;
+
+/*!
+ * @property resetGateActivation
+ * @discussion Activation function to use with the r-gate of the GRU op.
+ * Default value: @code MPSGraphRNNActivationSigmoid @endcode
+ */
+@property (readwrite, nonatomic) MPSGraphRNNActivation resetGateActivation;
+
+/*!
+ * @property outputGateActivation
+ * @discussion Activation function to use with the o-gate of the LSTM op.
+ * Default value: @code MPSGraphRNNActivationTanh @endcode
+ */
+@property (readwrite, nonatomic) MPSGraphRNNActivation outputGateActivation;
+
++(nullable instancetype) descriptor;
+
+@end
+
MPS_CLASS_AVAILABLE_STARTING(macos(12.3), ios(15.4), tvos(15.4))
@interface MPSGraph(MPSGraphRNNOps)
@@ -366,8 +440,8 @@
* @param recurrentWeight Tensor containing the recurrent weights `R`.
* For `bidirectional` the layout is [2,4H,H] and otherwise it is [4H,H].
* @param sourceGradient Input gradient, that is gradient of a tensor wrt. to first output of the forward pass.
- * @param cellOutputFwd The second output of `LSTMWithSourceTensor` with @ref `descriptor.training = true` or `descriptor.produceCell = true`.
* @param zState The third output of `LSTMWithSourceTensor` with @ref `descriptor.training = true`.
+ * @param cellOutputFwd The second output of `LSTMWithSourceTensor` with @ref `descriptor.training = true` or `descriptor.produceCell = true`.
* @param stateGradient Input gradient for state coming from the future timestep - optional, if missing assumes zeroes.
* @param cellGradient Input gradient for cell coming from the future timestep - optional, if missing assumes zeroes.
* @param inputWeight Tensor containing the input weights matrix `W` - optional, if missing assumes diagonal unit-matrix.
@@ -445,6 +519,155 @@
MPS_SWIFT_NAME( LSTMGradients(_:recurrentWeight:sourceGradient:zState:cellOutputFwd:descriptor:name:))
MPS_AVAILABLE_STARTING(macos(12.3), ios(15.4), tvos(15.4));
+/*!
+ * @abstract Create a GRU op and return the value and optionally the training state tensor.
+ * @discussion This operation returns tensors `h` and optionally `z` that are defined recursively as follows:
+ * @code
+ * for t = 0 to T-1
+ * z[t] = fz( (h[t-1] m) R^T + x[t] W^T + b ),
+ * r[t] = fr( (h[t-1] m) R^T + x[t] W^T + b ),
+ * c[t] = (h[t-1] r[t] m) R^T
+ * o[t] = fo( c[t] + x[t] W^T + b )
+ * h[t] = z[t]h[t-1] + (1-z[t])o[t]
+ * @endcode
+ * If `resetAfter = YES` then `c[t]` is replaced by
+ * @code
+ * c[t] = ( (h[t-1] m) R^T + b2 ) r[t]
+ * @endcode
+ * If `flipZ = YES` then `h[t]` is replaced by
+ * @code
+ * h[t] = (1-z[t])h[t-1] + z[t]o[t].
+ * @endcode
+ * `W` is optional @ref inputWeight, `R` is @ref recurrentWeight, `b` is optional @ref bias, `m` is optional @mask,
+ * `x[t]` is @ref source `h[t]` is the first output, `z[t]` is the second output (optional) and `h[-1]` is @ref initState.
+ * `b2` is an optional `resetBias` vector, only used when `resetAfter = YES`.
+ * See @ref MPSGraphGRUDescriptor for different `activation` options for `f()`.
+ *
+ * @param source Tensor containing the source data `x[t]` - shape should be [T,N,I].
+ * In case `inputWeight = nil` and `bidirectional = NO` then the layout is [T,N,3H]
+ * and for `inputWeight = nil` and `bidirectional = YES` the layout is [T,N,6H].
+ * @param recurrentWeight Tensor containing the recurrent weights `R`.
+ * For `bidirectional` the layout is [2,3H,H] and otherwise it is [3H,H].
+ * @param inputWeight Tensor containing the input weights matrix `W` - optional, if missing assumes diagonal unit-matrix.
+ * For `bidirectional` the layout is [6H,I] and otherwise it is [3H,I].
+ * @param bias Tensor containing the bias `b` - optional, if missing assumes zeroes.
+ * For `bidirectional` the layout is [6H] and otherwise it is [3H].
+ * @param initState Initial internal state of the LSTM `h[-1]` - optional, if missing assumes zeroes.
+ * For `bidirectional` the layout is [N,2H] and otherwise it is [N,H].
+ * @param mask Tensor containing the mask `m` - optional, if missing assumes ones. Useful for dropout.
+ * @param secondaryBias Tensor containing the secondary bias vector `b2` - optional, if missing assumes zeroes.
+ * Only used with `reset_after = YES`.
+ * Shape is [H], ie. a vector for each gate, or [2H] for bidirectional.
+ * @param descriptor The GRU op definition.
+ * @param name The name for the operation.
+ *
+ * @return A valid MPSGraphTensor array of size 1 or 2 depending on value of @ref `descriptor.training`.
+ * The layout of the state output is [T,N,H] or [T,N,2H] for bidirectional,
+ * and the layout of the trainingState output is [T,N,3H] or [T,N,6H] for bidirectional,.
+ */
+
+-(NSArray<MPSGraphTensor *> *) GRUWithSourceTensor:(MPSGraphTensor *) source
+ recurrentWeight:(MPSGraphTensor *) recurrentWeight
+ inputWeight:(MPSGraphTensor * _Nullable) inputWeight
+ bias:(MPSGraphTensor * _Nullable) bias
+ initState:(MPSGraphTensor * _Nullable) initState
+ mask:(MPSGraphTensor * _Nullable) mask
+ secondaryBias:(MPSGraphTensor * _Nullable) secondaryBias
+ descriptor:(MPSGraphGRUDescriptor *) descriptor
+ name:(NSString * _Nullable) name
+MPS_SWIFT_NAME( GRU(_:recurrentWeight:inputWeight:bias:initState:mask:secondaryBias:descriptor:name:))
+MPS_AVAILABLE_STARTING(macos(13.0), ios(16.0), tvos(16.0));
+
+-(NSArray<MPSGraphTensor *> *) GRUWithSourceTensor:(MPSGraphTensor *) source
+ recurrentWeight:(MPSGraphTensor *) recurrentWeight
+ inputWeight:(MPSGraphTensor * _Nullable) inputWeight
+ bias:(MPSGraphTensor * _Nullable) bias
+ initState:(MPSGraphTensor * _Nullable) initState
+ descriptor:(MPSGraphGRUDescriptor *) descriptor
+ name:(NSString * _Nullable) name
+MPS_SWIFT_NAME( GRU(_:recurrentWeight:inputWeight:bias:initState:descriptor:name:))
+MPS_AVAILABLE_STARTING(macos(13.0), ios(16.0), tvos(16.0));
+
+-(NSArray<MPSGraphTensor *> *) GRUWithSourceTensor:(MPSGraphTensor *) source
+ recurrentWeight:(MPSGraphTensor *) recurrentWeight
+ inputWeight:(MPSGraphTensor * _Nullable) inputWeight
+ bias:(MPSGraphTensor * _Nullable) bias
+ descriptor:(MPSGraphGRUDescriptor *) descriptor
+ name:(NSString * _Nullable) name
+MPS_SWIFT_NAME( GRU(_:recurrentWeight:inputWeight:bias:descriptor:name:))
+MPS_AVAILABLE_STARTING(macos(13.0), ios(16.0), tvos(16.0));
+
+/*!
+ * @abstract Create a GRU gradient op and return the gradient tensor values.
+ *
+ * @param source Tensor containing the source data `x[t]` - shape should be [T,N,I].
+ * In case `inputWeight = nil` and `bidirectional = NO` then the layout is [T,N,3H]
+ * and for `inputWeight = nil` and `bidirectional = YES` the layout is [T,N,6H].
+ * @param recurrentWeight Tensor containing the recurrent weights `R`.
+ * For `bidirectional` the layout is [2,3H,H] and otherwise it is [3H,H].
+ * @param sourceGradient Input gradient, that is gradient of a tensor wrt. to first output of the forward pass.
+ * @param zState The second output of `GRUWithSourceTensor` with @ref `descriptor.training = true`.
+ * @param outputFwd The first output of `GRUWithSourceTensor` with @ref `descriptor.training = true`.
+ * @param stateGradient Input gradient for state coming from the future timestep - optional, if missing assumes zeroes.
+ * @param inputWeight Tensor containing the input weights matrix `W` - optional, if missing assumes diagonal unit-matrix.
+ * For `bidirectional` the layout is [6H,I] and otherwise it is [3H,I].
+ * @param bias Tensor containing the bias `b` - optional, if missing assumes zeroes.
+ * For `bidirectional` the layout is [6H] and otherwise it is [3H].
+ * @param initState Initial internal state of the LSTM `h[-1]` - optional, if missing assumes zeroes.
+ * For `bidirectional` the layout is [N,2H] and otherwise it is [N,H].
+ * @param mask Tensor containing the mask `m` - optional, if missing assumes ones. Useful for dropout.
+ * @param secondaryBias Tensor containing the secondary bias vector `b2` - optional, if missing assumes zeroes.
+ * Only used with `reset_after = YES`.
+ * Shape is [H], ie. a vector for each gate, or [2H] for bidirectional.
+ * @param descriptor The GRU op definition.
+ * @param name The name for the operation.
+ *
+ * @return A valid MPSGraphTensor array containing gradients for each input tensor, except for `sourceGradient` and `mask`.
+ * In case an input is nil, no gradient will be returned for it.
+ * The order of the gradients will be: for source, for recurrentWeight, for inputWeight, for bias, for initState, for secondaryBias.
+ */
+
+-(NSArray<MPSGraphTensor *> *) GRUGradientsWithSourceTensor:(MPSGraphTensor *) source
+ recurrentWeight:(MPSGraphTensor *) recurrentWeight
+ sourceGradient:(MPSGraphTensor *) sourceGradient
+ zState:(MPSGraphTensor *) zState
+ outputFwd:(MPSGraphTensor *) outputFwd
+ stateGradient:(MPSGraphTensor * _Nullable) stateGradient
+ inputWeight:(MPSGraphTensor * _Nullable) inputWeight
+ bias:(MPSGraphTensor * _Nullable) bias
+ initState:(MPSGraphTensor * _Nullable) initState
+ mask:(MPSGraphTensor * _Nullable) mask
+ secondaryBias:(MPSGraphTensor * _Nullable) secondaryBias
+ descriptor:(MPSGraphGRUDescriptor *) descriptor
+ name:(NSString * _Nullable) name
+MPS_SWIFT_NAME( GRUGradients(_:recurrentWeight:sourceGradient:zState:outputFwd:stateGradient:inputWeight:bias:initState:mask:secondaryBias:descriptor:name:))
+MPS_AVAILABLE_STARTING(macos(13.0), ios(16.0), tvos(16.0));
+
+-(NSArray<MPSGraphTensor *> *) GRUGradientsWithSourceTensor:(MPSGraphTensor *) source
+ recurrentWeight:(MPSGraphTensor *) recurrentWeight
+ sourceGradient:(MPSGraphTensor *) sourceGradient
+ zState:(MPSGraphTensor *) zState
+ outputFwd:(MPSGraphTensor *) outputFwd
+ inputWeight:(MPSGraphTensor * _Nullable) inputWeight
+ bias:(MPSGraphTensor * _Nullable) bias
+ initState:(MPSGraphTensor * _Nullable) initState
+ descriptor:(MPSGraphGRUDescriptor *) descriptor
+ name:(NSString * _Nullable) name
+MPS_SWIFT_NAME( GRUGradients(_:recurrentWeight:sourceGradient:zState:outputFwd:inputWeight:bias:initState:descriptor:name:))
+MPS_AVAILABLE_STARTING(macos(13.0), ios(16.0), tvos(16.0));
+
+-(NSArray<MPSGraphTensor *> *) GRUGradientsWithSourceTensor:(MPSGraphTensor *) source
+ recurrentWeight:(MPSGraphTensor *) recurrentWeight
+ sourceGradient:(MPSGraphTensor *) sourceGradient
+ zState:(MPSGraphTensor *) zState
+ outputFwd:(MPSGraphTensor *) outputFwd
+ inputWeight:(MPSGraphTensor * _Nullable) inputWeight
+ bias:(MPSGraphTensor * _Nullable) bias
+ descriptor:(MPSGraphGRUDescriptor *) descriptor
+ name:(NSString * _Nullable) name
+MPS_SWIFT_NAME( GRUGradients(_:recurrentWeight:sourceGradient:zState:outputFwd:inputWeight:bias:descriptor:name:))
+MPS_AVAILABLE_STARTING(macos(13.0), ios(16.0), tvos(16.0));
+
@end
NS_ASSUME_NONNULL_END
diff -ruN /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MetalPerformanceShadersGraph.h /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MetalPerformanceShadersGraph.h
--- /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MetalPerformanceShadersGraph.h 2022-02-06 17:44:48.000000000 -0500
+++ /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MetalPerformanceShadersGraph.h 2022-05-21 07:04:46.000000000 -0400
@@ -29,6 +29,7 @@
#import <MetalPerformanceShadersGraph/MPSGraphRandomOps.h>
#import <MetalPerformanceShadersGraph/MPSGraphReductionOps.h>
#import <MetalPerformanceShadersGraph/MPSGraphResizeOps.h>
+#import <MetalPerformanceShadersGraph/MPSGraphRNNOps.h>
#import <MetalPerformanceShadersGraph/MPSGraphScatterNDOps.h>
#import <MetalPerformanceShadersGraph/MPSGraphStencilOps.h>
#import <MetalPerformanceShadersGraph/MPSGraphTensorShapeOps.h>
- README
- xcode13.0 Binding Status
- xcode13.1 Binding Status
- xcode13.2 Binding Status
- xcode13.3 Binding Status
- xcode13.4 Binding Status
- xcode14.0 Binding Status
- xcode14.1 Binding Status
- xcode14.2 Binding Status
- xcode14.3 Binding Status
- xcode15.0 Binding Status
- xcode15.1 Binding Status
- xcode15.3 Binding Status
- xcode15.4 Binding Status
- xcode16.0 Binding Status
- xcode16.1 Binding Status
- xcode16.2 Binding Status