small size buffer op ok
This commit is contained in:
@@ -99,9 +99,7 @@ namespace StgSharp.Collections
|
||||
|
||||
public void Push(T item)
|
||||
{
|
||||
_values[++_index] = _index < _values.Length - 1 ?
|
||||
item :
|
||||
throw new InvalidOperationException("Stack is full.");
|
||||
_values[++_index] = _index < _values.Length ? item : throw new InvalidOperationException("Stack is full.");
|
||||
}
|
||||
|
||||
public void PushRange(ReadOnlySpan<T> span)
|
||||
|
||||
@@ -38,7 +38,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.HighPerformance.Memory
|
||||
{
|
||||
internal sealed unsafe class ConcurrentChunkedSlabAllocator<T> : SlabAllocator<T> where T: unmanaged
|
||||
internal sealed unsafe class ConcurrentChunkedSlabAllocator<T> : SlabAllocator<T> where T : unmanaged
|
||||
{
|
||||
|
||||
private readonly BufferExpansionLock _lock = new();
|
||||
|
||||
@@ -30,6 +30,7 @@ using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.Marshalling;
|
||||
|
||||
namespace StgSharp.Internal.Intrinsic
|
||||
{
|
||||
@@ -38,11 +39,11 @@ namespace StgSharp.Internal.Intrinsic
|
||||
{
|
||||
|
||||
public delegate* unmanaged[Cdecl]<char*, int, int> city_hash_simplify;
|
||||
public delegate* unmanaged[Cdecl]<void*, void*, void*, void> f32_add;
|
||||
public delegate* unmanaged[Cdecl]<void*, ScalarPacket*, void> f32_fill;
|
||||
public delegate* unmanaged[Cdecl]<void*, void*, void*, long, void> f32_add;
|
||||
public delegate* unmanaged[Cdecl]<void*, ScalarPacket*,long, void> f32_fill;
|
||||
public delegate* unmanaged[Cdecl]<void*, void*, void*, void> f32_fma;
|
||||
public delegate* unmanaged[Cdecl]<void*, void*, ScalarPacket*, void> f32_scalar_mul;
|
||||
public delegate* unmanaged[Cdecl]<void*, void*, void*, void> f32_sub;
|
||||
public delegate* unmanaged[Cdecl]<void*, void*, ScalarPacket*, long, void> f32_scalar_mul;
|
||||
public delegate* unmanaged[Cdecl]<void*, void*, void*, long, void> f32_sub;
|
||||
public delegate* unmanaged[Cdecl]<void*, void*, void> f32_transpose;
|
||||
public delegate* unmanaged[Cdecl]<int, ulong> factorial_simd;
|
||||
public delegate* unmanaged[Cdecl]<char*, int, int, int> index_pair;
|
||||
|
||||
@@ -212,7 +212,7 @@ namespace StgSharp.Mathematics.Graphic
|
||||
public static unsafe Matrix44 operator -(Matrix44 left, Matrix44 right)
|
||||
{
|
||||
Matrix44 ret = new();
|
||||
NativeIntrinsic.Intrinsic.f32_sub(&left, &right, &ret);
|
||||
NativeIntrinsic.Intrinsic.f32_sub(&left, &right, &ret, 1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -254,7 +254,7 @@ namespace StgSharp.Mathematics.Graphic
|
||||
public static unsafe Matrix44 operator +(Matrix44 left, Matrix44 right)
|
||||
{
|
||||
Matrix44 ret = new();
|
||||
NativeIntrinsic.Intrinsic.f32_add(&left, &right, &ret);
|
||||
NativeIntrinsic.Intrinsic.f32_add(&left, &right, &ret, 1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Mathematics.Numeric
|
||||
{
|
||||
internal unsafe partial class GCMatrix<T> : Matrix<T> where T: unmanaged, INumber<T>
|
||||
internal unsafe partial class GCMatrix<T> : Matrix<T> where T : unmanaged, INumber<T>
|
||||
{
|
||||
|
||||
private readonly MatrixKernel<T>* _buffer;
|
||||
@@ -47,6 +47,8 @@ namespace StgSharp.Mathematics.Numeric
|
||||
{
|
||||
KernelColumnLength = (column + 3) / 4;
|
||||
KernelRowLength = (row + 3) / t_count;
|
||||
ColumnLength = column;
|
||||
RowLength = row;
|
||||
_buffer = (MatrixKernel<T>*)NativeMemory.AlignedAlloc((nuint)(column * row * sizeof(T)), (nuint)World.DefaultSIMDAlignment);
|
||||
}
|
||||
|
||||
@@ -95,7 +97,8 @@ namespace StgSharp.Mathematics.Numeric
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override unsafe MatrixSegmentEnumeration<T> GetColumnEnumeration()
|
||||
{
|
||||
return new MatrixSegmentEnumeration<T>(_buffer, KernelColumnLength, KernelColumnLength * KernelRowLength, 1, KernelColumnLength);
|
||||
return new MatrixSegmentEnumeration<T>(_buffer, KernelColumnLength, KernelColumnLength * KernelRowLength, 1,
|
||||
KernelColumnLength);
|
||||
}
|
||||
|
||||
public override unsafe MatrixSegmentEnumeration<T> GetRowEnumeration()
|
||||
@@ -106,7 +109,9 @@ namespace StgSharp.Mathematics.Numeric
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override unsafe MatrixSegmentEnumeration<T> GetSequentialEnumeration()
|
||||
{
|
||||
return new MatrixSegmentEnumeration<T>(_buffer, KernelRowLength * KernelColumnLength, KernelColumnLength * KernelRowLength, 1, KernelRowLength * KernelColumnLength);
|
||||
return new MatrixSegmentEnumeration<T>(_buffer, KernelRowLength * KernelColumnLength,
|
||||
KernelColumnLength * KernelRowLength, 1,
|
||||
KernelRowLength * KernelColumnLength);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -39,7 +39,7 @@ using hlsfHandle = global::StgSharp.HighPerformance.Memory.HybridLayerSegregated
|
||||
|
||||
namespace StgSharp.Mathematics.Numeric
|
||||
{
|
||||
internal unsafe partial class HlsfMatrix<T> : Matrix<T> where T: unmanaged, INumber<T>
|
||||
internal unsafe partial class HlsfMatrix<T> : Matrix<T> where T : unmanaged, INumber<T>
|
||||
{
|
||||
|
||||
private readonly MatrixKernel<T>* k_buffer;
|
||||
@@ -50,6 +50,8 @@ namespace StgSharp.Mathematics.Numeric
|
||||
{
|
||||
KernelColumnLength = (column + 3) / 4;
|
||||
KernelRowLength = (row + 3) / t_count;
|
||||
ColumnLength = column;
|
||||
RowLength = row;
|
||||
this.handle = allocator.Alloc((uint)(KernelColumnLength * KernelRowLength * sizeof(MatrixKernel<T>)));
|
||||
k_buffer = (MatrixKernel<T>*)handle.Pointer;
|
||||
}
|
||||
@@ -104,18 +106,22 @@ namespace StgSharp.Mathematics.Numeric
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override unsafe MatrixSegmentEnumeration<T> GetColumnEnumeration()
|
||||
{
|
||||
return new MatrixSegmentEnumeration<T>(k_buffer, KernelColumnLength, KernelColumnLength * KernelRowLength, 1, KernelColumnLength);
|
||||
return new MatrixSegmentEnumeration<T>(k_buffer, KernelColumnLength, KernelColumnLength * KernelRowLength,
|
||||
1, KernelColumnLength);
|
||||
}
|
||||
|
||||
public override unsafe MatrixSegmentEnumeration<T> GetRowEnumeration()
|
||||
{
|
||||
return new MatrixSegmentEnumeration<T>(k_buffer, 1, KernelColumnLength, KernelColumnLength, KernelRowLength);
|
||||
return new MatrixSegmentEnumeration<T>(k_buffer, 1, KernelColumnLength, KernelColumnLength,
|
||||
KernelRowLength);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override unsafe MatrixSegmentEnumeration<T> GetSequentialEnumeration()
|
||||
{
|
||||
return new MatrixSegmentEnumeration<T>(k_buffer, KernelRowLength * KernelColumnLength, KernelColumnLength * KernelRowLength, 1, KernelRowLength * KernelColumnLength);
|
||||
return new MatrixSegmentEnumeration<T>(k_buffer, KernelRowLength * KernelColumnLength,
|
||||
KernelColumnLength * KernelRowLength, 1,
|
||||
KernelRowLength * KernelColumnLength);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="NumaBuffer"
|
||||
// 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.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Common.Threading
|
||||
{
|
||||
public unsafe struct NumaBuffer<T> where T : unmanaged
|
||||
{
|
||||
|
||||
public readonly T* Buffers;
|
||||
public readonly int BufferColumnCapacity;
|
||||
public readonly int BufferRowCapacity;
|
||||
|
||||
public int CurrentColumnCount;
|
||||
public int CurrentRowCount;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user