Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CoreML] Add support for xcode 14 beta 1, 2 & 3 #15527

Merged
merged 2 commits into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 51 additions & 3 deletions src/coreml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public enum MLComputeUnits : long {
CpuOnly = 0,
CpuAndGpu = 1,
All = 2,
CPUAndNeuralEngine = 3,
}

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]
Expand Down Expand Up @@ -418,12 +419,28 @@ interface MLModel {
[Export ("loadContentsOfURL:configuration:completionHandler:")]
void LoadContents (NSUrl url, MLModelConfiguration configuration, Action<MLModel, NSError> handler);

[Async (ResultTypeName="MLModelCompilationLoadResult")]
[Watch (9,0), TV (16,0), Mac (13,0), iOS (16,0), MacCatalyst (16,0)]
[Static]
[Export ("loadModelAsset:configuration:completionHandler:")]
void Load (MLModelAsset asset, MLModelConfiguration configuration, Action<MLModel, NSError> handler);

// Category MLModel (MLModelCompilation)

[Deprecated (PlatformName.MacOSX, 13, 0, message: "Use 'CompileModel (NSUrl, Action<NSUrl, NSError>)' overload or 'CompileModelAsync' instead.")]
[Deprecated (PlatformName.iOS, 16, 0, message: "Use 'CompileModel (NSUrl, Action<NSUrl, NSError>)' overload or 'CompileModelAsync' instead.")]
[Deprecated (PlatformName.TvOS, 16, 0, message: "Use 'CompileModel (NSUrl, Action<NSUrl, NSError>)' overload or 'CompileModelAsync' instead.")]
[Deprecated (PlatformName.MacCatalyst, 16, 0, message: "Use 'CompileModel (NSUrl, Action<NSUrl, NSError>)' overload or 'CompileModelAsync' instead.")]
[Static]
[Export ("compileModelAtURL:error:")]
[return: NullAllowed]
NSUrl CompileModel (NSUrl modelUrl, out NSError error);

[Async (ResultTypeName="MLModelCompilationResult")]
[TV (16,0), NoWatch, Mac (13,0), iOS (16,0), MacCatalyst (16,0)]
[Static]
[Export ("compileModelAtURL:completionHandler:")]
void CompileModel (NSUrl modelUrl, Action<NSUrl, NSError> handler);
}

[Watch (4,0), TV (11,0), Mac (10,13), iOS (11,0)]
Expand Down Expand Up @@ -507,6 +524,11 @@ interface MLModelMetadata {
[BaseType (typeof (NSObject))]
interface MLMultiArray : NSSecureCoding {

[Deprecated (PlatformName.MacOSX, 13, 0, message: "Use 'GetBytes (Action<IntPtr, nint>)' or 'GetMutableBytes' async methods instead.")]
[Deprecated (PlatformName.iOS, 16, 0, message: "Use 'GetBytes (Action<IntPtr, nint>)' or 'GetMutableBytes' async methods instead.")]
[Deprecated (PlatformName.TvOS, 16, 0, message: "Use 'GetBytes (Action<IntPtr, nint>)' or 'GetMutableBytes' async methods instead.")]
[Deprecated (PlatformName.WatchOS, 9, 0, message: "Use 'GetBytes (Action<IntPtr, nint>)' or 'GetMutableBytes' async methods instead.")]
[Deprecated (PlatformName.MacCatalyst, 16, 0, message: "Use 'GetBytes (Action<IntPtr, nint>)' or 'GetMutableBytes' async methods instead.")]
[Export ("dataPointer")]
IntPtr DataPointer { get; }

Expand All @@ -525,7 +547,7 @@ interface MLMultiArray : NSSecureCoding {
nint Count { get; }

[NullAllowed]
[NoWatch, NoTV, NoiOS, Mac (12,0)]
[Watch (9,0), TV (16,0), Mac (12,0), iOS (16,0), MacCatalyst (16,0)]
[Export ("pixelBuffer")]
CVPixelBuffer PixelBuffer { get; }

Expand All @@ -537,7 +559,7 @@ interface MLMultiArray : NSSecureCoding {
[Export ("initWithDataPointer:shape:dataType:strides:deallocator:error:")]
NativeHandle Constructor (IntPtr dataPointer, NSNumber [] shape, MLMultiArrayDataType dataType, NSNumber [] strides, [NullAllowed] Action<IntPtr> deallocator, out NSError error);

[NoWatch, NoTV, NoiOS, Mac (12,0)]
[Watch (9,0), TV (16,0), Mac (12,0), iOS (16,0), MacCatalyst (16,0)]
[Export ("initWithPixelBuffer:shape:")]
IntPtr Constructor (CVPixelBuffer pixelBuffer, NSNumber [] shape);

Expand Down Expand Up @@ -573,6 +595,16 @@ interface MLMultiArray : NSSecureCoding {
[Static]
[Export ("multiArrayByConcatenatingMultiArrays:alongAxis:dataType:")]
MLMultiArray Concat (MLMultiArray[] multiArrays, nint axis, MLMultiArrayDataType dataType);

[Async (ResultTypeName="MLMultiArrayDataPointer")]
[Watch (8,5), TV (15,4), Mac (12,3), iOS (15,4), MacCatalyst (15,4)]
[Export ("getBytesWithHandler:")]
void GetBytes (Action<IntPtr, nint> handler);

[Async (ResultTypeName="MLMultiArrayMutableDataPointer")]
[Watch (8,5), TV (15,4), Mac (12,3), iOS (15,4), MacCatalyst (15,4)]
[Export ("getMutableBytesWithHandler:")]
void GetMutableBytes (Action<IntPtr, nint, NSArray<NSNumber>> handler);
}

[Watch (4,0), TV (11,0), Mac (10,13), iOS (11,0)]
Expand Down Expand Up @@ -633,7 +665,7 @@ interface MLPredictionOptions {
bool UsesCpuOnly { get; set; }

// Leaving it intentionally as NSDictionary to make it easier to use the lowlevel apis.
[NoWatch, NoTV, NoiOS, Mac (12,0)]
[Watch (9,0), TV (16,0), Mac (12,0), iOS (16,0), MacCatalyst (16,0)]
[Export ("outputBackings", ArgumentSemantic.Copy)]
NSDictionary OutputBackings { get; set; }
}
Expand Down Expand Up @@ -808,6 +840,10 @@ interface MLModelConfiguration : NSCopying, NSSecureCoding {
[Export ("computeUnits", ArgumentSemantic.Assign)]
MLComputeUnits ComputeUnits { get; set; }

[Watch (9,0), TV (16,0), Mac (13,0), iOS (16,0), MacCatalyst (16,0)]
[NullAllowed, Export ("modelDisplayName")]
string ModelDisplayName { get; set; }

// From MLModelConfiguration (MLGPUConfigurationOptions)

[NoWatch, TV (13,0), Mac (10,15), iOS (13,0)]
Expand Down Expand Up @@ -1097,4 +1133,16 @@ interface MLModelCollectionEntry {
[Export ("isEqualToModelCollectionEntry:")]
bool IsEqual (MLModelCollectionEntry entry);
}

[Watch (9,0), TV (16,0), Mac (13,0), iOS (16,0), MacCatalyst (16,0)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Watch (9,0) ? The type seems to be useless, the only method seems to be "NoWatch"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be needed for loadModelAsset:configuration:completionHandler: which is present on watchOS. The model asset can be loaded form a file. Maybe there is an API we are missing about that.

[BaseType (typeof (NSObject))]
[DisableDefaultCtor]
interface MLModelAsset
{
[TV (16,0), NoWatch, Mac (13,0), iOS (16,0)]
[Static]
[Export ("modelAssetWithSpecificationData:error:")]
[return: NullAllowed]
MLModelAsset Create (NSData specificationData, [NullAllowed] out NSError error);
}
}
15 changes: 0 additions & 15 deletions tests/xtro-sharpie/api-annotations-dotnet/MacCatalyst-CoreML.todo

This file was deleted.

14 changes: 0 additions & 14 deletions tests/xtro-sharpie/api-annotations-dotnet/iOS-CoreML.todo

This file was deleted.

10 changes: 0 additions & 10 deletions tests/xtro-sharpie/api-annotations-dotnet/macOS-CoreML.todo

This file was deleted.

14 changes: 0 additions & 14 deletions tests/xtro-sharpie/api-annotations-dotnet/tvOS-CoreML.todo

This file was deleted.

14 changes: 0 additions & 14 deletions tests/xtro-sharpie/iOS-CoreML.todo

This file was deleted.

10 changes: 0 additions & 10 deletions tests/xtro-sharpie/macOS-CoreML.todo

This file was deleted.

14 changes: 0 additions & 14 deletions tests/xtro-sharpie/tvOS-CoreML.todo

This file was deleted.

12 changes: 0 additions & 12 deletions tests/xtro-sharpie/watchOS-CoreML.todo

This file was deleted.