How to build tvm with openblas on macOS

I’m learning the example according to tvm docs. So i try to rebuild tvm with USE_BLAS option. my configuration as follow:

set(USE_BLAS openblas)
set(BLAS_LIBRARY /usr/local/opt/openblas/lib)

The steps i tried

1. install openblas by brew
After i executed brew install openblas, the two directories both have openblas library as below:

in /usr/local/opt/openblas and /usr/local/Cellar/openblas/0.3.5 , Their content is same.

 32K	Changelog.txt
4.0K	INSTALL_RECEIPT.json
4.0K	LICENSE
 12K	README.md
1.4M	include
119M	lib

2. export BLAS_LIB and BLAS_INCLUDE
the contents in .bash_profile as below, and I sourced it:

# openblas
BLAS_HOME=/usr/local/opt/openblas
BLAS_LIB=${BLAS_HOME}/lib
BLAS_INCLUDE=${BLAS_HOME}/include
export BLAS_LIB
export BLAS_INCLUDE

3. build tvm with openblas
execute cmake in build directory with cmake ..; make -j4, it tells cblas.h file not found. I don’t know why the env_vars of BLAS_LIB and BLAS_INCLUDE didn’t work. Then i executed cmake with CMAKE_CXX_FLAGS , the whole shell is cmake -DCMAKE_CXX_FLAGS=-I/usr/local/opt/openblas/include ..; make -j4, it tells another error as below:

Undefined symbols for architecture x86_64:
  "_cblas_dgemm", referenced from:
      void tvm::contrib::CallGemm<tvm::contrib::CblasDgemmOp>(tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*, tvm::contrib::CblasDgemmOp) in cblas.cc.o
  "_cblas_sgemm", referenced from:
      void tvm::contrib::CallGemm<tvm::contrib::CblasSgemmOp>(tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*, tvm::contrib::CblasSgemmOp) in cblas.cc.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [libtvm.dylib] Error 1
make[1]: *** [CMakeFiles/tvm.dir/all] Error 2
make: *** [all] Error 2

But the libblas.dylib lib has _cblas_dgemm symbol as below:

nm -gU /usr/local/opt/openblas/lib/libblas.dylib|grep dgemm
0000000000020e9f T _cblas_dgemm
000000000001f884 T _dgemm_

I don’t know how to config the BLAS library path to tvm. Waiting help. Thanks.

1 Like

When i set BLAS_LIBRARY to the detail lib file instead of the directory. It can be compiled successfully.

set(USE_BLAS openblas)
set(BLAS_LIBRARY /usr/local/opt/openblas/lib/libblas.dylib)