Skip to content

CoreML macOS xcode14.0 beta1

Manuel de la Pena edited this page Jul 15, 2022 · 3 revisions

#CoreML.framework https://github.com/xamarin/xamarin-macios/pull/15527

diff -ruN /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreML.framework/Headers/CoreML.h /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreML.framework/Headers/CoreML.h
--- /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreML.framework/Headers/CoreML.h	2022-02-12 04:50:51.000000000 -0500
+++ /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreML.framework/Headers/CoreML.h	2022-05-21 07:36:41.000000000 -0400
@@ -59,3 +59,4 @@
 
 #import <CoreML/MLModelCollection.h>
 #import <CoreML/MLModelCollectionEntry.h>
+#import <CoreML/MLModelAsset.h>
diff -ruN /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreML.framework/Headers/MLFeatureValue.h /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreML.framework/Headers/MLFeatureValue.h
--- /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreML.framework/Headers/MLFeatureValue.h	2022-02-23 10:58:12.000000000 -0500
+++ /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreML.framework/Headers/MLFeatureValue.h	2022-05-31 15:04:17.000000000 -0400
@@ -73,6 +73,18 @@
 
 
 
+/*!
+ * @abstract Returns a Boolean value that indicates whether a feature value is equal to another.
+ *
+ * @discussion If the types of the MLFeatureValue objects "self" and "value"  are integer in one case and
+ * double in the other (in either order) then those mixed mode numeric values are compared as NSNumbers.
+ * Otherwise if the types of the MLFeatureValue objects are different NO is returned.
+ * When "self" and "value" are both PixelBuffer MLFeatureValue types, only their CVPixelBufferRef values are compared for equality,
+ * the underlying arrays of pixelValues are not examined.
+ * [So, distinct PixelBuffer MLFeatureValue objects with distinct CVPixelBufferRef values which encapsulate the same array of pixels will compare *not* equal.]
+ * For all other (matching) MLFeatureValue types, the BOOL value returned is the result of comparing "self" with "value" via
+ * isEqualToNumber:, isEqualToString:, isEqualtoDictionary:, isEqualToMultiArray:, isEqualToArray: as chosen by the MLFeatureValue types.
+ */
 - (BOOL)isEqualToFeatureValue:(MLFeatureValue *)value;
 
 @end
diff -ruN /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreML.framework/Headers/MLModel+MLModelCompilation.h /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreML.framework/Headers/MLModel+MLModelCompilation.h
--- /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreML.framework/Headers/MLModel+MLModelCompilation.h	2022-02-23 10:58:11.000000000 -0500
+++ /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreML.framework/Headers/MLModel+MLModelCompilation.h	2022-05-31 15:04:16.000000000 -0400
@@ -24,9 +24,9 @@
  *
  * @returns a URL to the compiled .mlmodelc directory if successful
  * The model is compiled to a temporary location on disk
- * You must move the compiled model to a permenant location if you wish to keep it
+ * You must move the compiled model to a permanent location if you wish to keep it
  *
- * @discussion the returned model can be loaded using:
+ * @discussion The returned model can be loaded using:
  * @code
  * [MLModel modelWithContentsOfURL:error:]
  * @endcode
@@ -34,7 +34,28 @@
  */
 + (nullable NSURL *)compileModelAtURL:(NSURL *)modelURL
                                 error:(NSError **)error
-                                API_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0)) __WATCHOS_UNAVAILABLE;
+                                API_UNAVAILABLE(watchos)
+                                API_DEPRECATED("Use the asynchronous interface compileModelAtURL:completionHandler:error: instead.",
+                                macos(10.13, API_TO_BE_DEPRECATED), ios(11.0, API_TO_BE_DEPRECATED), tvos(11.0, API_TO_BE_DEPRECATED));
+
+/*!
+ * Compile a .mlmodel or .mlpackage for this device. Perform the compilation asynchronously.
+ *
+ * @param modelURL URL file path to .mlmodel file you wish to compile
+ * @param handler When the model compilation completes successfully  the completion handler is invoked with a valid URL to the compiled .mlmodelc directory.
+ * On failure, signified by nil  compiledModelURL, the NSError object is populated.
+ *
+ * @discussion The model is compiled to a temporary location in the file system. You must move the compiled model to a permanent location if you wish to keep it. Then the model can be loaded using the returned URL:
+ * @code
+ * [MLModel modelWithContentsOfURL:error:]
+ * @endcode
+ *
+ */
+
++ (void)compileModelAtURL:(NSURL *)modelURL
+        completionHandler:(void (^)(NSURL * _Nullable compiledModelURL, NSError * _Nullable error))handler
+        API_AVAILABLE(macos(13.0), ios(16.0), tvos(16.0)) API_UNAVAILABLE(watchos)
+        NS_REFINED_FOR_SWIFT NS_SWIFT_ASYNC_NAME(compileModel(at:));
 
 @end
 
diff -ruN /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreML.framework/Headers/MLModel.h /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreML.framework/Headers/MLModel.h
--- /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreML.framework/Headers/MLModel.h	2022-02-23 10:58:12.000000000 -0500
+++ /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreML.framework/Headers/MLModel.h	2022-05-31 15:04:17.000000000 -0400
@@ -11,6 +11,7 @@
 #import <CoreML/MLBatchProvider.h>
 #import <CoreML/MLPredictionOptions.h>
 #import <CoreML/MLModelConfiguration.h>
+#import <CoreML/MLModelAsset.h>
 #import <CoreML/MLExport.h>
 
 NS_ASSUME_NONNULL_BEGIN
@@ -76,6 +77,17 @@
 - (nullable id)parameterValueForKey:(MLParameterKey *)key
                               error:(NSError * _Nullable __autoreleasing * _Nullable)error API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0));
 
+/*!
+  Construct a model asynchronously from a compiled model asset.
+
+  @param asset Compiled model asset derived from in-memory or on-disk Core ML model
+  @param configuration Model configuration that hold options for loading a model
+  @param handler When the model load completes successfully or unsuccessfully, the completion handler is invoked with a valid MLModel instance or NSError object.
+*/
++ (void)loadModelAsset:(MLModelAsset *)asset
+         configuration:(MLModelConfiguration *)configuration
+     completionHandler:(void (^)(MLModel * _Nullable model, NSError * _Nullable error))handler API_AVAILABLE(macos(13.0), ios(16.0), tvos(16.0), watchos(9.0)) NS_REFINED_FOR_SWIFT NS_SWIFT_ASYNC_NAME(load(asset:configuration:));
+
 @end
 
 NS_ASSUME_NONNULL_END
diff -ruN /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreML.framework/Headers/MLModelAsset.h /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreML.framework/Headers/MLModelAsset.h
--- /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreML.framework/Headers/MLModelAsset.h	1969-12-31 19:00:00.000000000 -0500
+++ /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreML.framework/Headers/MLModelAsset.h	2022-05-31 15:04:17.000000000 -0400
@@ -0,0 +1,35 @@
+//
+//  MLModelAsset.h
+//  CoreML
+//
+//  Created by Anil Katti on 1/14/22.
+//  Copyright © 2022 Apple Inc. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+ML_EXPORT
+API_AVAILABLE(macos(13.0), ios(16.0), tvos(16.0), watchos(9.0))
+@interface MLModelAsset : NSObject
+
+/*!
+ * Construct an optimized model asset asynchronously from the contents of specification data.
+ *
+ * @param specificationData Contents of .mlmodel as a data blob.
+ * @param error When the model asset creation fails error is populated with the reason for failure.
+ *
+ */
++ (nullable instancetype)modelAssetWithSpecificationData:(NSData *)specificationData
+                                                   error:(NSError * _Nullable __autoreleasing *)error API_AVAILABLE(macos(13.0), ios(16.0), tvos(16.0)) API_UNAVAILABLE(watchos) NS_SWIFT_NAME(init(specification:));
+
+// cannot construct MLModelAsset without model specification data.
+- (instancetype)init NS_UNAVAILABLE;
+
+// cannot construct MLModelAsset without model specification data.
++ (instancetype)new NS_UNAVAILABLE;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff -ruN /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreML.framework/Headers/MLModelConfiguration.h /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreML.framework/Headers/MLModelConfiguration.h
--- /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreML.framework/Headers/MLModelConfiguration.h	2022-02-23 10:58:12.000000000 -0500
+++ /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreML.framework/Headers/MLModelConfiguration.h	2022-05-31 15:04:18.000000000 -0400
@@ -16,7 +16,8 @@
 typedef NS_ENUM(NSInteger, MLComputeUnits) {
     MLComputeUnitsCPUOnly = 0,
     MLComputeUnitsCPUAndGPU = 1,
-    MLComputeUnitsAll = 2
+    MLComputeUnitsAll = 2,
+    MLComputeUnitsCPUAndNeuralEngine API_AVAILABLE(macos(13.0), ios(16.0), watchos(9.0), tvos(16.0)) = 3
 } API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0));
 
 /*!
@@ -26,6 +27,17 @@
 ML_EXPORT
 @interface MLModelConfiguration : NSObject <NSCopying, NSSecureCoding>
 
+/// A human readable name of a MLModel instance for display purposes.
+///
+/// Use this property to set a name of a model instance so that runtime analysis tools (e.g. Instruments and os_log)
+/// can display that name in the user interface.
+///
+/// CoreML framework doesn't parse nor filter the text. It is the client's responsibility to use appropriate text,
+/// which may involve localization and privacy considerations.
+///
+/// When the property is nil, CoreML framework provides a default.
+@property (readwrite, copy, nullable) NSString *modelDisplayName API_AVAILABLE(macos(13.0), ios(16.0), watchos(9.0), tvos(16.0));
+
 @property (readwrite) MLComputeUnits computeUnits;
 
 @end
diff -ruN /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreML.framework/Headers/MLMultiArray.h /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreML.framework/Headers/MLMultiArray.h
--- /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreML.framework/Headers/MLMultiArray.h	2022-02-23 10:58:11.000000000 -0500
+++ /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreML.framework/Headers/MLMultiArray.h	2022-05-31 14:50:10.000000000 -0400
@@ -18,7 +18,7 @@
     MLMultiArrayDataTypeDouble  = 0x10000 | 64,
     MLMultiArrayDataTypeFloat64 API_AVAILABLE(macos(11.0), ios(14.0), watchos(7.0), tvos(14.0)) = 0x10000 | 64,
     MLMultiArrayDataTypeFloat32 = 0x10000 | 32,
-    MLMultiArrayDataTypeFloat16 API_AVAILABLE(macos(12.0)) API_UNAVAILABLE(ios, watchos, tvos) = 0x10000 | 16,
+    MLMultiArrayDataTypeFloat16 API_AVAILABLE(macos(12.0), ios(16.0), watchos(9.0), tvos(16.0)) = 0x10000 | 16,
     MLMultiArrayDataTypeFloat   API_AVAILABLE(macos(11.0), ios(14.0), watchos(7.0), tvos(14.0)) = 0x10000 | 32,
     MLMultiArrayDataTypeInt32   = 0x20000 | 32,
 } API_AVAILABLE(macos(10.13), ios(11.0), watchos(4.0), tvos(11.0));
@@ -32,7 +32,7 @@
 @interface MLMultiArray : NSObject <NSSecureCoding>
 
 /// Unsafe pointer to underlying buffer holding the data
-@property (readonly, nonatomic) void *dataPointer NS_RETURNS_INNER_POINTER;
+@property (readonly, nonatomic) void *dataPointer NS_RETURNS_INNER_POINTER API_DEPRECATED("Use getBytesWithHandler or getMutableBytesWithHandler instead. For Swift, use withUnsafeBytes or withUnsafeMutableBytes.", macos(10.13, API_TO_BE_DEPRECATED), ios(11.0, API_TO_BE_DEPRECATED), tvos(11.0, API_TO_BE_DEPRECATED), watchos(4.0, API_TO_BE_DEPRECATED));
 
 /// Type of element held
 @property (readonly, nonatomic) MLMultiArrayDataType dataType;
@@ -53,7 +53,7 @@
 /**
    Returns the backing pixel buffer if exists, otherwise nil.
  */
-@property (readonly, nullable, nonatomic) CVPixelBufferRef pixelBuffer API_AVAILABLE(macos(12.0)) API_UNAVAILABLE(ios, watchos, tvos);
+@property (readonly, nullable, nonatomic) CVPixelBufferRef pixelBuffer API_AVAILABLE(macos(12.0), ios(16.0), watchos(9.0), tvos(16.0));
 
 @end
 
@@ -98,7 +98,52 @@
  * @param shape The shape of the MLMultiArray. The last dimension of `shape` must match the pixel buffer's width. The product of the rest of the dimensions must match the height.
  */
 - (instancetype)initWithPixelBuffer:(CVPixelBufferRef)pixelBuffer
-                              shape:(NSArray<NSNumber *> *)shape API_AVAILABLE(macos(12.0)) API_UNAVAILABLE(ios, watchos, tvos);
+                              shape:(NSArray<NSNumber *> *)shape API_AVAILABLE(macos(12.0), ios(16.0), watchos(9.0), tvos(16.0));
+
+@end
+
+@interface MLMultiArray (ScopedBufferAccess)
+
+/*!
+ * Get the underlying buffer pointer to read.
+ *
+ * The buffer pointer is valid only within the block.
+ *
+ * \code
+ * MLMultiArray * A = [[MLMultiArray alloc] initWithShape:@[@3, @2] dataType:MLMultiArrayDataTypeInt32 error:NULL];
+ * A[@[@1, @2]] = @42;
+ * [A getBytesWithHandler:^(const void *bytes, NSInteger size) {
+ *     const int32_t *scalarBuffer = (const int32_t *)bytes;
+ *     const int strideY = A.strides[0].intValue;
+ *     // Print 42
+ *     NSLog(@"Scalar at (1, 2): %d", scalarBuffer[1 * strideY + 2]);
+ * }];
+ * \endcode
+ *
+ * @param handler The block to receive the buffer pointer and its size in bytes.
+ */
+- (void)getBytesWithHandler:(void (NS_NOESCAPE ^)(const void *bytes, NSInteger size))handler API_AVAILABLE(macos(12.3), ios(15.4), watchos(8.5), tvos(15.4)) NS_REFINED_FOR_SWIFT;
+
+/*!
+ * Get the underlying buffer pointer to mutate.
+ *
+ * The buffer pointer is valid only within the block.
+ *
+ * Use `strides` parameter passed in the block because the method may switch to a new backing buffer with different strides.
+ *
+ * \code
+ * MLMultiArray * A = [[MLMultiArray alloc] initWithShape:@[@3, @2] dataType:MLMultiArrayDataTypeInt32 error:NULL];
+ * [A getMutableBytesWithHandler:^(void *bytes, NSInteger __unused size, NSArray<NSNumber *> *strides) {
+ *     int32_t *scalarBuffer = (int32_t *)bytes;
+ *     const int strideY = strides[0].intValue;
+ *     scalarBuffer[1 * strideY + 2] = 42;  // Set 42 at A[1, 2]
+ * }];
+ * \endcode
+ *
+ * @param handler The block to receive the buffer pointer, size in bytes, and strides.
+ *
+ */
+- (void)getMutableBytesWithHandler:(void (NS_NOESCAPE ^)(void *mutableBytes, NSInteger size, NSArray<NSNumber *> *strides))handler API_AVAILABLE(macos(12.3), ios(15.4), watchos(8.5), tvos(15.4)) NS_REFINED_FOR_SWIFT;
 
 @end
 
diff -ruN /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreML.framework/Headers/MLPredictionOptions.h /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreML.framework/Headers/MLPredictionOptions.h
--- /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreML.framework/Headers/MLPredictionOptions.h	2022-02-23 10:58:12.000000000 -0500
+++ /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreML.framework/Headers/MLPredictionOptions.h	2022-05-31 15:04:18.000000000 -0400
@@ -86,7 +86,7 @@
  * underlying inference engine.
  *
  */
-@property (readwrite, copy, nonatomic) NSDictionary<NSString *, id> *outputBackings API_AVAILABLE(macos(11.0)) API_UNAVAILABLE(ios, watchos, tvos);
+@property (readwrite, copy, nonatomic) NSDictionary<NSString *, id> *outputBackings API_AVAILABLE(macos(11.0), ios(16.0), watchos(9.0), tvos(16.0));
 
 @end
 
Clone this wiki locally