Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MIPS64 MADPS instruction illegal instruction #2621

Closed
yaoguangchao opened this issue May 19, 2020 · 8 comments
Closed

MIPS64 MADPS instruction illegal instruction #2621

yaoguangchao opened this issue May 19, 2020 · 8 comments

Comments

@yaoguangchao
Copy link

Hi All,
Today, I tried to compile openblas on linux system with loongson3a cpu. The compilation didn't get any problem, but when i ran cblas_sgemm, I got an illegal instruction failure. After then, I recompiled openblas with DEBUG=1, and got more detailed core information like below:

Program terminated with signal SIGILL, Illegal instruction.
#0 sgemm_kernel () at ../kernel/mips64/sgemm_kernel_8x4_ps.S:624
624 MADPS C11, C11, A5, B5
[Current thread is 1 (LWP 3368)]
(gdb) bt
#0 sgemm_kernel () at ../kernel/mips64/sgemm_kernel_8x4_ps.S:624
#1 0x000000fff5da62f0 in sgemm_nn (args=0xffffab9700, range_m=0x0, range_n=0x0, sa=0xffedae0000, sb=0xffedaec000, dummy=0) at level3.c:358
#2 0x000000fff5c73ab0 in cblas_sgemm (order=CblasRowMajor, TransA=CblasNoTrans, TransB=CblasNoTrans, m=10, n=512, k=1286, alpha=1, a=0xffd403def0, lda=1286, b=0xffe3158010, ldb=512, beta=1, c=0xffd4052080, ldc=512) at gemm.c:433

I checked the file in kernel/mips64/sgemm_kernel_8x4_ps.S, and found that it does use MADPS instruction! But why did I get an illegal instruction failure?
Could anyone give me a correct compile options?
Thanks a lot.

@martin-frbg
Copy link
Collaborator

Unfortunately there has not been any significant work on the Loongson kernels in recent years, and I am not really familiar with the architecture.
From what I could find, apparently an illegal instruction error can be raised when the madd instruction ("MADPS" is expanded to "madd.ps" in common_mips64.h) is called with arguments that are denormalized or NaN, so perhaps it depends on what input values you have in your matrix. (But it could also be a problem in the code. Which version of OpenBLAS did you build ?

@yaoguangchao
Copy link
Author

yaoguangchao commented May 19, 2020 via email

@martin-frbg
Copy link
Collaborator

I certainly hope so, as Loongson Ltd. has already expressed their intention to help with development in #2368 - unfortunately the ongoing health crisis has delayed everything.

@yaoguangchao
Copy link
Author

Thank you very much for your reply. I get in touch with the software engineer worked for loongson.
I will reply in time if there is a progress.

@martin-frbg
Copy link
Collaborator

It would probably help to know the register contents for the failing instruction, or to have a minimal testcase that reproduces the fault. You could also try to revert the changes from cb02147 (param.h and KERNEL.LOONGSON3A) to go back to the earlier 4x4 SGEMM kernel. (Or compile for TARGET=GENERIC to get a less performant OpenBLAS without all the hand-coded assembler routines)

@yaoguangchao
Copy link
Author

I test the easier way: compile on

TARGET=GENERIC

and it works! Thank you martin~

I also test another way based on the advice from loongson engineer:

modify KERNEL.LOONGSON3A in kernel/mips64, change SGEMMKERNEL = sgemm_kernel_8x4_ps.S to SGEMMKERNEL =sgemm_kernel_loongson3a_4_4.S

code can be ran using this way,but the result is totally wrong. So I decide to use the first way temporarily.

@martin-frbg
Copy link
Collaborator

If you take the advice of the Loongson engineer, you also need to make the other changes related to the commit I linked to (change param.h and change also the sgemm ncopy/tcopy entries in KERNEL.LOONGSON3A)

@XiWeiGu
Copy link
Contributor

XiWeiGu commented Nov 20, 2020

@yaoguangchao. Thank you for your feedback. Could you show me more details about your problems like toolchain, compile command?

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

No branches or pull requests

3 participants