Skip to content

Fix incorrect TRMM for mips/P5600 - #6289

Open
rcurtin wants to merge 5 commits into
OpenMathLib:developfrom
rcurtin:mips-p5600-trmm-kernels
Open

rcurtin wants to merge 5 commits into
OpenMathLib:developfrom
rcurtin:mips-p5600-trmm-kernels

Conversation

@rcurtin

@rcurtin rcurtin commented Nov 27, 2026

Copy link
Copy Markdown

It seems that kernel/mips/KERNEL.generic and kernel/mips/KERNEL.P5600 specify the use of the generic GEMM kernel kernel/generic/gemmkernel_2x2.c as DGEMMKERNEL, but don't specify any TRMM kernel. To my understanding, this means that OpenBLAS will compile and use the GEMM kernel with TRMMKERNEL defined so that it acts like a TRMM operation---but, the generic GEMM kernel actually does not return correct results with TRMMKERNEL defined! Instead, it seems like kernel/generic/trmmkernel_2x2.c should be used in these cases.

So, my fix simply adds TRMM kernel definitions to the mips kernel definitions, and then specifies that on the mips architecture, separate TRMM kernels are to be used. I think but am not sure that this is the right way to handle the problem. (Well, I think it is a problem, but I am also not 100% sure of that, given that this would mean a whole lot of higher-level LAPACK functionality is broken for any mipsel build. But perhaps there are not hordes of people out there computing SVDs on tiny devices...)

I checked other architectures that use the generic GEMM kernels, and all of those also explicitly specify generic TRMM kernels.

This is my first contribution to OpenBLAS despite building software on it for well over a decade (p.s. thanks for OpenBLAS!), so, please let me know if I overlooked or misunderstood something and I'm happy to provide a PR with a different approach.

(1) mlpack, a machine learning library, tests its algorithms on all kinds of hardware, including a VoCore, which is a mips32 system. A test for kernel principal components analysis was failing... only on that system. The failure appeared to come from Armadillo's svd() function, and upon further digging, Armadillo appeared to not be the cause of the bad results. This led me on a trace through OpenBLAS's dgesdd_() implementation where I discovered that a call to dtrmm_() was returning incorrect results. It was a long and fun adventure. At least, I am telling myself it was fun. 😄

@martin-frbg

Copy link
Copy Markdown
Collaborator

Thanks - it is a little more complicated, the P5600 GEMM kernels do provide code paths for TRMM, but only in the MSA version. Apparently your build uses NO_MSA=1 for some reason, falling back to the generic kernels where indeed the TRMMKERNEL lines were removed when the MSA kernels got added in 57df795 ten years ago. Apparently putting them back for the NO_MSA branch was forgotten when the NO_MSA conditional was introduced two years ago. So I think the ?TRMMKERNEL entries need to go on the respective NO_MSA branch in KERNEL.P5600 rather than being added as a common definition block.

@rcurtin

rcurtin commented Nov 27, 2026

Copy link
Copy Markdown
Author

Thanks for pointing that out... the little system we are testing on doesn't even have an FPU, so no MSA either. (Why test a machine learning library on a system that doesn't even have an FPU?, you ask. It was cheap and readily available!, I answer.)

Anyway, just pushed a commit that should fix the behavior on MSA MIPS systems. Sorry about the oversight there.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants