back to matrix
This commit is contained in:
@@ -49,36 +49,16 @@ namespace StgSharp.Mathematics.Numeric
|
||||
|
||||
private static CapacityFixedStack<MatrixParallelThread> _threads;
|
||||
|
||||
private static ConcurrentDictionary<SIMDID, nint> contextMap;
|
||||
|
||||
private static SlabAllocator<IntrinsicContext> contextAllocator;
|
||||
|
||||
public static bool IsParallelSupported { get; } = Environment.ProcessorCount > 6;
|
||||
|
||||
public static bool IsParallelMeaningful => Environment.ProcessorCount > 6 && IsInitialized;
|
||||
public static bool IsParallelMeaningful => (Environment.ProcessorCount > 6) && IsInitialized;
|
||||
|
||||
private static bool IsInitialized { get; set; } = false;
|
||||
|
||||
internal static unsafe IntrinsicContext* GetContext(
|
||||
SIMDID simd
|
||||
)
|
||||
{
|
||||
if (!IsParallelSupported) {
|
||||
return null;
|
||||
}
|
||||
if (contextMap.TryGetValue(simd, out nint handle))
|
||||
{
|
||||
return (IntrinsicContext*)handle;
|
||||
} else
|
||||
{
|
||||
IntrinsicContext* context = (IntrinsicContext*)contextAllocator.Allocate();
|
||||
|
||||
return context;
|
||||
}
|
||||
}
|
||||
private static bool IsInitialized { get; set; }
|
||||
|
||||
internal static void Init()
|
||||
{
|
||||
Dictionary<SIMDID, int> contextMap = [];
|
||||
|
||||
if (IsInitialized) {
|
||||
return;
|
||||
}
|
||||
@@ -87,16 +67,15 @@ namespace StgSharp.Mathematics.Numeric
|
||||
IsInitialized = true;
|
||||
return;
|
||||
}
|
||||
MatrixParallelFactory.Init();
|
||||
contextAllocator = SlabAllocator.Create<IntrinsicContext>(4, SlabBufferLayout.Chunked, false);
|
||||
contextMap = [];
|
||||
int count = Environment.ProcessorCount;
|
||||
_threads = new(count);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
MatrixParallelThread thread = new MatrixParallelThread(i);
|
||||
MatrixParallelThread thread = new(i);
|
||||
_threads.Push(thread);
|
||||
SpinWait.SpinUntil(() => thread.State == MatrixThreadState.Ready);
|
||||
var index = (IsParallelSupported && contextMap.TryGetValue(simd, out int index)) ? index : (-1);
|
||||
}
|
||||
|
||||
// TODO 构建全局的保底上下文
|
||||
|
||||
Reference in New Issue
Block a user