Skip to content

Commit

Permalink
Add useIntrinsics optional parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmada committed Dec 29, 2023
1 parent 98a9355 commit e39e44d
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/NetFabric.Numerics.Tensors/Apply.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static partial class Tensor
static bool SpansOverlapAndAreNotSame<T>(ReadOnlySpan<T> span1, ReadOnlySpan<T> span2)
=> !Unsafe.AreSame(ref MemoryMarshal.GetReference(span1), ref MemoryMarshal.GetReference(span2)) && span1.Overlaps(span2);

public static void Apply<T, TOperator>(ReadOnlySpan<T> x, Span<T> destination)
public static void Apply<T, TOperator>(ReadOnlySpan<T> x, Span<T> destination, bool useIntrinsics = true)

Check warning on line 14 in src/NetFabric.Numerics.Tensors/Apply.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'Tensor.Apply<T, TOperator>(ReadOnlySpan<T>, Span<T>, bool)'
where T : struct
where TOperator : struct, IUnaryOperator<T>
{
Expand All @@ -25,7 +25,8 @@ public static void Apply<T, TOperator>(ReadOnlySpan<T> x, Span<T> destination)

// Check if hardware acceleration and Vector<T> support are available,
// and if the length of the x is greater than the Vector<T>.Count.
if (Vector.IsHardwareAccelerated &&
if (useIntrinsics &&
Vector.IsHardwareAccelerated &&
Vector<T>.IsSupported &&
x.Length >= Vector<T>.Count)
{
Expand Down Expand Up @@ -56,7 +57,7 @@ public static void Apply<T, TOperator>(ReadOnlySpan<T> x, Span<T> destination)
}
}

public static void Apply<T, TOperator>(ReadOnlySpan<T> x, ReadOnlySpan<T> y, Span<T> destination)
public static void Apply<T, TOperator>(ReadOnlySpan<T> x, ReadOnlySpan<T> y, Span<T> destination, bool useIntrinsics = true)

Check warning on line 60 in src/NetFabric.Numerics.Tensors/Apply.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'Tensor.Apply<T, TOperator>(ReadOnlySpan<T>, ReadOnlySpan<T>, Span<T>, bool)'
where T : struct
where TOperator : struct, IBinaryOperator<T>
{
Expand All @@ -74,7 +75,8 @@ public static void Apply<T, TOperator>(ReadOnlySpan<T> x, ReadOnlySpan<T> y, Spa

// Check if hardware acceleration and Vector<T> support are available,
// and if the length of the x is greater than the Vector<T>.Count.
if (Vector.IsHardwareAccelerated &&
if (useIntrinsics &&
Vector.IsHardwareAccelerated &&
Vector<T>.IsSupported &&
x.Length >= Vector<T>.Count)
{
Expand Down Expand Up @@ -110,7 +112,7 @@ public static void Apply<T, TOperator>(ReadOnlySpan<T> x, ReadOnlySpan<T> y, Spa
}
}

public static void Apply<T, TOperator>(ReadOnlySpan<T> x, T y, Span<T> destination)
public static void Apply<T, TOperator>(ReadOnlySpan<T> x, T y, Span<T> destination, bool useIntrinsics = true)

Check warning on line 115 in src/NetFabric.Numerics.Tensors/Apply.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'Tensor.Apply<T, TOperator>(ReadOnlySpan<T>, T, Span<T>, bool)'
where T : struct
where TOperator : struct, IBinaryOperator<T>
{
Expand All @@ -124,7 +126,8 @@ public static void Apply<T, TOperator>(ReadOnlySpan<T> x, T y, Span<T> destinati

// Check if hardware acceleration and Vector<T> support are available,
// and if the length of the x is greater than the Vector<T>.Count.
if (Vector.IsHardwareAccelerated &&
if (useIntrinsics &&
Vector.IsHardwareAccelerated &&
Vector<T>.IsSupported &&
x.Length >= Vector<T>.Count)
{
Expand Down Expand Up @@ -158,7 +161,7 @@ public static void Apply<T, TOperator>(ReadOnlySpan<T> x, T y, Span<T> destinati
}
}

public static void Apply<T, TOperator>(ReadOnlySpan<T> x, ReadOnlySpan<T> y, ReadOnlySpan<T> z, Span<T> destination)
public static void Apply<T, TOperator>(ReadOnlySpan<T> x, ReadOnlySpan<T> y, ReadOnlySpan<T> z, Span<T> destination, bool useIntrinsics = true)
where T : struct
where TOperator : struct, ITernaryOperator<T>
{
Expand All @@ -178,7 +181,8 @@ public static void Apply<T, TOperator>(ReadOnlySpan<T> x, ReadOnlySpan<T> y, Rea

// Check if hardware acceleration and Vector<T> support are available,
// and if the length of the x is greater than the Vector<T>.Count.
if (Vector.IsHardwareAccelerated &&
if (useIntrinsics &&
Vector.IsHardwareAccelerated &&
Vector<T>.IsSupported &&
x.Length >= Vector<T>.Count)
{
Expand Down Expand Up @@ -219,7 +223,7 @@ public static void Apply<T, TOperator>(ReadOnlySpan<T> x, ReadOnlySpan<T> y, Rea
}
}

public static void Apply<T, TOperator>(ReadOnlySpan<T> x, T y, ReadOnlySpan<T> z, Span<T> destination)
public static void Apply<T, TOperator>(ReadOnlySpan<T> x, T y, ReadOnlySpan<T> z, Span<T> destination, bool useIntrinsics = true)
where T : struct
where TOperator : struct, ITernaryOperator<T>
{
Expand All @@ -237,7 +241,8 @@ public static void Apply<T, TOperator>(ReadOnlySpan<T> x, T y, ReadOnlySpan<T> z

// Check if hardware acceleration and Vector<T> support are available,
// and if the length of the x is greater than the Vector<T>.Count.
if (Vector.IsHardwareAccelerated &&
if (useIntrinsics &&
Vector.IsHardwareAccelerated &&
Vector<T>.IsSupported &&
x.Length >= Vector<T>.Count)
{
Expand Down Expand Up @@ -276,7 +281,7 @@ public static void Apply<T, TOperator>(ReadOnlySpan<T> x, T y, ReadOnlySpan<T> z
}
}

public static void Apply<T, TOperator>(ReadOnlySpan<T> x, ReadOnlySpan<T> y, T z, Span<T> destination)
public static void Apply<T, TOperator>(ReadOnlySpan<T> x, ReadOnlySpan<T> y, T z, Span<T> destination, bool useIntrinsics = true)
where T : struct
where TOperator : struct, ITernaryOperator<T>
{
Expand All @@ -294,7 +299,8 @@ public static void Apply<T, TOperator>(ReadOnlySpan<T> x, ReadOnlySpan<T> y, T z

// Check if hardware acceleration and Vector<T> support are available,
// and if the length of the x is greater than the Vector<T>.Count.
if (Vector.IsHardwareAccelerated &&
if (useIntrinsics &&
Vector.IsHardwareAccelerated &&
Vector<T>.IsSupported &&
x.Length >= Vector<T>.Count)
{
Expand Down Expand Up @@ -333,7 +339,7 @@ public static void Apply<T, TOperator>(ReadOnlySpan<T> x, ReadOnlySpan<T> y, T z
}
}

public static void Apply<T, TOperator>(ReadOnlySpan<T> x, T y, T z, Span<T> destination)
public static void Apply<T, TOperator>(ReadOnlySpan<T> x, T y, T z, Span<T> destination, bool useIntrinsics = true)
where T : struct
where TOperator : struct, ITernaryOperator<T>
{
Expand All @@ -347,7 +353,8 @@ public static void Apply<T, TOperator>(ReadOnlySpan<T> x, T y, T z, Span<T> dest

// Check if hardware acceleration and Vector<T> support are available,
// and if the length of the x is greater than the Vector<T>.Count.
if (Vector.IsHardwareAccelerated &&
if (useIntrinsics &&
Vector.IsHardwareAccelerated &&
Vector<T>.IsSupported &&
x.Length >= Vector<T>.Count)
{
Expand Down

0 comments on commit e39e44d

Please sign in to comment.