From d59ddc070465539bc9b30e5632d62ac7ceefcb04 Mon Sep 17 00:00:00 2001 From: Manuel de la Pena Date: Tue, 5 Sep 2023 10:41:07 -0400 Subject: [PATCH] [CoreML] Add xcode 15 beta 7 support. (#18898) Co-authored-by: GitHub Actions Autoformatter --- src/CoreML/MLModel.cs | 39 +++++++++++++++ src/coreml.cs | 47 +++++++++++++++++++ src/frameworks.sources | 1 + .../api-annotations-dotnet/iOS-CoreML.todo | 11 ----- .../api-annotations-dotnet/macOS-CoreML.todo | 11 ----- .../api-annotations-dotnet/tvOS-CoreML.todo | 11 ----- tests/xtro-sharpie/iOS-CoreML.todo | 11 ----- tests/xtro-sharpie/macOS-CoreML.todo | 11 ----- tests/xtro-sharpie/tvOS-CoreML.todo | 11 ----- tests/xtro-sharpie/watchOS-CoreML.todo | 11 ----- 10 files changed, 87 insertions(+), 77 deletions(-) create mode 100644 src/CoreML/MLModel.cs delete mode 100644 tests/xtro-sharpie/api-annotations-dotnet/iOS-CoreML.todo delete mode 100644 tests/xtro-sharpie/api-annotations-dotnet/macOS-CoreML.todo delete mode 100644 tests/xtro-sharpie/api-annotations-dotnet/tvOS-CoreML.todo delete mode 100644 tests/xtro-sharpie/iOS-CoreML.todo delete mode 100644 tests/xtro-sharpie/macOS-CoreML.todo delete mode 100644 tests/xtro-sharpie/tvOS-CoreML.todo delete mode 100644 tests/xtro-sharpie/watchOS-CoreML.todo diff --git a/src/CoreML/MLModel.cs b/src/CoreML/MLModel.cs new file mode 100644 index 000000000000..b3cf5522dfaf --- /dev/null +++ b/src/CoreML/MLModel.cs @@ -0,0 +1,39 @@ +using System; +using System.Runtime.InteropServices; +using Foundation; +using ObjCRuntime; + +#nullable enable + +namespace CoreML { + + public partial class MLModel { +#if NET + [SupportedOSPlatform ("tvos17.0")] + [SupportedOSPlatform ("macos14.0")] + [SupportedOSPlatform ("ios17.0")] + [SupportedOSPlatform ("maccatalyst17.0")] +#else + [Watch (10, 0), TV (17, 0), Mac (14, 0), iOS (17, 0), MacCatalyst (17, 0)] +#endif + [DllImport (Constants.CoreMLLibrary)] + static extern /* MLComputeDeviceProtocol[] */ IntPtr MLAllComputeDevices (); + +#if NET + [SupportedOSPlatform ("tvos17.0")] + [SupportedOSPlatform ("macos14.0")] + [SupportedOSPlatform ("ios17.0")] + [SupportedOSPlatform ("maccatalyst17.0")] +#else + [Watch (10, 0), TV (17, 0), Mac (14, 0), iOS (17, 0), MacCatalyst (17, 0)] +#endif + public static IMLComputeDeviceProtocol [] AllComputeDevices { + get { + var ptr = MLAllComputeDevices (); + if (ptr == IntPtr.Zero) + return Array.Empty (); + return NSArray.ArrayFromHandle (ptr); + } + } + } +} diff --git a/src/coreml.cs b/src/coreml.cs index 893b1c2f0f54..c6c497e4483e 100644 --- a/src/coreml.cs +++ b/src/coreml.cs @@ -61,6 +61,7 @@ public enum MLModelError : long { ModelDecryptionKeyFetch = 8, ModelDecryption = 9, ModelCollection = 10, + PredictionCancelled = 11, } [MacCatalyst (13, 1)] @@ -474,6 +475,22 @@ interface MLModel { [Static] [Export ("compileModelAtURL:completionHandler:")] void CompileModel (NSUrl modelUrl, Action handler); + + [Async] + [Watch (10, 0), TV (17, 0), Mac (14, 0), iOS (17, 0), MacCatalyst (17, 0)] + [Export ("predictionFromFeatures:completionHandler:")] + void GetPrediction (IMLFeatureProvider input, Action completionHandler); + + [Async] + [Watch (10, 0), TV (17, 0), Mac (14, 0), iOS (17, 0), MacCatalyst (17, 0)] + [Export ("predictionFromFeatures:options:completionHandler:")] + void GetPrediction (IMLFeatureProvider input, MLPredictionOptions options, Action completionHandler); + + // from the category MLComputeDevice (MLModel) + [Watch (10, 0), TV (17, 0), Mac (14, 0), iOS (17, 0), MacCatalyst (17, 0)] + [Static] + [Export ("availableComputeDevices", ArgumentSemantic.Copy)] + IMLComputeDeviceProtocol [] AvailableComputeDevices { get; } } [MacCatalyst (13, 1)] @@ -1217,4 +1234,34 @@ interface MLModelAsset { [return: NullAllowed] MLModelAsset Create (NSData specificationData, [NullAllowed] out NSError error); } + + interface IMLComputeDeviceProtocol { } + + [Watch (10, 0), TV (17, 0), Mac (14, 0), iOS (17, 0), MacCatalyst (17, 0)] + [Protocol] + interface MLComputeDeviceProtocol { + } + + [Watch (10, 0), TV (17, 0), Mac (14, 0), iOS (17, 0), MacCatalyst (17, 0)] + [BaseType (typeof (NSObject))] + [DisableDefaultCtor] + interface MLNeuralEngineComputeDevice : MLComputeDeviceProtocol { + [Export ("totalCoreCount")] + nint TotalCoreCount { get; } + } + + [Watch (10, 0), TV (17, 0), Mac (14, 0), iOS (17, 0), MacCatalyst (17, 0)] + [BaseType (typeof (NSObject), Name = "MLCPUComputeDevice")] + [DisableDefaultCtor] + interface MLCpuComputeDevice : MLComputeDeviceProtocol { + } + + [Watch (10, 0), TV (17, 0), Mac (14, 0), iOS (17, 0), MacCatalyst (17, 0)] + [BaseType (typeof (NSObject), Name = "MLGPUComputeDevice")] + [DisableDefaultCtor] + interface MLGpuComputeDevice : MLComputeDeviceProtocol { + [Export ("metalDevice", ArgumentSemantic.Strong)] + IMTLDevice MetalDevice { get; } + } + } diff --git a/src/frameworks.sources b/src/frameworks.sources index 62b6f3400f87..dc62119373fc 100644 --- a/src/frameworks.sources +++ b/src/frameworks.sources @@ -621,6 +621,7 @@ COREMIDI_SOURCES = \ COREML_SOURCES = \ CoreML/MLDictionaryFeatureProvider.cs \ + CoreML/MLModel.cs \ CoreML/MLMultiArray.cs \ CoreML/MLMultiArrayConstraint.cs \ diff --git a/tests/xtro-sharpie/api-annotations-dotnet/iOS-CoreML.todo b/tests/xtro-sharpie/api-annotations-dotnet/iOS-CoreML.todo deleted file mode 100644 index 22309be51bdb..000000000000 --- a/tests/xtro-sharpie/api-annotations-dotnet/iOS-CoreML.todo +++ /dev/null @@ -1,11 +0,0 @@ -!missing-enum-value! MLModelError native value MLModelErrorPredictionCancelled = 11 not bound -!missing-pinvoke! MLAllComputeDevices is not bound -!missing-protocol! MLComputeDeviceProtocol not bound -!missing-selector! +MLModel::availableComputeDevices not bound -!missing-selector! MLGPUComputeDevice::metalDevice not bound -!missing-selector! MLModel::predictionFromFeatures:completionHandler: not bound -!missing-selector! MLModel::predictionFromFeatures:options:completionHandler: not bound -!missing-selector! MLNeuralEngineComputeDevice::totalCoreCount not bound -!missing-type! MLCPUComputeDevice not bound -!missing-type! MLGPUComputeDevice not bound -!missing-type! MLNeuralEngineComputeDevice not bound diff --git a/tests/xtro-sharpie/api-annotations-dotnet/macOS-CoreML.todo b/tests/xtro-sharpie/api-annotations-dotnet/macOS-CoreML.todo deleted file mode 100644 index 22309be51bdb..000000000000 --- a/tests/xtro-sharpie/api-annotations-dotnet/macOS-CoreML.todo +++ /dev/null @@ -1,11 +0,0 @@ -!missing-enum-value! MLModelError native value MLModelErrorPredictionCancelled = 11 not bound -!missing-pinvoke! MLAllComputeDevices is not bound -!missing-protocol! MLComputeDeviceProtocol not bound -!missing-selector! +MLModel::availableComputeDevices not bound -!missing-selector! MLGPUComputeDevice::metalDevice not bound -!missing-selector! MLModel::predictionFromFeatures:completionHandler: not bound -!missing-selector! MLModel::predictionFromFeatures:options:completionHandler: not bound -!missing-selector! MLNeuralEngineComputeDevice::totalCoreCount not bound -!missing-type! MLCPUComputeDevice not bound -!missing-type! MLGPUComputeDevice not bound -!missing-type! MLNeuralEngineComputeDevice not bound diff --git a/tests/xtro-sharpie/api-annotations-dotnet/tvOS-CoreML.todo b/tests/xtro-sharpie/api-annotations-dotnet/tvOS-CoreML.todo deleted file mode 100644 index 22309be51bdb..000000000000 --- a/tests/xtro-sharpie/api-annotations-dotnet/tvOS-CoreML.todo +++ /dev/null @@ -1,11 +0,0 @@ -!missing-enum-value! MLModelError native value MLModelErrorPredictionCancelled = 11 not bound -!missing-pinvoke! MLAllComputeDevices is not bound -!missing-protocol! MLComputeDeviceProtocol not bound -!missing-selector! +MLModel::availableComputeDevices not bound -!missing-selector! MLGPUComputeDevice::metalDevice not bound -!missing-selector! MLModel::predictionFromFeatures:completionHandler: not bound -!missing-selector! MLModel::predictionFromFeatures:options:completionHandler: not bound -!missing-selector! MLNeuralEngineComputeDevice::totalCoreCount not bound -!missing-type! MLCPUComputeDevice not bound -!missing-type! MLGPUComputeDevice not bound -!missing-type! MLNeuralEngineComputeDevice not bound diff --git a/tests/xtro-sharpie/iOS-CoreML.todo b/tests/xtro-sharpie/iOS-CoreML.todo deleted file mode 100644 index 22309be51bdb..000000000000 --- a/tests/xtro-sharpie/iOS-CoreML.todo +++ /dev/null @@ -1,11 +0,0 @@ -!missing-enum-value! MLModelError native value MLModelErrorPredictionCancelled = 11 not bound -!missing-pinvoke! MLAllComputeDevices is not bound -!missing-protocol! MLComputeDeviceProtocol not bound -!missing-selector! +MLModel::availableComputeDevices not bound -!missing-selector! MLGPUComputeDevice::metalDevice not bound -!missing-selector! MLModel::predictionFromFeatures:completionHandler: not bound -!missing-selector! MLModel::predictionFromFeatures:options:completionHandler: not bound -!missing-selector! MLNeuralEngineComputeDevice::totalCoreCount not bound -!missing-type! MLCPUComputeDevice not bound -!missing-type! MLGPUComputeDevice not bound -!missing-type! MLNeuralEngineComputeDevice not bound diff --git a/tests/xtro-sharpie/macOS-CoreML.todo b/tests/xtro-sharpie/macOS-CoreML.todo deleted file mode 100644 index 22309be51bdb..000000000000 --- a/tests/xtro-sharpie/macOS-CoreML.todo +++ /dev/null @@ -1,11 +0,0 @@ -!missing-enum-value! MLModelError native value MLModelErrorPredictionCancelled = 11 not bound -!missing-pinvoke! MLAllComputeDevices is not bound -!missing-protocol! MLComputeDeviceProtocol not bound -!missing-selector! +MLModel::availableComputeDevices not bound -!missing-selector! MLGPUComputeDevice::metalDevice not bound -!missing-selector! MLModel::predictionFromFeatures:completionHandler: not bound -!missing-selector! MLModel::predictionFromFeatures:options:completionHandler: not bound -!missing-selector! MLNeuralEngineComputeDevice::totalCoreCount not bound -!missing-type! MLCPUComputeDevice not bound -!missing-type! MLGPUComputeDevice not bound -!missing-type! MLNeuralEngineComputeDevice not bound diff --git a/tests/xtro-sharpie/tvOS-CoreML.todo b/tests/xtro-sharpie/tvOS-CoreML.todo deleted file mode 100644 index 22309be51bdb..000000000000 --- a/tests/xtro-sharpie/tvOS-CoreML.todo +++ /dev/null @@ -1,11 +0,0 @@ -!missing-enum-value! MLModelError native value MLModelErrorPredictionCancelled = 11 not bound -!missing-pinvoke! MLAllComputeDevices is not bound -!missing-protocol! MLComputeDeviceProtocol not bound -!missing-selector! +MLModel::availableComputeDevices not bound -!missing-selector! MLGPUComputeDevice::metalDevice not bound -!missing-selector! MLModel::predictionFromFeatures:completionHandler: not bound -!missing-selector! MLModel::predictionFromFeatures:options:completionHandler: not bound -!missing-selector! MLNeuralEngineComputeDevice::totalCoreCount not bound -!missing-type! MLCPUComputeDevice not bound -!missing-type! MLGPUComputeDevice not bound -!missing-type! MLNeuralEngineComputeDevice not bound diff --git a/tests/xtro-sharpie/watchOS-CoreML.todo b/tests/xtro-sharpie/watchOS-CoreML.todo deleted file mode 100644 index 22309be51bdb..000000000000 --- a/tests/xtro-sharpie/watchOS-CoreML.todo +++ /dev/null @@ -1,11 +0,0 @@ -!missing-enum-value! MLModelError native value MLModelErrorPredictionCancelled = 11 not bound -!missing-pinvoke! MLAllComputeDevices is not bound -!missing-protocol! MLComputeDeviceProtocol not bound -!missing-selector! +MLModel::availableComputeDevices not bound -!missing-selector! MLGPUComputeDevice::metalDevice not bound -!missing-selector! MLModel::predictionFromFeatures:completionHandler: not bound -!missing-selector! MLModel::predictionFromFeatures:options:completionHandler: not bound -!missing-selector! MLNeuralEngineComputeDevice::totalCoreCount not bound -!missing-type! MLCPUComputeDevice not bound -!missing-type! MLGPUComputeDevice not bound -!missing-type! MLNeuralEngineComputeDevice not bound