OpenBLAS icon indicating copy to clipboard operation
OpenBLAS copied to clipboard

gmake compilation issue with LLVM clang/flang on Loongarch64 when INTERFACE64=1 is set

Open azuresky01 opened this issue 6 months ago • 0 comments

Compilation of OpenBLAS on loongarch64 is now possible with LLVM clang/flang(flang-new) version 20 and above. Recently I tried to build OpenBLAS 0.3.30 (should also apply to current dev version) on Debian sid with different parameters and found gmake compilation failure when INTERFACE64=1 is set (cmake compilation is OK). See below.

Linux System details: Loongson 3A6000 CPU, Debian sid, kernel 6.12.33+deb13-loong64, GNU Make 4.4.1, clang/flang(flang-new) 20.1.7 both are compiled from the source.

gmake:

building command: CC=/usr/local/llvm-20.1.7/bin/clang FC=/usr/local/llvm-20.1.7/bin/flang make INTERFACE64=1

During the compilation I found that INTERFACE64=1 is not implemented by flang:

...
/usr/local/llvm-20.1.7/bin/flang -O2 -march=loongarch64 -fPIC -c -o sgerq2.o sgerq2.f
...

And finally I got the following error message:

...
/usr/local/llvm-20.1.7/bin/flang -O2 -march=loongarch64   -o zblat2 zblat2.o ../libopenblas_la464p-r0.3.30.a -lm -lpthread -lm -lpthread -L/usr/local/llvm-20.1.7/bin/../lib/loongarch64-unknown-linux-gnu -L/usr/local/llvm-20.1.7/lib/clang/20/lib/loongarch64-unknown-linux-gnu -L/usr/lib/gcc/loongarch64-linux-gnu/14 -L/usr/lib/gcc/loongarch64-linux-gnu/14/../../../../lib64 -L/lib/loongarch64-linux-gnu -L/lib/../lib64 -L/usr/lib/loongarch64-linux-gnu -L/usr/lib/../lib64 -L/lib -L/usr/lib  -lc 
OPENBLAS_NUM_THREADS=1 OMP_NUM_THREADS=1 ./sblat1
 Real BLAS Test Program Results


 Test of subprogram number  1             SDOT 
Bus error
make[1]: *** [Makefile:51: level1] Error 135
...

Cmake compilation with clang/flang 20.1.7 finished without any error though. To fix the above error, based on the hint in cmake/fc.cmake I checked the code in Makefile.system from the lines 1167-1195:

https://github.com/OpenMathLib/OpenBLAS/blob/993fad6aebbce34a97d3f8c34d6d79d35b64cc48/Makefile.system#L1167-L1195

After the line 1193 I add the following lines:

ifeq ($(ARCH), $(filter $(ARCH),loongarch64))
ifdef INTERFACE64
ifneq ($(INTERFACE64), 0)
FCOMMON_OPT +=  -fdefault-integer-8
endif
endif
endif

Then flang can pick up the -fdefault-integer-8 parameter and the compilation error disappears.

@XiWeiGu @martin-frbg

azuresky01 avatar Jun 23 '25 05:06 azuresky01