From 6e27c6219d8c76a323b63cca73a8666d4e8c6f1b Mon Sep 17 00:00:00 2001
From: Youmu Liu <105042599+Nitload-NSI@users.noreply.github.com>
Date: Wed, 17 Sep 2025 20:39:27 +0800
Subject: [PATCH] daily commit on 0917
---
.../Mathematics/Linear/Matrix.Basic.cs | 22 +++++++++++++++++--
StgSharp.Common/Mathematics/Linear/Matrix.cs | 13 ++++++++---
.../Linear/MatrixParallel.TaskFactory.cs | 17 ++++++++++++++
3 files changed, 47 insertions(+), 5 deletions(-)
diff --git a/StgSharp.Common/Mathematics/Linear/Matrix.Basic.cs b/StgSharp.Common/Mathematics/Linear/Matrix.Basic.cs
index 0cb4baf3..ccc5db76 100644
--- a/StgSharp.Common/Mathematics/Linear/Matrix.Basic.cs
+++ b/StgSharp.Common/Mathematics/Linear/Matrix.Basic.cs
@@ -52,9 +52,27 @@ namespace StgSharp.Mathematics
unsafe
{
MatrixParallelTaskPackage* handle = MatrixParallelFactory.CreateBaseTask();
- handle->Left = left.;
- handle->Right = right.Kernel;
+ handle->Left = left.Buffer;
+ handle->Right = right.Buffer;
+ handle->Result = result.Buffer;
+ handle->ComputeHandle = (IntPtr)InternalIO.Intrinsic.kernel_add;
+ handle->LeftPrimOffset = 0;
+ handle->RightPrimOffset = 0;
+ handle->LeftPrimStride = left.KernelColumnLength;
+ handle->LeftSecOffset = 1;
+ handle->LeftPrimOffset = 0;
+ handle->RightPrimOffset = 0;
+ handle->RightPrimStride = right.KernelColumnLength;
+ handle->RightSecOffset = 1;
+ handle->RightPrimOffset = 0;
+ handle->ResultPrimOffset = 0;
+ handle->ResultPrimStride = result.KernelColumnLength;
+ handle->ResultSecOffset = 1;
+ handle->ResultPrimOffset = 0;
+ handle->PrimCount = left.KernelRowLength;
+ handle->SecCount = left.KernelColumnLength;
}
+
MatrixParallel.LaunchParallel(SleepMode.DeepSleep);
return result;
}
diff --git a/StgSharp.Common/Mathematics/Linear/Matrix.cs b/StgSharp.Common/Mathematics/Linear/Matrix.cs
index fd9312ab..87147455 100644
--- a/StgSharp.Common/Mathematics/Linear/Matrix.cs
+++ b/StgSharp.Common/Mathematics/Linear/Matrix.cs
@@ -33,7 +33,8 @@ using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using hlsfAllocator = global::StgSharp.HighPerformance.Memory.HybridLayerSegregatedFitAllocator;
-using hlsfHandle = global::StgSharp.HighPerformance.Memory.HybridLayerSegregatedFitAllocationHandle;
+
+// using hlsfHandle = global::StgSharp.HighPerformance.Memory.HybridLayerSegregatedFitAllocationHandle;
namespace StgSharp.Mathematics
{
@@ -67,17 +68,23 @@ namespace StgSharp.Mathematics
set;
} = null;
+ ///
+ /// Length of the matrix in columns.
+ ///
public int ColumnLength { get; init; }
+ ///
+ /// Length of the matrix in rows.
+ ///
public int RowLength { get; init; }
public static MatrixAllocation DefaultAllocation { get; set; } = MatrixAllocation.GC;
internal abstract MatrixKernel* Buffer { get; }
- protected int KernelColumnLength { get; init; }
+ protected internal int KernelColumnLength { get; init; }
- protected int KernelRowLength { get; init; }
+ protected internal int KernelRowLength { get; init; }
public static Matrix FromDefault(int columnLength, int rowLength)
{
diff --git a/StgSharp.Common/Mathematics/Linear/MatrixParallel.TaskFactory.cs b/StgSharp.Common/Mathematics/Linear/MatrixParallel.TaskFactory.cs
index 94234752..9475dc90 100644
--- a/StgSharp.Common/Mathematics/Linear/MatrixParallel.TaskFactory.cs
+++ b/StgSharp.Common/Mathematics/Linear/MatrixParallel.TaskFactory.cs
@@ -28,19 +28,33 @@
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
+using StgSharp.HighPerformance;
using StgSharp.HighPerformance.Memory;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
+using System.Threading;
using System.Threading.Tasks;
+using hlsfAllocator = StgSharp.HighPerformance.Memory.HybridLayerSegregatedFitAllocator;
+
namespace StgSharp.Mathematics
{
internal static unsafe class MatrixParallelFactory
{
+ private static hlsfAllocator _intermediateResult;
+
+ private static
+#if NET9_0_OR_GREATER
+ Lock
+#else
+ object
+#endif
+ _hlsfLock = new();
+
private static SlabAllocator _scalarAllocator ;
private static SlabAllocator _wrapAllocator ;
@@ -49,6 +63,8 @@ namespace StgSharp.Mathematics
public static MatrixParallelTaskPackage* CreateBaseTask()
{
MatrixParallelTaskPackage* p = (MatrixParallelTaskPackage*)_wrapAllocator.Allocate();
+ Span s = new Span((byte*)p, sizeof(MatrixParallelTaskPackage));
+ s.Fill(0);
return p;
}
@@ -79,6 +95,7 @@ namespace StgSharp.Mathematics
{
_scalarAllocator = SlabAllocator.Create(64, SlabBufferLayout.Chunked, true);
_wrapAllocator = SlabAllocator.Create(64, SlabBufferLayout.Chunked, true);
+ _intermediateResult = new hlsfAllocator((nuint)(sizeof(MatrixKernel) * 64));
}
}