merge main branch

This commit is contained in:
Nitload
2025-12-16 23:16:57 +08:00
276 changed files with 53498 additions and 0 deletions
@@ -0,0 +1,98 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="IRegisterType"
// Project: StgSharp
// AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.HighPerformance
{
/// <summary>
/// Abstraction for a wide SIMD register or equivalent packed numeric storage. Provides raw
/// reference access, broadcast initialization and element level access. Typical
/// implementations map to 128/256/512-bit hardware registers or software emulated blocks.
/// </summary>
public interface IRegisterPresentation
{
/// <summary>
/// Gets a reference to the first element of the register reinterpreted as type <typeparamref
/// name="T" />.
/// </summary>
/// <typeparam name="T">
/// Unmanaged numeric element type implementing <see cref="INumber{T}" />.
/// </typeparam>
/// <returns>
/// Writable reference to element 0 (lowest lane / lowest bits).
/// </returns>
/// <remarks>
/// Intended for treating the register as a contiguous block of elements. The returned reference
/// must remain valid for the lifetime of the register and be identical to <see
/// cref="Member{T}(int)" /> with index 0. Caller must choose a type layout compatible with the
/// actual register representation.
/// </remarks>
ref T AsRef<T>() where T: unmanaged, INumber<T>;
/// <summary>
/// Fills all elements (lanes) of the register with the provided scalar <paramref name="value" />.
/// </summary>
/// <typeparam name="T">
/// Unmanaged numeric element type implementing <see cref="INumber{T}" />.
/// </typeparam>
/// <param name="value">
/// Scalar value to replicate to every element.
/// </param>
/// <remarks>
/// Should map to a single broadcast/shuffle instruction where possible. After completion all
/// lanes read back the same value.
/// </remarks>
void BroadCastFrom<T>(T value) where T: unmanaged, INumber<T>;
/// <summary>
/// Gets a writable reference to the element at the specified <paramref name="index" />.
/// </summary>
/// <typeparam name="T">
/// Unmanaged numeric element type implementing <see cref="INumber{T}" />.
/// </typeparam>
/// <param name="index">
/// Zero-based lane index (range defined by implementation).
/// </param>
/// <returns>
/// Writable reference to the lane.
/// </returns>
/// <remarks>
/// Enables scalar lane edits without unpacking the entire register. Implementations may omit
/// bounds checks for performance. Caller is responsible for passing a valid index.
/// </remarks>
ref T Member<T>(int index) where T: unmanaged, INumber<T>;
}
}
+68
View File
@@ -0,0 +1,68 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="Lable"
// Project: StgSharp
// AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using System;
using System.Runtime.CompilerServices;
namespace StgSharp.HighPerformance
{
public class DataLabel
{
public DataLabel(string labelName)
{
Name = labelName;
}
public string Name
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
init;
}
public override unsafe int GetHashCode()
{
ReadOnlySpan<char> nameSpan = Name.AsSpan();
fixed (char* cptr = nameSpan) {
return NativeIntrinsic.Intrinsic.city_hash_simplify(cptr, Name.Length);
}
}
}
public static class DataLabelBuilder
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static DataLabel AsLabel(this string name)
{
return new DataLabel(name);
}
}
}
+120
View File
@@ -0,0 +1,120 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="M128"
// Project: StgSharp
// AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;
using System.Text;
namespace StgSharp.HighPerformance
{
[StructLayout(LayoutKind.Explicit, Pack = 16)]
public unsafe struct M128 : IRegisterPresentation
{
[FieldOffset(0)] internal fixed byte Buffer[16];
[FieldOffset(0)] internal Vector128<float> Vec;
internal M128(Vector4 v)
{
Unsafe.SkipInit(out this);
Unsafe.SkipInit(out Vec);
Vec = v.AsVector128();
}
internal M128(Vector128<float> v)
{
Unsafe.SkipInit(out this);
Vec = v;
}
public ref T AsRef<T>() where T : unmanaged, INumber<T>
{
return ref Unsafe.As<byte, T>(ref Buffer[0]);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly Vector4 AsVector4()
{
return Vec.AsVector4();
}
public void BroadCastFrom<T>(T value) where T : unmanaged, INumber<T>
{
Vec = Vector128.Create<T>(value).AsSingle();
}
public override readonly bool Equals([NotNullWhen(true)] object obj)
{
return obj is M128 other && this == other;
}
public override readonly int GetHashCode()
{
return Vec.GetHashCode();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref T Member<T>(int index) where T : unmanaged, INumber<T>
{
return ref Unsafe.Add(ref AsRef<T>(), index);
}
public override string ToString()
{
return string.Empty;
}
public string ToString(int sample)
{
string str = string.Empty;
for (int i = 15; i >= 0; i--) {
str += $"{Convert.ToString(Buffer[i], sample)} ";
}
return str;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(M128 left, M128 right)
{
return left.Vec != right.Vec;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(M128 left, M128 right)
{
return left.Vec == right.Vec;
}
}
}
+65
View File
@@ -0,0 +1,65 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="M256"
// Project: StgSharp
// AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.HighPerformance
{
[StructLayout(LayoutKind.Explicit, Pack = 16)]
public unsafe struct M256 : IRegisterPresentation
{
[FieldOffset(0)] internal fixed byte Buffer[32];
[FieldOffset(0)] internal Vector256<float> Vec;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref T AsRef<T>() where T: unmanaged, INumber<T>
{
return ref Unsafe.As<byte, T>(ref Buffer[0]);
}
public void BroadCastFrom<T>(T value) where T: unmanaged, INumber<T>
{
Vec = Vector256.Create(value).AsSingle();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref T Member<T>(int index) where T: unmanaged, INumber<T>
{
return ref Unsafe.Add(ref AsRef<T>(), index);
}
}
}
+100
View File
@@ -0,0 +1,100 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="M64"
// Project: StgSharp
// AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics;
namespace StgSharp.HighPerformance
{
[StructLayout(LayoutKind.Explicit, Pack = 8)]
public unsafe struct M64 : IRegisterPresentation
{
[FieldOffset(0)] private fixed byte buffer[8];
[FieldOffset(0)] private ulong value;
[FieldOffset(0)] private Vector64<float> vec;
public M64()
{
Unsafe.SkipInit(out this);
Unsafe.SkipInit(out vec);
Unsafe.SkipInit(out value);
}
public ref T AsRef<T>() where T : unmanaged,INumber<T>
{
return ref Unsafe.As<byte, T>(ref buffer[0]);
}
public void BroadCastFrom<T>(T value) where T : unmanaged, INumber<T>
{
vec = Vector64.Create(value).AsSingle();
}
public override bool Equals(object obj)
{
return obj is M64 m64 && this == m64;
}
public override readonly int GetHashCode()
{
return value.GetHashCode();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref T Member<T>(int index) where T : unmanaged, INumber<T>
{
return ref Unsafe.As<byte, T>(ref buffer[index * sizeof(T)]);
}
public static bool operator !=(M64 left, M64 right)
{
return !(left == right);
}
public static M64 operator <<(M64 value, int shift)
{
M64 result = new M64();
result.value = value.value << shift;
return result;
}
public static bool operator ==(M64 left, M64 right)
{
return left.value == right.value;
}
public static M64 operator >>(M64 value, int shift)
{
M64 result = new M64();
result.value = value.value << shift;
return result;
}
}
}
@@ -1,4 +1,8 @@
<<<<<<< HEAD
//-----------------------------------------------------------------------
=======
//-----------------------------------------------------------------------
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
// -----------------------------------------------------------------------
// file="MatrixKernel"
// Project: StgSharp
@@ -32,6 +36,7 @@ using System.Runtime.InteropServices;
namespace StgSharp.HighPerformance
{
<<<<<<< HEAD
public unsafe struct MatrixKernel
{
@@ -42,6 +47,11 @@ namespace StgSharp.HighPerformance
[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
{
private T c0r0;
@@ -1,4 +1,8 @@
<<<<<<< HEAD
//-----------------------------------------------------------------------
=======
//-----------------------------------------------------------------------
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
// -----------------------------------------------------------------------
// file="MatrixPanel"
// Project: StgSharp
@@ -25,7 +29,10 @@
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
<<<<<<< HEAD
using StgSharp.Internal;
=======
>>>>>>> 7bcb460a3994dda40f24cae0044b5a36f4f16515
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
@@ -33,6 +40,7 @@ using System.Runtime.InteropServices;
namespace StgSharp.HighPerformance
{
<<<<<<< HEAD
public unsafe struct MatrixPanel
{
@@ -162,3 +170,269 @@ namespace StgSharp.HighPerformance
}
}
=======
#pragma warning disable CA1000
public interface IMatrixPanel<T> : IDisposable where T : unmanaged,INumber<T>
{
ref T this[int column, int row] { get; }
static abstract int MaxElementCount { get; }
static abstract int ElementSideLength { get; }
static abstract nuint Size { get; }
void Dispose();
}
/// <summary>
/// Buffer for SSE 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 MatrixPanelSSE<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 MatrixPanelSSE() { }
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(4, 16 / sizeof(T));
public static 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 MatrixPanelSSE<T>* Create()
{
MatrixPanelSSE<T>* kernel = (MatrixPanelSSE<T>*)NativeMemory.AlignedAlloc(Size, 16);
return kernel;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Destroy(MatrixPanelSSE<T>* kernel)
{
NativeMemory.AlignedFree(kernel);
}
public void Dispose()
{
fixed (MatrixPanelSSE<T>* thisPtr = &this) {
NativeMemory.AlignedFree(thisPtr);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref M128 GetVectorChunk(int column, int chunk)
{
int lanes = LanesPerVector();
int rowStart = chunk * lanes;
ref T colBase = ref this[column, 0];
return ref Unsafe.As<T, M128>(ref Unsafe.Add(ref colBase, rowStart));
}
// SIMD access helpers (column-major)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int LanesPerVector() => 16 / sizeof(T);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetVectorChunk(int column, int chunk, in M128 value)
{
GetVectorChunk(column, chunk) = value;
}
}
/// <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
@@ -0,0 +1,54 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="UnsafeCompute"
// Project: StgSharp
// AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using System.Runtime.CompilerServices;
namespace StgSharp.HighPerformance
{
public static class UnsafeCompute
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe int CityHashSimplify(char* span, int length)
{
return NativeIntrinsic.Intrinsic.city_hash_simplify(span, length);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe int CityHashSimplify(char* span, int begin, int length)
{
return NativeIntrinsic.Intrinsic.city_hash_simplify(span + begin, length);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe int IndexOfCharPair(char* source, int pairValue, int length)
{
return NativeIntrinsic.Intrinsic.index_pair(source, pairValue, length);
}
}
}