Skip to content

Commit

Permalink
Fix downlevel build break in TensorPrimitives (dotnet#92269)
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

* Add net6.0 and net7.0 to Tensors temporarily since those are shipping in 8.0 branch

* Only build net6.0 and net7.0 Tensors when not in source-build

---------

Co-authored-by: Eric StJohn <[email protected]>
  • Loading branch information
stephentoub and ericstj authored Sep 20, 2023
1 parent e8c3052 commit 32c3355
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppPrevious);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<TargetFrameworks Condition="'$(DotNetBuildFromSource)' != 'true'">$(TargetFrameworks);net7.0;net6.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<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 @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppPrevious);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<TargetFrameworks Condition="'$(DotNetBuildFromSource)' != 'true'">$(TargetFrameworks);net7.0;net6.0</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<IsPackable>true</IsPackable>
<PackageDescription>Provides support for operating over tensors.</PackageDescription>
Expand All @@ -16,11 +17,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 32c3355

Please sign in to comment.