implemet wrap builder

This commit is contained in:
Youmu Liu
2025-09-15 09:06:23 +08:00
parent 4769986c37
commit 0a16f8317f
20 changed files with 33 additions and 96 deletions
+7 -14
View File
@@ -4,18 +4,11 @@
/.idea /.idea
/.vs /.vs
/.vscode /.vscode
/StgSharp.Common/obj */obj
/StgSharp.Common/bin */bin
/StgSharp.Model/obj */build
/StgSharp.Model/bin */Debug
/StgSharp.Script/obj */Release
/StgSharp.Script/bin
/StgSharp.TerminalDialogue/obj
/StgSharp.TerminalDialogue/build
/StgSharpDebug/obj
/StgSharpDebug/bin
/STgSharpTest/obj
/STgSharpTest/bin
/TestResults /TestResults
/StgSharp.Native/x64 */x64
/StgSharp.Native/x64 */.vs
-17
View File
@@ -1,17 +0,0 @@
<?xml version="1.0"?>
<package>
<metadata>
<id>StgSharp</id>
<version>1.0.0</version>
<authors>Nitload</authors>
<owners>Nitload</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description></description>
<tags></tags>
</metadata>
<files>
<file src="netstandard2.1\StgSharp.dll" target="lib\netstandard2.1\StgSharp.dll" />
<file src="netstandard2.1\StgSharp.xml" target="lib\netstandard2.1\StgSharp.xml" />
<file src="netstandard2.1\StgSharpC.dll" target="lib\netstandard2.1\StgSharpC.dll" />
</files>
</package>
Binary file not shown.
Binary file not shown.
@@ -1,12 +0,0 @@
{
"Version": 1,
"WorkspaceRootPath": "D:\\NitloadIndustry\\\u7814\u7A76\u9879\u76EE\\1-Flagship\\TH2020\\ProjectFile\\\u5185\u6838\u6E90\u4EE3\u7801\\StgSharp\\",
"Documents": [],
"DocumentGroupContainers": [
{
"Orientation": 0,
"VerticalTabListWidth": 256,
"DocumentGroups": []
}
]
}
@@ -1,12 +0,0 @@
{
"Version": 1,
"WorkspaceRootPath": "D:\\NitloadIndustry\\\u7814\u7A76\u9879\u76EE\\1-Flagship\\TH2020\\ProjectFile\\\u5185\u6838\u6E90\u4EE3\u7801\\StgSharp\\",
"Documents": [],
"DocumentGroupContainers": [
{
"Orientation": 0,
"VerticalTabListWidth": 256,
"DocumentGroups": []
}
]
}
+2
View File
@@ -28,6 +28,7 @@
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Mathematics;
using System; using System;
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
@@ -87,6 +88,7 @@ namespace StgSharp
} }
InternalIO.InitIntrinsicContext(); InternalIO.InitIntrinsicContext();
MatrixParallel.Init();
} }
public static void LogError(Exception ex) public static void LogError(Exception ex)
+2 -2
View File
@@ -154,7 +154,7 @@ namespace StgSharp.Mathematics
private readonly int _secondaryStride = enumeration._secondaryStride; private readonly int _secondaryStride = enumeration._secondaryStride;
private readonly int _stride = enumeration._stride; private readonly int _stride = enumeration._stride;
public readonly Segment Current public readonly MatrixSegment Current
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
get => new(_current, _secondarySize, _secondaryStride); get => new(_current, _secondarySize, _secondaryStride);
@@ -170,7 +170,7 @@ namespace StgSharp.Mathematics
} }
public readonly unsafe ref struct Segment(MatrixKernel* source, int size, int stride) public readonly unsafe ref struct MatrixSegment(MatrixKernel* source, int size, int stride)
{ {
private readonly MatrixKernel* _source = source; private readonly MatrixKernel* _source = source;
@@ -50,16 +50,6 @@ namespace StgSharp.Mathematics
return p; return p;
} }
public static MatrixParallelTaskPackage* FromTaskWrap(MatrixParallelTaskPackage* source, int offset)
{
MatrixParallelTaskPackage* p = (MatrixParallelTaskPackage*)_wrapAllocator.Allocate();
*p = *source;
p->left += offset * p->leftStride;
p->right += offset * p->rightStride;
p->result += offset * p->resultStride;
return p;
}
public static void Release(ScalarPacket* source) public static void Release(ScalarPacket* source)
{ {
_scalarAllocator.Free((nuint)source); _scalarAllocator.Free((nuint)source);
@@ -67,35 +57,11 @@ namespace StgSharp.Mathematics
public static void Release(MatrixParallelTaskPackage* source) public static void Release(MatrixParallelTaskPackage* source)
{ {
if (source->scalerPacket != null) { if (source->Scalar != null) {
_scalarAllocator.Free((nuint)source->scalerPacket); _scalarAllocator.Free((nuint)source->Scalar);
} }
_wrapAllocator.Free((nuint)source); _wrapAllocator.Free((nuint)source);
} }
public static void SliceTask(MatrixParallelTaskPackage* source, Span<IntPtr> group)
{
int count = group.Length;
group[0] = (nint)source;
int l = source->leftStride, r = source->rightStride, res = source->resultStride, c = source->count / count;
source->leftStride *= count;
source->rightStride *= count;
source->resultStride *= count;
int remain = source->count - (c * count);
for (int i = 1; i < count; i++)
{
nint handle = (nint)_wrapAllocator.Allocate();
MatrixParallelTaskPackage* p = (MatrixParallelTaskPackage*)handle;
*p = *source;
p->left += l;
p->right += r;
p->result += res;
group[i] = handle;
}
for (int i = 0; i < remain; i++) {
((MatrixParallelTaskPackage*)group[^i])->count++;
}
}
} }
} }
@@ -107,9 +107,26 @@ namespace StgSharp.Mathematics
{ {
int count = Environment.ProcessorCount - 4; int count = Environment.ProcessorCount - 4;
count = count == 5 ? 4 : count; count = count == 5 ? 4 : count;
int _3wrap = 0, _4wrap = 0;
_threads = new Thread[count]; _threads = new Thread[count];
if (count < 6) { } else if (count == 6) { } else { } if (count < 6)
{
_wraps = [new MatrixParallelWrap(0, count, true)];
} else if (count == 6)
{
_wraps = [new MatrixParallelWrap(0, 3, true),
new MatrixParallelWrap(3, 3, false)];
} else
{
(int _3wrap, int _4wrap) = FastDecompose(count);
_wraps = new MatrixParallelWrap[_3wrap + _4wrap];
int id = 0, idx = 0;
for (; idx < _3wrap; idx++, id += 3) {
_wraps[idx] = new MatrixParallelWrap(idx, 3, id == 0);
}
for (; idx < _3wrap + _4wrap; idx++, id += 4) {
_wraps[idx] = new MatrixParallelWrap(id, 4, id == 0);
}
}
LeaderHandle = new MatrixParallelWrap.Handle(0, _wraps[0]); LeaderHandle = new MatrixParallelWrap.Handle(0, _wraps[0]);
} }
+1 -1
View File
@@ -66,7 +66,7 @@ namespace StgSharp
Matrix<float> m = Matrix<float>.FromHlsf(400, 200, hlsf); Matrix<float> m = Matrix<float>.FromHlsf(400, 200, hlsf);
int i = 0, ii = 0; int i = 0, ii = 0;
foreach (Matrix<float>.Segment lines in m.GetRowEnumeration()) foreach (MatrixSegment lines in m.GetRowEnumeration())
{ {
i = 0; i = 0;
foreach (MatrixKernel* item in lines) foreach (MatrixKernel* item in lines)