Skip to content

Commit

Permalink
Merge branch 'main' into Xcode13-ShazamKit-beta1
Browse files Browse the repository at this point in the history
  • Loading branch information
tj-devel709 authored Aug 5, 2021
2 parents d1eb2f6 + 818198b commit e7b0874
Show file tree
Hide file tree
Showing 35 changed files with 1,848 additions and 1,280 deletions.
64 changes: 64 additions & 0 deletions runtime/bindings-generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2694,6 +2694,70 @@ static IEnumerable<FunctionData> GetFunctionData ()
}
);

data.Add (
new FunctionData {
Comment = " // IntPtr func (IntPtr, Quaternion)",
Prefix = "simd__",
Variants = Variants.All,
ReturnType = Types.IntPtr,
Parameters = new ParameterData [] {
new ParameterData { TypeData = Types.IntPtr },
new ParameterData { TypeData = Types.QuatF }
},
}
);

data.Add (
new FunctionData {
Comment = " // IntPtr func (IntPtr, Quaternion, IntPtr)",
Prefix = "simd__",
Variants = Variants.All,
ReturnType = Types.IntPtr,
Parameters = new ParameterData [] {
new ParameterData { TypeData = Types.IntPtr },
new ParameterData { TypeData = Types.QuatF },
new ParameterData { TypeData = Types.IntPtr }
},
}
);

data.Add (
new FunctionData {
Comment = " // IntPtr func (Vector2D, IntPtr)",
Prefix = "simd__",
Variants = Variants.All,
ReturnType = Types.IntPtr,
Parameters = new ParameterData [] {
new ParameterData { TypeData = Types.Vector2d},
new ParameterData { TypeData = Types.IntPtr }
},
}
);

data.Add (
new FunctionData {
Comment = " // IntPtr func (Vector2D, int)",
Prefix = "simd__",
Variants = Variants.All,
ReturnType = Types.IntPtr,
Parameters = new ParameterData [] {
new ParameterData { TypeData = Types.Vector2d },
new ParameterData { TypeData = Types.NInt }
},
}
);

data.Add (
new FunctionData {
Comment = " // void func (Vector2D)",
Prefix = "simd__",
Variants = Variants.msgSend | Variants.msgSendSuper,
Parameters = new ParameterData [] {
new ParameterData { TypeData = Types.Vector2d },
},
}
);

// We must expand functions with native types to their actual type as well.
for (int i = data.Count - 1; i >= 0; i--) {
if (!data [i].HasNativeType)
Expand Down
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));
}
}
}
8 changes: 6 additions & 2 deletions src/ModelIO/MIEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ public enum MDLVertexFormat : ulong {
public enum MDLMeshBufferType : ulong
{
Vertex = 1,
Index = 2
Index = 2,
[iOS (15,0), TV (15,0), Mac (12,0), MacCatalyst (15,0)]
Custom = 3,
}

[Native]
Expand Down Expand Up @@ -177,7 +179,9 @@ public enum MDLMaterialPropertyType : ulong {
Float2,
Float3,
Float4,
Matrix44
Matrix44,
[iOS (15,0), TV (15,0), Mac (12,0), MacCatalyst (15,0)]
Buffer,
}

[Native]
Expand Down
3 changes: 3 additions & 0 deletions src/frameworks.sources
Original file line number Diff line number Diff line change
Expand Up @@ -1994,6 +1994,7 @@ MAC_FRAMEWORKS = \
PassKit \
PdfKit \
PencilKit \
Phase \
Photos \
PhotosUI \
PrintCore \
Expand Down Expand Up @@ -2102,6 +2103,7 @@ IOS_FRAMEWORKS = \
PassKit \
PdfKit \
PencilKit \
Phase \
Photos \
PhotosUI \
PushKit \
Expand Down Expand Up @@ -2271,6 +2273,7 @@ MACCATALYST_FRAMEWORKS = \
PassKit \
PdfKit \
PencilKit \
Phase \
Photos \
PhotosUI \
PushKit \
Expand Down
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
// 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,
}

[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))]
[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);
}

}
5 changes: 5 additions & 0 deletions src/mobilecoreservices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,11 @@ interface UTType {
[Field ("kUTTypeUniversalSceneDescription", "ModelIO")]
NSString UniversalSceneDescription { get; }

[NoWatch]
[iOS (15,0), Mac(12,0), TV (15,0), MacCatalyst (15,0)]
[Field ("kUTTypeUniversalSceneDescriptionMobile", "ModelIO")]
NSString UniversalSceneDescriptionMobile { get; }

[Watch (2,2)]
[iOS (9,1)][TV (9,0)]
[NoMac]
Expand Down
Loading

0 comments on commit e7b0874

Please sign in to comment.