This commit is contained in:
Youmu Liu
2026-03-26 18:02:13 +08:00
parent d960d02972
commit 06e3aa119b
20 changed files with 198 additions and 169 deletions
@@ -30,6 +30,7 @@ using StgSharp.Mathematics.Numeric.Runtime;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
@@ -71,34 +72,45 @@ namespace StgSharp.Mathematics.Numeric.Linear
t->Mat1 = (MatrixKernel*)leftPtr;
t->Mat2 = (MatrixKernel*)rightPtr;
t->Mat3 = (MatrixKernel*)ansPtr;
t->ElementType = MatrixElementType.F64;
t->ElementType = f32;
t->ComputeHandle = MatrixIntrinsicHandle.Add;
t->Scalar.Data<long>(0) = count;
SequentialOperation(t, count);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void SequentialOperation(
MatrixParallelTask* task,
long count
)
{
MatrixElementType elementType = task->ElementType;
MatrixParallelThread[] pool;
MkProc op = (MkProc)NumericalModule.GlobalContext.
mat_mk[elementType.IntrinsicNode].
Get(task->ComputeHandle);
if (count <= 256)
{
add(t);
// .buffer_add(leftPtr, rightPtr, ansPtr, count);
op(task);
return;
} else if (count <= 1024)
{
pool = MatrixParallel.LeadParallel(1);
add(t);
op(task);
MatrixParallel.ReturnParallelResources(ref pool);
return;
}
pool = MatrixParallel.LeadParallel((int)(count / 1024));
MatrixParallelWrap taskGroup = MatrixParallel.ScheduleTask<SequentialPredictor>(pool, t);
pool = MatrixParallel.LeadParallel(count / 1024);
MatrixParallelWrap taskGroup = MatrixParallel.ScheduleTask<SequentialPredictor>(pool, task);
taskGroup.LaunchParallel(SleepMode.DeepSleep);
taskGroup.Dispose();
return;
}
private struct SequentialPredictor : IMatrixPredictor<SequentialPredictor>
{
public static PredictPolicy Policy => PredictPolicy.Sequential;
public bool Predict(
Span<CacheLinePrediction> node,
out int count