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

[MLCompute] Add support for Xcode 13 beta 4. #12348

Merged
merged 3 commits into from Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/MLCompute/MLHelpers.cs
Expand Up @@ -235,4 +235,23 @@ public static string GetDebugDescription (this MLCComparisonOperation self)
return CFString.FromHandle (MLCComparisonOperationDebugDescription (self));
}
}

#if NET
[SupportedOSPlatform ("ios15.0")]
[SupportedOSPlatform ("tvos15.0")]
[SupportedOSPlatform ("macos12.0")]
#else
[NoWatch]
[TV (15,0), Mac (12,0), iOS (15,0)]
Copy link
Contributor

Choose a reason for hiding this comment

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

catalyst ?

#endif
public static class MLCGradientClippingTypeExtensions {

[DllImport (Constants.MLComputeLibrary)]
static extern /* NSString */ IntPtr MLCGradientClippingTypeDebugDescription (MLCGradientClippingType gradientClippingType);

public static string GetDebugDescription (this MLCGradientClippingType self)
{
return CFString.FromHandle (MLCGradientClippingTypeDebugDescription (self));
}
}
}
139 changes: 138 additions & 1 deletion src/mlcompute.cs
Expand Up @@ -92,9 +92,15 @@ enum MLCConvolutionType {
enum MLCDataType {
Invalid = 0,
Float32 = 1,
[iOS (15,0), TV (15,0), Mac (12,0), MacCatalyst (15,0)]
Float16 = 3,
Boolean = 4,
Int64 = 5,
Int32 = 7,
Inot32 = 7,
[iOS (15,0), TV (15,0), Mac (12,0), MacCatalyst (15,0)]
Int8 = 8,
[iOS (15,0), TV (15,0), Mac (12,0), MacCatalyst (15,0)]
UInt8 = 9,
// Count, // must be last, not available in swift
}

Expand All @@ -104,6 +110,7 @@ enum MLCDeviceType /* int32_t */ {
Cpu = 0,
Gpu = 1,
Any = 2,
Ane = 3, // Apple neural engine
spouliot marked this conversation as resolved.
Show resolved Hide resolved
// Count, // must be last, not available in swift
}

Expand All @@ -116,6 +123,7 @@ enum MLCExecutionOptions : ulong {
Synchronous = 0x2,
Profiling = 0x4,
ForwardForInference = 0x8,
PerLayerProfiling = 0x10,
spouliot marked this conversation as resolved.
Show resolved Hide resolved
}

[iOS (14,0)][TV (14,0)][Mac (11,0)]
Expand Down Expand Up @@ -229,6 +237,14 @@ enum MLCSoftmaxOperation {
LogSoftmax = 1,
}

[iOS (15,0), TV (15,0), Mac (12,0), NoWatch]
Copy link
Contributor

Choose a reason for hiding this comment

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

catalyst ?

public enum MLCGradientClippingType {
Value = 0,
Norm = 1,
GlobalNorm = 2,
}


[iOS (14,0)][TV (14,0)][Mac (11,0)]
[NoWatch]
[BaseType (typeof (NSObject))]
Expand Down Expand Up @@ -286,6 +302,10 @@ interface MLCLayer {
[Static]
[Export ("supportsDataType:onDevice:")]
bool SupportsDataType (MLCDataType dataType, MLCDeviceType device);

[TV (15,0), Mac (12,0), iOS (15,0), MacCatalyst (15,0)]
[Export ("deviceType")]
MLCDeviceType DeviceType { get; }
}

[iOS (14,0)][TV (14,0)][Mac (11,0)]
Expand Down Expand Up @@ -442,6 +462,18 @@ interface MLCOptimizer : NSCopying {

[Export ("regularizationType")]
MLCRegularizationType RegularizationType { get; }

[TV (15,0), Mac (12,0), iOS (15,0), MacCatalyst (15,0)]
[Export ("gradientClippingType")]
MLCGradientClippingType GradientClippingType { get; }

[TV (15,0), Mac (12,0), iOS (15,0), MacCatalyst (15,0)]
[Export ("maximumClippingNorm")]
float MaximumClippingNorm { get; }

[TV (15,0), Mac (12,0), iOS (15,0), MacCatalyst (15,0)]
[Export ("customGlobalNorm")]
float CustomGlobalNorm { get; }
}

[iOS (14,0)][TV (14,0)][Mac (11,0)]
Expand Down Expand Up @@ -478,6 +510,23 @@ interface MLCOptimizerDescriptor : NSCopying {
[Static]
[Export ("descriptorWithLearningRate:gradientRescale:appliesGradientClipping:gradientClipMax:gradientClipMin:regularizationType:regularizationScale:")]
MLCOptimizerDescriptor Create (float learningRate, float gradientRescale, bool appliesGradientClipping, float gradientClipMax, float gradientClipMin, MLCRegularizationType regularizationType, float regularizationScale);

[TV (15,0), Mac (12,0), iOS (15,0), MacCatalyst (15,0)]
[Static]
[Export ("descriptorWithLearningRate:gradientRescale:appliesGradientClipping:gradientClippingType:gradientClipMax:gradientClipMin:maximumClippingNorm:customGlobalNorm:regularizationType:regularizationScale:")]
MLCOptimizerDescriptor Create (float learningRate, float gradientRescale, bool appliesGradientClipping, MLCGradientClippingType gradientClippingType, float gradientClipMax, float gradientClipMin, float maximumClippingNorm, float customGlobalNorm, MLCRegularizationType regularizationType, float regularizationScale);

[TV (15, 0), Mac (12, 0), iOS (15, 0), MacCatalyst (15,0)]
[Export ("gradientClippingType")]
MLCGradientClippingType GradientClippingType { get; }

[TV (15, 0), Mac (12, 0), iOS (15, 0), MacCatalyst (15,0)]
[Export ("maximumClippingNorm")]
float MaximumClippingNorm { get; }

[TV (15, 0), Mac (12, 0), iOS (15, 0), MacCatalyst (15,0)]
[Export ("customGlobalNorm")]
float CustomGlobalNorm { get; }
}

[iOS (14,0)][TV (14,0)][Mac (11,0)]
Expand All @@ -498,13 +547,22 @@ interface MLCAdamOptimizer : NSCopying {
[Export ("timeStep")]
nuint TimeStep { get; }

[TV (15,0), Mac (12,0), iOS (15,0), MacCatalyst (15,0)]
[Export ("usesAMSGrad")]
bool UsesAmsGrad { get; }

[Static]
[Export ("optimizerWithDescriptor:")]
MLCAdamOptimizer Create (MLCOptimizerDescriptor optimizerDescriptor);

[Static]
[Export ("optimizerWithDescriptor:beta1:beta2:epsilon:timeStep:")]
MLCAdamOptimizer Create (MLCOptimizerDescriptor optimizerDescriptor, float beta1, float beta2, float epsilon, nuint timeStep);

[TV (15,0), Mac (12,0), iOS (15,0), MacCatalyst (15,0)]
[Static]
[Export ("optimizerWithDescriptor:beta1:beta2:epsilon:usesAMSGrad:timeStep:")]
MLCAdamOptimizer Create (MLCOptimizerDescriptor optimizerDescriptor, float beta1, float beta2, float epsilon, bool usesAmsGrad, nuint timeStep);
}

[iOS (14,0)][TV (14,0)][Mac (11,0)]
Expand Down Expand Up @@ -538,11 +596,21 @@ interface MLCDevice : NSCopying {
[return: NullAllowed]
MLCDevice GetDevice (IMTLDevice[] gpus);

[TV (15,0), Mac (12,0), iOS (15,0)]
Copy link
Contributor

Choose a reason for hiding this comment

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

catalyst ?

[Static]
[Export ("aneDevice")]
[return: NullAllowed]
MLCDevice GetAneDevice ();

[iOS (14,2)][TV (14,2)]
[Static]
[Export ("deviceWithType:selectsMultipleComputeDevices:")]
[return: NullAllowed]
MLCDevice GetDevice (MLCDeviceType type, bool selectsMultipleComputeDevices);

[TV (15,0), Mac (12,0), iOS (15,0), MacCatalyst (15,0)]
[Export ("actualDeviceType")]
MLCDeviceType ActualDeviceType { get; }
}

[iOS (14,0)][TV (14,0)][Mac (11,0)]
Expand Down Expand Up @@ -673,6 +741,31 @@ interface MLCTensor : NSCopying {

[Export ("bindOptimizerData:deviceData:")]
bool BindOptimizer (MLCTensorData[] data, [NullAllowed] MLCTensorOptimizerDeviceData[] deviceData);

[TV (15,0), Mac (12,0), iOS (15,0), MacCatalyst (15,0)]
[Export ("tensorByQuantizingToType:scale:bias:")]
[return: NullAllowed]
MLCTensor CreateByQuantizing (MLCDataType type, float scale, nint bias);

[TV (15,0), Mac (12,0), iOS (15,0), MacCatalyst (15,0)]
[Export ("tensorByDequantizingToType:scale:bias:")]
[return: NullAllowed]
MLCTensor CreateByDequantizing (MLCDataType type, MLCTensor scale, MLCTensor bias);

[TV (15,0), Mac (12,0), iOS (15,0), MacCatalyst (15,0)]
[Export ("tensorByQuantizingToType:scale:bias:axis:")]
[return: NullAllowed]
MLCTensor CreateByQuantizing (MLCDataType type, MLCTensor scale, MLCTensor bias, nint axis);

[TV (15,0), Mac (12,0), iOS (15,0), MacCatalyst (15,0)]
[Export ("tensorByDequantizingToType:scale:bias:axis:")]
[return: NullAllowed]
MLCTensor CreateByDequantizing (MLCDataType type, MLCTensor scale, MLCTensor bias, nint axis);

[Static]
[TV (15,0), Mac (12,0), iOS (15,0), MacCatalyst (15,0)]
[Export ("tensorWithShape:randomInitializerType:dataType:")]
MLCTensor Create (NSNumber[] shape, MLCRandomInitializerType randomInitializerType, MLCDataType dataType);
Copy link
Contributor

Choose a reason for hiding this comment

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

[BindAs (typeof (nint[]))] NSNumber[] shape was used for tensorWithShape:

}

[iOS (14,0)][TV (14,0)][Mac (11,0)]
Expand Down Expand Up @@ -2282,4 +2375,48 @@ interface MLCSelectionLayer {
[Export ("layer")]
MLCSelectionLayer Create ();
}

[TV (15,0), Mac (12,0), iOS (15,0), MacCatalyst (15,0)]
[BaseType (typeof (NSObject))]
spouliot marked this conversation as resolved.
Show resolved Hide resolved
interface MLCPlatform {

[Static]
[Export ("setRNGSeedTo:")]
void SetRngSeedTo ([BindAs (typeof (nuint))] NSNumber seed);
Copy link
Contributor

Choose a reason for hiding this comment

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

-> SetRngSeed


[return: BindAs (typeof (nuint)), NullAllowed]
[Static]
[Export ("getRNGseed")]
NSNumber GetRngSeed ();
}

[TV (15,0), Mac (12,0), iOS (15,0)]
Copy link
Contributor

Choose a reason for hiding this comment

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

catalyst ?

[BaseType (typeof (MLCOptimizer))]
[DisableDefaultCtor]
interface MLCAdamWOptimizer : NSCopying
{
[Export ("beta1")]
float Beta1 { get; }

[Export ("beta2")]
float Beta2 { get; }

[Export ("epsilon")]
float Epsilon { get; }

[Export ("usesAMSGrad")]
bool UsesAmsGrad { get; }

[Export ("timeStep")]
nuint TimeStep { get; }

[Static]
[Export ("optimizerWithDescriptor:")]
MLCAdamWOptimizer GetOptimizer (MLCOptimizerDescriptor optimizerDescriptor);

[Static]
[Export ("optimizerWithDescriptor:beta1:beta2:epsilon:usesAMSGrad:timeStep:")]
MLCAdamWOptimizer GetOptimizer (MLCOptimizerDescriptor optimizerDescriptor, float beta1, float beta2, float epsilon, bool usesAMSGrad, nuint timeStep);
spouliot marked this conversation as resolved.
Show resolved Hide resolved
}

}
37 changes: 0 additions & 37 deletions tests/xtro-sharpie/MacCatalyst-MLCompute.todo

This file was deleted.

2 changes: 2 additions & 0 deletions tests/xtro-sharpie/common-MLCompute.ignore
Expand Up @@ -8,3 +8,5 @@
!missing-enum-value! MLCPoolingType native value MLCPoolingTypeCount = 4 not bound
!missing-enum-value! MLCRandomInitializerType native value MLCRandomInitializerTypeCount = 4 not bound
!missing-enum-value! MLCReductionType native value MLCReductionTypeCount = 10 not bound
!missing-enum-value! MLCDeviceType native value MLCDeviceTypeCount = 4 not bound
!missing-enum-value! MLCDataType native value MLCDataTypeCount = 10 not bound
spouliot marked this conversation as resolved.
Show resolved Hide resolved
37 changes: 0 additions & 37 deletions tests/xtro-sharpie/iOS-MLCompute.todo

This file was deleted.

37 changes: 0 additions & 37 deletions tests/xtro-sharpie/macOS-MLCompute.todo

This file was deleted.