Skip to content

MetalPerformanceShadersGraph macOS xcode16.0 b1

Rolf Bjarne Kvinge edited this page Aug 30, 2024 · 3 revisions

#MetalPerformanceShadersGraph.framework https://github.com/xamarin/xamarin-macios/pull/21154

diff -ruN /Applications/Xcode_15.4.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraph.h /Applications/Xcode_16.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraph.h
--- /Applications/Xcode_15.4.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraph.h	2024-04-13 16:01:45
+++ /Applications/Xcode_16.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraph.h	2024-05-30 04:43:28
@@ -89,7 +89,11 @@
 typedef void (^MPSGraphCompilationCompletionHandler)(MPSGraphExecutable* executable,
                                                      NSError * _Nullable error);
 
-/// This is a class that consists of all the levers for compiling graphs.
+/// A dictionary of symbol names and the corresponding executables for them.
+MPS_AVAILABLE_STARTING(macos(14.1), ios(17.1), tvos(17.1))
+typedef NSDictionary<NSString *, MPSGraphExecutable *> MPSGraphCallableMap;
+
+/// A class that consists of all the levers for compiling graphs.
 MPS_CLASS_AVAILABLE_STARTING(macos(12.0), ios(15.0), tvos(15.0))
 @interface MPSGraphCompilationDescriptor : MPSGraphObject <NSCopying>
 
@@ -102,33 +106,50 @@
 @property (readwrite, nonatomic) MPSGraphOptimizationProfile optimizationProfile
 MPS_AVAILABLE_STARTING_BUT_DEPRECATED("MPSGraph will automatically provide the best performance and power efficiency with MPSGraphOptimizationLevel1.",
                                       macos(12.3, 14.0), ios(15.4, 17.0), tvos(15.4, 17.0));
 
+/// The dictionary used during runtime to lookup the ``MPSGraphExecutable`` which correspond to the ``symbolName``.
+@property (readwrite, atomic, nullable) MPSGraphCallableMap *callables MPS_AVAILABLE_STARTING(macos(14.1), ios(17.1), tvos(17.1));
+
 @end
diff -ruN /Applications/Xcode_15.4.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphCallOps.h /Applications/Xcode_16.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphCallOps.h
--- /Applications/Xcode_15.4.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphCallOps.h	1970-01-01 01:00:00
+++ /Applications/Xcode_16.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphCallOps.h	2024-05-30 03:27:10
@@ -0,0 +1,36 @@
+//
+//  MPSGraphCallOps.h
+//  MPSGraph
+//
+//  Created by George Pawelczak on 7/26/23.
+//  Copyright © 2023 Apple Inc. All rights reserved.
+//
+
+#ifndef MPSGraphCallOps_h
+#define MPSGraphCallOps_h
+
+#import <MetalPerformanceShadersGraph/MPSGraph.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface MPSGraph(CallOp)
+
+/// Creates an operation which invokes another executable.
+///
+/// - Parameters:
+///   - symbolName: The unique identifier used to find the executable in the ``MPSGraphCompilationDescriptor.callables`` directory.
+///   - inputTensors: The tensors which are passed as inputs to the executable being invoked.
+///   - outputTypes: The expected return types of the executable being invoked.
+///   - name: name of operation.
+/// - Returns: An array of valid ``MPSGraphTensor`` objects representing the return tensors of the invoked executable.
+-(NSArray<MPSGraphTensor *> *) callSymbolName:(NSString *) symbolName
+                                 inputTensors:(NSArray<MPSGraphTensor *> *) inputTensors
+                                  outputTypes:(NSArray<MPSGraphType *> *) outputTypes
+                                         name:(NSString * _Nullable) name
+MPS_SWIFT_NAME( call(symbolName:inputTensors:outputTypes:name:) )
+MPS_AVAILABLE_STARTING(macos(15.0), ios(18.0), macCatalyst(18.0), tvos(18.0), xros(2.0));
+
+@end
+NS_ASSUME_NONNULL_END
+
+#endif /* MPSGraphCallOps_h */
diff -ruN /Applications/Xcode_15.4.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphExecutable.h /Applications/Xcode_16.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphExecutable.h
--- /Applications/Xcode_15.4.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphExecutable.h	2024-04-13 16:01:44
+++ /Applications/Xcode_16.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphExecutable.h	2024-05-30 05:56:17
@@ -200,6 +215,16 @@
                        compilationDescriptor:(MPSGraphCompilationDescriptor * _Nullable) compilationDescriptor
 MPS_SWIFT_NAME( init(package:descriptor:) )
 MPS_AVAILABLE_STARTING(macos(14.0), ios(17.0), tvos(17.0));
+
+/// Initialize the executable with the Core ML model package at the provided URL.
+///
+/// - Parameters:
+///   - coreMLPackageURL: The URL where to read the Core ML model package.
+///   - compilationDescriptor: Compilation descriptor to be used to specialize, since the executable was created with a compilationDescriptor already this one overrides those settings to the extent it can.
+-(instancetype) initWithCoreMLPackageAtURL:(NSURL *)coreMLPackageURL
+                     compilationDescriptor:(MPSGraphCompilationDescriptor * _Nullable) compilationDescriptor
+MPS_SWIFT_NAME( init(package:descriptor:) )
+MPS_AVAILABLE_STARTING(macos(15.0), ios(18.0), tvos(18.0));
 
 @end

diff -ruN /Applications/Xcode_15.4.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphMatrixMultiplicationOps.h /Applications/Xcode_16.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphMatrixMultiplicationOps.h
--- /Applications/Xcode_15.4.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphMatrixMultiplicationOps.h	2024-04-13 21:12:48
+++ /Applications/Xcode_16.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphMatrixMultiplicationOps.h	2024-05-30 04:58:36
@@ -46,6 +46,48 @@
 MPS_SWIFT_NAME( HammingDistance(primary:secondary:resultDataType:name:) )
 MPS_AVAILABLE_STARTING(macos(13.0), ios(16.0), tvos(16.0));
 
+/// Creates a scaled dot product attention (SDPA) operation and returns the result tensor.
+///
+/// SDPA Op computes attention by computing softmax(scale * QK^T + M)V.
+/// queryTensor Q with shape [B, Hq, Nq, F] and keyTensor K with shape [B, Hq, Nkv, F],
+/// with Q's H dimension expandable to satisfy matmul QK^T. maskTensor M's shape
+/// should be broadcast compatible to satisfy (QK^T + M). valueTensor V with shape
+/// [B, Hv, Nkv, F] should satisfy the matmul (QK^T + M)V.
+///
+/// - Parameters:
+///   - queryTensor: A tensor that represents the query projection.
+///   - keyTensor: A tensor that represents the key projection.
+///   - valueTensor: A tensor that represents the value projection.
+///   - maskTensor: An optional tensor that contains a mask that is applied to the scaled, matrix
+///   multiplied query and value matrices. If mask tensor is nil, the QK^T is not element-wise masked.
+///   - scale: A scale that is applied to the result of query and value matrix multiply.
+///   - name: The name for the operation.
+/// - Returns: A valid MPSGraphTensor object.
+- (MPSGraphTensor *)scaledDotProductAttentionWithQueryTensor:(MPSGraphTensor *)queryTensor
+                                                   keyTensor:(MPSGraphTensor *)keyTensor
+                                                 valueTensor:(MPSGraphTensor *)valueTensor
+                                                  maskTensor:(MPSGraphTensor *_Nullable)maskTensor
+                                                       scale:(float)scale
+                                                        name:(NSString *_Nullable)name
+    MPS_SWIFT_NAME(scaledDotProductAttention(query:key:value:mask:scale:name:) )
+MPS_AVAILABLE_STARTING(macos(15.0), ios(18.0), macCatalyst(18.0), tvos(18.0), xros(2.0));
+
+/// Creates a scaled dot product attention (SDPA) operation (without a mask) and returns the result tensor.
+///
+/// - Parameters:
+///   - queryTensor: A tensor that represents the query projection.
+///   - keyTensor: A tensor that represents the key projection.
+///   - valueTensor: A tensor that represents the value projection.
+///   - scale: A scale that is applied on the result of query and value matrix multiply.
+///   - name: The name for the operation.
+/// - Returns: A valid MPSGraphTensor object.
+- (MPSGraphTensor *)scaledDotProductAttentionWithQueryTensor:(MPSGraphTensor *)queryTensor
+                                                   keyTensor:(MPSGraphTensor *)keyTensor
+                                                 valueTensor:(MPSGraphTensor *)valueTensor
+                                                       scale:(float)scale
+                                                        name:(NSString *_Nullable)name
+    MPS_SWIFT_NAME(scaledDotProductAttention(query:key:value:scale:name:) )
+MPS_AVAILABLE_STARTING(macos(15.0), ios(18.0), macCatalyst(18.0), tvos(18.0), xros(2.0));
 
 @end
 
diff -ruN /Applications/Xcode_15.4.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphMemoryOps.h /Applications/Xcode_16.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphMemoryOps.h
--- /Applications/Xcode_15.4.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphMemoryOps.h	2024-04-13 16:01:45
+++ /Applications/Xcode_16.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphMemoryOps.h	2024-05-30 03:27:11
@@ -138,6 +138,17 @@
                             dataType:(MPSDataType) dataType
                                 name:(NSString * _Nullable) name;
 
+/// Creates a variable from an input tensor.
+///
+/// - Parameters:
+///   - tensor: The tensor from which to form the variable.
+///   - name: The name for the operation.
+/// - Returns: A valid MPSGraphTensor object.
+    -(MPSGraphTensor *) variableFromTensorWithTensor:(MPSGraphTensor * _Nonnull) tensor
+                                                name:(NSString * _Nullable) name
+MPS_SWIFT_NAME( variableFromTensor(_:name:) )
+MPS_AVAILABLE_STARTING(macos(15.0), ios(18.0), macCatalyst(18.0), tvos(18.0));
+
 /// Creates a read op which reads at this point of execution of the graph and returns the result tensor.
 ///
 /// - Parameters:
diff -ruN /Applications/Xcode_15.4.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphQuantizationOps.h /Applications/Xcode_16.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphQuantizationOps.h
--- /Applications/Xcode_15.4.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphQuantizationOps.h	2024-04-13 15:01:00
+++ /Applications/Xcode_16.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphQuantizationOps.h	2024-05-30 04:43:27
@@ -144,6 +142,92 @@
                                name:(NSString * _Nullable) name
 MPS_AVAILABLE_STARTING(macos(13.1), ios(16.2), tvos(16.2))
 MPS_SWIFT_NAME( dequantize(_:scaleTensor:zeroPointTensor:dataType:axis:name:) );
+
+
+/// Creates a dequantize operation and returns the result tensor.
+///
+/// Convert the i8, u8, i4 or u4 `tensor` to a float tensor by applying a scale and bias transform:
+/// ```md
+/// result = scaleTensor(tensor - zeroPointTensor).
+/// ```
+///
+/// - Parameters:
+///   - tensor: Input tensor to be dequantized.
+///   - scaleTensor: The scale tensor with groups support.
+///   - zeroPointTensor: The bias tensor with groups support.
+///   - dataType: Float data type of the result tensor.
+///   - name: The name for the operation.
+/// - Returns: A valid ``MPSGraphTensor`` array of datatype `dataType`.
+-(MPSGraphTensor*) dequantizeTensor:(MPSGraphTensor*)tensor
+                        scaleTensor:(MPSGraphTensor*)scaleTensor
+                    zeroPointTensor:(MPSGraphTensor*)zeroPointTensor
+                           dataType:(MPSDataType)dataType
+                               name:(NSString * _Nullable) name
+MPS_AVAILABLE_STARTING(macos(15.0), ios(18.0), macCatalyst(18.0), tvos(18.0), xros(2.0))
+MPS_SWIFT_NAME( dequantize(_:scaleTensor:zeroPointTensor:dataType:name:) );
+
+
+/// Creates a dequantize operation and returns the result tensor.
+///
+/// Converts the i8, u8, i4 or u4 `tensor` to a float tensor by applying a scale and bias transform:
+/// ```md
+/// result = scaleTensor * tensor.
+/// ```
+///
+/// - Parameters:
+///   - tensor: Input tensor to be dequantized.
+///   - scaleTensor: Scale Tensor parameter with groups support.
+///   - dataType: Float data type of the result tensor.
+///   - name: The name for the operation.
+/// - Returns: A valid ``MPSGraphTensor`` array of datatype `dataType`.
+-(MPSGraphTensor*) dequantizeTensor:(MPSGraphTensor*)tensor
+                        scaleTensor:(MPSGraphTensor*)scaleTensor
+                           dataType:(MPSDataType)dataType
+                               name:(NSString * _Nullable) name
+MPS_AVAILABLE_STARTING(macos(15.0), ios(18.0), macCatalyst(18.0), tvos(18.0), xros(2.0))
+MPS_SWIFT_NAME( dequantize(_:scaleTensor:dataType:name:) );
+
+/// Creates a lookup-table based quantization operation and returns the result tensor.
+///
+/// Converts a u8 or u4 `tensor` to a float tensor by applying a lookup operation:
+/// ```md
+/// result[i1,...,in] = LUTTensor[i1',...,in',tensor[i1,...,in]].
+/// ```
+/// Note: The operation supports LUT groups up to the last 3 dimensions for `tensor`.
+///
+/// - Parameters:
+///   - tensor: Input tensor to be dequantized.
+///   - LUTTensor: The lookup table to use - for u4 the last dimension should have 16 elements, and for u8 256 elements.
+///   - name: The name for the operation.
+/// - Returns: A valid ``MPSGraphTensor`` object.
+-(MPSGraphTensor *) dequantizeTensor:(MPSGraphTensor *) tensor
+                           LUTTensor:(MPSGraphTensor *) LUTTensor
+                                name:(NSString * _Nullable) name
+MPS_SWIFT_NAME( dequantize(_:LUTTensor:name:) )
+MPS_AVAILABLE_STARTING(macos(15.0), ios(18.0), macCatalyst(18.0), tvos(18.0), xros(2.0));
+
+/// Creates a vector lookup-table based quantization operation and returns the result tensor.
+///
+/// Converts a u8 or u4 `tensor` to a float tensor by applying a lookup operation, where each
+/// input index defines a vector of values. The operation reads the vector values from the last dimension of the lookup table
+/// tensor and stores them into the dimension defined by `axis` on the result tensor.
+/// ```md
+/// result[i1, ... , i_axis, ..., in] = LUTTensor[i1', ..., in', tensor[i1, ..., in], i_axis]
+/// ```
+/// Note: The operation supports LUT groups up to the last 2 dimensions for `tensor`.
+///
+/// - Parameters:
+///   - tensor: Input tensor to be dequantized.
+///   - LUTTensor: The lookup table to use - for u4 the second to last dimension should have 16 elements, and for u8 256 elements.
+///   - axis: Axis on which the scale 1D value is being broadcasted.
+///   - name: The name for the operation.
+/// - Returns: A valid ``MPSGraphTensor`` object.
+-(MPSGraphTensor *) dequantizeTensor:(MPSGraphTensor *) tensor
+                           LUTTensor:(MPSGraphTensor *) LUTTensor
+                                axis:(NSInteger) axis
+                                name:(NSString * _Nullable) name
+MPS_SWIFT_NAME( dequantize(_:LUTTensor:axis:name:) )
+MPS_AVAILABLE_STARTING(macos(15.0), ios(18.0), macCatalyst(18.0), tvos(18.0), xros(2.0));
 
 @end
 
diff -ruN /Applications/Xcode_15.4.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphTensorShapeOps.h /Applications/Xcode_16.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphTensorShapeOps.h
--- /Applications/Xcode_15.4.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphTensorShapeOps.h	2024-04-13 16:01:45
+++ /Applications/Xcode_16.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Headers/MPSGraphTensorShapeOps.h	2024-05-30 11:26:36
@@ -227,6 +227,44 @@
                                      name:(NSString * _Nullable) name
 MPS_AVAILABLE_STARTING(macos(14.4), ios(17.4), tvos(17.4));
 
+/// Creates a strided-slice update operation with zero masks and returns the result tensor.
+///
+/// - Parameters:
+///   - dataTensor: The large tensor that will receive the update.
+///   - updateTensor: The tensor with the new values that will replace values in the dataTensor.
+///   - startsTensor: A Tensor that contains an array of numbers that specify the starting points for each dimension.
+///   - endsTensor: A Tensor that contains an array of numbers that specify the ending points for each dimension.
+///   - stridesTensor: A Tensor that contains an array of numbers that specify the strides for each dimension.
+///   - name: The name for the operation.
+/// - Returns: A valid MPSGraphTensor object
+-(MPSGraphTensor *) sliceUpdateDataTensor:(MPSGraphTensor *) dataTensor
+                             updateTensor:(MPSGraphTensor *) updateTensor
+                             startsTensor:(MPSGraphTensor *) startsTensor
+                               endsTensor:(MPSGraphTensor *) endsTensor
+                            stridesTensor:(MPSGraphTensor *) stridesTensor
+                                     name:(NSString * _Nullable) name
+MPS_AVAILABLE_STARTING(macos(15.0), ios(18.0), macCatalyst(18.0), tvos(18.0), xros(2.0));
+
+/// Creates a strided-slice update operation with zero masks and returns the result tensor.
+///
+/// - Parameters:
+///   - dataTensor: The large tensor that will receive the update.
+///   - updateTensor: The tensor with the new values that will replace values in the dataTensor.
+///   - starts: An array of numbers that specify the starting points for each dimension.
+///   - ends: An array of numbers that specify the ending points for each dimension.
+///   - strides: An array of numbers that specify the strides for each dimension.
+///   - name: The name for the operation.
+/// - Returns: A valid MPSGraphTensor object
+-(MPSGraphTensor *) sliceUpdateDataTensor:(MPSGraphTensor *) dataTensor
+                             updateTensor:(MPSGraphTensor *) updateTensor
+                                   starts:(NSArray<NSNumber *> *) starts
+                                     ends:(NSArray<NSNumber *> *) ends
+                                  strides:(NSArray<NSNumber *> *) strides
+                                     name:(NSString * _Nullable) name
+MPS_AVAILABLE_STARTING(macos(15.0), ios(18.0), macCatalyst(18.0), tvos(18.0), xros(2.0));
+
+
+
 /// Creates a concatenation operation and returns the result tensor.
 ///
 /// Concatenates two input tensors along the specified dimension. Tensors must be broadcast
Clone this wiki locally