working on matrix mul matrix

This commit is contained in:
Youmu Liu
2025-12-10 17:52:17 +08:00
parent 7bcb460a39
commit 631bc2b6e8
8 changed files with 151 additions and 221 deletions
@@ -1,4 +1,4 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="MatrixCompute.Basic"
// Project: StgSharp
@@ -30,6 +30,7 @@ using StgSharp.HighPerformance;
using StgSharp.Internal;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Numerics;
using System.Security.AccessControl;
@@ -124,11 +125,35 @@ namespace StgSharp.Mathematics.Numeric
Matrix<float> right,
Matrix<float> ans)
{
if (left.RowLength != right.ColumnLength ||
left.RowLength != ans.RowLength ||
right.ColumnLength != ans.ColumnLength) {
// For matrix multiplication (left: MxK) * (right: KxN) => ans: MxN
// ColumnLength = number of columns (N), RowLength = number of rows (M)
if (left.ColumnLength != right.RowLength ||
ans.ColumnLength != right.ColumnLength ||
ans.RowLength != left.RowLength)
{
throw new IndexOutOfRangeException("Matrix dimensions must agree.");
}
long count = (long)left.KernelColumnLength * left.KernelRowLength;
if (count <= 256)
{
MatrixPanel<float>* leftPanel = MatrixPanel<float>.Create();
MatrixPanel<float>* rightPanel = MatrixPanel<float>.Create();
MatrixPanel<float>* ansPanel = MatrixPanel<float>.Create();
int size = MatrixPanel<float>.KernelSideCount();
for (int i = 0; i < left.RowLength; i += size)
{
for (int j = 0; j < right.ColumnLength; j += size)
{
for (int k = 0; k < left.ColumnLength; k += size) {
NativeIntrinsic.Intrinsic
.f32_build_panel((MatrixKernel*)left.Buffer,
(MatrixPanel*)leftPanel,
left.ColumnLength, left.RowLength, i,
k);
}
}
}
}
throw new NotImplementedException();
}