working on per-PoolThread context loading and global context loading

This commit is contained in:
Youmu Liu
2026-02-24 18:05:16 +08:00
parent d62e59cb93
commit 7ee9c749e5
12 changed files with 535 additions and 305 deletions
+8 -20
View File
@@ -26,6 +26,8 @@
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using StgSharp.Collections;
using StgSharp.HighPerformance.Memory;
using StgSharp.Internal.Intrinsic;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -41,45 +43,31 @@ namespace StgSharp.Mathematics.Numeric
private static CapacityFixedStack<MatrixParallelThread> _threads;
private static readonly
#if NET10_0_OR_GREATER
Lock
#else
object
#endif
_lock = new();
private static SlabAllocator<IntrinsicContext> contextAllocator;
// private static ThreadPriority _AfterWork = ThreadPriority.Lowest;
public static bool SupportParallel { get; } = Environment.ProcessorCount > 6;
public static bool IsParallelSupported { get; } = Environment.ProcessorCount > 6;
public static bool IsParallelMeaningful => Environment.ProcessorCount > 6 && IsInitialized;
private static bool IsInitialized { get; set; } = false;
private static Queue<IntPtr> LeaderTask { get; set; }
public static void EndParallel()
{
Monitor.Exit(_lock);
}
internal static void Init()
{
if (IsInitialized) {
return;
}
MatrixParallelFactory.Init();
if (!SupportParallel)
if (!IsParallelSupported)
{
IsInitialized = true;
return;
}
MatrixParallelFactory.Init();
contextAllocator = SlabAllocator<IntrinsicContext>.Create(4, SlabBufferLayout.Chunked, false);
int count = Environment.ProcessorCount - 4;
_threads = new(count);
for (int i = 0; i < count; i++)
{
MatrixParallelThread thread = new MatrixParallelThread();
MatrixParallelThread thread = new MatrixParallelThread(i);
_threads.Push(thread);
}
_awaitingLeaderHandle = new AwaitingQueue();