diff --git a/StgSharp.Common/HighPerformance/M64.cs b/StgSharp.Common/HighPerformance/M64.cs
index ceb59890..7dd12af7 100644
--- a/StgSharp.Common/HighPerformance/M64.cs
+++ b/StgSharp.Common/HighPerformance/M64.cs
@@ -78,10 +78,23 @@ namespace StgSharp.HighPerformance
return !(left == right);
}
+ public static M64 operator <<(M64 value, int shift)
+ {
+ M64 result = new M64();
+ result.value = value.value << shift;
+ return result;
+ }
+
public static bool operator ==(M64 left, M64 right)
{
return left.value == right.value;
}
+ public static M64 operator >>(M64 value, int shift)
+ {
+ M64 result = new M64();
+ result.value = value.value << shift;
+ return result;
+ }
}
}
diff --git a/StgSharp.Common/HighPerformance/Memory/HLSFAllocator.Alloc.cs b/StgSharp.Common/HighPerformance/Memory/HLSFAllocator.Alloc.cs
index 473e9cc2..99b6a755 100644
--- a/StgSharp.Common/HighPerformance/Memory/HLSFAllocator.Alloc.cs
+++ b/StgSharp.Common/HighPerformance/Memory/HLSFAllocator.Alloc.cs
@@ -2,8 +2,8 @@
// -----------------------------------------------------------------------
// file="HLSFAllocator.Alloc"
// 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
@@ -74,7 +74,6 @@ namespace StgSharp.HighPerformance.Memory
SliceMemory(handle, (segmentIndex + 1) * levelSizeArray[level]);
}
handle->State = EntryState.Allocated;
- Console.WriteLine($"handle alloced at {handle->Position}");
return new hlsfHandle(handle, size);
}
@@ -213,7 +212,8 @@ namespace StgSharp.HighPerformance.Memory
_spareMemory->Position = newPos;
BucketNode* b = (BucketNode*)handle->Position;
b->EntryRef = handle;
- PushLevel(handle->Level, DetermineSegmentIndex((uint)blockSize, handle->Level), b);
+
+ // PushLevel(handle->Level, DetermineSegmentIndex((uint)blockSize, handle->Level), b);
// update position linked list
handle->NextNear = (ulong)_spareMemory;
diff --git a/StgSharp.Common/HighPerformance/Memory/HLSFAllocator.BucketNode.cs b/StgSharp.Common/HighPerformance/Memory/HLSFAllocator.BucketNode.cs
index e9c14a87..e4a5ebb6 100644
--- a/StgSharp.Common/HighPerformance/Memory/HLSFAllocator.BucketNode.cs
+++ b/StgSharp.Common/HighPerformance/Memory/HLSFAllocator.BucketNode.cs
@@ -2,8 +2,8 @@
// -----------------------------------------------------------------------
// file="HLSFAllocator.BucketNode"
// 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
@@ -55,6 +55,10 @@ namespace StgSharp.HighPerformance.Memory
{
_bucketHeads[index] = (nuint)node;
node->IsInBucket = true;
+ node->NextLevel = EmptyHandle;
+ node->PreviousLevel = EmptyHandle;
+
+ // Console.WriteLine($"Push to empty level of {levelIndex} {sizeIndex}, bucket pos {(ulong)node}");
return;
} else
{
@@ -62,7 +66,10 @@ namespace StgSharp.HighPerformance.Memory
node->NextLevel = head;
BucketNode* headNode = (BucketNode*)head;
node->IsInBucket = true;
- if (headNode != null) {
+
+ // Console.WriteLine($"Push to head of level of {levelIndex} {sizeIndex}, bucket pos {(ulong)node}, previous head is at {head}");
+ if (headNode != null)
+ {
headNode->PreviousLevel = (ulong)node;
}
return;
@@ -111,6 +118,7 @@ namespace StgSharp.HighPerformance.Memory
return false;
}
+ // Console.WriteLine($"level popped from level {levelIndex} {sizeIndex}, node is at {(ulong)head}");
BucketNode* next = (BucketNode*)head->NextLevel;
if (next == null)
@@ -123,14 +131,8 @@ namespace StgSharp.HighPerformance.Memory
node = head;
node->IsInBucket = false;
node->NextLevel = EmptyHandle;
- if (next != null)
- {
- Console.WriteLine("////////////// catching error ///////////////");
- Console.WriteLine($"ref next: {(ulong)next}");
- Console.WriteLine($"base pos: {(ulong)m_Buffer}");
- Console.WriteLine(_size);
+ if (next != null) {
next->PreviousLevel = EmptyHandle;
- Console.WriteLine("///////////// no error caught ///////////////");
}
return true;
}
@@ -157,6 +159,8 @@ namespace StgSharp.HighPerformance.Memory
node->NextLevel = EmptyHandle;
node->PreviousLevel = EmptyHandle;
node->IsInBucket = false;
+
+
return true;
}
@@ -164,30 +168,15 @@ namespace StgSharp.HighPerformance.Memory
/// BucketNode structure - specialized node for bucket linked lists Stored in main
/// allocation area (user-overwritable region)
///
- [StructLayout(LayoutKind.Explicit, Size = 40)]
+ [StructLayout(LayoutKind.Explicit)]
internal struct BucketNode
{
[FieldOffset(0)] internal Entry* EntryRef; // Pointer to corresponding Entry
[FieldOffset(32)] internal bool IsInBucket; // Whether in bucket
-
- [FieldOffset(8)] internal ulong _nextLevel; // Bucket stack linked list: next pointer
[FieldOffset(16)] internal ulong LockBuffer;
- [FieldOffset(24)] internal ulong PreviousLevel; // Bucket stack linked list: previous pointer
-
- internal ulong NextLevel
- {
- get
- {
- Console.WriteLine($"get next level {_nextLevel}");
- return _nextLevel;
- }
- set
- {
- Console.WriteLine($"NextLevel set to {value}.");
- _nextLevel = value;
- }
- }
+ [FieldOffset(8)] internal ulong NextLevel; // Bucket stack linked list: next pointer
+ [FieldOffset(24)] internal ulong PreviousLevel; // Bucket stack linked list: previous pointer
}
diff --git a/StgSharp.Common/HighPerformance/Memory/HLSFAllocator.SegmentEntry.cs b/StgSharp.Common/HighPerformance/Memory/HLSFAllocator.SegmentEntry.cs
index 506201ce..86b278bb 100644
--- a/StgSharp.Common/HighPerformance/Memory/HLSFAllocator.SegmentEntry.cs
+++ b/StgSharp.Common/HighPerformance/Memory/HLSFAllocator.SegmentEntry.cs
@@ -38,6 +38,21 @@ namespace StgSharp.HighPerformance.Memory
public unsafe partial class HybridLayerSegregatedFitAllocator
{
+ ///
+ /// check out if a bucket is within the same higher-level boundary as currentOffset
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
private bool AssertBackwardBoundary(ulong currentOffset, Entry* target, int level)
{
int nextLevelSize = levelSizeArray[level] * 4;
@@ -45,6 +60,21 @@ namespace StgSharp.HighPerformance.Memory
return (currentOffset / (ulong)nextLevelSize) == (targetHead / (ulong)nextLevelSize);
}
+ ///
+ /// check out if a bucket is within the same higher-level boundary as currentOffset
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
private bool AssertForwardBoundary(ulong currentOffset, Entry* target, int level)
{
int nextLevelSize = levelSizeArray[level] * 4;
@@ -75,7 +105,7 @@ namespace StgSharp.HighPerformance.Memory
///
/// Used in Free operations, efficiently remove from buckets and merge adjacent blocks.
/// Current Entry will serve as the final merged block. The Merge will be in lazy
- /// strategy, any fail in acquiring spin lock will end a merging process.
+ /// strategy.
///
private void MergeAndRemoveFromBuckets(Entry* entry)
{
@@ -99,8 +129,7 @@ namespace StgSharp.HighPerformance.Memory
ulong p = entry->PreviousNear;
Entry* prev = (Entry*)p;
-
- // 计算当��相对于分�空间基�的�移�
+ // compute offset of current block and base position
ulong currentOffset = entry->Position - (ulong)m_Buffer;
if (prev == null ||
diff --git a/StgSharp.Common/HighPerformance/Memory/HLSFAllocator.cs b/StgSharp.Common/HighPerformance/Memory/HLSFAllocator.cs
index b801c7d2..5fe3b5ce 100644
--- a/StgSharp.Common/HighPerformance/Memory/HLSFAllocator.cs
+++ b/StgSharp.Common/HighPerformance/Memory/HLSFAllocator.cs
@@ -2,8 +2,8 @@
// -----------------------------------------------------------------------
// file="HLSFAllocator"
// 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
@@ -28,6 +28,7 @@
using System;
using System.Buffers;
using System.Runtime.InteropServices;
+using System.Text;
namespace StgSharp.HighPerformance.Memory
{
diff --git a/StgSharp.Mathematics/Numeric/MatrixCompute.Basic.cs b/StgSharp.Mathematics/Numeric/MatrixCompute.Basic.cs
index 5cdd8808..7d26f234 100644
--- a/StgSharp.Mathematics/Numeric/MatrixCompute.Basic.cs
+++ b/StgSharp.Mathematics/Numeric/MatrixCompute.Basic.cs
@@ -2,8 +2,8 @@
// -----------------------------------------------------------------------
// file="MatrixCompute.Basic"
// 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
@@ -86,7 +86,7 @@ namespace StgSharp.Mathematics.Numeric
return ans;
}
- public static unsafe void Fill(Matrix ans, T value) where T: unmanaged, INumber
+ public static unsafe void Fill(Matrix ans, T value) where T : unmanaged, INumber
{
long count = (long)ans.KernelColumnLength * ans.KernelRowLength;
ScalarPacket* scalar = MatrixParallelFactory.CreateScalarPacket();
diff --git a/StgSharp.Mathematics/Numeric/MatrixComputeModel.cs b/StgSharp.Mathematics/Numeric/MatrixComputeModel.cs
index bb6ad4ad..f0012e5f 100644
--- a/StgSharp.Mathematics/Numeric/MatrixComputeModel.cs
+++ b/StgSharp.Mathematics/Numeric/MatrixComputeModel.cs
@@ -57,7 +57,7 @@ namespace StgSharp.Mathematics.Numeric
MatrixParallelFactory.Release(p);
}
- internal static unsafe void BufferComputeUnaryScalar(MatrixParallelTaskPackage* p)
+ internal static unsafe void BufferComputeUnary(MatrixParallelTaskPackage* p)
{
int size = p->ElementSize * 16;
long count = Unsafe.As(ref p->PrimCount);
@@ -69,6 +69,17 @@ namespace StgSharp.Mathematics.Numeric
MatrixParallelFactory.Release(p);
}
+ internal static unsafe void BufferComputeUnaryScalar(MatrixParallelTaskPackage* p)
+ {
+ int size = p->ElementSize * 16;
+ long count = Unsafe.As(ref p->PrimCount);
+ long offset = Unsafe.As(ref p->PrimTileOffset) * size;
+ ((delegate* unmanaged[Cdecl]< void*, void*, ScalarPacket*, long, void>)p->ComputeHandle)((void*)(p->Right + offset),
+ (void*)(p->Result + offset),
+ p->Scalar, count);
+ MatrixParallelFactory.Release(p);
+ }
+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static unsafe void Compute_Binary(MatrixParallelTaskPackage* p)
{
diff --git a/StgSharp.Mathematics/Numeric/MatrixParallelThread.cs b/StgSharp.Mathematics/Numeric/MatrixParallelThread.cs
index 500f84be..d2afce4b 100644
--- a/StgSharp.Mathematics/Numeric/MatrixParallelThread.cs
+++ b/StgSharp.Mathematics/Numeric/MatrixParallelThread.cs
@@ -2,8 +2,8 @@
// -----------------------------------------------------------------------
// file="MatrixParallelThread"
// 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
@@ -93,6 +93,7 @@ namespace StgSharp.Mathematics.Numeric
switch (p->ComputeMode.ParameterStyle)
{
case MatrixOperationParam.RIGHT_ANS_PARAM:
+ MatrixComputeModel.BufferComputeUnary(p);
break;
case MatrixOperationParam.LEFT_RIGHT_ANS_PARAM:
MatrixComputeModel.BufferComputeBinary(p);
diff --git a/StgSharpDebug/HlsfStressTest.cs b/StgSharpDebug/HlsfStressTest.cs
new file mode 100644
index 00000000..c4ba409e
--- /dev/null
+++ b/StgSharpDebug/HlsfStressTest.cs
@@ -0,0 +1,259 @@
+//-----------------------------------------------------------------------
+// -----------------------------------------------------------------------
+// file="HlsfStressTest"
+// Project: StgSharp
+// 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
+// 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.
+//
+// -----------------------------------------------------------------------
+// -----------------------------------------------------------------------
+// -----------------------------------------------------------------------
+// file="HlsfStressTest" (performance benchmark)
+// Project: StgSharp
+// -----------------------------------------------------------------------
+using StgSharp.HighPerformance.Memory;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+
+namespace StgSharp
+{
+ internal static class HlsfStressTest
+ {
+
+ private const uint MaxAllocSize = 32 * 1024 * 1024; // 32MB documented cap
+
+ // Allow overriding arena size via env HLSF_ARENA_MB (must be >=64MB)
+ private static readonly ulong ArenaBytes = Environment.GetEnvironmentVariable("HLSF_ARENA_MB") is string mbStr &&
+ int.TryParse(mbStr, out int mb) &&
+ mb >= 64 ?
+ (ulong)mb * 1024UL * 1024UL :
+ 3UL * 1024UL * 1024UL * 1024UL;
+
+ private static readonly uint[] SizeSweep = {
+ 64, 128, 192, 256, 512, 768, 1024, 2048, 3072, 4096, 8192, 12288, 16384, 32768, 49152, 65536, 131072, 196608, 262144, 524288, 786432, 1_048_576, 2_097_152, 3_145_728, 4_194_304, 8_388_608, 12_582_912, 16_777_216, 25_165_824, 33_554_432
+ };
+
+ public static unsafe void Run()
+ {
+ Console.WriteLine("=== HLSF Allocator Single-Thread Performance Benchmark ===");
+ Console.WriteLine($"Arena size: {ArenaBytes / (1024 * 1024)} MiB (env override: HLSF_ARENA_MB)");
+ using HybridLayerSegregatedFitAllocator allocator = new HybridLayerSegregatedFitAllocator((nuint)ArenaBytes);
+
+ Warmup(allocator);
+
+ Console.WriteLine();
+ Console.WriteLine("[1] Allocation throughput (no touch)");
+ foreach (uint sz in SizeSweep)
+ {
+ uint size = sz > MaxAllocSize ? MaxAllocSize : sz;
+ BenchAllocThroughput(allocator, size, touch:false);
+ GC.Collect();
+ GC.WaitForPendingFinalizers();
+ }
+
+ Console.WriteLine();
+ Console.WriteLine("[2] Allocation throughput (touch first byte)");
+ foreach (uint sz in SizeSweep)
+ {
+ uint size = sz > MaxAllocSize ? MaxAllocSize : sz;
+ BenchAllocThroughput(allocator, size, touch:true);
+ GC.Collect();
+ GC.WaitForPendingFinalizers();
+ }
+
+ Console.WriteLine();
+ Console.WriteLine("[3] Free throughput after pre-allocation (256k blocks of 1KB)");
+ BenchFreeThroughput(allocator, 256 * 1024, 1024);
+
+ Console.WriteLine();
+ Console.WriteLine("[4] Alloc+Immediate Free pairs (5,000,000 x 256B)");
+ BenchAllocFreePairs(allocator, 5_000_000, 256);
+
+ Console.WriteLine();
+ Console.WriteLine("[5] Fragmentation cycle (allocate ~1024MB random, free half, reallocate)");
+ BenchFragmentationCycle(allocator, 1024);
+
+ Console.WriteLine();
+ Console.WriteLine("=== Benchmark Complete ===");
+ }
+
+ private static void BenchAllocFreePairs(
+ HybridLayerSegregatedFitAllocator allocator,
+ int pairs,
+ uint blockSize)
+ {
+ Stopwatch sw = Stopwatch.StartNew();
+ for (int i = 0; i < pairs; i++)
+ {
+ HybridLayerSegregatedFitAllocationHandle h = allocator.Alloc(blockSize);
+ allocator.Free(h);
+ }
+ sw.Stop();
+ double opsPerSec = pairs / sw.Elapsed.TotalSeconds;
+ Console.WriteLine($" size={Fmt(blockSize),7} pairs={pairs,9} alloc+free/s={opsPerSec,12:0.0}");
+ }
+
+ private static void BenchAllocThroughput(
+ HybridLayerSegregatedFitAllocator allocator,
+ uint blockSize,
+ bool touch)
+ {
+ ulong budget = ArenaBytes / 2; // use half arena for test
+ if (blockSize == 0) {
+ return;
+ }
+
+ long ops = (long)(budget / blockSize);
+ ops = Math.Min(ops, blockSize >= (4 * 1024 * 1024) ? 2048 : 2_000_000);
+ if (ops <= 0) {
+ return;
+ }
+
+ List list = new List((int)ops);
+ Stopwatch sw = Stopwatch.StartNew();
+ for (long i = 0; i < ops; i++)
+ {
+ HybridLayerSegregatedFitAllocationHandle h = allocator.Alloc(blockSize);
+ if (touch)
+ {
+ Span span = h.BufferHandle;
+ if (!span.IsEmpty) {
+ span[0] = (byte)(i & 0xFF);
+ }
+ }
+ list.Add(h);
+ }
+ sw.Stop();
+ double allocOpsPerSec = ops / sw.Elapsed.TotalSeconds;
+ foreach (HybridLayerSegregatedFitAllocationHandle h in list) {
+ allocator.Free(h);
+ }
+
+ Console.WriteLine($" size={Fmt(blockSize),7} ops={ops,9} alloc/s={allocOpsPerSec,12:0.0} touch={touch}");
+ }
+
+ private static void BenchFragmentationCycle(
+ HybridLayerSegregatedFitAllocator allocator,
+ int targetMiB)
+ {
+ int targetBytes = targetMiB * 1024 * 1024;
+ Random rng = new Random(123);
+ List live = new List(128 * 1024);
+ long allocated = 0;
+ Stopwatch swA = Stopwatch.StartNew();
+ while (allocated < targetBytes)
+ {
+ uint sz = PickSize(rng);
+ HybridLayerSegregatedFitAllocationHandle h = allocator.Alloc(sz);
+ live.Add(h);
+ allocated += sz;
+ }
+ swA.Stop();
+ Console.WriteLine($" phaseA alloc {targetMiB}MB in {swA.Elapsed.TotalSeconds:0.00}s blocks={live.Count}");
+
+ Stopwatch swB = Stopwatch.StartNew();
+ int freed = 0;
+ for (int i = live.Count - 1; i >= 0; i -= 2)
+ {
+ allocator.Free(live[i]);
+ live.RemoveAt(i);
+ freed++;
+ }
+ swB.Stop();
+ Console.WriteLine($" phaseB freed {freed} in {swB.Elapsed.TotalSeconds:0.00}s remain={live.Count}");
+
+ allocated = 0;
+ int reCount = 0;
+ Stopwatch swC = Stopwatch.StartNew();
+ while (allocated < targetBytes / 2)
+ {
+ uint sz = PickSize(rng);
+ HybridLayerSegregatedFitAllocationHandle h = allocator.Alloc(sz);
+ live.Add(h);
+ allocated += sz;
+ reCount++;
+ }
+ swC.Stop();
+ Console.WriteLine($" phaseC re-alloc {reCount} in {swC.Elapsed.TotalSeconds:0.00}s ~{allocated / (1024.0 * 1024.0):0}MB");
+
+ Stopwatch swD = Stopwatch.StartNew();
+ foreach (HybridLayerSegregatedFitAllocationHandle h in live) {
+ allocator.Free(h);
+ }
+
+ swD.Stop();
+ Console.WriteLine($" cleanup freed {live.Count} in {swD.Elapsed.TotalSeconds:0.00}s");
+ }
+
+ private static void BenchFreeThroughput(
+ HybridLayerSegregatedFitAllocator allocator,
+ int count,
+ uint blockSize)
+ {
+ List list = new List(count);
+ for (int i = 0; i < count; i++) {
+ list.Add(allocator.Alloc(blockSize));
+ }
+
+ Stopwatch sw = Stopwatch.StartNew();
+ for (int i = 0; i < count; i++) {
+ allocator.Free(list[i]);
+ }
+
+ sw.Stop();
+ double freesPerSec = count / sw.Elapsed.TotalSeconds;
+ Console.WriteLine($" size={Fmt(blockSize),7} count={count,9} free/s={freesPerSec,12:0.0}");
+ }
+
+ private static string Fmt(uint bytes)
+ {
+ if (bytes >= 1024 * 1024) {
+ return $"{bytes / (1024 * 1024)}MB";
+ }
+
+ if (bytes >= 1024) {
+ return $"{bytes / 1024}KB";
+ }
+
+ return $"{bytes}B";
+ }
+
+ private static uint PickSize(Random rng)
+ {
+ uint raw = SizeSweep[rng.Next(SizeSweep.Length)];
+ return raw > MaxAllocSize ? MaxAllocSize : raw;
+ }
+
+ private static void Warmup(HybridLayerSegregatedFitAllocator allocator)
+ {
+ List tmp = new List(4096);
+ for (int i = 0; i < 4096; i++) {
+ tmp.Add(allocator.Alloc(256));
+ }
+
+ foreach (HybridLayerSegregatedFitAllocationHandle h in tmp) {
+ allocator.Free(h);
+ }
+ }
+
+ }
+}
diff --git a/StgSharpDebug/MatrixParallelTest.cs b/StgSharpDebug/MatrixParallelTest.cs
deleted file mode 100644
index 55bb5119..00000000
--- a/StgSharpDebug/MatrixParallelTest.cs
+++ /dev/null
@@ -1,198 +0,0 @@
-//-----------------------------------------------------------------------
-// -----------------------------------------------------------------------
-// file="MatrixParallelTest"
-// Project: StgSharp
-// 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.
-//
-// -----------------------------------------------------------------------
-// -----------------------------------------------------------------------
-using StgSharp.Mathematics;
-using StgSharp.Mathematics.Numeric;
-
-using System;
-using System.Diagnostics;
-using System.Threading;
-
-namespace StgSharp
-{
- internal partial class Program
- {
- /*
- public static void TestMatrixParallel()
- {
- // 4. Ï̵߳÷¶È»ù´¡¹¦ÄܲâÊÔ
- Console.WriteLine("=== Ï̵߳÷¶È»ù´¡¹¦ÄܲâÊÔ ===");
- TestSchedulingBasics();
- Console.WriteLine();
-
- // 5. ²¢ÐпØÖÆÁ÷²âÊÔ
- Console.WriteLine("=== ²¢ÐпØÖÆÁ÷²âÊÔ ===");
- TestParallelControlFlow();
- Console.WriteLine();
-
- // 6. ÖØ¸´²Ù×÷Îȶ¨ÐÔ²âÊÔ
- Console.WriteLine("=== ÖØ¸´²Ù×÷Îȶ¨ÐÔ²âÊÔ ===");
- TestRepeatedOperations();
- Console.WriteLine();
-
- // 7. Ïß³Ì״̬¼à¿Ø²âÊÔ
- Console.WriteLine("=== Ïß³Ì״̬¼à¿Ø²âÊÔ ===");
-
- // TestThreadStateMonitoring();
- Console.WriteLine();
-
- Console.WriteLine("? MatrixParallel ·Ö²ãÏ̵߳÷¶Èϵͳ¿ÕÅܲâÊÔÍê³É");
- }
-
- private static void TestParallelControlFlow()
- {
- try
- {
- Console.WriteLine("²âÊÔ²¢ÐпØÖÆÁ÷...");
-
- for (int i = 0; i < 5; i++)
- {
- Console.WriteLine($" µÚ {i + 1} ÂÖ¿ØÖÆÁ÷²âÊÔ:");
-
-
- // »ñÈ¡²¢ÐÐËø
- Console.WriteLine(" Ö´ÐÐ LeadParallel()...");
- MatrixParallel.LeadParallel();
-
- try
- {
- // Æô¶¯²¢Ðд¦Àí
- Console.WriteLine($" Ö´ÐÐ LaunchParallel({(SleepMode)(i % 3 + 1)})...");
- MatrixParallel.LaunchParallel((SleepMode)(i % 3 + 1));
-
- // ÉèÖÃËùÓÐ Wrap
- MatrixParallel.SetAllWrap();
-
- // ·¢²¼ÈÎÎñ£¨¿ÕÈÎÎñ£©
- // MatrixParallel.PublishTask();
-
- // ¶ÌÔݵȴý£¬Ä£Äâʵ¼Ê¹¤×÷
- Thread.Sleep(10 + i * 5);
-
- Console.WriteLine(" ? ¿ØÖÆÁ÷Ö´ÐÐÕý³£");
- }
- finally
- {
- // ÊͷŲ¢ÐÐËø
- Console.WriteLine(" Ö´ÐÐ EndParallel()...");
- MatrixParallel.EndParallel();
- }
- }
-
- Console.WriteLine("? ²¢ÐпØÖÆÁ÷²âÊÔͨ¹ý");
- }
- catch (Exception ex)
- {
- Console.WriteLine($"? ²¢ÐпØÖÆÁ÷²âÊÔʧ°Ü: {ex.Message}");
- }
- }
-
- private static void TestRepeatedOperations()
- {
- try
- {
- Console.WriteLine("Ö´ÐÐÖØ¸´²Ù×÷Îȶ¨ÐÔ²âÊÔ...");
-
- Stopwatch stopwatch = Stopwatch.StartNew();
- int iterations = 50;
- int successCount = 0;
-
- for (int i = 0; i < iterations; i++)
- {
- try
- {
- MatrixParallel.LeadParallel();
-
- MatrixParallel.LaunchParallel(SleepMode.QuickWakeup);
- MatrixParallel.SetAllWrap();
-
- // MatrixParallel.PublishTask();
-
-
- // ¼«¶ÌÔݵĵȴý
- Thread.Sleep(1);
-
- successCount++;
- }
- catch (Exception ex)
- {
- Console.WriteLine($" µÚ {i + 1} ´Î²Ù×÷ʧ°Ü: {ex.Message}");
- }
- finally
- {
- try
- {
- MatrixParallel.EndParallel();
- }
- catch (Exception ex)
- {
- Console.WriteLine($" µÚ {i + 1} ´Î EndParallel ʧ°Ü: {ex.Message}");
- }
- }
-
- // ÿ10´Î²Ù×÷ÏÔʾһ´Î½ø¶È
- if ((i + 1) % 10 == 0)
- {
- Console.WriteLine($" ÒÑÍê³É {i + 1}/{iterations} ´Î²Ù×÷");
- }
- }
-
- stopwatch.Stop();
-
- Console.WriteLine($"? ÖØ¸´²Ù×÷²âÊÔÍê³É:");
- Console.WriteLine($" ×ܲÙ×÷´ÎÊý: {iterations}");
- Console.WriteLine($" ³É¹¦´ÎÊý: {successCount}");
- Console.WriteLine($" ³É¹¦ÂÊ: {(double)successCount / iterations * 100:F1}%");
- Console.WriteLine($" ×ܺÄʱ: {stopwatch.ElapsedMilliseconds} ms");
- Console.WriteLine($" ƽ¾ùºÄʱ: {stopwatch.ElapsedMilliseconds / (double)iterations:F2} ms/´Î");
- }
- catch (Exception ex)
- {
- Console.WriteLine($"? ÖØ¸´²Ù×÷²âÊÔʧ°Ü: {ex.Message}");
- }
- }
-
- private static void TestSchedulingBasics()
- {
- try
- {
- Console.WriteLine("²âÊÔ»ù±¾µ÷¶È²Ù×÷...");
-
- // ²âÊÔÉèÖÃËùÓÐ Wrap
- Console.WriteLine(" Ö´ÐÐ SetAllWrap()...");
- MatrixParallel.SetAllWrap();
- Console.WriteLine(" ? SetAllWrap() Ö´Ðгɹ¦");
- }
- catch (Exception ex)
- {
- Console.WriteLine($"? »ù±¾µ÷¶È²Ù×÷²âÊÔʧ°Ü: {ex.Message}");
- }
- }
- /**/
-
- }
-}
\ No newline at end of file
diff --git a/StgSharpDebug/Program.cs b/StgSharpDebug/Program.cs
index d708a55a..34018b0b 100644
--- a/StgSharpDebug/Program.cs
+++ b/StgSharpDebug/Program.cs
@@ -2,8 +2,8 @@
// -----------------------------------------------------------------------
// file="Program"
// 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
@@ -61,12 +61,15 @@ namespace StgSharp
{
try
{
- World.Initialize().UseModule().UseModule().InitializeModule();
+ World.Initialize()
+ .UseModule()
+ .UseModule()
+ .InitializeModule();
// TestRender();
-
- // 原有的矩阵测试代ç �
+ HlsfStressTest.Run();
+ /*
HybridLayerSegregatedFitAllocator hlsf = new HybridLayerSegregatedFitAllocator((nuint)(64 * (ulong)10000 * 10000));
Matrix m = Matrix.FromHlsf(1000, 1000, hlsf);
@@ -87,7 +90,7 @@ namespace StgSharp
GC.Collect();
}
- // MatrixCompute.Mul(n, 12, n);
+ MatrixCompute.Mul(n, 12, n);
for (int i = 0; i < 20; i++)
{
for (int j = 0; j < 20; j++) {
@@ -96,13 +99,13 @@ namespace StgSharp
Console.WriteLine();
}
/**/
- /**/
+ /*
}
catch (Exception ex)
{
Console.WriteLine(ex);
Console.ReadLine();
- /**/
+ /*
World.WriteLog($"{ex}", LogType.Error);
Dialogue.PostError(ex);
/**/
diff --git a/StgSharpDebug/SimdDemo.cs b/StgSharpDebug/SimdDemo.cs
deleted file mode 100644
index 949671b2..00000000
--- a/StgSharpDebug/SimdDemo.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-//-----------------------------------------------------------------------
-// -----------------------------------------------------------------------
-// file="SimdDemo.cs"
-// Project: StgSharp
-// 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.
-//
-// -----------------------------------------------------------------------
-// -----------------------------------------------------------------------
-using StgSharp.Mathematics;
-
-namespace StgSharp
-{
- public static class SimdDemo
- {
-
- public static void TestMethod() { }
-
- }
-}
\ No newline at end of file