Browse Source

Use AVX-512 for byte tensor addition

pull/3161/head
James Jackson-South 3 weeks ago
parent
commit
fb7ed72629
  1. 8
      src/ImageSharp/Common/Helpers/TensorPrimitives.cs

8
src/ImageSharp/Common/Helpers/TensorPrimitives.cs

@ -204,15 +204,15 @@ internal static partial class TensorPrimitives_
ref T yRef = ref MemoryMarshal.GetReference(y); ref T yRef = ref MemoryMarshal.GetReference(y);
ref T destinationRef = ref MemoryMarshal.GetReference(destination); ref T destinationRef = ref MemoryMarshal.GetReference(destination);
nuint length = (uint)x.Length; nuint length = (uint)x.Length;
nuint vector512Threshold = Unsafe.SizeOf<T>() == 1 ? (uint)Vector512<T>.Count : 512;
// AVX-512 setup only pays off for larger multi-byte inputs. Byte addition remains on AVX2 because direct // Match the runtime's AVX-512 selection for byte-sized elements once one complete vector is available.
// PNG/WebP measurements show that its higher lane count does not recover the wider dispatch cost. // Wider elements retain the measured crossover point where their 512-bit setup cost becomes worthwhile.
// Each pipeline preloads its final inputs when a tail overlaps so same-start in-place operation remains correct. // Each pipeline preloads its final inputs when a tail overlaps so same-start in-place operation remains correct.
if (TOperator.Vectorizable if (TOperator.Vectorizable
&& Vector512.IsHardwareAccelerated && Vector512.IsHardwareAccelerated
&& Vector512<T>.IsSupported && Vector512<T>.IsSupported
&& Unsafe.SizeOf<T>() > 1 && length >= vector512Threshold)
&& length >= 512)
{ {
InvokeVectorized512<T, TOperator>(ref xRef, ref yRef, ref destinationRef, length); InvokeVectorized512<T, TOperator>(ref xRef, ref yRef, ref destinationRef, length);
return; return;

Loading…
Cancel
Save