-
Notifications
You must be signed in to change notification settings - Fork 6.8k
[MXNET-679] Refactor handling BLAS libraries with cmake #11148
Conversation
cmake/ChooseBlas.cmake
Outdated
endif() | ||
endif() | ||
|
||
return() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have a default case?
How is this related to #11094? |
#11094 does not fix the problem that there is no liblapack library for OpenBLAS as well as for no library except Atlas. The logic to determine whether lapack functionality is available is broken in disregards of the USE_LAPACK flag being used. This PR is an attempt to fix and improve the situation and automatically detect lapack for each blas library used in the right way. |
Okay, please resolve conflicts so I can continue to review |
Does this perhaps fix #11769? |
Yes, I think this should help. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really cool stuff. Seems like this will be a much smoother experience. I had some minor nits on capitalization and consistency in the libraries' names... and some questions/suggestions.
Will we be moving / copying some of info in the comments of the CMakeLists.txt file to web pages in/around the install pages?
CMakeLists.txt
Outdated
# * MKL (MKL, MKLML, MKLDNN) | ||
# * Apple Accelerate | ||
# | ||
# The default order of choice for the libraries if found follows the path from probably the most |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably? 😆
CMakeLists.txt
Outdated
# 1. MKLDNN (requires and checks for MKL or MKLML) | ||
# 2. MKL | ||
# 3. MKLML (downloaded) | ||
# 4. Accelerate (on mac) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
triggered by apple
correct? Maybe worth putting in each one's param value, so when reading this you're associating the correct values...
CMakeLists.txt
Outdated
# (recommended) to less performant backends. The order is as follows: | ||
# | ||
# 1. MKLDNN (requires and checks for MKL or MKLML) | ||
# 2. MKL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(must register, download, and install separately)
link to it?
CMakeLists.txt
Outdated
# Apple's mathematical framework, probably the best choice on a Mac if MKL/MKLML/MKLDNN | ||
# are not available. | ||
# https://developer.apple.com/documentation/accelerate | ||
mxnet_option(USE_ACCELERATE_IF_AVAILABLE "Use Apple Accelerate framework if found, \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get it now, after digging in, but on first glance, I would confuse this with a generic acceleration option, and say, "YEAH! Turn that one on for sure!", and not realize it is for Apple. What if you called it USE_APPLE_ACCELERATE_IF_AVAILABLE?
cmake/ChooseBlas.cmake
Outdated
if(NOT MKL_FOUND) | ||
function(switch_lapack enable) | ||
if(${enable}) | ||
message(STATUS "Enabling lapack functionality") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LAPACK
cmake/Modules/FindAtlas.cmake
Outdated
find_library(Atlas_LAPACK_LIBRARY NAMES alapack_r alapack lapack_atlas PATHS ${Atlas_LIB_SEARCH_PATHS}) | ||
set(LOOKED_FOR ${LOOKED_FOR} Atlas_CLAPACK_INCLUDE_DIR Atlas_LAPACK_LIBRARY) | ||
endif(Atlas_NEED_LAPACK) | ||
message(STATUS "Looking for lapack support...") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LAPACK
cmake/Modules/FindAtlas.cmake
Outdated
Atlas_CLAPACK_INCLUDE_DIR | ||
Atlas_LAPACK_LIBRARY) | ||
|
||
message(STATUS "Lapack found") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LAPACK
cmake/Modules/FindAtlas.cmake
Outdated
message(STATUS "Lapack found") | ||
else() | ||
set(Atlas_LAPACK_FOUND False) | ||
message(WARNING "Lapack with Atlas could not be found, lapack functionality will not be available") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LAPACK x2
cmake/Modules/FindOpenBLAS.cmake
Outdated
) | ||
|
||
if(OpenBLAS_NEED_LAPACK) | ||
message(STATUS "Looking for lapack support...") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LAPACK
cmake/Modules/FindOpenBLAS.cmake
Outdated
message(STATUS "Lapack found") | ||
else() | ||
set(OpenBLAS_LAPACK_FOUND False) | ||
message(WARNING "OpenBlas has not been compiled with Lapack support, lapack functionality will not be available") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LAPACK x2
Thanks! Yes, probably building from source section would be the right place, what do you think? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0bd2103
to
a909551
Compare
@lebeg - are you planning to fix the issues that fail the tests? |
@lupesko sure, just came back from vacation, working on the fixes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great PR! Are the changes to random in cpp code intended?
|
||
# workaround to store CMAKE_CROSSCOMPILING because is getting reset by the project command | ||
if(CMAKE_CROSSCOMPILING) | ||
set(__CMAKE_CROSSCOMPILING ${CMAKE_CROSSCOMPILING}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! And good comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks)
message(STATUS "CMAKE_SYSTEM_NAME ${CMAKE_SYSTEM_NAME}") | ||
# Choose BLAS (Basic Linear Algebra Subprograms) computation libraries | ||
|
||
# MXNet supports multiple mathematical backends for computations on the CPU: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome documentation!
CMakeLists.txt
Outdated
if(MSVC) | ||
set(SYSTEM_ARCHITECTURE x86_64) | ||
else() | ||
execute_process(COMMAND uname -m COMMAND tr -d '\n' OUTPUT_VARIABLE SYSTEM_ARCHITECTURE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we are cross compiling?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That supposed to be the host architecture. It's used to not try to download MKLML in case we are on an arm platform.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we cross compile for ARM in the host...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For cross compilation we use the CMAKE_CROSSCOMPILING flag to prevent a download
Yes, the |
@larroy @szha @aaronmarkham @marcoabreu @anirudh2290 @piiswrong @lupesko @nswamy could you have another look? Thanks! |
cmake/ChooseBLAS.cmake
Outdated
endif() | ||
|
||
if(NOT MKL_FOUND) | ||
message(WARNING "MKLDNN requires either MKL or MKLML, MKLDNN will not be available") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding was that MKLDNN could be installed stand-alone, without any other MKL flavours.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had actually the opposite opinion, but after taking a closer look I've realised that this is true. I will make the needed changes.
This PR needs to be separated and, as I have stated in on the @dev list, refactored to used as much built-in cmake functionality as possible. |
* update mkml * refine DownloadMKLML.cmake * merge DownloadMKLML.cmake from apache#11148 * fix mkldnn release version * fix windows compilation
@lebeg what would the plan for next step on this PR? |
@stu1130 I'm out of capacity for it right now, I would be glad if anyone has interest in taking it over. I would be happy to make reviews and provide support as much as I can. |
Description
This is fixing a number of issues with handling BLAS libraries with cmake:
[MXNET-115] USE_LAPACK is forced on all platforms
#8702 [DISCUSSION] Should we deprecate Makefile and only use CMake?
#8532 mxnet-mkl (v0.12.0) crash when using (conda-installed) numpy with MKL // (general MKL handling in comments)
#10175 MXNet MKLDNN build dependency/flow discussion
#9868 MKL and CMake
#9105 libmxnet.so load path error
#8729 Build amalgamation using a docker // (LAPACK with cross compilation in the comments)
#7852 Trouble installing MXNet on Raspberry Pi 3
Checklist
Essentials
Changes
Comments