From e1544da7f21469acb7e8bf7049d3ad2c4ac23a84 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Tue, 19 Sep 2023 08:32:09 -0400 Subject: [PATCH 1/4] Fix downlevel build break in TensorPrimitives --- .../src/System/Numerics/Tensors/TensorPrimitives.netcore.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/TensorPrimitives.netcore.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/TensorPrimitives.netcore.cs index 4f40aa31494c9..ae5af404ac1af 100644 --- a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/TensorPrimitives.netcore.cs +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/TensorPrimitives.netcore.cs @@ -1159,7 +1159,9 @@ public static float Invoke(Vector512 x) public static float Invoke(float x) => -x; public static Vector128 Invoke(Vector128 x) => -x; public static Vector256 Invoke(Vector256 x) => -x; +#if NET8_0_OR_GREATER public static Vector512 Invoke(Vector512 x) => -x; +#endif } private readonly struct AddMultiplyOperator : ITernaryOperator @@ -1167,7 +1169,9 @@ public static float Invoke(Vector512 x) public static float Invoke(float x, float y, float z) => (x + y) * z; public static Vector128 Invoke(Vector128 x, Vector128 y, Vector128 z) => (x + y) * z; public static Vector256 Invoke(Vector256 x, Vector256 y, Vector256 z) => (x + y) * z; +#if NET8_0_OR_GREATER public static Vector512 Invoke(Vector512 x, Vector512 y, Vector512 z) => (x + y) * z; +#endif } private readonly struct MultiplyAddOperator : ITernaryOperator @@ -1175,7 +1179,9 @@ public static float Invoke(Vector512 x) public static float Invoke(float x, float y, float z) => (x * y) + z; public static Vector128 Invoke(Vector128 x, Vector128 y, Vector128 z) => (x * y) + z; public static Vector256 Invoke(Vector256 x, Vector256 y, Vector256 z) => (x * y) + z; +#if NET8_0_OR_GREATER public static Vector512 Invoke(Vector512 x, Vector512 y, Vector512 z) => (x * y) + z; +#endif } private readonly struct LoadIdentity : IUnaryOperator From 899077f4dc1c648e4294fb9669d4eea50b5b0394 Mon Sep 17 00:00:00 2001 From: Eric StJohn Date: Tue, 19 Sep 2023 07:14:42 -0700 Subject: [PATCH 2/4] Make net6.0 Tensors use ns2.0 implementation --- .../ref/System.Numerics.Tensors.csproj | 2 +- .../src/System.Numerics.Tensors.csproj | 4 ++-- .../Tensors/TensorPrimitives.netstandard.cs | 20 +++++++++---------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.csproj b/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.csproj index 89bdef6ea38ed..8d28b0e077d9c 100644 --- a/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.csproj +++ b/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.csproj @@ -8,7 +8,7 @@ - + diff --git a/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj b/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj index 097fa244ad491..be4a04702af5e 100644 --- a/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj +++ b/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj @@ -16,11 +16,11 @@ - + - + diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/TensorPrimitives.netstandard.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/TensorPrimitives.netstandard.cs index 134364708b8e5..ba3fc69bab527 100644 --- a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/TensorPrimitives.netstandard.cs +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/TensorPrimitives.netstandard.cs @@ -69,8 +69,8 @@ private static float CosineSimilarityCore(ReadOnlySpan x, ReadOnlySpan( float identityValue, ReadOnlySpan x, TLoad load = default, TAggregate aggregate = default) - where TLoad : IUnaryOperator - where TAggregate : IBinaryOperator + where TLoad : struct, IUnaryOperator + where TAggregate : struct, IBinaryOperator { // Initialize the result to the identity value float result = identityValue; @@ -112,8 +112,8 @@ private static float Aggregate( private static float Aggregate( float identityValue, ReadOnlySpan x, ReadOnlySpan y, TBinary binary = default, TAggregate aggregate = default) - where TBinary : IBinaryOperator - where TAggregate : IBinaryOperator + where TBinary : struct, IBinaryOperator + where TAggregate : struct, IBinaryOperator { // Initialize the result to the identity value float result = identityValue; @@ -156,7 +156,7 @@ private static float Aggregate( private static void InvokeSpanIntoSpan( ReadOnlySpan x, Span destination, TUnaryOperator op = default) - where TUnaryOperator : IUnaryOperator + where TUnaryOperator : struct, IUnaryOperator { if (x.Length > destination.Length) { @@ -203,7 +203,7 @@ private static void InvokeSpanIntoSpan( private static void InvokeSpanSpanIntoSpan( ReadOnlySpan x, ReadOnlySpan y, Span destination, TBinaryOperator op = default) - where TBinaryOperator : IBinaryOperator + where TBinaryOperator : struct, IBinaryOperator { if (x.Length != y.Length) { @@ -258,7 +258,7 @@ private static void InvokeSpanSpanIntoSpan( private static void InvokeSpanScalarIntoSpan( ReadOnlySpan x, float y, Span destination, TBinaryOperator op = default) - where TBinaryOperator : IBinaryOperator + where TBinaryOperator : struct, IBinaryOperator { if (x.Length > destination.Length) { @@ -309,7 +309,7 @@ private static void InvokeSpanScalarIntoSpan( private static void InvokeSpanSpanSpanIntoSpan( ReadOnlySpan x, ReadOnlySpan y, ReadOnlySpan z, Span destination, TTernaryOperator op = default) - where TTernaryOperator : ITernaryOperator + where TTernaryOperator : struct, ITernaryOperator { if (x.Length != y.Length || x.Length != z.Length) { @@ -369,7 +369,7 @@ private static void InvokeSpanSpanSpanIntoSpan( private static void InvokeSpanSpanScalarIntoSpan( ReadOnlySpan x, ReadOnlySpan y, float z, Span destination, TTernaryOperator op = default) - where TTernaryOperator : ITernaryOperator + where TTernaryOperator : struct, ITernaryOperator { if (x.Length != y.Length) { @@ -430,7 +430,7 @@ private static void InvokeSpanSpanScalarIntoSpan( private static void InvokeSpanScalarSpanIntoSpan( ReadOnlySpan x, float y, ReadOnlySpan z, Span destination, TTernaryOperator op = default) - where TTernaryOperator : ITernaryOperator + where TTernaryOperator : struct, ITernaryOperator { if (x.Length != z.Length) { From 932481f146fc5427546cd5c51dc7f986ce95a086 Mon Sep 17 00:00:00 2001 From: Eric StJohn Date: Tue, 19 Sep 2023 08:28:20 -0700 Subject: [PATCH 3/4] Add net6.0 and net7.0 to Tensors temporarily since those are shipping in 8.0 branch --- .../System.Numerics.Tensors/ref/System.Numerics.Tensors.csproj | 2 +- .../System.Numerics.Tensors/src/System.Numerics.Tensors.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.csproj b/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.csproj index 8d28b0e077d9c..7d5a43c6dbe32 100644 --- a/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.csproj +++ b/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.csproj @@ -1,7 +1,7 @@ - $(NetCoreAppCurrent);$(NetCoreAppPrevious);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum) + $(NetCoreAppCurrent);$(NetCoreAppPrevious);$(NetCoreAppMinimum);net7.0;net6.0;netstandard2.0;$(NetFrameworkMinimum) diff --git a/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj b/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj index be4a04702af5e..bc8ea69f43b65 100644 --- a/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj +++ b/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj @@ -1,7 +1,7 @@ - $(NetCoreAppCurrent);$(NetCoreAppPrevious);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum) + $(NetCoreAppCurrent);$(NetCoreAppPrevious);$(NetCoreAppMinimum);net7.0;net6.0;netstandard2.0;$(NetFrameworkMinimum) true true Provides support for operating over tensors. From 33d096caf69e67a15d5e963aacd3dce7cab540ed Mon Sep 17 00:00:00 2001 From: Eric StJohn Date: Tue, 19 Sep 2023 19:46:19 -0700 Subject: [PATCH 4/4] Only build net6.0 and net7.0 Tensors when not in source-build --- .../System.Numerics.Tensors/ref/System.Numerics.Tensors.csproj | 3 ++- .../System.Numerics.Tensors/src/System.Numerics.Tensors.csproj | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.csproj b/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.csproj index 7d5a43c6dbe32..a8090a6f6995d 100644 --- a/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.csproj +++ b/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.csproj @@ -1,7 +1,8 @@ - $(NetCoreAppCurrent);$(NetCoreAppPrevious);$(NetCoreAppMinimum);net7.0;net6.0;netstandard2.0;$(NetFrameworkMinimum) + $(NetCoreAppCurrent);$(NetCoreAppPrevious);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum) + $(TargetFrameworks);net7.0;net6.0 diff --git a/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj b/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj index bc8ea69f43b65..b0449170860b4 100644 --- a/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj +++ b/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj @@ -1,7 +1,8 @@ - $(NetCoreAppCurrent);$(NetCoreAppPrevious);$(NetCoreAppMinimum);net7.0;net6.0;netstandard2.0;$(NetFrameworkMinimum) + $(NetCoreAppCurrent);$(NetCoreAppPrevious);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum) + $(TargetFrameworks);net7.0;net6.0 true true Provides support for operating over tensors.