Skip to content

MPSNDArray iOS xcode16.0 b1

Rolf Bjarne Kvinge edited this page Jun 26, 2024 · 2 revisions

#MPSNDArray.framework

Rolf

diff -ruN /Applications/Xcode_15.4.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShaders.framework/Frameworks/MPSNDArray.framework/Headers/MPSNDArray.h /Applications/Xcode_16.0.0-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShaders.framework/Frameworks/MPSNDArray.framework/Headers/MPSNDArray.h
--- /Applications/Xcode_15.4.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShaders.framework/Frameworks/MPSNDArray.framework/Headers/MPSNDArray.h	2024-04-13 15:19:17
+++ /Applications/Xcode_16.0.0-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShaders.framework/Frameworks/MPSNDArray.framework/Headers/MPSNDArray.h	2024-05-30 10:46:00
@@ -10,3 +10,6 @@
 #import <MPSNDArray/MPSNDArrayMatrixMultiplication.h>
 #import <MPSNDArray/MPSNDArrayStridedSlice.h>
 #import <MPSNDArray/MPSNDArrayGather.h>
+#import <MPSNDArray/MPSNDArrayIdentity.h>
+#import <MPSNDArray/MPSNDArrayQuantization.h>
+#import <MPSNDArray/MPSNDArrayQuantizedMatrixMultiplication.h>
diff -ruN /Applications/Xcode_15.4.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShaders.framework/Frameworks/MPSNDArray.framework/Headers/MPSNDArrayIdentity.h /Applications/Xcode_16.0.0-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShaders.framework/Frameworks/MPSNDArray.framework/Headers/MPSNDArrayIdentity.h
--- /Applications/Xcode_15.4.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShaders.framework/Frameworks/MPSNDArray.framework/Headers/MPSNDArrayIdentity.h	1970-01-01 01:00:00
+++ /Applications/Xcode_16.0.0-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShaders.framework/Frameworks/MPSNDArray.framework/Headers/MPSNDArrayIdentity.h	2024-05-30 10:46:03
@@ -0,0 +1,65 @@
+//
+//  MPSNDArrayIdentity.h
+//  MPS
+//
+//  Created by Dhruv Saksena on 8/3/19.
+//  Copyright © 2019 Apple. All rights reserved.
+//
+
+#ifndef MPSNDArrayIdentity_h
+#define MPSNDArrayIdentity_h
+
+#import <MPSNDArray/MPSNDArrayKernel.h>
+
+#pragma mark - Base class Identity Kernels
+
+/*!
+ *  @class      MPSNDArrayIdentityKernel
+ *
+ *  @dependency This depends on Metal.framework.
+ *  @abstract   An efficient kernel to handle copies, transposed-copies and reshapes.
+ *
+ *
+ */
+MPS_CLASS_AVAILABLE_STARTING( macos(15.0), ios(18.0), macCatalyst(18.0), tvos(18.0), xros(2.0) )
+@interface MPSNDArrayIdentity : MPSNDArrayUnaryKernel
+
+-(nonnull instancetype) initWithDevice: (nonnull id <MTLDevice>) device NS_DESIGNATED_INITIALIZER;
+
+/*! @abstract   Do a reshape operation, either by trying to alias the array, returning an arrayview, or by copying.
+ *  @param      cmdBuf          The command buffer into which to encode the kernel, or to create a temporary array alias.
+ *  @param      sourceArray    Source array. If this function returns a non-nil result, then the readCount of `sourceArray` is decremented.
+ *  @param      shape       The new shape, given in TF dimension ordering (as always with MPSShape).
+ *  @param      destinationArray    If not nil, then the result of reshape will be copied to this. Shape of `destinationArray` must match `shape`.
+ *  @result     If `destinationArray` is not nil, then `destinationArray`. Otherwise aliasing is tried, and if aliasing is not possible
+ *              due to existing slices or transposes nil is returned. If aliasing is successful, then a new arrayview of `sourceArray`
+ *              is returned; If `sourceArray` is a `MPSTemporaryArray` then a `MPSTemporaryArray` is returned referencing the same data,
+ *              otherwise a `MPSNDArray` type result is returned.
+ *   */
+-(MPSNDArray * __nullable) reshapeWithCommandBuffer: (__nullable id <MTLCommandBuffer>) cmdBuf
+                                        sourceArray: (MPSNDArray * __nonnull) sourceArray
+                                              shape: (MPSShape * __nonnull) shape
+                                   destinationArray: (MPSNDArray * __nullable) destinationArray;
+// Variant with MPS dimension-ordering
+-(MPSNDArray * __nullable) reshapeWithCommandBuffer: (__nullable id <MTLCommandBuffer>) cmdBuf
+                                        sourceArray: (MPSNDArray * __nonnull) sourceArray
+                                     dimensionCount: (NSUInteger) numberOfDimensions
+                                     dimensionSizes: (NSUInteger*__nonnull) dimensionSizes
+                                   destinationArray: (MPSNDArray * __nullable) destinationArray;
+
+-(MPSNDArray * __nullable) reshapeWithCommandEncoder: (__nullable id <MTLComputeCommandEncoder>) encoder
+                                       commandBuffer: (__nullable id <MTLCommandBuffer>) cmdBuf
+                                        sourceArray: (MPSNDArray * __nonnull) sourceArray
+                                              shape: (MPSShape * __nonnull) shape
+                                   destinationArray: (MPSNDArray * __nullable) destinationArray;
+// Variant with MPS dimension-ordering
+-(MPSNDArray * __nullable) reshapeWithCommandEncoder: (__nullable id <MTLComputeCommandEncoder>) encoder
+                                       commandBuffer: (__nullable id <MTLCommandBuffer>) cmdBuf
+                                        sourceArray: (MPSNDArray * __nonnull) sourceArray
+                                     dimensionCount: (NSUInteger) numberOfDimensions
+                                     dimensionSizes: (NSUInteger*__nonnull) dimensionSizes
+                                   destinationArray: (MPSNDArray * __nullable) destinationArray;
+
+@end    // MPSNDArrayIdentity
+
+#endif /* MPSNDArrayIdentity_h */
diff -ruN /Applications/Xcode_15.4.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShaders.framework/Frameworks/MPSNDArray.framework/Headers/MPSNDArrayQuantization.h /Applications/Xcode_16.0.0-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShaders.framework/Frameworks/MPSNDArray.framework/Headers/MPSNDArrayQuantization.h
--- /Applications/Xcode_15.4.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShaders.framework/Frameworks/MPSNDArray.framework/Headers/MPSNDArrayQuantization.h	1970-01-01 01:00:00
+++ /Applications/Xcode_16.0.0-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShaders.framework/Frameworks/MPSNDArray.framework/Headers/MPSNDArrayQuantization.h	2024-05-30 05:07:59
@@ -0,0 +1,125 @@
+//
+//  MPSNDArrayQuantization.h
+//  MPSNDArray
+//
+//  Created by Saharsh Oza on 4/24/23.
+//  Copyright © 2023 Apple. All rights reserved.
+//
+
+#ifndef MPSNDArrayQuantization_h
+#define MPSNDArrayQuantization_h
+
+#import <MPSCore/MPSCoreTypes.h>
+#import <MPSCore/MPSKernel.h>
+#import <MPSCore/MPSNDArray.h>
+
+/*! @enum       MPSNDArrayQuantizationScheme
+ *  @discussion  Which quantization mode is applied to an MPSNDArray
+ *
+ *  @constant   MPSNDArrayQuantizationTypeNone              No quantization - inputs are read and outputs are produced in the original datatype.
+ *  @constant   MPSNDArrayQuantizationTypeAffine           Dequantization with: y = scale( input - zeroPoint) + minValue
+ *  @constant   MPSNDArrayQuantizationTypeLUT           Dequantization with y = lookuptable[ input ]
+ */
+
+#if defined(DOXYGEN)
+    typedef enum MPSNDArrayQuantizationScheme
+#else
+    typedef NS_OPTIONS(NSUInteger, MPSNDArrayQuantizationScheme)
+#endif
+{
+    MPSNDArrayQuantizationTypeNone MPS_ENUM_AVAILABLE_STARTING( macos(15.0), ios(18.0), macCatalyst(18.0), tvos(18.0), xros(2.0) ) MPS_SWIFT_NAME( none ) = 0,
+    MPSNDArrayQuantizationTypeAffine MPS_ENUM_AVAILABLE_STARTING( macos(15.0), ios(18.0), macCatalyst(18.0), tvos(18.0), xros(2.0) ),
+    MPSNDArrayQuantizationTypeLUT MPS_ENUM_AVAILABLE_STARTING( macos(15.0), ios(18.0), macCatalyst(18.0), tvos(18.0), xros(2.0) ),
+}
+#if defined(DOXYGEN)
+    MPSNDArrayQuantizationScheme
+#endif
+;
+
+
+/*!
+ *  @class      MPSNDArrayQuantizationDescriptor
+ *
+ *  @dependency This depends on Metal.framework.
+ *  @abstract   Common methods for quantization descriptors
+ *
+ *
+ */
+MPS_CLASS_AVAILABLE_STARTING( macos(15.0), ios(18.0), macCatalyst(18.0), tvos(18.0), xros(2.0) )
+@interface MPSNDArrayQuantizationDescriptor : NSObject <NSCopying>
+
+/*! @property  quantizationDataType
+ *  @abstract  The datatype to use with quantization - the default is MPSDataTypeUint8
+ */
+@property (readonly, nonatomic) MPSDataType quantizationDataType;
+
+/*! @property  quantizationScheme
+ *  @abstract  The quantization scheme for this descriptor. The default is MPSNDArrayQuantizationTypeNone.
+ */
+@property (readonly, nonatomic) MPSNDArrayQuantizationScheme quantizationScheme;
+
+@end
+
+/*!
+ *  @class      MPSNDArrayAffineQuantizationDescriptor
+ *
+ *  @dependency This depends on Metal.framework.
+ *  @abstract   Describes an affine quantization scheme
+ *
+ */
+MPS_CLASS_AVAILABLE_STARTING( macos(15.0), ios(18.0), macCatalyst(18.0), tvos(18.0), xros(2.0) )
+@interface MPSNDArrayAffineQuantizationDescriptor : MPSNDArrayQuantizationDescriptor
+
+/*! @property  hasZeroPoint
+ *  @abstract  If yes then asymmetric quantization is used. See MPSNDArrayQuantizationScheme.
+ */
+@property (readwrite, nonatomic) BOOL hasZeroPoint;
+
+/*! @property  hasMinValue
+ *  @abstract  If yes then offset is used. See MPSNDArrayQuantizationScheme.
+ */
+@property (readwrite, nonatomic) BOOL hasMinValue;
+
+
+- (nonnull instancetype) init;
+
+/*! @abstract   Initializes an affine quantization descriptor.
+ *  @param      quantizationDataType    Which quantized datatype is used.
+ *  @param      hasZeroPoint        A flag indicating that a zero-point input is expected.
+ *  @param      hasMinValue        A flag indicating that a minimum value input is expected.
+ *  @result     A new quantization descriptor.
+ *   */
+- (nonnull instancetype) initWithDataType: (MPSDataType) quantizationDataType
+                             hasZeroPoint: (BOOL) hasZeroPoint
+                              hasMinValue: (BOOL) hasMinValue;
+
+@end
+
+
+/*!
+ *  @class      MPSNDArrayLUTQuantizationDescriptor
+ *
+ *  @dependency This depends on Metal.framework.
+ *  @abstract   Describes a lookup-table based quantization scheme
+ *
+ */
+MPS_CLASS_AVAILABLE_STARTING( macos(15.0), ios(18.0), macCatalyst(18.0), tvos(18.0), xros(2.0) )
+@interface MPSNDArrayLUTQuantizationDescriptor : MPSNDArrayQuantizationDescriptor
+
+/*! @abstract   Initializes a scalar lookup-table quantization descriptor.
+ *  @param      quantizationDataType    Which quantized datatype is used.
+ *  @result     A new quantization descriptor.
+ *   */
+- (nonnull instancetype) initWithDataType: (MPSDataType) quantizationDataType;
+
+/*! @abstract   Initializes a vector lookup-table quantization descriptor.
+ *  @param      quantizationDataType    Which quantized datatype is used.
+ *  @param      vectorAxis        The quantization vector axis - this axis will receive the vector component in the destination.
+ *  @result     A new quantization descriptor.
+ *   */
+- (nonnull instancetype) initWithDataType: (MPSDataType) quantizationDataType
+                               vectorAxis: (NSUInteger) vectorAxis;
+
+@end
+
+#endif /* MPSNDArrayQuantization_h */
diff -ruN /Applications/Xcode_15.4.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShaders.framework/Frameworks/MPSNDArray.framework/Headers/MPSNDArrayQuantizedMatrixMultiplication.h /Applications/Xcode_16.0.0-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShaders.framework/Frameworks/MPSNDArray.framework/Headers/MPSNDArrayQuantizedMatrixMultiplication.h
--- /Applications/Xcode_15.4.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShaders.framework/Frameworks/MPSNDArray.framework/Headers/MPSNDArrayQuantizedMatrixMultiplication.h	1970-01-01 01:00:00
+++ /Applications/Xcode_16.0.0-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/MetalPerformanceShaders.framework/Frameworks/MPSNDArray.framework/Headers/MPSNDArrayQuantizedMatrixMultiplication.h	2024-05-30 03:40:26
@@ -0,0 +1,127 @@
+//
+//  MPSNDArrayQuantizedMatrixMultiplication.h
+//  MPSNDArray
+//
+//  Copyright © 2023 Apple. All rights reserved.
+//
+
+#ifndef MPSNDArrayQuantizedMatrixMultiplication_h
+#define MPSNDArrayQuantizedMatrixMultiplication_h
+
+#import <MPSNDArray/MPSNDArrayMatrixMultiplication.h>
+#import <MPSNDArray/MPSNDArrayQuantization.h>
+
+/*!
+ *  @class      MPSNDArrayQuantizedMatrixMultiplication
+ *
+ *  @dependency This depends on Metal.framework.
+ *  @abstract   A quantized matrix multiplication kernel: C = AB, where each input A and B can be quantized.
+ *  @discussion The kernel works with 2-8 inputs, order of inputs: First all LHS inputs, then all RHS inputs.
+ *              The order of inputs for LUT based LHS or RHS: 1) quantized input 2) Lookup Table.
+ *              The order of inputs for affine LHS or RHS: 1) quantized input 2) scale 3) zeropoint 4) minValue.
+ *              The full order of inputs for the encode methods is:
+ *                   `[LHS, RHS, <LHS quantization inputs>, <RHS quantization inputs>]`,
+ *              where `LHS` is the left input (quantized or float) `RHS` is the right input (quantized or float) and
+ *              `<LHS quantization inputs>` are the auxiliary quantization inputs for the LHS array (scales, zeropoints etc).
+ *              and `<RHS quantization inputs>` are the auxiliary quantization input for the RHS array.
+ *              The inputs are provided as a compacted `NSArray<MPSNDArray *>`, for example for computing
+ *              `C = A * B^T` where `A` is quantized with a LUT and `B` is quantized with affine quantization that
+ *              uses scale and minValue the array of inputs is:
+ *              ` [ Aq, Bq^T, ALUT, BScale^T, BMin^T ] `.
+ *              NOTE: For affine scale, zeropoint and minValue must have same transposes as quantized input.
+ *
+ */
+MPS_CLASS_AVAILABLE_STARTING( macos(15.0), ios(18.0), macCatalyst(18.0), tvos(18.0), xros(2.0) )
+@interface MPSNDArrayQuantizedMatrixMultiplication : MPSNDArrayMatrixMultiplication
+
+-(nonnull instancetype) initWithDevice:(nonnull id<MTLDevice>)device
+                           sourceCount:(NSUInteger) sourceCount NS_UNAVAILABLE;
+
+/*! @abstract   Initializes a quantized matrix multiplication kernel.
+ *  @param      leftQuantizationDescriptor    The quantization definition for the LHS input.
+ *  @param      rightQuantizationDescriptor    The quantization definition for the RHS input.
+ *  @result     A new valid quantized matrix multiplication kernel.
+ *   */
+- (nonnull instancetype) initWithDevice: (nonnull id<MTLDevice>) device
+             leftQuantizationDescriptor: (MPSNDArrayQuantizationDescriptor* _Nullable) leftQuantizationDescriptor
+            rightQuantizationDescriptor: (MPSNDArrayQuantizationDescriptor* _Nullable) rightQuantizationDescriptor;
+
+@end
+
+/*!
+ *  @class      MPSNDArrayLUTDequantize
+ *
+ *  @dependency This depends on Metal.framework.
+ *  @abstract   A kernel which dequantizes a lookup-table based NDArray.
+ *  @discussion The kernel works with 2 inputs: 1) The quantized input, 2) The LookUp table array.
+ *
+ */
+
+MPS_CLASS_AVAILABLE_STARTING( macos(15.0), ios(18.0), macCatalyst(18.0), tvos(18.0), xros(2.0) )
+@interface MPSNDArrayLUTDequantize : MPSNDArrayMultiaryKernel
+
+-(nonnull instancetype) initWithDevice: (nonnull id <MTLDevice>) device
+NS_DESIGNATED_INITIALIZER;
+
+-(nonnull instancetype) initWithDevice:(nonnull id<MTLDevice>)device
+                           sourceCount:(NSUInteger) sourceCount NS_UNAVAILABLE;
+
+@end
+
+/*!
+ *  @class      MPSNDArrayVectorLUTDequantize
+ *
+ *  @dependency This depends on Metal.framework.
+ *  @abstract   A kernel which dequantizes a lookup-table based NDArray with vector LUT support.
+ *  @discussion The kernel works with 2 inputs: 1) The quantized input, 2) The LookUp table array.
+ *
+ */
+MPS_CLASS_AVAILABLE_STARTING( macos(15.0), ios(18.0), macCatalyst(18.0), tvos(18.0), xros(2.0) )
+@interface MPSNDArrayVectorLUTDequantize : MPSNDArrayMultiaryKernel
+
+/*! @property  vectorAxis
+ *  @abstract  Which axis in the destination will receive the vector component, must be less than 4.
+ */
+@property(readwrite, nonatomic) NSUInteger vectorAxis;
+
+/*! @abstract   Initializes a kernel for vector-based LUT dequantization.
+ *  @param      device    The Metal device to be used with this kernel.
+ *  @param      axis        The vector axis in the output.
+ *  @result     A new vector LUT dequantization kernel.
+ *   */
+-(nonnull instancetype) initWithDevice: (nonnull id <MTLDevice>) device
+                                  axis: (NSUInteger) axis
+NS_DESIGNATED_INITIALIZER;
+
+-(nonnull instancetype) initWithDevice:(nonnull id<MTLDevice>)device
+                           sourceCount:(NSUInteger) sourceCount NS_UNAVAILABLE;
+
+@end
+
+/*!
+ *  @class      MPSNDArrayAffineInt4Dequantize
+ *
+ *  @dependency This depends on Metal.framework.
+ *  @abstract   A kernel which dequantizes an input with affine quantization scheme.
+ *  @discussion The kernel works with 2-4 inputs, order of inputs: 1) quantized input, 2) scale, 3) zeropoint, 4) minValue
+ *
+ */
+MPS_CLASS_AVAILABLE_STARTING( macos(15.0), ios(18.0), macCatalyst(18.0), tvos(18.0), xros(2.0) )
+@interface MPSNDArrayAffineInt4Dequantize : MPSNDArrayMultiaryKernel
+
+-(nonnull instancetype) initWithDevice: (nonnull id <MTLDevice>) device NS_UNAVAILABLE;
+
+/*! @abstract   Initializes a kernel for 4-bit affine dequantization.
+ *  @param      device    The Metal device to be used with this kernel.
+ *  @param      quantizationDescriptor        Describes the quantization scheme.
+ *  @result     A new vector LUT dequantization kernel.
+ *   */
+-(nonnull instancetype) initWithDevice:(nonnull id<MTLDevice>)device
+                quantizationDescriptor:(MPSNDArrayAffineQuantizationDescriptor* __nonnull) quantizationDescriptor;
+
+-(nonnull instancetype) initWithDevice:(nonnull id<MTLDevice>)device
+                           sourceCount:(NSUInteger) sourceCount NS_UNAVAILABLE;
+
+@end
+
+#endif /* MPSNDArrayQuantizedMatrixMultiplication_h */
Clone this wiki locally