buffer op brief ok, but blocks on unkown reason

This commit is contained in:
Youmu Liu
2025-11-20 16:17:24 +08:00
parent a29a442723
commit c595076005
14 changed files with 434 additions and 325 deletions
@@ -67,17 +67,21 @@ namespace StgSharp.Mathematics.Numeric
int primCount = package->PrimCount;
int secCount = package->SecCount;
long count = (long)primCount * secCount;
Console.WriteLine($"amount of kernels is {count}");
long recommendCount = count / 1024;
MatrixParallelThread[] pool = LeadParallel((int)recommendCount);
MatrixParallelHandle handle = new MatrixParallelHandle(pool);
if (handle.Wraps.Count() == 1)
if (handle.Wraps.Length == 1)
{
// Console.WriteLine($"Scheduling into {pool.Length} threads.");
ref long offsetRef = ref Unsafe.As<int, long>(ref package->PrimTileOffset);
offsetRef = 0;
ref long lengthRef = ref Unsafe.As<int, long>(ref package->PrimCount);
lengthRef = count;
handle.Wraps.First().WrapTask.Enqueue((nint)package);
handle.Wraps[0].WrapTask.Enqueue((nint)package);
// Console.WriteLine($"Scheduling {count} kernels into thread");
return handle;
}
long actual = count / pool.Length;
@@ -85,18 +89,25 @@ namespace StgSharp.Mathematics.Numeric
long offset = 0;
MatrixParallelTaskPackage* current = package;
// Console.WriteLine($"Scheduling into {pool.Length} threads.");
foreach (MatrixParallelWrap wrap in handle.Wraps)
{
long wrapTaskLength = actual * wrap.WrapTaskCapacity;
long ex = Math.Min(extra, wrap.WrapTaskCapacity);
long length = wrapTaskLength + ex;
extra -= ex;
ref long offsetRef = ref Unsafe.As<int, long>(ref current->PrimTileOffset);
offsetRef = offset;
ref long lengthRef = ref Unsafe.As<int, long>(ref current->PrimCount);
lengthRef = wrapTaskLength + ex;
lengthRef = length;
wrap.WrapTask.Enqueue((nint) current);
Console.WriteLine($"Offset is {offset}");
Console.WriteLine($"Scheduling {length} kernels into {wrap.WrapTaskCapacity} threads");
Console.WriteLine();
current = MatrixParallelFactory.FromExistPackage(current);
offset += wrapTaskLength;
offset += length;
}
return handle;
}
@@ -117,9 +128,9 @@ namespace StgSharp.Mathematics.Numeric
}
/**/
MatrixParallelHandle handle = new MatrixParallelHandle(pool);
if (handle.Wraps.Count() == 1)
if (handle.Wraps.Length == 1)
{
handle.Wraps.First().WrapTask.Enqueue((nint)package);
handle.Wraps[0].WrapTask.Enqueue((nint)package);
return handle;
}
int threadCount = pool.Length;
@@ -129,7 +140,6 @@ namespace StgSharp.Mathematics.Numeric
int extraColumnCount = columnAfterBaseTile % threadCount; // columns to be sliced
int total = primCount;
Stack<MatrixParallelWrap> taskBunch = new Stack<MatrixParallelWrap>(threadCount);
MatrixParallelTaskPackage* current = package;
foreach (MatrixParallelWrap wrap in handle.Wraps)
{