going on big buffer, need three diff task scheduler
This commit is contained in:
@@ -68,18 +68,22 @@ namespace StgSharp.Mathematics.Numeric
|
||||
MatrixParallel.ReturnParallelResources(ref pool);
|
||||
return ans;
|
||||
}
|
||||
MatrixParallelHandle taskGroup = /**/ default
|
||||
/*
|
||||
MatrixParallel.PublicTask(left.GetColumnEnumeration(),
|
||||
right.GetColumnEnumeration(),
|
||||
ans.GetColumnEnumeration(),
|
||||
(delegate*<MatrixKernel<float>*, MatrixKernel<float>*, MatrixKernel<float>*, void>)NativeIntrinsic.Intrinsic.f32_add)
|
||||
/**/
|
||||
;
|
||||
MatrixParallelTaskPackage<float>* package = MatrixParallelFactory.CreateBaseTask<float>();
|
||||
package->Left = left.Buffer;
|
||||
package->Right = right.Buffer;
|
||||
package->Result = ans.Buffer;
|
||||
package->ElementSize = sizeof(float);
|
||||
package->PrimCount = left.KernelColumnLength;
|
||||
package->SecCount = left.KernelRowLength;
|
||||
package->ComputeMode = new MatrixOpMode(MatrixOperationStyle.BUFFER_OP, MatrixOperationParam.LEFT_RIGHT_ANS_PARAM);
|
||||
package->ComputeHandle = (IntPtr)NativeIntrinsic.Intrinsic.f32_add;
|
||||
MatrixParallelHandle taskGroup = MatrixParallel.ScheduleTask(package);
|
||||
|
||||
MatrixParallel.LaunchParallel(taskGroup, SleepMode.DeepSleep);
|
||||
/*
|
||||
* run parallel
|
||||
*/
|
||||
MatrixParallelFactory.Release(package);
|
||||
taskGroup.Dispose();
|
||||
return ans;
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
lCount = (long)p->LeftPrimOffset * p->LeftPrimStride,
|
||||
rCount = (long)p->RightPrimOffset * p->RightPrimStride,
|
||||
aCount = (long)p->ResultPrimOffset * p->ResultPrimStride,
|
||||
pCount = int.Min(p->PrimCount, p->PrimCountInTile + p->PrimTileOffset) /*_count of tile may be too much*/,
|
||||
pCount = int.Min(p->PrimCount, p->PrimColumnCountInTile + p->PrimTileOffset) /*_count of tile may be too much*/,
|
||||
//edge to reset counters
|
||||
lLimit = pCount - p->LeftPrimOffset,
|
||||
rLimit = pCount - p->RightPrimOffset,
|
||||
@@ -93,7 +93,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
lc = (long)p->LeftSecOffset * p->LeftSecStride,
|
||||
rc = (long)p->RightSecOffset * p->RightSecStride,
|
||||
ac = (long)p->ResultSecOffset * p->ResultSecStride,
|
||||
sCount = int.Min(p->SecCount, p->SecCountInTile * p->SecTileOffset);
|
||||
sCount = int.Min(p->SecCount, p->PrimColumnCountInTile * p->SecTileOffset);
|
||||
long
|
||||
ll = sCount - p->LeftSecOffset,
|
||||
rl = sCount - p->RightSecOffset,
|
||||
@@ -121,7 +121,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
lCount = (long)p->LeftPrimOffset * p->LeftPrimStride,
|
||||
rCount = (long)p->RightPrimOffset * p->RightPrimStride,
|
||||
aCount = (long)p->ResultPrimOffset * p->ResultPrimStride,
|
||||
pCount = int.Min(p->PrimCount, p->PrimCountInTile + p->PrimTileOffset) /*_count of tile may be too much*/,
|
||||
pCount = int.Min(p->PrimCount, p->PrimColumnCountInTile + p->PrimTileOffset) /*_count of tile may be too much*/,
|
||||
//edge to reset counters
|
||||
lLimit = pCount - p->LeftPrimOffset,
|
||||
rLimit = pCount - p->RightPrimOffset,
|
||||
@@ -144,7 +144,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
lc = (long)p->LeftSecOffset * p->LeftSecStride,
|
||||
rc = (long)p->RightSecOffset * p->RightSecStride,
|
||||
ac = (long)p->ResultSecOffset * p->ResultSecStride,
|
||||
sCount = int.Min(p->SecCount, p->SecCountInTile * p->SecTileOffset);
|
||||
sCount = int.Min(p->SecCount, p->PrimColumnCountInTile * p->SecTileOffset);
|
||||
long
|
||||
ll = sCount - p->LeftSecOffset,
|
||||
rl = sCount - p->RightSecOffset,
|
||||
@@ -171,7 +171,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
// set beginning value to counters for primary offsets
|
||||
rCount = (long)p->RightPrimOffset * p->RightPrimStride,
|
||||
aCount = (long)p->ResultPrimOffset * p->ResultPrimStride,
|
||||
pCount = int.Min(p->PrimCount, p->PrimCountInTile + p->PrimTileOffset) /*_count of tile may be too much*/,
|
||||
pCount = int.Min(p->PrimCount, p->PrimColumnCountInTile + p->PrimTileOffset) /*_count of tile may be too much*/,
|
||||
//edge to reset counters
|
||||
rLimit = pCount - p->RightPrimOffset,
|
||||
aLimit = pCount - p->ResultPrimOffset;
|
||||
@@ -190,7 +190,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
long
|
||||
rc = (long)p->RightSecOffset * p->RightSecStride,
|
||||
ac = (long)p->ResultSecOffset * p->ResultSecStride,
|
||||
sCount = int.Min(p->SecCount, p->SecCountInTile * p->SecTileOffset);
|
||||
sCount = int.Min(p->SecCount, p->PrimColumnCountInTile * p->SecTileOffset);
|
||||
long
|
||||
rl = sCount - p->RightSecOffset,
|
||||
al = sCount - p->ResultSecOffset;
|
||||
@@ -215,7 +215,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
// set beginning value to counters for primary offsets
|
||||
rCount = (long)p->RightPrimOffset * p->RightPrimStride,
|
||||
aCount = (long)p->ResultPrimOffset * p->ResultPrimStride,
|
||||
pCount = int.Min(p->PrimCount, p->PrimCountInTile + p->PrimTileOffset) /*_count of tile may be too much*/,
|
||||
pCount = int.Min(p->PrimCount, p->PrimColumnCountInTile + p->PrimTileOffset) /*_count of tile may be too much*/,
|
||||
//edge to reset counters
|
||||
rLimit = pCount - p->RightPrimOffset,
|
||||
aLimit = pCount - p->ResultPrimOffset;
|
||||
@@ -234,7 +234,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
long
|
||||
rc = (long)p->RightSecOffset * p->RightSecStride,
|
||||
ac = (long)p->ResultSecOffset * p->ResultSecStride,
|
||||
sCount = int.Min(p->SecCount, p->SecCountInTile * p->SecTileOffset);
|
||||
sCount = int.Min(p->SecCount, p->PrimColumnCountInTile * p->SecTileOffset);
|
||||
long
|
||||
rl = sCount - p->RightSecOffset,
|
||||
al = sCount - p->ResultSecOffset;
|
||||
|
||||
@@ -32,6 +32,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -40,8 +41,16 @@ namespace StgSharp.Mathematics.Numeric
|
||||
public static partial class MatrixParallel
|
||||
{
|
||||
|
||||
private static unsafe MatrixParallelHandle PublicTaskPrivate<T>(MatrixParallelTaskPackage<T>* package)
|
||||
where T : unmanaged, INumber<T>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
||||
internal static unsafe MatrixParallelHandle ScheduleTask<T>(MatrixParallelTaskPackage<T>* package)
|
||||
where T : unmanaged
|
||||
{
|
||||
MatrixParallelTaskPackageNonGeneric* nonGeneric = (MatrixParallelTaskPackageNonGeneric*)package;
|
||||
return ScheduleTask(nonGeneric);
|
||||
}
|
||||
|
||||
internal static unsafe MatrixParallelHandle ScheduleTask(MatrixParallelTaskPackageNonGeneric* package)
|
||||
{
|
||||
int primCount = package->PrimCount;
|
||||
int secCount = package->SecCount;
|
||||
@@ -59,7 +68,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
MatrixParallelHandle handle = new MatrixParallelHandle(pool);
|
||||
if (handle.Wraps.Count() == 1)
|
||||
{
|
||||
handle.Wraps.First().WrapTask = (MatrixParallelTaskPackageNonGeneric*)package;
|
||||
handle.Wraps.First().WrapTask = package;
|
||||
return handle;
|
||||
}
|
||||
int threadCount = pool.Length;
|
||||
@@ -70,7 +79,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
|
||||
int total = primCount;
|
||||
Stack<MatrixParallelWrap> taskBunch = new Stack<MatrixParallelWrap>(threadCount);
|
||||
MatrixParallelTaskPackage<T>* current = package;
|
||||
MatrixParallelTaskPackageNonGeneric* current = package;
|
||||
foreach (MatrixParallelWrap wrap in handle.Wraps)
|
||||
{
|
||||
bool hasSlice = columnAfterBaseTile > 0;
|
||||
@@ -103,7 +112,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
total -= columnInWrap;
|
||||
|
||||
// set to wrap and push
|
||||
wrap.WrapTask = (MatrixParallelTaskPackageNonGeneric*)current;
|
||||
wrap.WrapTask = current;
|
||||
|
||||
if (total <= 0)
|
||||
{
|
||||
|
||||
@@ -43,7 +43,14 @@ namespace StgSharp.Mathematics.Numeric
|
||||
private static CapacityFixedStack<MatrixParallelThread> _threads;
|
||||
|
||||
private static volatile int RemainThreadCount = 0;
|
||||
private static readonly object _lock = new();
|
||||
private static readonly
|
||||
#if NET10_0_OR_GREATER
|
||||
Lock
|
||||
#else
|
||||
object
|
||||
#endif
|
||||
_lock = new();
|
||||
|
||||
private static ThreadPriority _AfterWork = ThreadPriority.Lowest;
|
||||
|
||||
public static bool SupportParallel { get; } = Environment.ProcessorCount > 6;
|
||||
|
||||
@@ -73,11 +73,11 @@ namespace StgSharp.Mathematics.Numeric
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct MatrixOpMode
|
||||
public struct MatrixOpMode(MatrixOperationStyle style, MatrixOperationParam paramLayout)
|
||||
{
|
||||
|
||||
public MatrixOperationParam ParameterStyle;
|
||||
public MatrixOperationStyle OperationStyle;
|
||||
public MatrixOperationParam ParameterStyle = paramLayout;
|
||||
public MatrixOperationStyle OperationStyle = style;
|
||||
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
#region source
|
||||
|
||||
// Group 1: Left/Right matrix kernel base address
|
||||
[FieldOffset(0)]public IntPtr Left; // 8
|
||||
[FieldOffset(0)] public IntPtr Left; // 8
|
||||
[FieldOffset(8)] public IntPtr Right; // 8
|
||||
|
||||
#endregion
|
||||
@@ -106,7 +106,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
|
||||
// Group 2: Result kernel base address + reserved
|
||||
[FieldOffset(16)] public IntPtr Result; // 8
|
||||
[FieldOffset(24)]public int ElementSize;
|
||||
[FieldOffset(24)] public int ElementSize;
|
||||
[FieldOffset(28)] public int ReservedPtr0; // 4 (extension/reserved)
|
||||
|
||||
#endregion
|
||||
@@ -158,8 +158,8 @@ namespace StgSharp.Mathematics.Numeric
|
||||
|
||||
[FieldOffset(112)]public int PrimTileOffset; // 4
|
||||
[FieldOffset(116)]public int SecTileOffset; // 4
|
||||
[FieldOffset(120)]public int PrimCountInTile; // 4
|
||||
[FieldOffset(124)]public int SecCountInTile; // 4
|
||||
[FieldOffset(120)] public int PrimColumnCountInTile; // 4
|
||||
[FieldOffset(124)] public int SecColumnCountInTile; // 4
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -173,7 +173,6 @@ namespace StgSharp.Mathematics.Numeric
|
||||
BindedWrap.PublishTaskToWorkers(Tasks);
|
||||
BindedWrap.SetAllWorker();
|
||||
ExecuteTaskPackage(Tasks);
|
||||
|
||||
break;
|
||||
case 2://leader, error because leader should be at outer thread but not here
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user