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] Implement Xcode 16.0 beta 1-6 changes. #21145

Merged
merged 4 commits into from
Sep 12, 2024
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
117 changes: 113 additions & 4 deletions src/coreml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public enum MLFeatureType : long {
[Watch (5, 0), TV (12, 0), iOS (12, 0)]
[MacCatalyst (13, 1)]
Sequence = 7,
[Watch (11, 0), TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)]
State = 8,
}

/// <summary>Enumerates errors that may occur in the use of Core ML.</summary>
Expand Down Expand Up @@ -74,10 +76,8 @@ public enum MLMultiArrayDataType : long {
// added in xcode12 but it's the same a `Double` and can be used in earlier versions
Float64 = 0x10000 | 64,
Float32 = 0x10000 | 32,
#if MONOMAC // macOS 12 Only
[Mac (12,0)][NoiOS][NoMacCatalyst][NoWatch][NoTV]
[Mac (12, 0), iOS (16, 0), MacCatalyst (16, 0), Watch (9, 0), TV (16, 0)]
Float16 = 0x10000 | 16,
#endif
// added in xcode12 but it's the same a `Float32` and can be used in earlier versions
Float = 0x10000 | 32,
Int32 = 0x20000 | 32,
Expand Down Expand Up @@ -185,6 +185,10 @@ interface MLFeatureDescription : NSCopying, NSSecureCoding {
[MacCatalyst (13, 1)]
[NullAllowed, Export ("sequenceConstraint")]
MLSequenceConstraint SequenceConstraint { get; }

[TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0), Watch (11, 0)]
[NullAllowed, Export ("stateConstraint")]
MLStateConstraint StateConstraint { get; }
}

interface IMLFeatureProvider { }
Expand Down Expand Up @@ -563,6 +567,10 @@ interface MLModelDescription : NSSecureCoding {
[MacCatalyst (13, 1)]
[Export ("parameterDescriptionsByKey")]
NSDictionary<MLParameterKey, MLParameterDescription> ParameterDescriptionsByKey { get; }

[Watch (11, 0), TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)]
[Export ("stateDescriptionsByName")]
NSDictionary<NSString, MLFeatureDescription> StateDescriptionsByName { get; }
}

[MacCatalyst (13, 1)]
Expand Down Expand Up @@ -635,6 +643,10 @@ interface MLMultiArray : NSSecureCoding {
[Export ("initWithShape:dataType:error:")]
NativeHandle Constructor (NSNumber [] shape, MLMultiArrayDataType dataType, out NSError error);

[iOS (18, 0), TV (18, 0), MacCatalyst (18, 0), Mac (15, 0), Watch (11, 0)]
[Export ("initWithShape:dataType:strides:")]
NativeHandle Constructor (NSNumber [] shape, MLMultiArrayDataType dataType, NSNumber [] strides);

[Export ("initWithDataPointer:shape:dataType:strides:deallocator:error:")]
NativeHandle Constructor (IntPtr dataPointer, NSNumber [] shape, MLMultiArrayDataType dataType, NSNumber [] strides, [NullAllowed] Action<IntPtr> deallocator, out NSError error);

Expand Down Expand Up @@ -685,6 +697,11 @@ interface MLMultiArray : NSSecureCoding {
[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);

// From MLMultiArray (Transferring) category
[iOS (18, 0), TV (18, 0), MacCatalyst (18, 0), Mac (15, 0), Watch (11, 0)]
[Export ("transferToMultiArray:")]
void TransferToMultiArray (MLMultiArray destinationMultiArray);
}

/// <summary>Contains a value that constrains the type of dictionary keys.</summary>
Expand Down Expand Up @@ -971,6 +988,11 @@ interface MLModelConfiguration : NSCopying, NSSecureCoding {
[MacCatalyst (13, 1)]
[NullAllowed, Export ("parameters", ArgumentSemantic.Assign)]
NSDictionary<MLParameterKey, NSObject> Parameters { get; set; }

// From MLModelConfiguration (MultiFunctions)
[Watch (11, 0), TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)]
[Export ("functionName", ArgumentSemantic.Copy), NullAllowed]
string FunctionName { get; set; }
}

[Watch (6, 0), TV (13, 0), iOS (13, 0)]
Expand Down Expand Up @@ -1210,6 +1232,7 @@ interface MLWritable {
bool Write (NSUrl url, [NullAllowed] out NSError error);
}

#if !XAMCORE_5_0
[Deprecated (PlatformName.MacOSX, 13, 3, message: "Use Background Assets or 'NSUrlSession' instead.")]
[Deprecated (PlatformName.MacCatalyst, 16, 4, message: "Use Background Assets or 'NSUrlSession' instead.")]
[Deprecated (PlatformName.iOS, 16, 4, message: "Use Background Assets or 'NSUrlSession' instead.")]
Expand Down Expand Up @@ -1244,7 +1267,9 @@ interface MLModelCollection {
[Field ("MLModelCollectionDidChangeNotification")]
NSString DidChangeNotification { get; }
}
#endif // !XAMCORE_5_0

#if !XAMCORE_5_0
[Deprecated (PlatformName.MacOSX, 13, 3, message: "Use Background Assets or 'NSUrlSession' instead.")]
[Deprecated (PlatformName.MacCatalyst, 16, 4, message: "Use Background Assets or 'NSUrlSession' instead.")]
[Deprecated (PlatformName.iOS, 16, 4, message: "Use Background Assets or 'NSUrlSession' instead.")]
Expand All @@ -1265,6 +1290,10 @@ interface MLModelCollectionEntry {
[Export ("isEqualToModelCollectionEntry:")]
bool IsEqual (MLModelCollectionEntry entry);
}
#endif // !XAMCORE_5_0

delegate void MLModelAssetGetModelDescriptionCompletionHandler ([NullAllowed] MLModelDescription modelDescription, [NullAllowed] NSError error);
delegate void MLModelAssetGetFunctionNamesCompletionHandler ([NullAllowed] string [] functionNames, [NullAllowed] NSError error);

[Watch (9, 0), TV (16, 0), Mac (13, 0), iOS (16, 0), MacCatalyst (16, 0)]
[BaseType (typeof (NSObject))]
Expand All @@ -1276,6 +1305,31 @@ interface MLModelAsset {
[Export ("modelAssetWithSpecificationData:error:")]
[return: NullAllowed]
MLModelAsset Create (NSData specificationData, [NullAllowed] out NSError error);

[Watch (11, 0), TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)]
[Static]
[Export ("modelAssetWithURL:error:")]
[return: NullAllowed]
MLModelAsset Create (NSUrl compiledModelUrl, [NullAllowed] out NSError error);

[Watch (11, 0), TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)]
[Export ("modelDescriptionWithCompletionHandler:")]
void GetModelDescription (MLModelAssetGetModelDescriptionCompletionHandler handler);

[Watch (11, 0), TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)]
[Export ("modelDescriptionOfFunctionNamed:completionHandler:")]
void GetModelDescription (string functionName, MLModelAssetGetModelDescriptionCompletionHandler handler);

[Watch (11, 0), TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)]
[Export ("functionNamesWithCompletionHandler:")]
void GetFunctionNames (MLModelAssetGetFunctionNamesCompletionHandler handler);

[NoWatch, TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)]
[Static]
[Export ("modelAssetWithSpecificationData:blobMapping:error:")]
[return: NullAllowed]
MLModelAsset Create (NSData specificationData, NSDictionary<NSUrl, NSData> blobMapping, [NullAllowed] out NSError error);

}

interface IMLComputeDeviceProtocol { }
Expand Down Expand Up @@ -1336,6 +1390,58 @@ interface MLComputePlan {
MLModelStructure ModelStructure { get; }
}

delegate void MLStateGetMultiArrayForStateHandler (MLMultiArray buffer);

[Watch (11, 0), TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)]
[BaseType (typeof (NSObject))]
[DisableDefaultCtor]
interface MLState {
[Export ("getMultiArrayForStateNamed:handler:")]
void GetMultiArrayForState (string stateName, MLStateGetMultiArrayForStateHandler handler);
}

delegate void MLStateGetPredictionCompletionHandler ([NullAllowed] IMLFeatureProvider output, NSError error);

[Watch (11, 0), TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)]
[Category]
[BaseType (typeof (MLModel))]
interface MLModel_MLState {
[Export ("newState")]
[return: Release]
MLState CreateNewState ();

[Export ("predictionFromFeatures:usingState:error:")]
[return: NullAllowed]
IMLFeatureProvider GetPrediction (IMLFeatureProvider inputFeatures, MLState state, out NSError error);

[Export ("predictionFromFeatures:usingState:options:error:")]
[return: NullAllowed]
IMLFeatureProvider GetPrediction (IMLFeatureProvider inputFeatures, MLState state, MLPredictionOptions options, out NSError error);

[Export ("predictionFromFeatures:usingState:options:completionHandler:")]
[return: NullAllowed]
IMLFeatureProvider GetPrediction (IMLFeatureProvider inputFeatures, MLState state, MLPredictionOptions options, MLStateGetPredictionCompletionHandler completionHandler);
}

[Watch (11, 0), TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)]
[BaseType (typeof (NSObject))]
[DisableDefaultCtor]
interface MLStateConstraint : NSSecureCoding {
// BindAs: No documentation about which types of NSNumbers we get back
[Export ("bufferShape")]
NSNumber [] BufferShape { get; }

[Export ("dataType")]
MLMultiArrayDataType DataType { get; }
}

[Watch (11, 0), TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)]
[Native]
public enum MLSpecializationStrategy : long {
Default = 0,
FastPrediction = 1,
}

[Watch (10, 4), TV (17, 4), Mac (14, 4), iOS (17, 4), MacCatalyst (17, 4)]
[BaseType (typeof (NSObject))]
[DisableDefaultCtor]
Expand Down Expand Up @@ -1525,6 +1631,9 @@ interface MLOptimizationHints : NSCopying, NSSecureCoding {

[Export ("reshapeFrequency", ArgumentSemantic.Assign)]
MLReshapeFrequencyHint ReshapeFrequency { get; set; }
}

[Watch (11, 0), TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)]
[Export ("specializationStrategy", ArgumentSemantic.Assign)]
MLSpecializationStrategy SpecializationStrategy { get; set; }
}
}
30 changes: 30 additions & 0 deletions tests/cecil-tests/Documentation.KnownFailures.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7626,6 +7626,7 @@ F:CoreML.MLFeatureType.Int64
F:CoreML.MLFeatureType.Invalid
F:CoreML.MLFeatureType.MultiArray
F:CoreML.MLFeatureType.Sequence
F:CoreML.MLFeatureType.State
F:CoreML.MLFeatureType.String
F:CoreML.MLImageSizeConstraintType.Enumerated
F:CoreML.MLImageSizeConstraintType.Range
Expand All @@ -7652,6 +7653,8 @@ F:CoreML.MLMultiArrayShapeConstraintType.Range
F:CoreML.MLMultiArrayShapeConstraintType.Unspecified
F:CoreML.MLReshapeFrequencyHint.Frequent
F:CoreML.MLReshapeFrequencyHint.Infrequent
F:CoreML.MLSpecializationStrategy.Default
F:CoreML.MLSpecializationStrategy.FastPrediction
F:CoreML.MLTaskState.Cancelling
F:CoreML.MLTaskState.Completed
F:CoreML.MLTaskState.Failed
Expand Down Expand Up @@ -32806,6 +32809,10 @@ M:CoreML.MLImageSize.EncodeTo(Foundation.NSCoder)
M:CoreML.MLImageSizeConstraint.EncodeTo(Foundation.NSCoder)
M:CoreML.MLKey.Copy(Foundation.NSZone)
M:CoreML.MLKey.EncodeTo(Foundation.NSCoder)
M:CoreML.MLModel_MLState.CreateNewState(CoreML.MLModel)
M:CoreML.MLModel_MLState.GetPrediction(CoreML.MLModel,CoreML.IMLFeatureProvider,CoreML.MLState,CoreML.MLPredictionOptions,CoreML.MLStateGetPredictionCompletionHandler)
M:CoreML.MLModel_MLState.GetPrediction(CoreML.MLModel,CoreML.IMLFeatureProvider,CoreML.MLState,CoreML.MLPredictionOptions,Foundation.NSError@)
M:CoreML.MLModel_MLState.GetPrediction(CoreML.MLModel,CoreML.IMLFeatureProvider,CoreML.MLState,Foundation.NSError@)
M:CoreML.MLModel.CompileModel(Foundation.NSUrl,Foundation.NSError@)
M:CoreML.MLModel.CompileModel(Foundation.NSUrl,System.Action{Foundation.NSUrl,Foundation.NSError})
M:CoreML.MLModel.CompileModelAsync(Foundation.NSUrl)
Expand All @@ -32824,7 +32831,12 @@ M:CoreML.MLModel.Load(CoreML.MLModelAsset,CoreML.MLModelConfiguration,System.Act
M:CoreML.MLModel.LoadAsync(CoreML.MLModelAsset,CoreML.MLModelConfiguration)
M:CoreML.MLModel.LoadContents(Foundation.NSUrl,CoreML.MLModelConfiguration,System.Action{CoreML.MLModel,Foundation.NSError})
M:CoreML.MLModel.LoadContentsAsync(Foundation.NSUrl,CoreML.MLModelConfiguration)
M:CoreML.MLModelAsset.Create(Foundation.NSData,Foundation.NSDictionary{Foundation.NSUrl,Foundation.NSData},Foundation.NSError@)
M:CoreML.MLModelAsset.Create(Foundation.NSData,Foundation.NSError@)
M:CoreML.MLModelAsset.Create(Foundation.NSUrl,Foundation.NSError@)
M:CoreML.MLModelAsset.GetFunctionNames(CoreML.MLModelAssetGetFunctionNamesCompletionHandler)
M:CoreML.MLModelAsset.GetModelDescription(CoreML.MLModelAssetGetModelDescriptionCompletionHandler)
M:CoreML.MLModelAsset.GetModelDescription(System.String,CoreML.MLModelAssetGetModelDescriptionCompletionHandler)
M:CoreML.MLModelCollection.BeginAccessingModelCollection(System.String,System.Action{CoreML.MLModelCollection,Foundation.NSError})
M:CoreML.MLModelCollection.BeginAccessingModelCollectionAsync(System.String,Foundation.NSProgress@)
M:CoreML.MLModelCollection.BeginAccessingModelCollectionAsync(System.String)
Expand All @@ -32843,6 +32855,7 @@ M:CoreML.MLModelStructure.Load(CoreML.MLModelAsset,System.Action{CoreML.MLModelS
M:CoreML.MLModelStructure.Load(Foundation.NSUrl,System.Action{CoreML.MLModelStructure,Foundation.NSError})
M:CoreML.MLMultiArray.#ctor(CoreVideo.CVPixelBuffer,Foundation.NSNumber[])
M:CoreML.MLMultiArray.#ctor(Foundation.NSNumber[],CoreML.MLMultiArrayDataType,Foundation.NSError@)
M:CoreML.MLMultiArray.#ctor(Foundation.NSNumber[],CoreML.MLMultiArrayDataType,Foundation.NSNumber[])
M:CoreML.MLMultiArray.#ctor(System.IntPtr,Foundation.NSNumber[],CoreML.MLMultiArrayDataType,Foundation.NSNumber[],System.Action{System.IntPtr},Foundation.NSError@)
M:CoreML.MLMultiArray.#ctor(System.IntPtr,System.IntPtr[],CoreML.MLMultiArrayDataType,System.IntPtr[],System.Action{System.IntPtr},Foundation.NSError@)
M:CoreML.MLMultiArray.#ctor(System.IntPtr[],CoreML.MLMultiArrayDataType,Foundation.NSError@)
Expand All @@ -32858,6 +32871,7 @@ M:CoreML.MLMultiArray.GetObject(System.IntPtr[])
M:CoreML.MLMultiArray.SetObject(Foundation.NSNumber,Foundation.NSNumber[])
M:CoreML.MLMultiArray.SetObject(Foundation.NSNumber,System.IntPtr)
M:CoreML.MLMultiArray.SetObject(Foundation.NSNumber,System.IntPtr[])
M:CoreML.MLMultiArray.TransferToMultiArray(CoreML.MLMultiArray)
M:CoreML.MLMultiArrayConstraint.EncodeTo(Foundation.NSCoder)
M:CoreML.MLMultiArrayDataPointer.#ctor(System.IntPtr,System.IntPtr)
M:CoreML.MLMultiArrayMutableDataPointer.#ctor(System.IntPtr,System.IntPtr,Foundation.NSArray{Foundation.NSNumber})
Expand All @@ -32873,6 +32887,8 @@ M:CoreML.MLSequence.CreateEmpty(CoreML.MLFeatureType)
M:CoreML.MLSequence.EncodeTo(Foundation.NSCoder)
M:CoreML.MLSequenceConstraint.Copy(Foundation.NSZone)
M:CoreML.MLSequenceConstraint.EncodeTo(Foundation.NSCoder)
M:CoreML.MLState.GetMultiArrayForState(System.String,CoreML.MLStateGetMultiArrayForStateHandler)
M:CoreML.MLStateConstraint.EncodeTo(Foundation.NSCoder)
M:CoreML.MLTask.Cancel
M:CoreML.MLTask.Resume
M:CoreML.MLUpdateProgressHandlers.#ctor(CoreML.MLUpdateProgressEvent,System.Action{CoreML.MLUpdateContext},System.Action{CoreML.MLUpdateContext})
Expand Down Expand Up @@ -63704,6 +63720,7 @@ P:CoreML.MLFeatureDescription.MultiArrayConstraint
P:CoreML.MLFeatureDescription.Name
P:CoreML.MLFeatureDescription.Optional
P:CoreML.MLFeatureDescription.SequenceConstraint
P:CoreML.MLFeatureDescription.StateConstraint
P:CoreML.MLFeatureDescription.Type
P:CoreML.MLFeatureValue.DictionaryValue
P:CoreML.MLFeatureValue.DoubleValue
Expand Down Expand Up @@ -63746,6 +63763,7 @@ P:CoreML.MLModelCompilationLoadResult.Arg1
P:CoreML.MLModelCompilationResult.Arg1
P:CoreML.MLModelConfiguration.AllowLowPrecisionAccumulationOnGpu
P:CoreML.MLModelConfiguration.ComputeUnits
P:CoreML.MLModelConfiguration.FunctionName
P:CoreML.MLModelConfiguration.ModelDisplayName
P:CoreML.MLModelConfiguration.OptimizationHints
P:CoreML.MLModelConfiguration.Parameters
Expand All @@ -63758,6 +63776,7 @@ P:CoreML.MLModelDescription.OutputDescriptionsByName
P:CoreML.MLModelDescription.ParameterDescriptionsByKey
P:CoreML.MLModelDescription.PredictedFeatureName
P:CoreML.MLModelDescription.PredictedProbabilitiesName
P:CoreML.MLModelDescription.StateDescriptionsByName
P:CoreML.MLModelDescription.TrainingInputDescriptionsByName
P:CoreML.MLModelMetadata.Author
P:CoreML.MLModelMetadata.CreatorDefined
Expand Down Expand Up @@ -63814,6 +63833,7 @@ P:CoreML.MLNumericConstraint.EnumeratedNumbers
P:CoreML.MLNumericConstraint.MaxNumber
P:CoreML.MLNumericConstraint.MinNumber
P:CoreML.MLOptimizationHints.ReshapeFrequency
P:CoreML.MLOptimizationHints.SpecializationStrategy
P:CoreML.MLParameterDescription.DefaultValue
P:CoreML.MLParameterDescription.Key
P:CoreML.MLParameterDescription.NumericConstraint
Expand All @@ -63838,6 +63858,8 @@ P:CoreML.MLSequence.StringValues
P:CoreML.MLSequence.Type
P:CoreML.MLSequenceConstraint.CountRange
P:CoreML.MLSequenceConstraint.ValueDescription
P:CoreML.MLStateConstraint.BufferShape
P:CoreML.MLStateConstraint.DataType
P:CoreML.MLTask.Error
P:CoreML.MLTask.State
P:CoreML.MLTask.TaskIdentifier
Expand Down Expand Up @@ -80679,7 +80701,10 @@ T:CoreML.MLFeatureValueImageOption
T:CoreML.MLGpuComputeDevice
T:CoreML.MLKey
T:CoreML.MLMetricKey
T:CoreML.MLModel_MLState
T:CoreML.MLModelAsset
T:CoreML.MLModelAssetGetFunctionNamesCompletionHandler
T:CoreML.MLModelAssetGetModelDescriptionCompletionHandler
T:CoreML.MLModelCollection
T:CoreML.MLModelCollectionEntry
T:CoreML.MLModelCompilationLoadResult
Expand Down Expand Up @@ -80707,6 +80732,11 @@ T:CoreML.MLOptimizationHints
T:CoreML.MLParameterDescription
T:CoreML.MLParameterKey
T:CoreML.MLReshapeFrequencyHint
T:CoreML.MLSpecializationStrategy
T:CoreML.MLState
T:CoreML.MLStateConstraint
T:CoreML.MLStateGetMultiArrayForStateHandler
T:CoreML.MLStateGetPredictionCompletionHandler
T:CoreML.MLTask
T:CoreML.MLTaskState
T:CoreML.MLUpdateContext
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# These types are marked as unavailable in the headers if the min OS version is >= Xcode 16's OS versions, so xtro doesn't detect them as available.
# We're removing them in XAMCORE_5_0.
!unknown-field! MLModelCollectionDidChangeNotification bound
!unknown-type! MLModelCollection bound
!unknown-type! MLModelCollectionEntry bound
28 changes: 0 additions & 28 deletions tests/xtro-sharpie/api-annotations-dotnet/MacCatalyst-CoreML.todo

This file was deleted.

7 changes: 5 additions & 2 deletions tests/xtro-sharpie/api-annotations-dotnet/iOS-CoreML.ignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# Not available on iOS
!missing-enum-value! MLMultiArrayDataType native value MLMultiArrayDataTypeFloat16 = 65552 not bound
# These types are marked as unavailable in the headers if the min OS version is >= Xcode 16's OS versions, so xtro doesn't detect them as available.
# We're removing them in XAMCORE_5_0.
!unknown-field! MLModelCollectionDidChangeNotification bound
!unknown-type! MLModelCollection bound
!unknown-type! MLModelCollectionEntry bound
Loading
Loading