New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup BLAS detection #8561

Open
soumith opened this Issue Jun 15, 2018 · 2 comments

Comments

Projects
None yet
3 participants
@soumith
Copy link
Member

soumith commented Jun 15, 2018

PyTorch and Caffe2 use the following libraries as preferred for BLAS/LAPACK capabilities:

  • MKL - first preference in unified build system

  • Eigen - 2nd preference in unified build system, but first preference if ATen is not being compiled

  • PyTorch finds OpenBLAS, Accelerate, cblas if MKL is not found -- finding OpenBLAS is useful for PPC64

  • I have to explore what Caffe2 does if Eigen is not found

There are however additional subtelities.
MKL and Eigen are not used JUST for BLAS/LAPACK, but also for additional functionality:

Additionally, we also use fortran-blas interface in pytorch, cblas interface in Caffe2 (if not Eigen), and eigen::MatrixMap interface if Eigen is found and CAFFE2_USE_EIGEN_FOR_BLAS is set.

Cleanup plan:

  • separate what it means to detect MKL / Eigen from what it means to detect BLAS capabilities
    • Find MKL at a single entry point across PyTorch, Caffe2, and if it's found, set a USE_BLAS="mkl" with BLAS_INCLUDE and BLAS_LIBRARIES variables set to MKL paths. This is in addition to setting MKL_FOUND
    • [Should we] Find Eigen by default (unless USE_EIGEN=OFF (which we can set via setup.py) and use it for everything (building caffe2 operators etc.) except BLAS (i.e. only not set CAFFE2_USE_EIGEN_FOR_BLAS). If MKL was not found, use Eigen for BLAS as well cc: @Yangqing for guidance.
    • On PPC64 and OSX, should we prefer OpenBLAS and Accelerate respectively (instead of Eigen) for the BLAS capabilities? cc: @Yangqing
@Yangqing

This comment has been minimized.

Copy link
Contributor

Yangqing commented Jun 15, 2018

Thanks! Pasting replies from internal chat here:

  • re "Eigen - 2nd preference, but first preference in caffe2 if ATen is not being compiled" - we can do MKL as first preference to be consistent, and use MKL if it is found.
  • C2 actually needs Eigen for its vectorization work, although if we do not use Eigen for BLAS (aka, not -DBLAS=Eigen), then simple inclusion is all needed (header-only).
  • on PPC and OSX - yes.

In general, it sounds reasonable to use the BLAS found by CMake first, and use Eigen as the last option if others are not found.

@orionr

This comment has been minimized.

Copy link
Contributor

orionr commented Jun 15, 2018

FYI, the fallback to Eigen from MKL roughly matches what is being done at https://github.com/pytorch/pytorch/blob/master/cmake/Dependencies.cmake#L73-L77 so makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment