Daily update on 20250921-173333 by Nitload Youmu. Additional Message : New design of matrix enumeration, capable for parallel task publication.

Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
Nitload
2025-09-21 17:33:33 +08:00
parent 0404ecf044
commit b8a51c13dd
15 changed files with 463 additions and 304 deletions
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="MatrixParallel.TaskWrapFactory.cs"
// file="MatrixParallel.TaskFactory.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
@@ -33,6 +33,7 @@ using StgSharp.HighPerformance.Memory;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
@@ -57,13 +58,13 @@ namespace StgSharp.Mathematics
private static SlabAllocator<ScalarPacket> _scalarAllocator ;
private static SlabAllocator<MatrixParallelTaskPackage> _wrapAllocator ;
private static SlabAllocator<MatrixParallelTaskPackageNonGeneric> _wrapAllocator ;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static MatrixParallelTaskPackage* CreateBaseTask()
public static MatrixParallelTaskPackage<T>* CreateBaseTask<T>() where T: unmanaged, INumber<T>
{
MatrixParallelTaskPackage* p = (MatrixParallelTaskPackage*)_wrapAllocator.Allocate();
Span<byte> s = new Span<byte>((byte*)p, sizeof(MatrixParallelTaskPackage));
MatrixParallelTaskPackage<T>* p = (MatrixParallelTaskPackage<T>*)_wrapAllocator.Allocate();
Span<byte> s = new Span<byte>((byte*)p, sizeof(MatrixParallelTaskPackage<T>));
s.Fill(0);
return p;
}
@@ -75,10 +76,10 @@ namespace StgSharp.Mathematics
return p;
}
<<<<<<< HEAD:StgSharp.Common/Mathematics/Linear/MatrixParallel.TaskWrapFactory.cs
public static MatrixParallelTaskPackage* FromTaskWrap(MatrixParallelTaskPackage* source, int offset)
public static MatrixParallelTaskPackage<T>* FromTaskWrap<T>(MatrixParallelTaskPackage<T>* source, int offset)
where T: unmanaged, INumber<T>
{
MatrixParallelTaskPackage* p = (MatrixParallelTaskPackage*)_wrapAllocator.Allocate();
MatrixParallelTaskPackage<T>* p = (MatrixParallelTaskPackage<T>*)_wrapAllocator.Allocate();
/*
*p = *source;
p->Left += offset * p->LeftStride;
@@ -88,16 +89,24 @@ namespace StgSharp.Mathematics
return p;
}
=======
[MethodImpl(MethodImplOptions.AggressiveInlining)]
>>>>>>> 8007eee8461498a85a9515e8fd076f03cb552b64:StgSharp.Common/Mathematics/Linear/MatrixParallel.TaskFactory.cs
public static void Release(ScalarPacket* source)
{
_scalarAllocator.Free((nuint)source);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Release(MatrixParallelTaskPackage* source)
public static void Release(MatrixParallelTaskPackageNonGeneric* source)
{
if (source->Scalar != null) {
_scalarAllocator.Free((nuint)source->Scalar);
}
_wrapAllocator.Free((nuint)source);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Release<T>(MatrixParallelTaskPackage<T>* source) where T: unmanaged, INumber<T>
{
if (source->Scalar != null) {
_scalarAllocator.Free((nuint)source->Scalar);
@@ -108,40 +117,13 @@ namespace StgSharp.Mathematics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void Init()
{
<<<<<<< HEAD:StgSharp.Common/Mathematics/Linear/MatrixParallel.TaskWrapFactory.cs
int count = group.Length;
group[0] = (nint)source;
int l = source->LeftPrimStride, r = source->RightPrimStride, res = source->ResultPrimStride, c = source->PrimCount / count;
source->LeftPrimStride *= count;
source->RightPrimStride *= count;
source->ResultPrimStride *= count;
source->PrimCount = c;
int remain = source->PrimCount - (c * count);
for (int i = 1; i < count; i++)
if (_intermediateResult is null)
{
nint handle = (nint)_wrapAllocator.Allocate();
MatrixParallelTaskPackage* p = (MatrixParallelTaskPackage*)handle;
*p = *source;
p->Left += l * i;
p->Right += r * i;
p->Result += res * i;
p->PrimCount = c;
group[i] = handle;
_intermediateResult = new hlsfAllocator(64 * 16 * 16);
_scalarAllocator = SlabAllocator<ScalarPacket>.Create(64 * 1024, SlabBufferLayout.Chunked);
_wrapAllocator = SlabAllocator<MatrixParallelTaskPackageNonGeneric>.
Create(128 * 1024, SlabBufferLayout.Chunked);
}
// Distribute remaining work to the last few tasks
for (int i = 0; i < remain; i++)
{
int targetIndex = count - 1 - i;
if (targetIndex >= 0) {
((MatrixParallelTaskPackage*)group[targetIndex])->PrimCount++;
}
}
=======
_scalarAllocator = SlabAllocator<ScalarPacket>.Create(64, SlabBufferLayout.Chunked, true);
_wrapAllocator = SlabAllocator<MatrixParallelTaskPackage>.Create(64, SlabBufferLayout.Chunked, true);
_intermediateResult = new hlsfAllocator((nuint)(sizeof(MatrixKernel) * 64));
>>>>>>> 8007eee8461498a85a9515e8fd076f03cb552b64:StgSharp.Common/Mathematics/Linear/MatrixParallel.TaskFactory.cs
}
}