matrix parallel start to use two different policy
This commit is contained in:
@@ -71,7 +71,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
op(task);
|
||||
return;
|
||||
}
|
||||
MatrixParallelWrap taskWrap = MatrixParallel.ScheduleTask<BufferSequentialQueue>(task);
|
||||
MatrixParallelWrap taskWrap = MatrixParallel.ScheduleTask<BufferQueueLeftRightAns>(task);
|
||||
taskWrap.LaunchParallel(SleepMode.DeepSleep);
|
||||
taskWrap.Dispose();
|
||||
}
|
||||
|
||||
@@ -42,78 +42,139 @@ namespace StgSharp.Mathematics.Numeric
|
||||
internal unsafe interface IMatrixParallelQueue<TSelf> where TSelf : IMatrixParallelQueue<TSelf>
|
||||
{
|
||||
|
||||
static abstract bool NeedNumaBuffer { get; }
|
||||
|
||||
static abstract TSelf Create(
|
||||
MatrixParallelTask* baseTask,
|
||||
L4 buffer
|
||||
L4 buffer,
|
||||
int numaCount
|
||||
);
|
||||
|
||||
void Return(
|
||||
MatrixParallelTask* task
|
||||
MatrixParallelTask* task,
|
||||
in L4CacheLine left,
|
||||
in L4CacheLine right,
|
||||
in L4CacheLine ans
|
||||
);
|
||||
|
||||
bool Steal(
|
||||
MatrixParallelTask* task
|
||||
MatrixParallelTask* task,
|
||||
out L4CacheLine left,
|
||||
out L4CacheLine right,
|
||||
out L4CacheLine ans
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
internal sealed unsafe class BufferSequentialQueue : IMatrixParallelQueue<BufferSequentialQueue>
|
||||
internal sealed unsafe class BufferQueueLeftRightAns : IMatrixParallelQueue<BufferQueueLeftRightAns>
|
||||
{
|
||||
|
||||
private MatrixParallelTask* baseTask;
|
||||
private MatrixParallelTask* _baseTask;
|
||||
private bool _needNuma;
|
||||
private L4 _buffer;
|
||||
private volatile nuint _cursor;
|
||||
private readonly nuint Count;
|
||||
|
||||
private BufferSequentialQueue() { }
|
||||
private BufferQueueLeftRightAns() { }
|
||||
|
||||
private BufferSequentialQueue(
|
||||
private BufferQueueLeftRightAns(
|
||||
MatrixParallelTask* baseTask
|
||||
)
|
||||
{
|
||||
this.baseTask = baseTask;
|
||||
_baseTask = baseTask;
|
||||
Count = ((nuint)_baseTask->CommonX) * ((nuint)_baseTask->CommonY);
|
||||
}
|
||||
|
||||
public static bool NeedNumaBuffer => throw new NotImplementedException();
|
||||
|
||||
public static unsafe BufferSequentialQueue Create(
|
||||
MatrixParallelTask* baseTask,
|
||||
L4 buffer
|
||||
public static unsafe BufferQueueLeftRightAns Create(
|
||||
MatrixParallelTask* baseTask,
|
||||
L4 buffer,
|
||||
int numaCount
|
||||
)
|
||||
{
|
||||
return new BufferSequentialQueue(baseTask);
|
||||
return new BufferQueueLeftRightAns(baseTask);
|
||||
}
|
||||
|
||||
public unsafe void Return(
|
||||
MatrixParallelTask* task
|
||||
) { }
|
||||
MatrixParallelTask* task,
|
||||
in L4CacheLine left,
|
||||
in L4CacheLine right,
|
||||
in L4CacheLine ans
|
||||
)
|
||||
{
|
||||
if (left.Address != 0) {
|
||||
left.Dispose();
|
||||
}
|
||||
if (right.Address != 0) {
|
||||
right.Dispose();
|
||||
}
|
||||
if (ans.Address != 0) {
|
||||
ans.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe bool Steal(
|
||||
MatrixParallelTask* task
|
||||
MatrixParallelTask* task,
|
||||
out L4CacheLine left,
|
||||
out L4CacheLine right,
|
||||
out L4CacheLine ans
|
||||
)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private class Predictor : IL4Predict
|
||||
private class Predictor(
|
||||
BufferQueueLeftRightAns host
|
||||
) : IL4Predict
|
||||
{
|
||||
|
||||
private readonly BufferQueueLeftRightAns _host;
|
||||
|
||||
public PredictResult Predict(
|
||||
Span<CacheLineDescription> node,
|
||||
out int count
|
||||
)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
nuint begin = _host._cursor;
|
||||
nuint mat1 = (nuint)_host._baseTask->Mat1;
|
||||
nuint mat2 = (nuint)_host._baseTask->Mat2;
|
||||
nuint mat3 = (nuint)_host._baseTask->Mat3;
|
||||
nuint _cur = begin * _host._baseTask->ElementType.Size;
|
||||
nuint mat1_cur = ((nuint)_host._baseTask->Mat1) + _cur;
|
||||
nuint mat2_cur = ((nuint)_host._baseTask->Mat2) + _cur;
|
||||
nuint mat3_cur = ((nuint)_host._baseTask->Mat3) + _cur;
|
||||
nuint end = ((nuint)_host._baseTask->Mat1) + (((nuint)_host._baseTask->CommonX) * ((nuint)_host._baseTask->CommonY) * _host._baseTask->ElementType.Size);
|
||||
nuint mat1_end = ((nuint)_host._baseTask->Mat1) + end;
|
||||
nuint mat2_end = ((nuint)_host._baseTask->Mat2) + end;
|
||||
nuint mat3_end = ((nuint)_host._baseTask->Mat3) + end;
|
||||
|
||||
nuint size = 1024 * 16 * _host._baseTask->ElementType.Size;
|
||||
for (int i = 0; i < node.Length; i += 3)
|
||||
{
|
||||
int cycle = i / 3;
|
||||
ref CacheLineDescription prediction = ref node[i];
|
||||
prediction.Address = mat1_cur + size;
|
||||
}
|
||||
count = 1;
|
||||
return PredictResult.Success;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Prefetch(
|
||||
nuint origin,
|
||||
uint policy,
|
||||
Span<byte> cache
|
||||
)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
MatrixCachePolicy pEnum = (MatrixCachePolicy)policy;
|
||||
if ((pEnum & (MatrixCachePolicy.Ans | MatrixCachePolicy.Sequential)) != 0)
|
||||
{
|
||||
if ((pEnum & (MatrixCachePolicy.Left | MatrixCachePolicy.Right)) != 0)
|
||||
{
|
||||
byte* bPtr = (byte*)origin;
|
||||
new Span<byte>(bPtr, cache.Length).CopyTo(cache);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void WriteBack(
|
||||
nuint origin,
|
||||
uint policy,
|
||||
@@ -123,8 +184,8 @@ namespace StgSharp.Mathematics.Numeric
|
||||
MatrixCachePolicy pEnum = (MatrixCachePolicy)policy;
|
||||
if ((pEnum & (MatrixCachePolicy.Ans | MatrixCachePolicy.Sequential)) != 0)
|
||||
{
|
||||
byte* span = (byte*) origin;
|
||||
cache.CopyTo(new Span<byte>(span, cache.Length));
|
||||
byte* bPtr = (byte*)origin;
|
||||
cache.CopyTo(new Span<byte>(bPtr, cache.Length));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,3 +193,4 @@ namespace StgSharp.Mathematics.Numeric
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user