advanced userinterface design

This commit is contained in:
Nitload
2026-04-01 22:20:49 +08:00
parent 24498c2717
commit aa7ece4ed0
42 changed files with 2876 additions and 463 deletions
@@ -2,8 +2,8 @@
// -----------------------------------------------------------------------
// file="MatrixParallel"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
// 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
@@ -29,6 +29,7 @@ using StgSharp.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
namespace StgSharp.Mathematics.Numeric
{
@@ -45,12 +46,28 @@ namespace StgSharp.Mathematics.Numeric
public static bool IsParallelSupported { get; } = Environment.ProcessorCount > 6;
public static bool IsParallelMeaningful => IsParallelSupported && IsInitialized && _meaningful;
public static bool IsParallelMeaningful => IsParallelSupported &&
IsInitialized &&
_meaningful;
public static int ContextCount { get; private set; }
private static bool IsInitialized { get; set; }
internal static void Deinit()
{
foreach (MatrixParallelThread t in _threads)
{
t.Retire();
t.Dispose();
}
foreach (MatrixParallelThread t in _retiredThreads) {
t.Dispose();
}
ContextCount = 0;
IsInitialized = false;
}
internal static void Init()
{
Dictionary<ulong, int> contextMap = [];
@@ -65,8 +82,7 @@ namespace StgSharp.Mathematics.Numeric
}
contextMap = [];
int count = Environment.ProcessorCount;
bool hasGlobalSimd = false;
SIMDID globalSimd = default;
SIMDID globalSimd = new SIMDID(0);
_threads = new(count);
_retiredThreads = new(RESERVED_THREAD_COUNT);
for (int i = 0; i < count; i++)
@@ -77,9 +93,10 @@ namespace StgSharp.Mathematics.Numeric
SIMDID simd = thread.Simd;
ulong mask = simd.Mask;
contextMap[mask] = contextMap.TryGetValue(mask, out int contextCount) ? (contextCount + 1) : 1;
globalSimd = hasGlobalSimd ? UniteSIMDID(globalSimd, simd) : simd;
hasGlobalSimd = true;
contextMap[mask] = contextMap.TryGetValue(mask, out int contextCount) ?
(contextCount + 1) :
1;
globalSimd = (globalSimd.Mask != 0) ? UniteSIMDID(globalSimd, simd) : simd;
}
IntrinsicContext globalContext = new();
@@ -96,7 +113,10 @@ namespace StgSharp.Mathematics.Numeric
} else
{
MatrixParallelThread[] allThreads = _threads.PopRange(_threads.Count);
Array.Sort(allThreads, static(left, right) => CompareSIMDID(left.Simd, right.Simd));
Array.Sort(allThreads, static(
left,
right
) => CompareSIMDID(left.Simd, right.Simd));
int retireCount = Math.Min(RESERVED_THREAD_COUNT, Math.Max(0, allThreads.Length - 1));
for (int i = 0; i < retireCount; i++) {
RetireThread(allThreads[i]);
@@ -111,15 +131,23 @@ namespace StgSharp.Mathematics.Numeric
[LibraryImport(Native.LibName, EntryPoint = "sn_compare_simd")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
[DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)]
private static partial int CompareSIMDID(SIMDID left, SIMDID right);
private static partial int CompareSIMDID(
SIMDID left,
SIMDID right
);
[LibraryImport(Native.LibName, EntryPoint = "load_intrinsic_function")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
[DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)]
private static partial void LoadIntrinsicFunction(IntrinsicContext* context, ulong id);
private static partial void LoadIntrinsicFunction(
IntrinsicContext* context,
ulong id
);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void RetireThread(MatrixParallelThread thread)
private static void RetireThread(
MatrixParallelThread thread
)
{
thread.Retire();
_retiredThreads.Push(thread);
@@ -128,7 +156,10 @@ namespace StgSharp.Mathematics.Numeric
[LibraryImport(Native.LibName, EntryPoint = "sn_get_unite_simd")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
[DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)]
private static partial SIMDID UniteSIMDID(SIMDID left, SIMDID right);
private static partial SIMDID UniteSIMDID(
SIMDID left,
SIMDID right
);
}
}