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

[MetalPerforanceShadersGraph] Implement Xcode 16.0 beta 1-6 changes. #21154

Merged
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
21 changes: 21 additions & 0 deletions src/MetalPerformanceShadersGraph/MPSGraphEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ public enum MPSGraphTensorNamedDataLayout : ulong {
Chw = 4,
Hwc = 5,
Hw = 6,
[Mac (13, 2), iOS (16, 3), TV (16, 3), MacCatalyst (16, 3)]
Ncdhw = 7,
[Mac (13, 2), iOS (16, 3), TV (16, 3), MacCatalyst (16, 3)]
Ndhwc = 8,
[Mac (13, 2), iOS (16, 3), TV (16, 3), MacCatalyst (16, 3)]
Oidhw = 9,
[Mac (13, 2), iOS (16, 3), TV (16, 3), MacCatalyst (16, 3)]
Dhwio = 10,
}

[Native]
Expand All @@ -31,6 +39,8 @@ public enum MPSGraphPaddingStyle : ulong {
Valid = 1,
Same = 2,
ExplicitOffset = 3,
[Mac (13, 0), iOS (16, 0), TV (16, 0), MacCatalyst (16, 0)]
OnnxSameLower = 4,
}

[Native]
Expand Down Expand Up @@ -101,4 +111,15 @@ public enum MPSGraphRandomNormalSamplingMethod : ulong {
BoxMuller = 1,
}

[TV (15, 4), Mac (12, 3), iOS (15, 4), MacCatalyst (15, 4)]
public enum MPSGraphOptimization : ulong {
Level0 = 0,
Level1 = 1L,
}

[TV (15, 4), Mac (12, 3), iOS (15, 4), MacCatalyst (15, 4)]
public enum MPSGraphOptimizationProfile : ulong {
Performance = 0,
PowerEfficiency = 1L,
}
}
66 changes: 66 additions & 0 deletions src/MetalPerformanceShadersGraph/MPSGraphExecutable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#nullable enable

using System;
using System.Buffers;
using System.Runtime.InteropServices;

using Foundation;
using ObjCRuntime;
using Metal;
using MetalPerformanceShaders;

namespace MetalPerformanceShadersGraph {
/// <summary>This enum is used to select how to initialize a new instance of a <see cref="MPSGraphExecutable" />.</summary>
#if NET
[SupportedOSPlatform ("ios17.0")]
[SupportedOSPlatform ("maccatalyst17.0")]
[SupportedOSPlatform ("macos14.0")]
[SupportedOSPlatform ("tvos17.0")]
#else
[TV (17, 0), Mac (14, 0), iOS (17, 0), MacCatalyst (17, 0)]
#endif
public enum MPSGraphExecutableInitializationOption {
/// <summary>The <c>packageUrl</c> parameter passed to the constructor is a url to a CoreML package.</summary>
#if NET
[SupportedOSPlatform ("ios18.0")]
[SupportedOSPlatform ("maccatalyst18.0")]
[SupportedOSPlatform ("macos15.0")]
[SupportedOSPlatform ("tvos18.0")]
#else
[TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)]
#endif
CoreMLPackage,

/// <summary>The <c>packageUrl</c> parameter passed to the constructor is a url to a MPSGraph package.</summary>
MPSGraphPackage,
}

public partial class MPSGraphExecutable {
/// <summary>Create a new MPSGraphExecutable instance from a package url and a compilation descriptor..</summary>
/// <param name="packageUrl">The url to the package to use.</param>
/// <param name="compilationDescriptor">The optional compilation descriptor use.</param>
/// <param name="option">Use this option to specify whether the package url points to a CoreML package or an MPSGraph package.</param>
#if NET
[SupportedOSPlatform ("ios17.0")]
[SupportedOSPlatform ("maccatalyst17.0")]
[SupportedOSPlatform ("macos14.0")]
[SupportedOSPlatform ("tvos17.0")]
#else
[TV (17, 0), Mac (14, 0), iOS (17, 0), MacCatalyst (17, 0)]
#endif
public MPSGraphExecutable (NSUrl packageUrl, MPSGraphCompilationDescriptor? compilationDescriptor, MPSGraphExecutableInitializationOption option)
Copy link
Member Author

Choose a reason for hiding this comment

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

I looked into creating a unit test for this constructor, but it turns out that in order to create a package to load, you have to create an MPSGraph that actually works, which is quite complex if you don't know how to use the API.

: base (NSObjectFlag.Empty)
{
switch (option) {
case MPSGraphExecutableInitializationOption.CoreMLPackage:
InitializeHandle (_InitWithCoreMLPackage (packageUrl, compilationDescriptor));
break;
case MPSGraphExecutableInitializationOption.MPSGraphPackage:
InitializeHandle (_InitWithMPSGraphPackage (packageUrl, compilationDescriptor));
break;
default:
throw new ArgumentOutOfRangeException (nameof (option), option, "Invalid enum value.");
}
}
}
}
1 change: 1 addition & 0 deletions src/frameworks.sources
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,7 @@ METALPERFORMANCESHADERSGRAPH_API_SOURCES = \
MetalPerformanceShadersGraph/MPSGraphEnums.cs \

METALPERFORMANCESHADERSGRAPH_SOURCES = \
MetalPerformanceShadersGraph/MPSGraphExecutable.cs \
MetalPerformanceShadersGraph/MPSGraphExtensions.cs \
MetalPerformanceShadersGraph/MPSGraphTensorData.cs \

Expand Down
1,185 changes: 1,164 additions & 21 deletions src/metalperformanceshadersgraph.cs

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions tests/cecil-tests/ApiTest.KnownFailures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public partial class ApiTest {
"The field 'Metal.MTLTextureType Metal.MTLTextureType::kCube' has incorrect capitalization: first letter is not upper case.",
"The field 'Metal.MTLTextureType Metal.MTLTextureType::kCubeArray' has incorrect capitalization: first letter is not upper case.",
"The field 'Metal.MTLTextureType Metal.MTLTextureType::kTextureBuffer' has incorrect capitalization: first letter is not upper case.",
"The field 'MetalPerformanceShadersGraph.MPSGraphDeploymentPlatform MetalPerformanceShadersGraph.MPSGraphDeploymentPlatform::iOS' has incorrect capitalization: first letter is not upper case.",
"The field 'MetalPerformanceShadersGraph.MPSGraphDeploymentPlatform MetalPerformanceShadersGraph.MPSGraphDeploymentPlatform::macOS' has incorrect capitalization: first letter is not upper case.",
"The field 'MetalPerformanceShadersGraph.MPSGraphDeploymentPlatform MetalPerformanceShadersGraph.MPSGraphDeploymentPlatform::tvOS' has incorrect capitalization: first letter is not upper case.",
"The field 'MetalPerformanceShadersGraph.MPSGraphDeploymentPlatform MetalPerformanceShadersGraph.MPSGraphDeploymentPlatform::visionOS' has incorrect capitalization: first letter is not upper case.",
"The field 'ObjCRuntime.LinkTarget ObjCRuntime.LinkTarget::i386' has incorrect capitalization: first letter is not upper case.",
"The field 'ObjCRuntime.LinkTarget ObjCRuntime.LinkTarget::x86_64' has incorrect capitalization: first letter is not upper case.",
"The field 'Photos.PHAssetSourceType Photos.PHAssetSourceType::iTunesSynced' has incorrect capitalization: first letter is not upper case.",
Expand Down
Loading
Loading