fixing tile fma
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="MatrixCompute.Float"
|
||||
// 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
|
||||
@@ -42,7 +42,11 @@ namespace StgSharp.Mathematics.Numeric
|
||||
public static partial class MatrixCompute
|
||||
{
|
||||
|
||||
public static unsafe void Add(Matrix<float> left, Matrix<float> right, Matrix<float> ans)
|
||||
public static unsafe void Add(
|
||||
Matrix<float> left,
|
||||
Matrix<float> right,
|
||||
Matrix<float> ans
|
||||
)
|
||||
{
|
||||
int f32 = (int)MatrixElementType.F32;
|
||||
if (left.ColumnLength != right.ColumnLength ||
|
||||
@@ -88,7 +92,10 @@ namespace StgSharp.Mathematics.Numeric
|
||||
return;
|
||||
}
|
||||
|
||||
public static unsafe void Fill(Matrix<float> ans, float value)
|
||||
public static unsafe void Fill(
|
||||
Matrix<float> ans,
|
||||
float value
|
||||
)
|
||||
{
|
||||
int f32 = (int)MatrixElementType.F32;
|
||||
long count = (long)ans.KernelColumnLength * ans.KernelRowLength;
|
||||
@@ -119,7 +126,11 @@ namespace StgSharp.Mathematics.Numeric
|
||||
taskGroup.Dispose();
|
||||
}
|
||||
|
||||
public static unsafe void Mul(Matrix<float> left, Matrix<float> right, Matrix<float> ans)
|
||||
public static unsafe void Mul(
|
||||
Matrix<float> left,
|
||||
Matrix<float> right,
|
||||
Matrix<float> ans
|
||||
)
|
||||
{
|
||||
int f32 = (int)MatrixElementType.F32;
|
||||
|
||||
@@ -145,31 +156,20 @@ namespace StgSharp.Mathematics.Numeric
|
||||
pool = MatrixParallel.LeadParallel(1);
|
||||
}
|
||||
M128* enumeration = stackalloc M128[4];
|
||||
enumeration->Member<int>(2) = left.KernelColumnLength;
|
||||
enumeration->Member<int>(3) = ans.KernelColumnLength;
|
||||
for (int i = 0; i < ans.KernelRowLength; i++)
|
||||
{
|
||||
for (int j = 0; j < ans.KernelColumnLength; j++)
|
||||
{
|
||||
enumeration->Member<int>(0) = i;
|
||||
enumeration->Member<int>(1) = j;
|
||||
enumeration->Member<int>(2) = ans.KernelRowLength;
|
||||
enumeration->Member<int>(3) = left.KernelColumnLength;
|
||||
|
||||
NativeIntrinsic.Context
|
||||
.mat[f32].kernel_tile_fma((MatrixKernel*)left.Buffer,
|
||||
(MatrixKernel*)right.Buffer,
|
||||
(MatrixKernel*)ans.Buffer, enumeration);
|
||||
/*
|
||||
for (int k = 0; k < left.KernelColumnLength; k++) {
|
||||
NativeIntrinsic.Context
|
||||
.mat[f32].kernel_fma(GetKernelAddressUnsafe(left.Buffer,
|
||||
left.KernelColumnLength, i,
|
||||
k),
|
||||
GetKernelAddressUnsafe(right.Buffer,
|
||||
right.KernelColumnLength, k, j),
|
||||
GetKernelAddressUnsafe(ans.Buffer,
|
||||
ans.KernelColumnLength, i, j));
|
||||
}
|
||||
/**/
|
||||
(MatrixKernel*)ans.Buffer,
|
||||
enumeration);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,13 +196,18 @@ namespace StgSharp.Mathematics.Numeric
|
||||
return;
|
||||
}
|
||||
|
||||
public static unsafe void Mul(Matrix<float> left, float right, Matrix<float> ans)
|
||||
public static unsafe void Mul(
|
||||
Matrix<float> left,
|
||||
float right,
|
||||
Matrix<float> ans
|
||||
)
|
||||
{
|
||||
int f32 = (int)MatrixElementType.F32;
|
||||
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;
|
||||
@@ -243,7 +248,11 @@ namespace StgSharp.Mathematics.Numeric
|
||||
return;
|
||||
}
|
||||
|
||||
public static unsafe void Sub(Matrix<float> left, Matrix<float> right, Matrix<float> ans)
|
||||
public static unsafe void Sub(
|
||||
Matrix<float> left,
|
||||
Matrix<float> right,
|
||||
Matrix<float> ans
|
||||
)
|
||||
{
|
||||
int f32 = (int)MatrixElementType.F32;
|
||||
if (left.ColumnLength != right.ColumnLength ||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="MatrixCompute"
|
||||
// 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
|
||||
@@ -40,7 +40,9 @@ namespace StgSharp.Mathematics.Numeric
|
||||
public partial class MatrixCompute
|
||||
{
|
||||
|
||||
internal static unsafe void ComputeFmaPanelF32(MatrixParallelTaskPackage* p)
|
||||
internal static unsafe void ComputeFmaPanelF32(
|
||||
MatrixParallelTaskPackage* p
|
||||
)
|
||||
{
|
||||
int f32 = (int)MatrixElementType.F32;
|
||||
MatrixKernel* leftBuffer = (MatrixKernel*)p->Left;
|
||||
@@ -57,19 +59,24 @@ namespace StgSharp.Mathematics.Numeric
|
||||
// in this occasion size must be 1
|
||||
for (long c = offsetRef; c < offsetRef + lengthRef; c++)
|
||||
{
|
||||
int i = (int)(c / ansWidth);
|
||||
int j = (int)(c % ansWidth);
|
||||
int i = (int)(c / ansHeight);
|
||||
int j = (int)(c % ansHeight);
|
||||
for (int k = 0; k < commonK; k++) {
|
||||
NativeIntrinsic.Context
|
||||
.mat[f32].kernel_fma(
|
||||
GetKernelAddressUnsafe((MatrixKernel<float>*)leftBuffer, ansHeight, k, j),
|
||||
GetKernelAddressUnsafe((MatrixKernel<float>*)rightBuffer, commonK, j, k),
|
||||
GetKernelAddressUnsafe((MatrixKernel<float>*)ansBuffer, ansHeight, i, j));
|
||||
GetKernelAddressUnsafe((MatrixKernel<float>*)leftBuffer,
|
||||
ansHeight, k, j),
|
||||
GetKernelAddressUnsafe((MatrixKernel<float>*)rightBuffer,
|
||||
commonK, j, k),
|
||||
GetKernelAddressUnsafe((MatrixKernel<float>*)ansBuffer,
|
||||
ansHeight, i, j));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static unsafe void ComputeFmaPanelF64(MatrixParallelTaskPackage* p)
|
||||
internal static unsafe void ComputeFmaPanelF64(
|
||||
MatrixParallelTaskPackage* p
|
||||
)
|
||||
{
|
||||
int f64 = (int)MatrixElementType.F64;
|
||||
|
||||
@@ -88,22 +95,14 @@ namespace StgSharp.Mathematics.Numeric
|
||||
// in this occasion size must be 1
|
||||
for (long c = offsetRef; c < offsetRef + lengthRef; c++)
|
||||
{
|
||||
int i = (int)(c / ansWidth);
|
||||
int j = (int)(c % ansWidth);
|
||||
int i = (int)(c / ansHeight);
|
||||
int j = (int)(c % ansHeight);
|
||||
enumeration->Member<int>(0) = i;
|
||||
enumeration->Member<int>(1) = j;
|
||||
enumeration->Member<int>(2) = commonK;
|
||||
enumeration->Member<int>(3) = ansHeight;
|
||||
NativeIntrinsic.Context.mat[f64].kernel_tile_fma(leftBuffer, rightBuffer, ansBuffer, enumeration);
|
||||
/*
|
||||
for (int k = 0; k < commonK; k += 1) {
|
||||
NativeIntrinsic.Context
|
||||
.mat[f64].kernel_fma(
|
||||
GetKernelAddressUnsafe((MatrixKernel<double>*)leftBuffer, ansHeight, k, j),
|
||||
GetKernelAddressUnsafe((MatrixKernel<double>*)rightBuffer, commonK, j, k),
|
||||
GetKernelAddressUnsafe((MatrixKernel<double>*)ansBuffer, ansHeight, i, j));
|
||||
}
|
||||
/**/
|
||||
NativeIntrinsic.Context.mat[f64].kernel_tile_fma(leftBuffer, rightBuffer, ansBuffer,
|
||||
enumeration);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,8 +111,8 @@ namespace StgSharp.Mathematics.Numeric
|
||||
MatrixKernel<T>* buffer,
|
||||
int colLength,
|
||||
int x,
|
||||
int y)
|
||||
where T: unmanaged, INumber<T>
|
||||
int y
|
||||
) where T : unmanaged, INumber<T>
|
||||
{
|
||||
return (MatrixKernel*)(buffer + (colLength * x + y));
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// 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
|
||||
@@ -38,7 +38,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 ||
|
||||
@@ -84,7 +88,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;
|
||||
@@ -115,7 +122,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;
|
||||
|
||||
@@ -137,34 +148,23 @@ namespace StgSharp.Mathematics.Numeric
|
||||
pool = MatrixParallel.LeadParallel(1);
|
||||
}
|
||||
M128* enumeration = stackalloc M128[1];
|
||||
enumeration->Member<int>(2) = left.KernelColumnLength;
|
||||
enumeration->Member<int>(3) = ans.KernelColumnLength;
|
||||
for (int i = 0; i < ans.KernelRowLength; i++)
|
||||
{
|
||||
for (int j = 0; j < ans.KernelColumnLength; j += 1)
|
||||
for (int j = 0; j < ans.KernelColumnLength; j++)
|
||||
{
|
||||
enumeration->Member<int>(0) = i;
|
||||
enumeration->Member<int>(1) = j;
|
||||
enumeration->Member<int>(2) = ans.KernelRowLength;
|
||||
enumeration->Member<int>(3) = left.KernelColumnLength;
|
||||
|
||||
NativeIntrinsic.Context
|
||||
.mat[f64].kernel_tile_fma((MatrixKernel*)left.Buffer,
|
||||
(MatrixKernel*)right.Buffer,
|
||||
(MatrixKernel*)ans.Buffer, enumeration);
|
||||
/*
|
||||
// Console.WriteLine($"{i}{j}");
|
||||
for (int k = 0; k < left.KernelColumnLength; k++)
|
||||
{
|
||||
NativeIntrinsic.Context
|
||||
.mat[f64].kernel_fma(GetKernelAddressUnsafe(left.Buffer,
|
||||
left.KernelColumnLength, i,
|
||||
k),
|
||||
GetKernelAddressUnsafe(right.Buffer,
|
||||
right.KernelColumnLength, k, j),
|
||||
GetKernelAddressUnsafe(ans.Buffer,
|
||||
ans.KernelColumnLength, i, j));
|
||||
}
|
||||
/**/
|
||||
(MatrixKernel*)ans.Buffer,
|
||||
enumeration);
|
||||
Console.WriteLine($"{i},{j},{ans[4*i,4*j]:0.0E00}\t");
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
if (count > 256) {
|
||||
MatrixParallel.ReturnParallelResources(ref pool!);
|
||||
@@ -189,13 +189,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;
|
||||
@@ -236,7 +241,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 ||
|
||||
|
||||
Reference in New Issue
Block a user