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 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
20 changes: 20 additions & 0 deletions src/MLCompute/MLHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,24 @@ public static string GetDebugDescription (this MLCComparisonOperation self)
return CFString.FromHandle (MLCComparisonOperationDebugDescription (self));
}
}

#if NET
[SupportedOSPlatform ("ios15.0")]
[SupportedOSPlatform ("tvos15.0")]
[SupportedOSPlatform ("macos12.0")]
[SupportedOSPlatform ("maccatalyst15.0")]
#else
[NoWatch]
[TV (15,0), Mac (12,0), iOS (15,0), MacCatalyst (15,0)]
#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));
}
}
}
142 changes: 141 additions & 1 deletion src/mlcompute.cs
Original file line number Diff line number Diff line change
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,8 @@ enum MLCDeviceType /* int32_t */ {
Cpu = 0,
Gpu = 1,
Any = 2,
[iOS (15,0), TV (15,0), Mac (12,0), MacCatalyst (15,0)]
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 +124,8 @@ enum MLCExecutionOptions : ulong {
Synchronous = 0x2,
Profiling = 0x4,
ForwardForInference = 0x8,
[iOS (15,0), TV (15,0), Mac (12,0), MacCatalyst (15,0)]
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 +239,14 @@ enum MLCSoftmaxOperation {
LogSoftmax = 1,
}

[iOS (15,0), TV (15,0), Mac (12,0), NoWatch, MacCatalyst (15,0)]
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 +304,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 +464,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 +512,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 +549,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 +598,21 @@ interface MLCDevice : NSCopying {
[return: NullAllowed]
MLCDevice GetDevice (IMTLDevice[] gpus);

[TV (15,0), Mac (12,0), iOS (15,0), MacCatalyst (15,0)]
[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 +743,31 @@ MLCTensorData[] OptimizerData {

[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 ([BindAs (typeof (nint[]))] NSNumber[] shape, MLCRandomInitializerType randomInitializerType, MLCDataType dataType);
}

[iOS (14,0)][TV (14,0)][Mac (11,0)]
Expand Down Expand Up @@ -2282,4 +2377,49 @@ 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
[DisableDefaultCtor]
interface MLCPlatform {

[Static]
[Export ("setRNGSeedTo:")]
void SetRngSeed ([BindAs (typeof (nuint))] NSNumber seed);

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

[TV (15,0), Mac (12,0), iOS (15,0), MacCatalyst (15,0)]
[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);
}

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

This file was deleted.

4 changes: 2 additions & 2 deletions tests/xtro-sharpie/common-MLCompute.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
!missing-enum-value! MLCActivationType native value MLCActivationTypeCount = 21 not bound
!missing-enum-value! MLCArithmeticOperation native value MLCArithmeticOperationCount = 30 not bound
!missing-enum-value! MLCComparisonOperation native value MLCComparisonOperationCount = 12 not bound
## missing-enum-value! MLCDataType native value MLCDataTypeCount = 8 not bound
## missing-enum-value! MLCDeviceType native value MLCDeviceTypeCount = 3 not bound
!missing-enum-value! MLCLossType native value MLCLossTypeCount = 9 not bound
!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.

Loading