Better L4 and array storage design
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
// -----------------------------------------------------------------------
|
||||
// file="MatrixCompute.double"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -27,6 +27,7 @@
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Internal;
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Internal;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -38,7 +39,11 @@ namespace StgSharp.Mathematics.Numeric
|
||||
public partial class MatrixCompute
|
||||
{
|
||||
|
||||
public static unsafe void Add(Matrix<double> left, Matrix<double> right, Matrix<double> ans)
|
||||
public static unsafe void Add(
|
||||
Matrix<double> left,
|
||||
Matrix<double> right,
|
||||
Matrix<double> ans
|
||||
)
|
||||
{
|
||||
int f64 = (int)MatrixElementType.F64;
|
||||
if (left.ColumnLength != right.ColumnLength ||
|
||||
@@ -53,7 +58,8 @@ namespace StgSharp.Mathematics.Numeric
|
||||
MatrixKernel<double>* leftPtr = left.Buffer;
|
||||
MatrixKernel<double>* rightPtr = right.Buffer;
|
||||
MatrixKernel<double>* ansPtr = ans.Buffer;
|
||||
MathematicsModule.GlobalContext.mat[f64].buffer_add(leftPtr, rightPtr, ansPtr, count);
|
||||
MathematicsModule.GlobalContext.mat_sk[f64].buffer_add(leftPtr, rightPtr, ansPtr,
|
||||
count);
|
||||
|
||||
return;
|
||||
} else if (count <= 1024)
|
||||
@@ -63,7 +69,8 @@ namespace StgSharp.Mathematics.Numeric
|
||||
MatrixKernel<double>* leftPtr = left.Buffer;
|
||||
MatrixKernel<double>* rightPtr = right.Buffer;
|
||||
MatrixKernel<double>* ansPtr = ans.Buffer;
|
||||
MathematicsModule.GlobalContext.mat[f64].buffer_add(leftPtr, rightPtr, ansPtr, count);
|
||||
MathematicsModule.GlobalContext.mat_sk[f64].buffer_add(leftPtr, rightPtr, ansPtr,
|
||||
count);
|
||||
|
||||
MatrixParallel.ReturnParallelResources(ref pool);
|
||||
return;
|
||||
@@ -76,7 +83,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
package->PrimCount = ans.KernelColumnLength;
|
||||
package->SecCount = ans.KernelRowLength;
|
||||
package->ComputeMode = new MatrixOpMode(MatrixIndexStyle.BUFFER_INDEX, MatrixOperationParam.LEFT_RIGHT_ANS_PARAM);
|
||||
package->ComputeHandle = (IntPtr)MathematicsModule.GlobalContext.mat[f64].buffer_add;
|
||||
package->ComputeHandle = (IntPtr)MathematicsModule.GlobalContext.mat_sk[f64].buffer_add;
|
||||
MatrixParallelWrap taskGroup = MatrixParallel.ScheduleTask(package);
|
||||
|
||||
taskGroup.LaunchParallel(SleepMode.DeepSleep);
|
||||
@@ -84,7 +91,10 @@ namespace StgSharp.Mathematics.Numeric
|
||||
return;
|
||||
}
|
||||
|
||||
public static unsafe void Fill(Matrix<double> ans, double value)
|
||||
public static unsafe void Fill(
|
||||
Matrix<double> ans,
|
||||
double value
|
||||
)
|
||||
{
|
||||
int f64 = (int)MatrixElementType.F64;
|
||||
long count = (long)ans.KernelColumnLength * ans.KernelRowLength;
|
||||
@@ -92,12 +102,12 @@ namespace StgSharp.Mathematics.Numeric
|
||||
scalar->Data<double>(0) = value;
|
||||
if (count <= 256)
|
||||
{
|
||||
MathematicsModule.GlobalContext.mat[f64].buffer_fill(ans.Buffer, scalar, count);
|
||||
MathematicsModule.GlobalContext.mat_sk[f64].buffer_fill(ans.Buffer, scalar, count);
|
||||
return;
|
||||
} else if (count <= 1024)
|
||||
{
|
||||
MatrixParallelThread[] pool = MatrixParallel.LeadParallel(1);
|
||||
MathematicsModule.GlobalContext.mat[f64].buffer_fill(ans.Buffer, scalar, count);
|
||||
MathematicsModule.GlobalContext.mat_sk[f64].buffer_fill(ans.Buffer, scalar, count);
|
||||
MatrixParallel.ReturnParallelResources(ref pool);
|
||||
return;
|
||||
}
|
||||
@@ -107,7 +117,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
package->PrimCount = ans.KernelColumnLength;
|
||||
package->SecCount = ans.KernelRowLength;
|
||||
package->ComputeMode = new MatrixOpMode(MatrixIndexStyle.BUFFER_INDEX, MatrixOperationParam.ANS_SCALAR_PARAM);
|
||||
package->ComputeHandle = (IntPtr)MathematicsModule.GlobalContext.mat[f64].buffer_fill;
|
||||
package->ComputeHandle = (IntPtr)MathematicsModule.GlobalContext.mat_sk[f64].buffer_fill;
|
||||
package->Scalar = scalar;
|
||||
MatrixParallelWrap taskGroup = MatrixParallel.ScheduleTask(package);
|
||||
taskGroup.LaunchParallel(SleepMode.DeepSleep);
|
||||
@@ -115,7 +125,11 @@ namespace StgSharp.Mathematics.Numeric
|
||||
taskGroup.Dispose();
|
||||
}
|
||||
|
||||
public static unsafe void Mul(Matrix<double> left, Matrix<double> right, Matrix<double> ans)
|
||||
public static unsafe void Mul(
|
||||
Matrix<double> left,
|
||||
Matrix<double> right,
|
||||
Matrix<double> ans
|
||||
)
|
||||
{
|
||||
int f64 = (int)MatrixElementType.F64;
|
||||
|
||||
@@ -145,9 +159,10 @@ namespace StgSharp.Mathematics.Numeric
|
||||
enumeration->Member<int>(1) = j;
|
||||
|
||||
MathematicsModule.GlobalContext
|
||||
.mat[f64].kernel_tile_fma((MatrixKernel*)left.Buffer,
|
||||
.mat_sk[f64].kernel_tile_fma((MatrixKernel*)left.Buffer,
|
||||
(MatrixKernel*)right.Buffer,
|
||||
(MatrixKernel*)ans.Buffer, enumeration);
|
||||
(MatrixKernel*)ans.Buffer,
|
||||
enumeration);
|
||||
}
|
||||
}
|
||||
if (count > 256) {
|
||||
@@ -173,13 +188,18 @@ namespace StgSharp.Mathematics.Numeric
|
||||
return;
|
||||
}
|
||||
|
||||
public static unsafe void Mul(Matrix<double> left, double right, Matrix<double> ans)
|
||||
public static unsafe void Mul(
|
||||
Matrix<double> left,
|
||||
double right,
|
||||
Matrix<double> ans
|
||||
)
|
||||
{
|
||||
int f64 = (int)MatrixElementType.F64;
|
||||
if (left.ColumnLength != ans.ColumnLength || left.RowLength != ans.RowLength) {
|
||||
throw new IndexOutOfRangeException("Matrix dimensions must agree.");
|
||||
}
|
||||
if (left.Layout != MatrixLayout.DenseRectangle || ans.Layout != MatrixLayout.DenseRectangle) {
|
||||
if (left.Layout != MatrixLayout.DenseRectangle ||
|
||||
ans.Layout != MatrixLayout.DenseRectangle) {
|
||||
throw new NotSupportedException("Only dense rectangle matrices are supported.");
|
||||
}
|
||||
long count = (long)left.KernelColumnLength * left.KernelRowLength;
|
||||
@@ -189,7 +209,8 @@ namespace StgSharp.Mathematics.Numeric
|
||||
{
|
||||
MatrixKernel<double>* leftPtr = left.Buffer;
|
||||
MatrixKernel<double>* ansPtr = ans.Buffer;
|
||||
MathematicsModule.GlobalContext.mat[f64].buffer_scalar_mul(leftPtr, ansPtr, scalar, count);
|
||||
MathematicsModule.GlobalContext.mat_sk[f64].buffer_scalar_mul(leftPtr, ansPtr, scalar,
|
||||
count);
|
||||
|
||||
return;
|
||||
} else if (count <= 1024)
|
||||
@@ -198,7 +219,8 @@ namespace StgSharp.Mathematics.Numeric
|
||||
|
||||
MatrixKernel<double>* leftPtr = left.Buffer;
|
||||
MatrixKernel<double>* ansPtr = ans.Buffer;
|
||||
MathematicsModule.GlobalContext.mat[f64].buffer_scalar_mul(leftPtr, ansPtr, scalar, count);
|
||||
MathematicsModule.GlobalContext.mat_sk[f64].buffer_scalar_mul(leftPtr, ansPtr, scalar,
|
||||
count);
|
||||
|
||||
MatrixParallel.ReturnParallelResources(ref pool);
|
||||
return;
|
||||
@@ -211,7 +233,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
package->SecCount = left.KernelRowLength;
|
||||
package->Scalar = scalar;
|
||||
package->ComputeMode = new MatrixOpMode(MatrixIndexStyle.BUFFER_INDEX, MatrixOperationParam.RIGHT_ANS_SCALAR_PARAM);
|
||||
package->ComputeHandle = (IntPtr)MathematicsModule.GlobalContext.mat[f64].buffer_scalar_mul;
|
||||
package->ComputeHandle = (IntPtr)MathematicsModule.GlobalContext.mat_sk[f64].buffer_scalar_mul;
|
||||
MatrixParallelWrap taskGroup = MatrixParallel.ScheduleTask(package);
|
||||
|
||||
taskGroup.LaunchParallel(SleepMode.DeepSleep);
|
||||
@@ -220,7 +242,11 @@ namespace StgSharp.Mathematics.Numeric
|
||||
return;
|
||||
}
|
||||
|
||||
public static unsafe void Sub(Matrix<double> left, Matrix<double> right, Matrix<double> ans)
|
||||
public static unsafe void Sub(
|
||||
Matrix<double> left,
|
||||
Matrix<double> right,
|
||||
Matrix<double> ans
|
||||
)
|
||||
{
|
||||
int f64 = (int)MatrixElementType.F64;
|
||||
if (left.ColumnLength != right.ColumnLength ||
|
||||
@@ -240,7 +266,8 @@ namespace StgSharp.Mathematics.Numeric
|
||||
MatrixKernel<double>* leftPtr = left.Buffer;
|
||||
MatrixKernel<double>* rightPtr = right.Buffer;
|
||||
MatrixKernel<double>* ansPtr = ans.Buffer;
|
||||
MathematicsModule.GlobalContext.mat[f64].buffer_sub(leftPtr, rightPtr, ansPtr, count);
|
||||
MathematicsModule.GlobalContext.mat_sk[f64].buffer_sub(leftPtr, rightPtr, ansPtr,
|
||||
count);
|
||||
|
||||
return;
|
||||
} else if (count <= 1024)
|
||||
@@ -250,7 +277,8 @@ namespace StgSharp.Mathematics.Numeric
|
||||
MatrixKernel<double>* leftPtr = left.Buffer;
|
||||
MatrixKernel<double>* rightPtr = right.Buffer;
|
||||
MatrixKernel<double>* ansPtr = ans.Buffer;
|
||||
MathematicsModule.GlobalContext.mat[f64].buffer_sub(leftPtr, rightPtr, ansPtr, count);
|
||||
MathematicsModule.GlobalContext.mat_sk[f64].buffer_sub(leftPtr, rightPtr, ansPtr,
|
||||
count);
|
||||
|
||||
MatrixParallel.ReturnParallelResources(ref pool);
|
||||
return;
|
||||
@@ -263,7 +291,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
package->PrimCount = left.KernelColumnLength;
|
||||
package->SecCount = left.KernelRowLength;
|
||||
package->ComputeMode = new MatrixOpMode(MatrixIndexStyle.BUFFER_INDEX, MatrixOperationParam.LEFT_RIGHT_ANS_PARAM);
|
||||
package->ComputeHandle = (IntPtr)MathematicsModule.GlobalContext.mat[f64].buffer_sub;
|
||||
package->ComputeHandle = (IntPtr)MathematicsModule.GlobalContext.mat_sk[f64].buffer_sub;
|
||||
MatrixParallelWrap taskGroup = MatrixParallel.ScheduleTask(package);
|
||||
|
||||
taskGroup.LaunchParallel(SleepMode.DeepSleep);
|
||||
|
||||
Reference in New Issue
Block a user