You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2018/06/05 21:13:46 UTC

[GitHub] marcoabreu commented on a change in pull request #11148: [WIP] [MXNET-115] USE_LAPACK is forced on all platforms

marcoabreu commented on a change in pull request #11148: [WIP] [MXNET-115] USE_LAPACK is forced on all platforms
URL: https://github.com/apache/incubator-mxnet/pull/11148#discussion_r193224312
 
 

 ##########
 File path: cmake/ChooseBlas.cmake
 ##########
 @@ -19,40 +19,120 @@ set(BLAS "Open" CACHE STRING "Selected BLAS library")
 set_property(CACHE BLAS PROPERTY STRINGS "Atlas;Open;MKL")
 
 if(USE_MKL_IF_AVAILABLE)
+  message(STATUS "Trying to find MKL library due to USE_MKL_IF_AVAILABLE=True...")
+
   if(NOT MKL_FOUND)
     find_package(MKL)
   endif()
+
   if(MKL_FOUND)
-	if(USE_MKLDNN)
+    message(STATUS "MKL library found, checking if USE_MKLDNN...")
+
+	  if(USE_MKLDNN)
+      message(STATUS "USE_MKLDNN=True, setting to use OpenBLAS")
       set(BLAS "open")
     else()
+      message(STATUS "USE_MKLDNN=False, setting to use MKL")
       set(BLAS "MKL")
     endif()
+  else()
+    message(STATUS "MKL library not found, BLAS=${BLAS}")
   endif()
 endif()
 
-if(BLAS STREQUAL "Atlas" OR BLAS STREQUAL "atlas")
-  find_package(Atlas REQUIRED)
-  include_directories(SYSTEM ${Atlas_INCLUDE_DIR})
+# cmake regexp does not support case insensitive match (?i) or //i
+if(BLAS MATCHES "[Aa][Tt][Ll][Aa][Ss]")
+  message(STATUS "Using Atlas for BLAS")
+
+  set(Atlas_NEED_LAPACK ${USE_LAPACK})
+
+  include(${CMAKE_CURRENT_LIST_DIR}/Modules/FindAtlas.cmake)
+
+  include_directories(SYSTEM ${Atlas_INCLUDE_DIRS})
   list(APPEND mshadow_LINKER_LIBS ${Atlas_LIBRARIES})
+
   add_definitions(-DMSHADOW_USE_CBLAS=1)
   add_definitions(-DMSHADOW_USE_MKL=0)
-elseif(BLAS STREQUAL "Open" OR BLAS STREQUAL "open")
-  find_package(OpenBLAS REQUIRED)
-  include_directories(SYSTEM ${OpenBLAS_INCLUDE_DIR})
-  list(APPEND mshadow_LINKER_LIBS ${OpenBLAS_LIB})
+
+  if(USE_LAPACK AND Atlas_LAPACK_FOUND)
+    add_definitions(-DMXNET_USE_LAPACK=1)
+  endif()
+
+  return()
+endif()
+
+if(BLAS MATCHES "[Oo][Pp][Ee][Nn]")
+  message(STATUS "Using OpenBLAS for BLAS")
+
+  set(OpenBLAS_NEED_LAPACK ${USE_LAPACK})
+
+  include(${CMAKE_CURRENT_LIST_DIR}/Modules/FindOpenBLAS.cmake)
+
+  include_directories(SYSTEM ${OpenBLAS_INCLUDE_DIRS})
+  list(APPEND mshadow_LINKER_LIBS ${OpenBLAS_LIBRARIES})
+
   add_definitions(-DMSHADOW_USE_CBLAS=1)
   add_definitions(-DMSHADOW_USE_MKL=0)
-elseif(BLAS STREQUAL "MKL" OR BLAS STREQUAL "mkl")
+
+  if(USE_LAPACK AND OpenBLAS_LAPACK_FOUND)
+    add_definitions(-DMXNET_USE_LAPACK=1)
+  endif()
+
+  return()
+endif()
+
+if(BLAS MATCHES "[Mm][Kk][Ll]")
+  message(STATUS "Using MKL for BLAS")
+
+  # todo(lebeg): include(${CMAKE_CURRENT_LIST_DIR}/Modules/FindMKL.cmake)
+
   find_package(MKL REQUIRED)
+
   include_directories(SYSTEM ${MKL_INCLUDE_DIR})
   list(APPEND mshadow_LINKER_LIBS ${MKL_LIBRARIES})
+
   add_definitions(-DMSHADOW_USE_CBLAS=0)
   add_definitions(-DMSHADOW_USE_MKL=1)
-elseif(BLAS STREQUAL "apple")
+
+  if(USE_LAPACK)
+    include(CheckFunctionExists)
+    check_function_exists("cheev_" LAPACK_FOUND)
+
+    if(LAPACK_FOUND)
+      add_definitions(-DMXNET_USE_LAPACK=1)
+    endif()
+  endif()
+
+  return()
+endif()
+
+if(BLAS MATCHES "[Aa][Pp][Pp][Ll][Ee]")
+  if(NOT APPLE)
+    message(FATAL_ERROR "Apple BLAS framework is available only on MAC")
+    return()
+  endif()
+
+  message(STATUS "Using Apple Accelerate for BLAS")
+
+  # Accelerate framework documentation
+  # https://developer.apple.com/documentation/accelerate?changes=_2
   find_package(Accelerate REQUIRED)
   include_directories(SYSTEM ${Accelerate_INCLUDE_DIR})
   list(APPEND mshadow_LINKER_LIBS ${Accelerate_LIBRARIES})
-  add_definitions(-DMSHADOW_USE_MKL=0)
+
   add_definitions(-DMSHADOW_USE_CBLAS=1)
+  add_definitions(-DMSHADOW_USE_MKL=0)
+
+  if(USE_LAPACK)
+    # Apples vecLib should contain lapack functionalities included in the Accelerate framework, but we will double check
+    # https://developer.apple.com/documentation/accelerate/veclib?changes=_2
+    include(CheckFunctionExists)
+    check_function_exists("cheev_" LAPACK_FOUND)
+
+    if(LAPACK_FOUND)
+      add_definitions(-DMXNET_USE_LAPACK=1)
+    endif()
+  endif()
+
+  return()
 
 Review comment:
   Do we have a default case?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services