Daily update on 20260111-005714 by Nitload Youmu. Additional Message : Use optimized tile operation to accelerate matrix mul, still has problem
Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="MatrixCompute.Float"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. 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,11 +42,7 @@ 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 ||
|
||||
@@ -92,10 +88,7 @@ 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;
|
||||
@@ -126,11 +119,7 @@ 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;
|
||||
|
||||
@@ -155,28 +144,32 @@ namespace StgSharp.Mathematics.Numeric
|
||||
if (count > 256) {
|
||||
pool = MatrixParallel.LeadParallel(1);
|
||||
}
|
||||
M128* enumeration = stackalloc M128[4];
|
||||
for (int i = 0; i < ans.KernelRowLength; i++)
|
||||
{
|
||||
for (int j = 0; j < ans.KernelColumnLength; j++)
|
||||
{
|
||||
MatrixKernel<float>* ansPanel = GetKernelAddressUnsafe(ans.Buffer,
|
||||
ans.KernelColumnLength,
|
||||
i, 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].clear_panel((MatrixPanel*)ansPanel);
|
||||
for (int k = 0; k < left.KernelColumnLength; k++)
|
||||
{
|
||||
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((MatrixPanel*)GetKernelAddressUnsafe(left.Buffer,
|
||||
left.KernelColumnLength,
|
||||
i,
|
||||
k),
|
||||
(MatrixPanel*)GetKernelAddressUnsafe(right.Buffer,
|
||||
right.KernelColumnLength,
|
||||
k,
|
||||
j),
|
||||
(MatrixPanel*)ansPanel);
|
||||
.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));
|
||||
}
|
||||
/**/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,18 +196,13 @@ 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;
|
||||
@@ -255,11 +243,7 @@ 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 ||
|
||||
|
||||
Reference in New Issue
Block a user