working on matrix mul matrix, rebuilding task model defines in C#
This commit is contained in:
@@ -34,7 +34,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
internal static class MatrixComputeModel
|
||||
{
|
||||
|
||||
internal static unsafe void BufferComputeBinary(MatrixParallelTaskPackage* p)
|
||||
internal static unsafe void KernelComputeBinary(MatrixParallelTaskPackage* p)
|
||||
{
|
||||
int size = p->ElementSize * 16;
|
||||
long count = Unsafe.As<int, long>(ref p->PrimCount);
|
||||
@@ -47,7 +47,21 @@ namespace StgSharp.Mathematics.Numeric
|
||||
MatrixParallelFactory.Release(p);
|
||||
}
|
||||
|
||||
internal static unsafe void BufferComputeNoOperatorScalar(MatrixParallelTaskPackage* p)
|
||||
internal static unsafe void KernelComputeBinaryScalar(MatrixParallelTaskPackage* p)
|
||||
{
|
||||
int size = p->ElementSize * 16;
|
||||
long count = Unsafe.As<int, long>(ref p->PrimCount);
|
||||
long offset = Unsafe.As<int, long>(ref p->PrimTileOffset) * size;
|
||||
ScalarPacket* scalar = p->Scalar;
|
||||
((delegate* unmanaged[Cdecl]<void*, void*, void*,ScalarPacket*, long, void>)p->ComputeHandle)((void*)(p->Left + offset),
|
||||
(void*)(p->Right + offset),
|
||||
(void*)(p->Result + offset),
|
||||
scalar,
|
||||
count);
|
||||
MatrixParallelFactory.Release(p);
|
||||
}
|
||||
|
||||
internal static unsafe void KernelComputeNoOperatorScalar(MatrixParallelTaskPackage* p)
|
||||
{
|
||||
int size = p->ElementSize * 16;
|
||||
long count = Unsafe.As<int, long>(ref p->PrimCount);
|
||||
@@ -57,7 +71,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
MatrixParallelFactory.Release(p);
|
||||
}
|
||||
|
||||
internal static unsafe void BufferComputeUnary(MatrixParallelTaskPackage* p)
|
||||
internal static unsafe void KernelComputeUnary(MatrixParallelTaskPackage* p)
|
||||
{
|
||||
int size = p->ElementSize * 16;
|
||||
long count = Unsafe.As<int, long>(ref p->PrimCount);
|
||||
@@ -69,7 +83,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
MatrixParallelFactory.Release(p);
|
||||
}
|
||||
|
||||
internal static unsafe void BufferComputeUnaryScalar(MatrixParallelTaskPackage* p)
|
||||
internal static unsafe void KernelComputeUnaryScalar(MatrixParallelTaskPackage* p)
|
||||
{
|
||||
int size = p->ElementSize * 16;
|
||||
long count = Unsafe.As<int, long>(ref p->PrimCount);
|
||||
@@ -81,201 +95,19 @@ namespace StgSharp.Mathematics.Numeric
|
||||
MatrixParallelFactory.Release(p);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static unsafe void KernelComputeBinary(MatrixParallelTaskPackage* p)
|
||||
{
|
||||
int eSize = p->ElementSize;
|
||||
|
||||
// base pointer to matrix kernels
|
||||
nint l = p->Left, r = p->Right, a = p->Result;
|
||||
long
|
||||
|
||||
// set beginning value to counters for primary offsets
|
||||
lCount = (long)p->LeftPrimOffset * p->LeftPrimStride,
|
||||
rCount = (long)p->RightPrimOffset * p->RightPrimStride,
|
||||
aCount = (long)p->ResultPrimOffset * p->ResultPrimStride,
|
||||
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,
|
||||
aLimit = pCount - p->ResultPrimOffset;
|
||||
delegate* unmanaged[Cdecl]<IntPtr, IntPtr, IntPtr, void> op =
|
||||
(delegate* unmanaged[Cdecl]<IntPtr, IntPtr, IntPtr, void>)p->ComputeHandle;
|
||||
for (long i = p->PrimTileOffset % pCount; i < pCount; i++)
|
||||
{
|
||||
// update primary counters
|
||||
// if reaches edge, reset to zero
|
||||
lCount = i < lLimit ? lCount + p->LeftPrimStride : 0;
|
||||
rCount = i < rLimit ? rCount + p->RightPrimStride : 0;
|
||||
aCount = i < rLimit ? aCount + p->ResultPrimStride : 0;
|
||||
|
||||
// get kernel column pointers
|
||||
nint left = l + (nint)(lCount * eSize);
|
||||
nint right = r + (nint)(rCount * eSize);
|
||||
nint ans = a + (nint)(aCount * eSize);
|
||||
long
|
||||
lc = (long)p->LeftSecOffset * p->LeftSecStride,
|
||||
rc = (long)p->RightSecOffset * p->RightSecStride,
|
||||
ac = (long)p->ResultSecOffset * p->ResultSecStride,
|
||||
sCount = int.Min(p->SecCount, p->PrimColumnCountInTile * p->SecTileOffset);
|
||||
long
|
||||
ll = sCount - p->LeftSecOffset,
|
||||
rl = sCount - p->RightSecOffset,
|
||||
al = sCount - p->ResultSecOffset;
|
||||
for (long j = p->SecTileOffset % sCount; j < sCount; j++)
|
||||
{
|
||||
lc = j < ll ? lc + p->LeftSecStride : 0;
|
||||
rc = j < rl ? rc + p->RightSecStride : 0;
|
||||
ac = j < al ? ac + p->ResultSecStride : 0;
|
||||
op(left + (nint)lc, right + (nint)rc, ans + (nint)ac);
|
||||
}
|
||||
}
|
||||
MatrixParallelFactory.Release(p);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static unsafe void KernelComputeBinaryScalar(MatrixParallelTaskPackage* p)
|
||||
{
|
||||
int eSize = p->ElementSize;
|
||||
|
||||
// base pointer to matrix kernels
|
||||
nint l = p->Left, r = p->Right, a = p->Result;
|
||||
long
|
||||
|
||||
// set beginning value to counters for primary offsets
|
||||
lCount = (long)p->LeftPrimOffset * p->LeftPrimStride,
|
||||
rCount = (long)p->RightPrimOffset * p->RightPrimStride,
|
||||
aCount = (long)p->ResultPrimOffset * p->ResultPrimStride,
|
||||
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,
|
||||
aLimit = pCount - p->ResultPrimOffset;
|
||||
delegate* unmanaged[Cdecl]<IntPtr, IntPtr, IntPtr, ScalarPacket*, void> op =
|
||||
(delegate* unmanaged[Cdecl]<IntPtr, IntPtr, IntPtr, ScalarPacket*, void>)p->ComputeHandle;
|
||||
for (long i = p->PrimTileOffset % pCount; i < pCount; i++)
|
||||
{
|
||||
// update primary counters
|
||||
// if reaches edge, reset to zero
|
||||
lCount = i < lLimit ? lCount + p->LeftPrimStride : 0;
|
||||
rCount = i < rLimit ? rCount + p->RightPrimStride : 0;
|
||||
aCount = i < rLimit ? aCount + p->ResultPrimStride : 0;
|
||||
|
||||
// get kernel column pointers
|
||||
nint left = l + (nint)(lCount * eSize);
|
||||
nint right = r + (nint)(rCount * eSize);
|
||||
nint ans = a + (nint)(aCount * eSize);
|
||||
long
|
||||
lc = (long)p->LeftSecOffset * p->LeftSecStride,
|
||||
rc = (long)p->RightSecOffset * p->RightSecStride,
|
||||
ac = (long)p->ResultSecOffset * p->ResultSecStride,
|
||||
sCount = int.Min(p->SecCount, p->PrimColumnCountInTile * p->SecTileOffset);
|
||||
long
|
||||
ll = sCount - p->LeftSecOffset,
|
||||
rl = sCount - p->RightSecOffset,
|
||||
al = sCount - p->ResultSecOffset;
|
||||
for (long j = p->SecTileOffset % sCount; j < sCount; j++)
|
||||
{
|
||||
lc = j < ll ? lc + p->LeftSecStride : 0;
|
||||
rc = j < rl ? rc + p->RightSecStride : 0;
|
||||
ac = j < al ? ac + p->ResultSecStride : 0;
|
||||
op(left + (nint)lc, right + (nint)rc, ans + (nint)ac, p->Scalar);
|
||||
}
|
||||
}
|
||||
MatrixParallelFactory.Release(p);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static unsafe void KernelComputeUnary(MatrixParallelTaskPackage* p)
|
||||
{
|
||||
int eSize = p->ElementSize;
|
||||
|
||||
// base pointer to matrix kernels
|
||||
nint r = p->Right, a = p->Result;
|
||||
long
|
||||
|
||||
// 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->PrimColumnCountInTile + p->PrimTileOffset) /*_count of tile may be too much*/,
|
||||
//edge to reset counters
|
||||
rLimit = pCount - p->RightPrimOffset,
|
||||
aLimit = pCount - p->ResultPrimOffset;
|
||||
delegate* unmanaged[Cdecl]<IntPtr, IntPtr, void> op =
|
||||
(delegate* unmanaged[Cdecl]<IntPtr, IntPtr, void>)p->ComputeHandle;
|
||||
for (long i = p->PrimTileOffset % pCount; i < pCount; i++)
|
||||
{
|
||||
// update primary counters
|
||||
// if reaches edge, reset to zero
|
||||
rCount = i < rLimit ? rCount + p->RightPrimStride : 0;
|
||||
aCount = i < rLimit ? aCount + p->ResultPrimStride : 0;
|
||||
|
||||
// get kernel column pointers
|
||||
nint right = r + (nint)(rCount * eSize);
|
||||
nint ans = a + (nint)(aCount * eSize);
|
||||
long
|
||||
rc = (long)p->RightSecOffset * p->RightSecStride,
|
||||
ac = (long)p->ResultSecOffset * p->ResultSecStride,
|
||||
sCount = int.Min(p->SecCount, p->PrimColumnCountInTile * p->SecTileOffset);
|
||||
long
|
||||
rl = sCount - p->RightSecOffset,
|
||||
al = sCount - p->ResultSecOffset;
|
||||
for (long j = p->SecTileOffset % sCount; j < sCount; j++)
|
||||
{
|
||||
rc = j < rl ? rc + p->RightSecStride : 0;
|
||||
ac = j < al ? ac + p->ResultSecStride : 0;
|
||||
op(right + (nint)rc, ans + (nint)ac);
|
||||
}
|
||||
}
|
||||
MatrixParallelFactory.Release(p);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static unsafe void KernelComputeUnaryScalar(MatrixParallelTaskPackage* p)
|
||||
{
|
||||
int eSize = p->ElementSize;
|
||||
|
||||
// base pointer to matrix kernels
|
||||
nint r = p->Right, a = p->Result;
|
||||
long
|
||||
|
||||
// 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->PrimColumnCountInTile + p->PrimTileOffset) /*_count of tile may be too much*/,
|
||||
//edge to reset counters
|
||||
rLimit = pCount - p->RightPrimOffset,
|
||||
aLimit = pCount - p->ResultPrimOffset;
|
||||
delegate* unmanaged[Cdecl]<IntPtr, IntPtr, ScalarPacket*, void> op =
|
||||
(delegate* unmanaged[Cdecl]<IntPtr, IntPtr, ScalarPacket*, void>)p->ComputeHandle;
|
||||
for (long i = p->PrimTileOffset % pCount; i < pCount; i++)
|
||||
{
|
||||
// update primary counters
|
||||
// if reaches edge, reset to zero
|
||||
rCount = i < rLimit ? rCount + p->RightPrimStride : 0;
|
||||
aCount = i < rLimit ? aCount + p->ResultPrimStride : 0;
|
||||
|
||||
// get kernel column pointers
|
||||
nint right = r + (nint)(rCount * eSize);
|
||||
nint ans = a + (nint)(aCount * eSize);
|
||||
long
|
||||
rc = (long)p->RightSecOffset * p->RightSecStride,
|
||||
ac = (long)p->ResultSecOffset * p->ResultSecStride,
|
||||
sCount = int.Min(p->SecCount, p->PrimColumnCountInTile * p->SecTileOffset);
|
||||
long
|
||||
rl = sCount - p->RightSecOffset,
|
||||
al = sCount - p->ResultSecOffset;
|
||||
for (long j = p->SecTileOffset % sCount; j < sCount; j++)
|
||||
{
|
||||
rc = j < rl ? rc + p->RightSecStride : 0;
|
||||
ac = j < al ? ac + p->ResultSecStride : 0;
|
||||
op(right + (nint)rc, ans + (nint)ac, p->Scalar);
|
||||
}
|
||||
}
|
||||
MatrixParallelFactory.Release(p);
|
||||
}
|
||||
|
||||
internal static unsafe void PanelComputeBinary(MatrixParallelTaskPackage* p) { }
|
||||
|
||||
internal static unsafe void SpecialCompute(MatrixParallelTaskPackage* p)
|
||||
{
|
||||
switch ((MatrixOperationSpecial)p->ComputeMode.OperationStyle)
|
||||
{
|
||||
case MatrixOperationSpecial.SEQ_FMA:
|
||||
MatrixCompute.ComputeFmaPanelF32(p);
|
||||
break;
|
||||
default:
|
||||
throw new NotSupportedException("The special matrix operation style is not supported.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user