Open Wang-Zhewei opened 2 years ago
@PeixinQiao I think I know what's wrong. The command flang-new -flang-experimental-exec -c -O3 *.f
only compiles .f files, and scnrm2.f90 needs to be compiled separately with the command flang-new -flang-experimental-exec -c -O3 *.f90
. Then libblas.a can be used to make CBLAS successfully.
@Wang-Zhewei Good job.
@PeixinQiao I did build blas and cblas and put the static link libraries libblas.a and libcblas.a in the /usr/local/lib folder, but when I compile in C it still doesn't pass. test_blas.c
#include <stdio.h>
#include <cblas.h>
int main()
{
const int dim=2;
double a[4]={1.0,1.0,1.0,1.0},b[4]={2.0,2.0,2.0,2.0},c[4];
int m=dim,n=dim,k=dim,lda=dim,ldb=dim,ldc=dim;
double al=1.0,be=0.0;
cblas_dgemm(101,111,111,m,n,k,al,a,lda,b,ldb,be,c,ldc);
printf("the matrix c is:%f,%f\n%f,%f\n",c[0],c[1],c[2],c[3]);
return 0;
}
The command line I used is clang test_blas.c -o test /usr/local/lib/libcblas.a /usr/local/lib/libblas.a -lm -I /root/workload/blas/CBLAS/include/
.
The compilation result:
/usr/local/lib/libblas.a(lsame.o): In function `lsame_':
/root/workload/blas/BLAS-3.10.0/./lsame.f:73: undefined reference to `_FortranACharacterCompareScalar1'
/usr/local/lib/libblas.a(xerbla.o): In function `xerbla_':
/root/workload/blas/BLAS-3.10.0/./xerbla.f:77: undefined reference to `_FortranAioBeginExternalFormattedOutput'
/root/workload/blas/BLAS-3.10.0/./xerbla.f:77: undefined reference to `_FortranAioOutputAscii'
/root/workload/blas/BLAS-3.10.0/./xerbla.f:77: undefined reference to `_FortranAioOutputInteger32'
/root/workload/blas/BLAS-3.10.0/./xerbla.f:77: undefined reference to `_FortranAioEndIoStatement'
/root/workload/blas/BLAS-3.10.0/./xerbla.f:79: undefined reference to `_FortranAStopStatement'
clang-16: error: linker command failed with exit code 1 (use -v to see invocation)
I feel like I should add some flang-new compile options, but I don't know how to add it correctly.
@Wang-Zhewei You can learn how to solve this problem here.
@PeixinQiao
It seems that clang does not link some dynamic or static libraries by itself. Meanwhile, although I have added the relevant environment variables in LD_LIBRARY_PATH, the -l command does not help it to find some libraries. So I try to link them manually and generate the corresponding executable file. This is the command line I used clang ~/test/test_blas.c -o test /usr/local/lib/libcblas.a /usr/local/lib/libblas.a ~/flang-install-f18/install/lib/*.so -lm
.
But when I run the "./test" command, it prints the following error:
: CommandLine Error: Option 'limited-coverage-experimental' registered more than once!
LLVM ERROR: inconsistency in registered CommandLine options
Aborted (core dumped)
And I found an issud about this: https://github.com/fireice-uk/xmr-stak/issues/1782 So I don't know how to solve it
Can you try the following?
clang ~/test/test_blas.c -o test /usr/local/lib/libcblas.a /usr/local/lib/libblas.a -lm -I/path-to-f18-install/install/lib -lFortran_main -lFortranRuntime -lFortranDecimal
Don't link all the so
files. It's one very bad idea.
@PeixinQiao
I tried this command: clang ~/test/test_blas.c -o test /usr/local/lib/libcblas.a /usr/local/lib/libblas.a -lm -I/root/flang-install-f18/install/lib/ -lFortran_main -lFortranRuntime -lFortranDecimal
But it reported some errors:
/usr/bin/ld: cannot find -lFortran_main
/usr/bin/ld: cannot find -lFortranRuntime
/usr/bin/ld: cannot find -lFortranDecimal
clang-16: error: linker command failed with exit code 1 (use -v to see invocation)
The source code for BLAS and CBLAS can be found from the following website: https://netlib.org/blas/
To build BLAS with LLVM Flang, we need to modify the compilation options in the Makefile.in file.
Save it and make.
Some errors were generated at this step of 'make'.