before rewrite of HLSF
This commit is contained in:
@@ -39,7 +39,7 @@ namespace StgSharp.HighPerformance.Memory
|
||||
nuint size
|
||||
)
|
||||
{
|
||||
if (size > _maxSize) {
|
||||
if (size > _maxAllocSize) {
|
||||
throw new InvalidOperationException("Requested size exceeds maximum allocatable size.");
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ namespace StgSharp.HighPerformance.Memory
|
||||
out HlsfHandle handle
|
||||
)
|
||||
{
|
||||
if (size > _maxSize)
|
||||
if (size > _maxAllocSize)
|
||||
{
|
||||
handle = default;
|
||||
return false;
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace StgSharp.HighPerformance.Memory
|
||||
private readonly Action<nuint> _freeHandle;
|
||||
private bool disposedValue;
|
||||
private readonly int _align;
|
||||
private readonly nuint _maxSize;
|
||||
private readonly nuint _maxAllocSize;
|
||||
private readonly nuint _size;
|
||||
private readonly SlabAllocator<Entry> _entries;
|
||||
|
||||
@@ -98,7 +98,7 @@ namespace StgSharp.HighPerformance.Memory
|
||||
size *= 4;
|
||||
_levelSizeArray[i] = size;
|
||||
}
|
||||
_maxSize = maxBlockSize;
|
||||
_maxAllocSize = maxBlockSize;
|
||||
_freeHandle = freeHandle ?? (static _ => { });
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
op(task);
|
||||
return;
|
||||
}
|
||||
MatrixParallelWrap taskWrap = MatrixParallel.ScheduleTask<BufferQueueLeftRightAns_FullNuma>(task);
|
||||
MatrixParallelWrap taskWrap = MatrixParallel.ScheduleTask<BufferQueueLeftRightAns_NoNuma>(task);
|
||||
taskWrap.LaunchParallel(SleepMode.DeepSleep);
|
||||
taskWrap.Dispose();
|
||||
}
|
||||
|
||||
@@ -43,29 +43,32 @@ namespace StgSharp.Mathematics.Numeric
|
||||
internal unsafe interface IMatrixParallelQueue<TSelf> where TSelf : IMatrixParallelQueue<TSelf>
|
||||
{
|
||||
|
||||
void Return(
|
||||
MatrixParallelTask* task,
|
||||
in L4CacheLine left,
|
||||
in L4CacheLine right,
|
||||
in L4CacheLine ans
|
||||
bool InitNumaPredictor(
|
||||
out IL4Predict predictor
|
||||
);
|
||||
|
||||
bool Steal(
|
||||
bool RequestTaskResource(
|
||||
MatrixParallelTask* task,
|
||||
out L4CacheLine left,
|
||||
out L4CacheLine right,
|
||||
out L4CacheLine ans
|
||||
);
|
||||
|
||||
void ReturnTaskResource(
|
||||
MatrixParallelTask* task,
|
||||
in L4CacheLine left,
|
||||
in L4CacheLine right,
|
||||
in L4CacheLine ans
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
internal interface IBufferQueueLeftRightAns : IMatrixParallelQueue<IBufferQueueLeftRightAns> { }
|
||||
|
||||
internal sealed unsafe class BufferQueueLeftRightAns_FullNuma : IMatrixParallelQueue<IBufferQueueLeftRightAns>
|
||||
internal sealed unsafe class BufferQueueLeftRightAns_NoNuma : IMatrixParallelQueue<IBufferQueueLeftRightAns>
|
||||
{
|
||||
|
||||
private MatrixParallelTask* _baseTask;
|
||||
private L4 _buffer;
|
||||
private readonly nuint _byteSize;
|
||||
private readonly nuint _count;
|
||||
private volatile nuint _cursor;
|
||||
@@ -74,9 +77,9 @@ namespace StgSharp.Mathematics.Numeric
|
||||
private volatile nuint _mat2;
|
||||
private volatile nuint _mat3;
|
||||
|
||||
private BufferQueueLeftRightAns_FullNuma() { }
|
||||
private BufferQueueLeftRightAns_NoNuma() { }
|
||||
|
||||
internal BufferQueueLeftRightAns_FullNuma(
|
||||
internal BufferQueueLeftRightAns_NoNuma(
|
||||
MatrixParallelTask* baseTask
|
||||
)
|
||||
{
|
||||
@@ -90,103 +93,35 @@ namespace StgSharp.Mathematics.Numeric
|
||||
_mat3 = (nuint)_baseTask->Mat3;
|
||||
}
|
||||
|
||||
public unsafe void Return(
|
||||
MatrixParallelTask* task,
|
||||
in L4CacheLine left,
|
||||
in L4CacheLine right,
|
||||
in L4CacheLine ans
|
||||
public bool InitNumaPredictor(
|
||||
out IL4Predict predictor
|
||||
)
|
||||
{
|
||||
if (left.Address != 0) {
|
||||
left.Dispose();
|
||||
}
|
||||
if (right.Address != 0) {
|
||||
right.Dispose();
|
||||
}
|
||||
if (ans.Address != 0) {
|
||||
ans.Dispose();
|
||||
}
|
||||
predictor = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public unsafe bool Steal(
|
||||
public unsafe bool RequestTaskResource(
|
||||
MatrixParallelTask* task,
|
||||
out L4CacheLine left,
|
||||
out L4CacheLine right,
|
||||
out L4CacheLine ans
|
||||
)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
left = new L4CacheLine(0, ref Unsafe.AsRef<int>(null), ref Unsafe.AsRef<int>(null));
|
||||
right = new L4CacheLine(0, ref Unsafe.AsRef<int>(null), ref Unsafe.AsRef<int>(null));
|
||||
ans = new L4CacheLine(0, ref Unsafe.AsRef<int>(null), ref Unsafe.AsRef<int>(null));
|
||||
return true;
|
||||
}
|
||||
|
||||
private class Predictor(
|
||||
BufferQueueLeftRightAns_FullNuma host
|
||||
) : IL4Predict
|
||||
{
|
||||
|
||||
private readonly BufferQueueLeftRightAns_FullNuma _host;
|
||||
|
||||
public PredictResult Predict(
|
||||
Span<CacheLineDescription> node,
|
||||
out int count
|
||||
public unsafe void ReturnTaskResource(
|
||||
MatrixParallelTask* task,
|
||||
in L4CacheLine left,
|
||||
in L4CacheLine right,
|
||||
in L4CacheLine ans
|
||||
)
|
||||
{
|
||||
nuint begin = _host._cursor;
|
||||
nuint mat1 = (nuint)_host._baseTask->Mat1;
|
||||
nuint mat2 = (nuint)_host._baseTask->Mat2;
|
||||
nuint mat3 = (nuint)_host._baseTask->Mat3;
|
||||
nuint _cur = 16 * 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 = _host._byteSize;
|
||||
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 * ((nuint)_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
|
||||
)
|
||||
{
|
||||
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,
|
||||
ReadOnlySpan<byte> cache
|
||||
)
|
||||
{
|
||||
MatrixCachePolicy pEnum = (MatrixCachePolicy)policy;
|
||||
if ((pEnum & (MatrixCachePolicy.Ans | MatrixCachePolicy.Sequential)) != 0)
|
||||
{
|
||||
byte* bPtr = (byte*)origin;
|
||||
cache.CopyTo(new Span<byte>(bPtr, cache.Length));
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user