Skip to content

Commit

Permalink
[CoreML] Add xcode 15 beta 7 support. (#18898)
Browse files Browse the repository at this point in the history
Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
  • Loading branch information
mandel-macaque and GitHub Actions Autoformatter committed Sep 5, 2023
1 parent 138884a commit d59ddc0
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 77 deletions.
39 changes: 39 additions & 0 deletions src/CoreML/MLModel.cs
Original file line number Diff line number Diff line change
@@ -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<IMLComputeDeviceProtocol> ();
return NSArray.ArrayFromHandle<IMLComputeDeviceProtocol> (ptr);
}
}
}
}
47 changes: 47 additions & 0 deletions src/coreml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public enum MLModelError : long {
ModelDecryptionKeyFetch = 8,
ModelDecryption = 9,
ModelCollection = 10,
PredictionCancelled = 11,
}

[MacCatalyst (13, 1)]
Expand Down Expand Up @@ -474,6 +475,22 @@ interface MLModel {
[Static]
[Export ("compileModelAtURL:completionHandler:")]
void CompileModel (NSUrl modelUrl, Action<NSUrl, NSError> 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<IMLFeatureProvider, NSError> 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<IMLFeatureProvider, NSError> 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)]
Expand Down Expand Up @@ -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; }
}

}
1 change: 1 addition & 0 deletions src/frameworks.sources
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ COREMIDI_SOURCES = \

COREML_SOURCES = \
CoreML/MLDictionaryFeatureProvider.cs \
CoreML/MLModel.cs \
CoreML/MLMultiArray.cs \
CoreML/MLMultiArrayConstraint.cs \

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

This file was deleted.

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

This file was deleted.

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

This file was deleted.

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

This file was deleted.

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

This file was deleted.

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

This file was deleted.

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

This file was deleted.

0 comments on commit d59ddc0

Please sign in to comment.