[MXNET-679] Refactor handling BLAS libraries with cmake#11148
[MXNET-679] Refactor handling BLAS libraries with cmake#11148lebeg wants to merge 78 commits intoapache:masterfrom
Conversation
| endif() | ||
| endif() | ||
|
|
||
| return() |
There was a problem hiding this comment.
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. |
aaronmarkham
left a comment
There was a problem hiding this comment.
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?
| # * MKL (MKL, MKLML, MKLDNN) | ||
| # * Apple Accelerate | ||
| # | ||
| # The default order of choice for the libraries if found follows the path from probably the most |
| # 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.
triggered by apple correct? Maybe worth putting in each one's param value, so when reading this you're associating the correct values...
| # (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.
(must register, download, and install separately)
link to it?
| # 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.
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?
| if(NOT MKL_FOUND) | ||
| function(switch_lapack enable) | ||
| if(${enable}) | ||
| message(STATUS "Enabling lapack functionality") |
| 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...") |
| Atlas_CLAPACK_INCLUDE_DIR | ||
| Atlas_LAPACK_LIBRARY) | ||
|
|
||
| message(STATUS "Lapack found") |
| 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") |
| ) | ||
|
|
||
| if(OpenBLAS_NEED_LAPACK) | ||
| message(STATUS "Looking for lapack support...") |
| 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") |
|
Thanks! Yes, probably building from source section would be the right place, what do you think? |
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 |
larroy
left a comment
There was a problem hiding this comment.
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.
Good catch! And good comment
| 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: |
| 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.
What if we are cross compiling?
There was a problem hiding this comment.
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.
But we cross compile for ARM in the host...
There was a problem hiding this comment.
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! |
| 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.
My understanding was that MKLDNN could be installed stand-alone, without any other MKL flavours.
There was a problem hiding this comment.
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