Skip to content

Commit

Permalink
[release/8.0] Fix downlevel build break in TensorPrimitives (#92270)
Browse files Browse the repository at this point in the history
* Fix downlevel build break in TensorPrimitives

* Make net6.0 Tensors use ns2.0 implementation

---------

Co-authored-by: Stephen Toub <[email protected]>
Co-authored-by: Eric StJohn <[email protected]>
  • Loading branch information
3 people authored Sep 19, 2023
1 parent 1881071 commit 575843d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Compile Include="System.Numerics.Tensors.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
<ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">
<Compile Include="System.Numerics.Tensors.netcore.cs" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
<Compile Include="System\ThrowHelper.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'">
<ItemGroup Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">
<Compile Include="System\Numerics\Tensors\TensorPrimitives.netstandard.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
<ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">
<Compile Include="System\Numerics\Tensors\TensorPrimitives.netcore.cs" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1159,23 +1159,29 @@ public static float Invoke(Vector512<float> x)
public static float Invoke(float x) => -x;
public static Vector128<float> Invoke(Vector128<float> x) => -x;
public static Vector256<float> Invoke(Vector256<float> x) => -x;
#if NET8_0_OR_GREATER
public static Vector512<float> Invoke(Vector512<float> x) => -x;
#endif
}

private readonly struct AddMultiplyOperator : ITernaryOperator
{
public static float Invoke(float x, float y, float z) => (x + y) * z;
public static Vector128<float> Invoke(Vector128<float> x, Vector128<float> y, Vector128<float> z) => (x + y) * z;
public static Vector256<float> Invoke(Vector256<float> x, Vector256<float> y, Vector256<float> z) => (x + y) * z;
#if NET8_0_OR_GREATER
public static Vector512<float> Invoke(Vector512<float> x, Vector512<float> y, Vector512<float> z) => (x + y) * z;
#endif
}

private readonly struct MultiplyAddOperator : ITernaryOperator
{
public static float Invoke(float x, float y, float z) => (x * y) + z;
public static Vector128<float> Invoke(Vector128<float> x, Vector128<float> y, Vector128<float> z) => (x * y) + z;
public static Vector256<float> Invoke(Vector256<float> x, Vector256<float> y, Vector256<float> z) => (x * y) + z;
#if NET8_0_OR_GREATER
public static Vector512<float> Invoke(Vector512<float> x, Vector512<float> y, Vector512<float> z) => (x * y) + z;
#endif
}

private readonly struct LoadIdentity : IUnaryOperator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ private static float CosineSimilarityCore(ReadOnlySpan<float> x, ReadOnlySpan<fl

private static float Aggregate<TLoad, TAggregate>(
float identityValue, ReadOnlySpan<float> 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;
Expand Down Expand Up @@ -112,8 +112,8 @@ private static float Aggregate<TLoad, TAggregate>(

private static float Aggregate<TBinary, TAggregate>(
float identityValue, ReadOnlySpan<float> x, ReadOnlySpan<float> 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;
Expand Down Expand Up @@ -156,7 +156,7 @@ private static float Aggregate<TBinary, TAggregate>(

private static void InvokeSpanIntoSpan<TUnaryOperator>(
ReadOnlySpan<float> x, Span<float> destination, TUnaryOperator op = default)
where TUnaryOperator : IUnaryOperator
where TUnaryOperator : struct, IUnaryOperator
{
if (x.Length > destination.Length)
{
Expand Down Expand Up @@ -203,7 +203,7 @@ private static void InvokeSpanIntoSpan<TUnaryOperator>(

private static void InvokeSpanSpanIntoSpan<TBinaryOperator>(
ReadOnlySpan<float> x, ReadOnlySpan<float> y, Span<float> destination, TBinaryOperator op = default)
where TBinaryOperator : IBinaryOperator
where TBinaryOperator : struct, IBinaryOperator
{
if (x.Length != y.Length)
{
Expand Down Expand Up @@ -258,7 +258,7 @@ private static void InvokeSpanSpanIntoSpan<TBinaryOperator>(

private static void InvokeSpanScalarIntoSpan<TBinaryOperator>(
ReadOnlySpan<float> x, float y, Span<float> destination, TBinaryOperator op = default)
where TBinaryOperator : IBinaryOperator
where TBinaryOperator : struct, IBinaryOperator
{
if (x.Length > destination.Length)
{
Expand Down Expand Up @@ -309,7 +309,7 @@ private static void InvokeSpanScalarIntoSpan<TBinaryOperator>(

private static void InvokeSpanSpanSpanIntoSpan<TTernaryOperator>(
ReadOnlySpan<float> x, ReadOnlySpan<float> y, ReadOnlySpan<float> z, Span<float> destination, TTernaryOperator op = default)
where TTernaryOperator : ITernaryOperator
where TTernaryOperator : struct, ITernaryOperator
{
if (x.Length != y.Length || x.Length != z.Length)
{
Expand Down Expand Up @@ -369,7 +369,7 @@ private static void InvokeSpanSpanSpanIntoSpan<TTernaryOperator>(

private static void InvokeSpanSpanScalarIntoSpan<TTernaryOperator>(
ReadOnlySpan<float> x, ReadOnlySpan<float> y, float z, Span<float> destination, TTernaryOperator op = default)
where TTernaryOperator : ITernaryOperator
where TTernaryOperator : struct, ITernaryOperator
{
if (x.Length != y.Length)
{
Expand Down Expand Up @@ -430,7 +430,7 @@ private static void InvokeSpanSpanScalarIntoSpan<TTernaryOperator>(

private static void InvokeSpanScalarSpanIntoSpan<TTernaryOperator>(
ReadOnlySpan<float> x, float y, ReadOnlySpan<float> z, Span<float> destination, TTernaryOperator op = default)
where TTernaryOperator : ITernaryOperator
where TTernaryOperator : struct, ITernaryOperator
{
if (x.Length != z.Length)
{
Expand Down

0 comments on commit 575843d

Please sign in to comment.