glinscott / leela-chess

**MOVED TO https://github.com/LeelaChessZero/leela-chess ** A chess adaption of GCP's Leela Zero
http://lczero.org
GNU General Public License v3.0
760 stars 299 forks source link

FindBLAS.cmake can't find INTEL MKL Blas Library API #467

Open hsntgm opened 6 years ago

hsntgm commented 6 years ago

Hello,

OS:Ubuntu 16.04 Intel MKL Version:Intel® Parallel Studio XE 2018 Cmake Version:3.5.1 #also tried to latest cmake version 3.11.1

I tried to use INTEL MKL for blas library but it seems FindBLAS.cmake can't find path of the blas API when compiling leela chess.I can't solve the problem.

1-I tried to add blas include library path to CMakeLists.txt manualy. /path/to/mkl/include

find_package (BLAS REQUIRED)
find_path (BLAS_INCLUDE_DIRS openblas_config.h
  /usr/include
  /usr/local/include
  /usr/include/openblas
  /opt/OpenBLAS/include
  /usr/include/x86_64-linux-gnu
  /path/to/mkl/include
$ENV{BLAS_HOME}/include)

2-I tried to add CMAKE_LIBRARY_PATH for blas manually to ~/.bashrc

export CMAKE_INCLUDE_PATH=/path/to/mkl/include export CMAKE_LIBRARY_PATH=/path/to/mkl/lib/intel64:/path/to/mkl/compiler/lib/intel64 export LD_LIBRARY_PATH=$CMAKE_LIBRARY_PATH:$LD_LIBRARY_PATH

3-I tried to reproduce FindBLAS.cmake code for INTEL MKL library file names.Maybe file names changed but they are same.

mkl_intel_lp64 mkl_sequential mkl_blas95_lp64
mkl_intel_thread mkl_core iomp5

Prcuvu commented 6 years ago

See these lines in CMakeLists.txt: https://github.com/glinscott/leela-chess/blob/ec091788eb3f1d215b534904396c99b73ea446f1/CMakeLists.txt#L36-L41 Modify line 40 and set BLA_VENDOR to mkl_sequential to solve your problem.

hsntgm commented 6 years ago

@Prcuvu thank you for the tip. BLA_VENDOR to mkl_sequential not work but i managed to solve problem with below config.

1-edit leela-chess/CMakeLists.txt

 if (NOT APPLE)
   set (BLA_VENDOR Intel10_64lp_seq) #changed OpenBLAS ==> Intel10_64lp_seq
 endif ()

 find_package (BLAS REQUIRED)
 find_path (BLAS_INCLUDE_DIRS mkl.h #changed openblas_config.h ==> mkl.h
   /usr/include
   /usr/local/include
   /usr/include/openblas
   /opt/OpenBLAS/include
   /usr/include/x86_64-linux-gnu
   /opt/intel/compilers_and_libraries_2018.2.199/linux/mkl/include #added mkl include path
   $ENV{BLAS_HOME}/include)

2-edit leela-chess/src/config.h change:

/* Features */
#define USE_BLAS
#if !defined(__APPLE__) && !defined(__MACOSX)
#define USE_OPENBLAS
#endif
//#define USE_MKL

to

/* Features */
#define USE_BLAS
#if !defined(__APPLE__) && !defined(__MACOSX)
//#define USE_OPENBLAS
#endif
#define USE_MKL

3-edit ~/.bashrc and define permanent CMAKE paths to MKL or use terminal for current session.

For MKL 2018:

export CMAKE_INCLUDE_PATH=/opt/intel/compilers_and_libraries_2018.2.199/linux/mkl/include export CMAKE_LIBRARY_PATH=/opt/intel/compilers_and_libraries_2018.2.199/linux/mkl/lib/intel64:/opt/intel/compilers_and_libraries_2018.2.199/linux/compiler/lib/intel64 export LD_LIBRARY_PATH=$CMAKE_LIBRARY_PATH:$LD_LIBRARY_PATH

Successfully compiled with Intel MKL 2018 Blas API. Solved.