From 24498c2717bebc21b4ba39dd16cbe22017b332b5 Mon Sep 17 00:00:00 2001 From: Nitload Date: Mon, 30 Mar 2026 01:42:09 +0800 Subject: [PATCH] matrix pool init ok, working on task publish --- .../HighPerformance/Memory/L4.Predict.cs | 68 ++++--------- .../Linear/MatrixCompute.Sequential.cs | 2 +- .../Numeric/NumericalModule.cs | 17 ++-- .../Numeric/Runtime/MatrixParallel.Publish.cs | 13 +-- .../Numeric/Runtime/MatrixParallel.cs | 72 ++++++++++---- .../Numeric/Runtime/MatrixParallelQueue.cs | 78 +++++---------- .../Numeric/Runtime/MatrixParallelTask.cs | 22 +++-- .../Numeric/Runtime/MatrixParallelThread.cs | 95 +++++++++++++------ .../Numeric/Runtime/MatrixParallelWrap.cs | 61 ++++++------ 9 files changed, 220 insertions(+), 208 deletions(-) diff --git a/StgSharp.Common/HighPerformance/Memory/L4.Predict.cs b/StgSharp.Common/HighPerformance/Memory/L4.Predict.cs index 7497b0f6..071149ca 100644 --- a/StgSharp.Common/HighPerformance/Memory/L4.Predict.cs +++ b/StgSharp.Common/HighPerformance/Memory/L4.Predict.cs @@ -33,32 +33,22 @@ using System.Threading.Tasks; namespace StgSharp.HighPerformance.Memory { + [Flags] + public enum PredictResult + { + + Success = 1, + Exhausted = 2, + + } + public interface IL4Predict { - bool IsExhausted { get; } + PredictResult Predict(Span node, out int count); /// - /// Writes predicted cache line descriptors into . - /// - /// - /// Prediction output buffer. - /// - /// - /// When this method returns, contains the number of valid entries written to . The value must not exceed .Length. - /// - /// - /// if any prediction data was produced; otherwise, . - /// - bool Predict( - Span node, - out int count - ); - - /// - /// Materializes the cache line identified by into into . /// /// @@ -70,11 +60,7 @@ namespace StgSharp.HighPerformance.Memory /// /// Destination cache line buffer. /// - void Prefetch( - nuint origin, - ulong policy, - Span cache - ); + void Prefetch(nuint origin, ulong policy, Span cache); /// /// Writes the cache line in back to . @@ -88,32 +74,24 @@ namespace StgSharp.HighPerformance.Memory /// /// Source cache line buffer. /// - void WriteBack( - nuint origin, - ulong policy, - ReadOnlySpan cache - ); + void WriteBack(nuint origin, ulong policy, ReadOnlySpan cache); } public struct CacheLinePrediction : IEquatable { - public override readonly bool Equals( - object? obj - ) + public override readonly bool Equals(object? obj) { - return obj is CacheLinePrediction prediction && + return (obj is CacheLinePrediction prediction) && Address.Equals(prediction.Address) && - MapPolicy == prediction.MapPolicy; + (MapPolicy == prediction.MapPolicy); } - public readonly bool Equals( - CacheLinePrediction other - ) + public readonly bool Equals(CacheLinePrediction other) { return - Address == other.Address && MapPolicy == other.MapPolicy; + (Address == other.Address) && (MapPolicy == other.MapPolicy); } public override readonly int GetHashCode() @@ -121,17 +99,11 @@ namespace StgSharp.HighPerformance.Memory return HashCode.Combine(Address, MapPolicy); } - public static bool operator !=( - CacheLinePrediction left, - CacheLinePrediction right - ) + public static bool operator !=(CacheLinePrediction left, CacheLinePrediction right) { return !(left == right); } - public static bool operator ==( - CacheLinePrediction left, - CacheLinePrediction right - ) + public static bool operator ==(CacheLinePrediction left, CacheLinePrediction right) { return left.Equals(right); } diff --git a/StgSharp.Mathematics/Numeric/Linear/MatrixCompute.Sequential.cs b/StgSharp.Mathematics/Numeric/Linear/MatrixCompute.Sequential.cs index 3b3c4be5..4ad66cbb 100644 --- a/StgSharp.Mathematics/Numeric/Linear/MatrixCompute.Sequential.cs +++ b/StgSharp.Mathematics/Numeric/Linear/MatrixCompute.Sequential.cs @@ -111,7 +111,7 @@ namespace StgSharp.Mathematics.Numeric.Linear public static PredictPolicy Policy => PredictPolicy.Sequential; - public bool Predict( + public PredictResult Predict( Span node, out int count ) diff --git a/StgSharp.Mathematics/Numeric/NumericalModule.cs b/StgSharp.Mathematics/Numeric/NumericalModule.cs index 3861adfe..754595aa 100644 --- a/StgSharp.Mathematics/Numeric/NumericalModule.cs +++ b/StgSharp.Mathematics/Numeric/NumericalModule.cs @@ -2,8 +2,8 @@ // ----------------------------------------------------------------------- // file="NumericalModule" // Project: StgSharp -// AuthorGroup: Nitload -// Copyright (c) Nitload. All rights reserved. +// AuthorGroup: Nitload Space +// Copyright (c) Nitload Space. 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 @@ -61,26 +61,23 @@ namespace StgSharp.Mathematics.Numeric public string ModuleName => "Math.Numerical"; - internal static IntrinsicContext GlobalContext - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get; - } = new(); + internal static IntrinsicContext GlobalContext { get; set; } = new(); internal static SIMDID GlobalIntrinsicMask { get; set; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void InitializeModule() { throw new NotImplementedException(); } - public void InitializeModule( - IModuleInitializeProfile profile - ) + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void InitializeModule(IModuleInitializeProfile profile) { MatrixParallel.Init(); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void UninitializeModule() { throw new NotImplementedException(); diff --git a/StgSharp.Mathematics/Numeric/Runtime/MatrixParallel.Publish.cs b/StgSharp.Mathematics/Numeric/Runtime/MatrixParallel.Publish.cs index c170defe..af4f10a5 100644 --- a/StgSharp.Mathematics/Numeric/Runtime/MatrixParallel.Publish.cs +++ b/StgSharp.Mathematics/Numeric/Runtime/MatrixParallel.Publish.cs @@ -2,8 +2,8 @@ // ----------------------------------------------------------------------- // file="MatrixParallel.Publish" // Project: StgSharp -// AuthorGroup: Nitload -// Copyright (c) Nitload. All rights reserved. +// AuthorGroup: Nitload Space +// Copyright (c) Nitload Space. 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 @@ -50,8 +50,8 @@ namespace StgSharp.Mathematics.Numeric internal static unsafe MatrixParallelWrap ScheduleTask( MatrixParallelThread[] workers, - MatrixParallelTask* package - ) where TTask : IL4Predict + MatrixParallelTask* package) + where TTask: IL4Predict { /* int primCount = package->PrimCount; @@ -61,10 +61,7 @@ namespace StgSharp.Mathematics.Numeric // Console.WriteLine($"amount of kernels is {count}"); - return new(workers) - { - TaskQueue = MatrixParallelQueue.Rent(package) - }; + return new(workers); } } diff --git a/StgSharp.Mathematics/Numeric/Runtime/MatrixParallel.cs b/StgSharp.Mathematics/Numeric/Runtime/MatrixParallel.cs index 761cee2e..edf3f372 100644 --- a/StgSharp.Mathematics/Numeric/Runtime/MatrixParallel.cs +++ b/StgSharp.Mathematics/Numeric/Runtime/MatrixParallel.cs @@ -2,8 +2,8 @@ // ----------------------------------------------------------------------- // file="MatrixParallel" // Project: StgSharp -// AuthorGroup: Nitload -// Copyright (c) Nitload. All rights reserved. +// AuthorGroup: Nitload Space +// Copyright (c) Nitload Space. 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 @@ -35,14 +35,17 @@ namespace StgSharp.Mathematics.Numeric public static unsafe partial class MatrixParallel { + private const int RESERVED_THREAD_COUNT = 4; + private static bool _meaningful; + private static CapacityFixedStack _retiredThreads; + private static CapacityFixedStack _threads; public static bool IsParallelSupported { get; } = Environment.ProcessorCount > 6; - public static bool IsParallelMeaningful { get; } = (Environment.ProcessorCount > 6) && - IsInitialized; + public static bool IsParallelMeaningful => IsParallelSupported && IsInitialized && _meaningful; public static int ContextCount { get; private set; } @@ -50,7 +53,7 @@ namespace StgSharp.Mathematics.Numeric internal static void Init() { - Dictionary contextMap = []; + Dictionary contextMap = []; if (IsInitialized) { return; @@ -62,37 +65,70 @@ namespace StgSharp.Mathematics.Numeric } contextMap = []; int count = Environment.ProcessorCount; + bool hasGlobalSimd = false; + SIMDID globalSimd = default; _threads = new(count); + _retiredThreads = new(RESERVED_THREAD_COUNT); for (int i = 0; i < count; i++) { MatrixParallelThread thread = new(i); _threads.Push(thread); SpinWait.SpinUntil(() => thread.State == MatrixThreadState.Ready); + + 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; } - // TODO 构建全局的保底上下文 - foreach (MatrixParallelThread thread in _threads) { } - if (contextMap.Keys.Count == 1) + IntrinsicContext globalContext = new(); + LoadIntrinsicFunction(&globalContext, globalSimd.Mask); + NumericalModule.GlobalContext = globalContext; + NumericalModule.GlobalIntrinsicMask = globalSimd; + ContextCount = contextMap.Count; + if (ContextCount == 1) { - for (int i = 0; i < 4; i++) - { - MatrixParallelThread thread = _threads.Pop(); - thread.Dispose(); + int retireCount = Math.Min(RESERVED_THREAD_COUNT, Math.Max(0, _threads.Count)); + for (int i = 0; i < retireCount; i++) { + RetireThread(_threads.Pop()); } } else { - // TODO 排序并丢弃四个能力最弱线程 + MatrixParallelThread[] allThreads = _threads.PopRange(_threads.Count); + 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]); + } + _threads.PushRange(allThreads.AsSpan(retireCount)); } + _meaningful = _threads.Count > 1; _awaitingLeaderHandle = new AwaitingQueue(); IsInitialized = true; } [LibraryImport(Native.LibName, EntryPoint = "sn_compare_simd")] - [UnmanagedCallConv(CallConvs = [ typeof(CallConvCdecl) ])] - private static unsafe partial ulong CompareSIMDID( - IntrinsicContext* context, - ulong id - ); + [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] + [DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)] + 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); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static void RetireThread(MatrixParallelThread thread) + { + thread.Retire(); + _retiredThreads.Push(thread); + } + + [LibraryImport(Native.LibName, EntryPoint = "sn_get_unite_simd")] + [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] + [DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)] + private static partial SIMDID UniteSIMDID(SIMDID left, SIMDID right); } } diff --git a/StgSharp.Mathematics/Numeric/Runtime/MatrixParallelQueue.cs b/StgSharp.Mathematics/Numeric/Runtime/MatrixParallelQueue.cs index 94de2561..3d12338e 100644 --- a/StgSharp.Mathematics/Numeric/Runtime/MatrixParallelQueue.cs +++ b/StgSharp.Mathematics/Numeric/Runtime/MatrixParallelQueue.cs @@ -1,27 +1,30 @@ //----------------------------------------------------------------------- // ----------------------------------------------------------------------- -// file="MatrixParallelQueue" +// file="MatrixParallelQueue.cs" // Project: StgSharp -// AuthorGroup: Nitload -// Copyright (c) Nitload. All rights reserved. +// AuthorGroup: Nitload Space +// Copyright (c) Nitload Space. 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. +// 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. // // ----------------------------------------------------------------------- // ----------------------------------------------------------------------- @@ -39,42 +42,11 @@ using System.Threading.Tasks; namespace StgSharp.Mathematics.Numeric { - internal unsafe class MatrixParallelQueue + internal unsafe ref struct MatrixParallelQueue { - private static readonly ConcurrentStack _recycle = []; - private long _cursor; - private long _maxCount; - - private MatrixParallelQueue() { } - - public MatrixParallelTask* BaseTask { get; private set; } - - public static MatrixParallelQueue Rent( - MatrixParallelTask* pack, - long count - ) - { - if (!_recycle.TryPop(out MatrixParallelQueue? queue)) { - queue = new MatrixParallelQueue(); - } - queue.BaseTask = pack; - queue._maxCount = count; - queue._cursor = 0; - return queue; - } - - public static void Return( - MatrixParallelQueue queue - ) - { - _recycle.Push(queue); - } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Steal( - MatrixParallelTask* task - ) + public bool Steal(MatrixParallelTask* task) { // TODO 使用提取的内容填充task throw new NotImplementedException(); diff --git a/StgSharp.Mathematics/Numeric/Runtime/MatrixParallelTask.cs b/StgSharp.Mathematics/Numeric/Runtime/MatrixParallelTask.cs index 782528e0..9d2b3b98 100644 --- a/StgSharp.Mathematics/Numeric/Runtime/MatrixParallelTask.cs +++ b/StgSharp.Mathematics/Numeric/Runtime/MatrixParallelTask.cs @@ -2,8 +2,8 @@ // ----------------------------------------------------------------------- // file="MatrixParallelTask" // Project: StgSharp -// AuthorGroup: Nitload -// Copyright (c) Nitload. All rights reserved. +// AuthorGroup: Nitload Space +// Copyright (c) Nitload Space. 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 @@ -32,6 +32,16 @@ using System.Runtime.InteropServices; namespace StgSharp.Mathematics.Numeric.Runtime { + [StructLayout(LayoutKind.Sequential)] + internal struct MatrixParallelSource + { + + public MatrixParallelTask Task; + public ulong Count; + public ulong Cursor; + + } + [StructLayout(LayoutKind.Explicit)] internal unsafe struct MatrixParallelTask { @@ -56,13 +66,9 @@ namespace StgSharp.Mathematics.Numeric.Runtime } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Copy( - MatrixParallelTask* source, - MatrixParallelTask* target - ) + public static void Copy(MatrixParallelTask* source, MatrixParallelTask* target) { - Buffer.MemoryCopy(source, target, sizeof(MatrixParallelTask), - sizeof(MatrixParallelTask)); + Buffer.MemoryCopy(source, target, sizeof(MatrixParallelTask), sizeof(MatrixParallelTask)); } } diff --git a/StgSharp.Mathematics/Numeric/Runtime/MatrixParallelThread.cs b/StgSharp.Mathematics/Numeric/Runtime/MatrixParallelThread.cs index 2aa539f7..cc4ddf76 100644 --- a/StgSharp.Mathematics/Numeric/Runtime/MatrixParallelThread.cs +++ b/StgSharp.Mathematics/Numeric/Runtime/MatrixParallelThread.cs @@ -2,8 +2,8 @@ // ----------------------------------------------------------------------- // file="MatrixParallelThread" // Project: StgSharp -// AuthorGroup: Nitload -// Copyright (c) Nitload. All rights reserved. +// AuthorGroup: Nitload Space +// Copyright (c) Nitload Space. 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 @@ -50,13 +50,11 @@ namespace StgSharp.Mathematics.Numeric private IntrinsicContext* _context; private MatrixParallelTask* _currentTask; - private volatile bool _disposed, _isRetireRequested ; + private volatile bool _disposed, _isRetireRequested, _isReinitRequested; private readonly ManualResetEventSlim _resetEvent; - private readonly Thread _managedThread; + private Thread _managedThread; - internal MatrixParallelThread( - int poolId - ) + internal MatrixParallelThread(int poolId) { _resetEvent = new ManualResetEventSlim(false); _managedThread = new Thread(MatrixParallelWorkLoad); @@ -91,29 +89,54 @@ namespace StgSharp.Mathematics.Numeric } [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal void SetSingleThreadTask( - ref MatrixParallelTask task - ) + internal void ReInit() + { + ObjectDisposedException.ThrowIf(_disposed, nameof(MatrixParallelThread)); + if (State != MatrixThreadState.Retired) { + return; + } + BindedWrap = null!; + _currentTask = null; + IsSingle = false; + _isRetireRequested = false; + _isReinitRequested = true; + _resetEvent.Set(); + _managedThread = new Thread(MatrixParallelWorkLoad); + SpinWait.SpinUntil(() => State != MatrixThreadState.Retired); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal void Retire() + { + ObjectDisposedException.ThrowIf(_disposed, nameof(MatrixParallelThread)); + if (State == MatrixThreadState.Retired) { + return; + } + _isRetireRequested = true; + _resetEvent.Set(); + SpinWait.SpinUntil(() => State == MatrixThreadState.Retired); + _managedThread.Join(); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal void SetSingleThreadTask(ref MatrixParallelTask task) { if (IsSingle) { *_currentTask = task; } } - protected virtual void Dispose( - bool disposing - ) + protected virtual void Dispose(bool disposing) { if (!_disposed) { if (disposing) { - _isRetireRequested = true; + _disposed = true; _resetEvent.Set(); _managedThread.Join(); _resetEvent.Dispose(); } - _disposed = true; } } @@ -124,21 +147,36 @@ namespace StgSharp.Mathematics.Numeric // Bind OS-thread affinity once when the worker starts running SetThreadAffinity(PoolId); _ = Thread.Yield(); - SIMDID feature = new(GetSimdId()); - IntrinsicContext* contextPtr = stackalloc IntrinsicContext[1]; + if (Simd.Mask != 0) + { + SIMDID feature = new(GetSimdId()); + IntrinsicContext* contextPtr = stackalloc IntrinsicContext[1]; + LoadIntrinsicFunction(contextPtr, feature.Mask); + Simd = feature; + _context = contextPtr; + } MatrixParallelTask* taskPtr = stackalloc MatrixParallelTask[4]; - LoadIntrinsicFunction(contextPtr, feature.Mask); - _context = contextPtr; State = MatrixThreadState.Ready; while (true) { // Thread self = Thread.CurrentThread; _resetEvent.Wait(); _resetEvent.Reset(); - if (_isRetireRequested) + if (_disposed) { break; } + if (_isRetireRequested) + { + State = MatrixThreadState.Retired; + continue; + } + if (_isReinitRequested) + { + _isReinitRequested = false; + State = MatrixThreadState.Idle; + continue; + } State = MatrixThreadState.Running; AfterWork = BindedWrap.AfterWork; _managedThread.Priority = ThreadPriority.Highest; @@ -148,7 +186,7 @@ namespace StgSharp.Mathematics.Numeric IsSingle = false; } else { - MatrixParallelQueue taskQueue = BindedWrap.TaskQueue; + // MatrixParallelQueue taskQueue = BindedWrap.TaskQueue; /* if (0 > (int)p ->ComputeHandle) { SpecialBufferCompute(p); @@ -172,24 +210,19 @@ namespace StgSharp.Mathematics.Numeric #pragma warning disable CA5393 [LibraryImport(Native.LibName, EntryPoint = "sn_get_simd_level_local")] - [UnmanagedCallConv(CallConvs = [ typeof(CallConvCdecl) ])] + [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] [DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)] internal static partial ulong GetSimdId(); [LibraryImport(Native.LibName, EntryPoint = "sn_set_thread_affinity")] - [UnmanagedCallConv(CallConvs = [ typeof(CallConvCdecl) ])] + [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] [DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)] - internal static partial void SetThreadAffinity( - int coreId - ); + internal static partial void SetThreadAffinity(int coreId); [LibraryImport(Native.LibName, EntryPoint = "load_intrinsic_function")] - [UnmanagedCallConv(CallConvs = [ typeof(CallConvCdecl) ])] + [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] [DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)] - private static unsafe partial void LoadIntrinsicFunction( - IntrinsicContext* context, - ulong id - ); + private static unsafe partial void LoadIntrinsicFunction(IntrinsicContext* context, ulong id); #pragma warning restore CA5393 } } diff --git a/StgSharp.Mathematics/Numeric/Runtime/MatrixParallelWrap.cs b/StgSharp.Mathematics/Numeric/Runtime/MatrixParallelWrap.cs index b4daf9da..e8065cec 100644 --- a/StgSharp.Mathematics/Numeric/Runtime/MatrixParallelWrap.cs +++ b/StgSharp.Mathematics/Numeric/Runtime/MatrixParallelWrap.cs @@ -1,32 +1,36 @@ //----------------------------------------------------------------------- // ----------------------------------------------------------------------- -// file="MatrixParallelWrap" +// file="MatrixParallelWrap.cs" // Project: StgSharp -// AuthorGroup: Nitload -// Copyright (c) Nitload. All rights reserved. +// AuthorGroup: Nitload Space +// Copyright (c) Nitload Space. 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. +// 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 StgSharp.Collections; using StgSharp.HighPerformance.Memory; +using StgSharp.Mathematics.Numeric.Runtime; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; @@ -48,16 +52,14 @@ namespace StgSharp.Mathematics.Numeric } - public sealed class MatrixParallelWrap : IDisposable + public class MatrixParallelWrap : IDisposable { private MatrixParallelThread[] _threads; private bool _disposed; private readonly CountdownEvent _countdownEvent; - internal MatrixParallelWrap( - MatrixParallelThread[] threadArray - ) + internal MatrixParallelWrap(MatrixParallelThread[] threadArray) { _threads = threadArray; _countdownEvent = new CountdownEvent(threadArray.Length); @@ -69,18 +71,17 @@ namespace StgSharp.Mathematics.Numeric internal L4 DataCache { get; set; } - internal MatrixParallelQueue TaskQueue { get; set; } + internal PredictPolicy Policy { get; set; } public void Dispose() { Dispose(true); + GC.SuppressFinalize(this); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void LaunchParallel( - SleepMode afterWork - ) + public void LaunchParallel(SleepMode afterWork) { ObjectDisposedException.ThrowIf(_disposed, nameof(MatrixParallelWrap)); AfterWork = (ThreadPriority)afterWork; @@ -107,9 +108,7 @@ namespace StgSharp.Mathematics.Numeric _ = _countdownEvent.Signal(); } - private void Dispose( - bool disposing - ) + private void Dispose(bool disposing) { if (_disposed) { return;