Skip to content

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

@azuresky01

Description

@azuresky01

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:

OpenBLAS/Makefile.system

Lines 1167 to 1195 in 993fad6

ifeq ($(F_COMPILER), $(filter $(F_COMPILER),GFORTRAN FLANGNEW))
CCOMMON_OPT += -DF_INTERFACE_GFORT
ifeq ($(F_COMPILER), GFORTRAN)
FCOMMON_OPT += -Wall
# make single-threaded LAPACK calls thread-safe #1847
FCOMMON_OPT += -frecursive
# work around ABI problem with passing single-character arguments
FCOMMON_OPT += -fno-optimize-sibling-calls
#Don't include -lgfortran, when NO_LAPACK=1 or lsbcc
ifneq ($(NOFORTRAN), 1)
ifneq ($(NOFORTRAN), 2)
ifneq ($(NO_LAPACK), 1)
EXTRALIB += -lgfortran
endif
endif
endif
endif
ifdef NO_BINARY_MODE
ifeq ($(ARCH), $(filter $(ARCH),mips64))
ifdef BINARY64
FCOMMON_OPT += -mabi=64
else
FCOMMON_OPT += -mabi=n32
endif
else ifeq ($(ARCH), $(filter $(ARCH),mips))
FCOMMON_OPT += -mabi=32
endif
else
ifdef BINARY64

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions