[rebuid]use dynamic wrapping instead of static wrapping

This commit is contained in:
Youmu Liu
2025-11-03 20:03:50 +08:00
parent ee97dfddfb
commit 9c4c71dc5b
15 changed files with 331 additions and 595 deletions
@@ -25,6 +25,7 @@
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using StgSharp.Collections;
using StgSharp.HighPerformance;
using StgSharp.Internal;
using System;
@@ -48,8 +49,8 @@ namespace StgSharp.Mathematics.Numeric
long count = (long)left.KernelColumnLength * left.KernelRowLength;
if (count <= 1024)
{
MatrixParallelPool pool = MatrixParallel.LeadParallel();
if (!pool.TryRentIndividualHandle(out MatrixParallelWrap.Handle? handle))
CapacityFixedStack<MatrixParallelThread> pool = MatrixParallel.LeadParallel();
if (!pool.TryPop(out MatrixParallelThread thread))
{
/*
* wait
@@ -82,8 +83,9 @@ namespace StgSharp.Mathematics.Numeric
long count = (long)left.KernelColumnLength * left.KernelRowLength;
if (count <= 1024)
{
MatrixParallelPool pool = MatrixParallel.LeadParallel();
if (!pool.TryRentIndividualHandle(out MatrixParallelWrap.Handle? handle))
// TODO: this is very awkward, blocking thread renting, need a better way to handle small tasks
CapacityFixedStack<MatrixParallelThread> pool = MatrixParallel.LeadParallel();
if (!pool.TryPop(out MatrixParallelThread thread))
{
/*
* wait
@@ -95,6 +97,7 @@ namespace StgSharp.Mathematics.Numeric
for (int i = 0; i < count; i++) {
NativeIntrinsic.Intrinsic.f32_sub(leftPtr + i, rightPtr + i, ansPtr + i);
}
return ans;
}
Stack<MatrixParallelWrap> taskGroup = MatrixParallel.PublicTask(left.GetColumnEnumeration(), right.GetColumnEnumeration(), ans.GetColumnEnumeration(),