-
Notifications
You must be signed in to change notification settings - Fork 516
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into src-improve-coreclr-debug-spew
- Loading branch information
Showing
58 changed files
with
3,426 additions
and
3,689 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
using Foundation; | ||
using ObjCRuntime; | ||
using Metal; | ||
|
||
namespace MetalPerformanceShadersGraph | ||
{ | ||
[Flags] | ||
public enum MPSGraphOptions : ulong | ||
{ | ||
None = 0, | ||
SynchronizeResults = 1, | ||
Verbose = 2, | ||
Default = SynchronizeResults, | ||
} | ||
|
||
[Native] | ||
public enum MPSGraphTensorNamedDataLayout : ulong | ||
{ | ||
Nchw = 0, | ||
Nhwc = 1, | ||
Oihw = 2, | ||
Hwio = 3, | ||
Chw = 4, | ||
Hwc = 5, | ||
Hw = 6, | ||
} | ||
|
||
[Native] | ||
public enum MPSGraphPaddingStyle : ulong | ||
{ | ||
Explicit = 0, | ||
Valid = 1, | ||
Same = 2, | ||
ExplicitOffset = 3, | ||
} | ||
|
||
[Native] | ||
public enum MPSGraphPaddingMode : long | ||
{ | ||
Constant = 0, | ||
Reflect = 1, | ||
Symmetric = 2, | ||
ClampToEdge = 3, | ||
Zero = 4, | ||
Periodic = 5, | ||
AntiPeriodic = 6, | ||
} | ||
|
||
[Native] | ||
public enum MPSGraphReductionMode : ulong | ||
{ | ||
Min = 0, | ||
Max = 1, | ||
Sum = 2, | ||
Product = 3, | ||
ArgumentMin = 4, | ||
ArgumentMax = 5, | ||
} | ||
|
||
[Native] | ||
public enum MPSGraphResizeMode : ulong | ||
{ | ||
Nearest = 0, | ||
Bilinear = 1, | ||
} | ||
|
||
[Native] | ||
public enum MPSGraphScatterMode : long | ||
{ | ||
Add = 0, | ||
Sub = 1, | ||
Mul = 2, | ||
Div = 3, | ||
Min = 4, | ||
Max = 5, | ||
Set = 6, | ||
} | ||
|
||
public enum MPSGraphDeviceType : uint | ||
{ | ||
Metal = 0, | ||
} | ||
|
||
public enum MPSGraphLossReductionType : ulong | ||
{ | ||
Axis = 0, | ||
Sum = 1, | ||
Mean = 2, | ||
} | ||
|
||
// For COO, indexTensor0 is x index and indexTensor1 is y index | ||
// For CSC, indexTensor0 and indexTensor1 correspond to rowIndex and colStarts respectively. | ||
// For CSR, indexTensor0 and indexTensor1 correspond to colIndex and rowStarts respectively. | ||
public enum MPSGraphSparseStorageType : ulong | ||
{ | ||
Coo = 0, | ||
Csc = 1, | ||
Csr = 2, | ||
} | ||
|
||
public enum MPSGraphRandomDistribution : ulong | ||
{ | ||
Uniform = 0, | ||
Normal = 1, | ||
TruncatedNormal = 2, | ||
} | ||
|
||
public enum MPSGraphRandomNormalSamplingMethod : ulong | ||
{ | ||
InvCdf = 0, | ||
BoxMuller = 1, | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#nullable enable | ||
|
||
using System; | ||
using System.Buffers; | ||
using System.Runtime.InteropServices; | ||
|
||
using Foundation; | ||
using ObjCRuntime; | ||
using Metal; | ||
using MetalPerformanceShaders; | ||
|
||
namespace MetalPerformanceShadersGraph | ||
{ | ||
public static partial class MPSGraphMemoryOps_Extensions | ||
{ | ||
public static unsafe MPSGraphTensor Constant (this MPSGraph graph, float scalar) | ||
{ | ||
return graph.Constant ((double) scalar, new [] { 1 }, MPSDataType.Float32); | ||
} | ||
|
||
public static unsafe MPSGraphTensor Constant (this MPSGraph graph, ReadOnlySpan<float> values, int[] shape) | ||
{ | ||
var length = 1; | ||
for (var i = 0; i < shape.Length; i++) | ||
length *= shape [i]; | ||
if (length != values.Length) | ||
throw new ArgumentException ($"The number of values ({values.Length}) does not match the shape length ({length})."); | ||
fixed (float* p = values) { | ||
using var data = NSData.FromBytesNoCopy ((IntPtr) p, (nuint) (values.Length * 4), freeWhenDone: false); | ||
return graph.Constant (data, shape, MPSDataType.Float32); | ||
} | ||
} | ||
|
||
public static MPSGraphTensor Variable (this MPSGraph graph, float initialValue, int[] shape, string? name = null) | ||
{ | ||
var length = 1; | ||
for (var i = 0; i < shape.Length; i++) | ||
length *= shape [i]; | ||
var pool = ArrayPool<float>.Shared; | ||
var a = pool.Rent (length); | ||
Array.Fill (a, initialValue); | ||
var v = Variable (graph, a, shape, name); | ||
pool.Return (a); | ||
return v; | ||
} | ||
|
||
public static unsafe MPSGraphTensor Variable (this MPSGraph graph, ReadOnlySpan<float> initialValues, int[] shape, string? name = null) | ||
{ | ||
var length = 1; | ||
for (var i = 0; i < shape.Length; i++) | ||
length *= shape [i]; | ||
if (length != initialValues.Length) | ||
throw new ArgumentException ($"The number of initial values ({initialValues.Length}) does not match the shape length ({length})."); | ||
fixed (float* p = initialValues) { | ||
using var data = NSData.FromBytesNoCopy ((IntPtr) p, (nuint) (initialValues.Length * 4), freeWhenDone: false); | ||
return graph.Variable (data, shape, MPSDataType.Float32, name); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.