remove branch conflict
This commit is contained in:
@@ -1,12 +1,4 @@
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
//-----------------------------------------------------------------------
|
||||
=======
|
||||
//-----------------------------------------------------------------------
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
=======
|
||||
//-----------------------------------------------------------------------
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
// -----------------------------------------------------------------------
|
||||
// file="MatrixKernel"
|
||||
// Project: StgSharp
|
||||
@@ -40,10 +32,6 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.HighPerformance
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
public unsafe struct MatrixKernel
|
||||
{
|
||||
|
||||
@@ -51,20 +39,9 @@ namespace StgSharp.HighPerformance
|
||||
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
[InlineArray(16)]
|
||||
public unsafe struct MatrixKernel<T> where T : unmanaged, INumber<T>
|
||||
=======
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
[InlineArray(16)]
|
||||
public unsafe struct MatrixKernel<T> where T: unmanaged, INumber<T>
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
=======
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
[InlineArray(16)]
|
||||
public unsafe struct MatrixKernel<T> where T : unmanaged, INumber<T>
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
{
|
||||
|
||||
private T c0r0;
|
||||
|
||||
@@ -1,12 +1,4 @@
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
//-----------------------------------------------------------------------
|
||||
=======
|
||||
//-----------------------------------------------------------------------
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
=======
|
||||
//-----------------------------------------------------------------------
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
// -----------------------------------------------------------------------
|
||||
// file="MatrixPanel"
|
||||
// Project: StgSharp
|
||||
@@ -33,14 +25,7 @@
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
using StgSharp.Internal;
|
||||
=======
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
=======
|
||||
using StgSharp.Internal;
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
@@ -48,8 +33,6 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.HighPerformance
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
public unsafe struct MatrixPanel
|
||||
{
|
||||
|
||||
@@ -178,308 +161,3 @@ namespace StgSharp.HighPerformance
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
=======
|
||||
#pragma warning disable CA1000
|
||||
|
||||
public interface IMatrixPanel<T> : IDisposable where T : unmanaged,INumber<T>
|
||||
=======
|
||||
public unsafe struct MatrixPanel
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
{
|
||||
|
||||
public const int AlignmentBytes = 64;
|
||||
|
||||
private byte Head;
|
||||
|
||||
// Allocate aligned memory for one panel; caller must free via Destroy.
|
||||
public static unsafe MatrixPanel<T>* Create<T>() where T : unmanaged, INumber<T>
|
||||
{
|
||||
return (MatrixPanel<T>*)NativeMemory.AlignedAlloc(Size<T>(), AlignmentBytes);
|
||||
}
|
||||
|
||||
public static unsafe void Destroy<T>(MatrixPanel<T>* panel) where T : unmanaged, INumber<T>
|
||||
{
|
||||
NativeMemory.AlignedFree(panel);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe Span<T> Elements<T>(ref T head) where T : unmanaged, INumber<T>
|
||||
{
|
||||
void* p = Unsafe.AsPointer(ref head);
|
||||
return new Span<T>(p, MaxElementCount<T>());
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int ElementSideLength<T>() where T : unmanaged, INumber<T>
|
||||
{
|
||||
return Math.Max(8, AlignmentBytes / sizeof(T));
|
||||
}
|
||||
|
||||
// View an existing pointer; caller guarantees lifetime/alignment.
|
||||
public static unsafe MatrixPanel<T>* FromPointer<T>(void* ptr)
|
||||
where T : unmanaged, INumber<T>
|
||||
{
|
||||
return (MatrixPanel<T>*)Align64(ptr);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int MaxElementCount<T>() where T : unmanaged, INumber<T>
|
||||
{
|
||||
int side = ElementSideLength<T>();
|
||||
return side * side;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static nuint Size<T>() where T : unmanaged, INumber<T>
|
||||
{
|
||||
return (nuint)(MaxElementCount<T>() * sizeof(T));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Number of 4x4 kernels that fit in a panel for the given ISA and element T.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static int KernelCapacity<T>() where T : unmanaged, INumber<T>
|
||||
{
|
||||
int perSide = KernelSideCount<T>();
|
||||
return perSide * perSide;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// How many 4x4 kernels fit along a single panel dimension for the given ISA.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static int KernelSideCount<T>() where T : unmanaged, INumber<T>
|
||||
{
|
||||
return NativeIntrinsic.IntrinsicLevel switch
|
||||
{
|
||||
IntrinsicLevel.SSE => KernelSideCountSse<T>(),
|
||||
IntrinsicLevel.AVX2 => KernelSideCountAvx2<T>(),
|
||||
IntrinsicLevel.AVX512 => KernelSideCountAvx512<T>(),
|
||||
_ => 0
|
||||
};
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static unsafe nuint Align64(void* p) => ((nuint)p + (AlignmentBytes - 1)) & ~(nuint)(AlignmentBytes - 1);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static int KernelSideCountAvx2<T>() where T : unmanaged, INumber<T>
|
||||
{
|
||||
const int minQ = 8;
|
||||
int lanes = 32 / sizeof(T);
|
||||
int side = Math.Max(lanes, minQ);
|
||||
return side / 4;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static int KernelSideCountAvx512<T>() where T : unmanaged, INumber<T>
|
||||
{
|
||||
const int minQ = 8;
|
||||
int lanes = 64 / sizeof(T);
|
||||
int side = Math.Max(lanes, minQ);
|
||||
return side / 4;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static int KernelSideCountSse<T>() where T : unmanaged, INumber<T>
|
||||
{
|
||||
const int minQ = 4;
|
||||
int lanes = 16 / sizeof(T);
|
||||
int side = Math.Max(lanes, minQ);
|
||||
return side / 4;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Single POD-style panel: ZMM-compatible size. Alignment handled by allocator, not by the struct.
|
||||
public unsafe struct MatrixPanel<T> where T : unmanaged, INumber<T>
|
||||
{
|
||||
|
||||
internal T Head; // first element of the panel buffer
|
||||
|
||||
public ref T this[int column, int row]
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => ref Unsafe.Add(ref Head, row * MatrixPanel.ElementSideLength<T>() + column);
|
||||
}
|
||||
|
||||
public Span<T> Elements
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => MatrixPanel.Elements(ref Head);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
/// <summary>
|
||||
/// Buffer for AVX targeted matrix panel, size of a panel is 4x4 elements, and no smaller than
|
||||
/// 16 bytes.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">
|
||||
/// Type of matrix element.
|
||||
/// </typeparam>
|
||||
public unsafe struct MatrixPanelAVX<T> : IMatrixPanel<T> where T : unmanaged, INumber<T>
|
||||
{
|
||||
|
||||
private T element;
|
||||
|
||||
[Obsolete("Compute kernel should not be created from new(), use Create instead", true)]
|
||||
public MatrixPanelAVX() { }
|
||||
|
||||
public ref T this[int column, int row]
|
||||
{
|
||||
get
|
||||
{
|
||||
int index = row * ElementSideLength + column;
|
||||
return ref Unsafe.Add(ref element, index);
|
||||
}
|
||||
}
|
||||
|
||||
public static int ElementSideLength
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get;
|
||||
} = int.Max(8, 32 / sizeof(T));
|
||||
|
||||
public static unsafe int MaxElementCount
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get;
|
||||
} = ElementSideLength * ElementSideLength;
|
||||
|
||||
public static unsafe nuint Size { get; } = (nuint)(MaxElementCount * sizeof(T));
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int ChunkCount() => (ElementSideLength + LanesPerVector() - 1) / LanesPerVector();
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static MatrixPanelAVX<T>* Create()
|
||||
{
|
||||
MatrixPanelAVX<T>* kernel = (MatrixPanelAVX<T>*)NativeMemory.AlignedAlloc(Size, 32);
|
||||
return kernel;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Destroy(MatrixPanelAVX<T>* kernel)
|
||||
{
|
||||
NativeMemory.AlignedFree(kernel);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
fixed (MatrixPanelAVX<T>* thisPtr = &this) {
|
||||
NativeMemory.AlignedFree(thisPtr);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public ref M256 GetVectorChunk(int column, int chunk)
|
||||
{
|
||||
int lanes = LanesPerVector();
|
||||
int rowStart = chunk * lanes;
|
||||
ref T colBase = ref this[column, 0];
|
||||
return ref Unsafe.As<T, M256>(ref Unsafe.Add(ref colBase, rowStart));
|
||||
}
|
||||
|
||||
// SIMD access helpers for AVX (column-major)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int LanesPerVector() => 32 / sizeof(T);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetVectorChunk(int column, int chunk, in M256 value)
|
||||
{
|
||||
GetVectorChunk(column, chunk) = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Buffer for AVX512 targeted matrix panel, size of a panel is 4x4 elements, and no smaller
|
||||
/// than 16 bytes.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">
|
||||
/// Type of matrix element.
|
||||
/// </typeparam>
|
||||
public unsafe struct MatrixComputeKernelAVX512<T> : IMatrixPanel<T>
|
||||
where T : unmanaged, INumber<T>
|
||||
{
|
||||
|
||||
private T element;
|
||||
|
||||
[Obsolete("Compute kernel should not be created from new(), use Create instead", true)]
|
||||
public MatrixComputeKernelAVX512() { }
|
||||
|
||||
public ref T this[int column, int row]
|
||||
{
|
||||
get
|
||||
{
|
||||
int index = row * ElementSideLength + column;
|
||||
return ref Unsafe.Add(ref element, index);
|
||||
}
|
||||
}
|
||||
|
||||
public static int ElementSideLength
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get;
|
||||
} = int.Max(8, 64 / sizeof(T));
|
||||
|
||||
public static unsafe int MaxElementCount
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get;
|
||||
} = ElementSideLength * ElementSideLength;
|
||||
|
||||
public static unsafe nuint Size { get; } = (nuint)(MaxElementCount * sizeof(T));
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int ChunkCount() => (ElementSideLength + LanesPerVector() - 1) / LanesPerVector();
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static MatrixComputeKernelAVX512<T>* Create()
|
||||
{
|
||||
MatrixComputeKernelAVX512<T>* kernel = (MatrixComputeKernelAVX512<T>*)NativeMemory.AlignedAlloc(Size, 64);
|
||||
return kernel;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Destroy(MatrixComputeKernelAVX512<T>* kernel)
|
||||
{
|
||||
NativeMemory.AlignedFree(kernel);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
fixed (MatrixComputeKernelAVX512<T>* thisPtr = &this) {
|
||||
NativeMemory.AlignedFree(thisPtr);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public ref M512 GetVectorChunk(int column, int chunk)
|
||||
{
|
||||
int lanes = LanesPerVector();
|
||||
int rowStart = chunk * lanes;
|
||||
ref T colBase = ref this[column, 0];
|
||||
return ref Unsafe.As<T, M512>(ref Unsafe.Add(ref colBase, rowStart));
|
||||
}
|
||||
|
||||
// SIMD access helpers for AVX-512 (column-major)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int LanesPerVector() => 64 / sizeof(T);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetVectorChunk(int column, int chunk, in M512 value)
|
||||
{
|
||||
GetVectorChunk(column, chunk) = value;
|
||||
}
|
||||
#pragma warning restore CA1000
|
||||
}
|
||||
}
|
||||
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
|
||||
=======
|
||||
>>>>>>> stgsharp-dev/giga
|
||||
|
||||
Reference in New Issue
Block a user