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 2020/12/03 18:47:57 UTC

[GitHub] [incubator-mxnet] leezu commented on a change in pull request #19174: Force static link to openblas on ci + add lapacke option for lapack

leezu commented on a change in pull request #19174:
URL: https://github.com/apache/incubator-mxnet/pull/19174#discussion_r535491060



##########
File path: cmake/ChooseBlas.cmake
##########
@@ -45,6 +45,78 @@ elseif(BLAS STREQUAL "Open" OR BLAS STREQUAL "open")
   add_definitions(-DMSHADOW_USE_CBLAS=1)
   add_definitions(-DMSHADOW_USE_MKL=0)
   add_definitions(-DMXNET_USE_BLAS_OPEN=1)
+  if(NOT MSVC)
+    # check if we need to link to omp
+    execute_process(COMMAND ${CMAKE_NM} -g ${OpenBLAS_LIB}
+                    COMMAND grep omp_get_num_threads
+                    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+                    OUTPUT_VARIABLE OPENBLAS_USES_OMP_OUT
+                    RESULT_VARIABLE OPENBLAS_USES_OMP_RET)
+    if(NOT OPENBLAS_USES_OMP_OUT STREQUAL "" AND NOT OPENBLAS_USES_OMP_RET AND NOT USE_OPENMP)
+      message("Openblas uses OMP, automatically linking to it")
+      find_package(OpenMP REQUIRED)
+      message("OpenMP_CXX_LIBRARIES is ${OpenMP_CXX_LIBRARIES}")
+      list(APPEND mshadow_LINKER_LIBS "${OpenMP_CXX_LIBRARIES}")
+    endif()
+    # check if we need to link to gfortran
+    execute_process(COMMAND ${CMAKE_NM} -g ${OpenBLAS_LIB}
+                    COMMAND grep gfortran
+                    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+                    OUTPUT_VARIABLE OPENBLAS_USES_GFORTRAN_OUT
+                    RESULT_VARIABLE OPENBLAS_USES_GFORTRAN_RET)
+    if(NOT OPENBLAS_USES_GFORTRAN_OUT STREQUAL "" AND NOT OPENBLAS_USES_GFORTRAN_RET)
+      message("Openblas uses GFortran, automatically linking to it")
+      file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/temp/CMakeLists.txt"
+      "cmake_minimum_required(VERSION ${CMAKE_VERSION})
+project(CheckFortran Fortran)
+set(CMAKE_Fortran_COMPILER gfortran)
+file(WRITE \"${CMAKE_CURRENT_BINARY_DIR}/temp/FortranDir.cmake\"
+\"
+set(FORTRAN_DIR \\\"\$\{CMAKE_Fortran_IMPLICIT_LINK_DIRECTORIES\}\\\")
+\")
+")
+      execute_process(
+        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/temp/
+        COMMAND ${CMAKE_COMMAND} .
+      )
+      set(FORTRAN_DIR "")
+      include(build/temp/FortranDir.cmake)
+      find_library(FORTRAN_LIB NAMES gfortran HINTS ${FORTRAN_DIR})
+      message("FORTRAN_DIR is ${FORTRAN_DIR}")
+      message("FORTRAN_LIB is ${FORTRAN_LIB}")
+      list(APPEND mshadow_LINKER_LIBS ${FORTRAN_LIB})
+      file(REMOVE_RECURSE "${CMAKE_CURRENT_BINARY_DIR}/temp/")
+    endif()
+    # check the lapack flavor of openblas
+    include(CheckSymbolExists)
+    check_symbol_exists(OPENBLAS_USE64BITINT "${OpenBLAS_INCLUDE_DIR}/openblas_config.h" OPENBLAS_ILP64)
+    if(OPENBLAS_ILP64)
+      message("Using ILP64 OpenBLAS")
+      if(NOT USE_INT64_TENSOR_SIZE)
+        message(FATAL_ERROR "Must set USE_INT64_TENSOR_SIZE=1 when using ILP64 OpenBLAS")
+      endif()
+    else()
+      message("Using LP64 OpenBLAS")
+    endif()
+    if(EXISTS "${OpenBLAS_INCLUDE_DIR}/lapacke.h")
+      message("Detected lapacke.h, automatically using the LAPACKE interface")
+      set(USE_LAPACKE_INTERFACE ON CACHE BOOL "Use LAPACKE interface for lapack support" FORCE)
+      if(OPENBLAS_ILP64)
+        message("Automatically setting USE_ILP64_LAPACKE=1")

Review comment:
       What's the use-case for manually setting `USE_ILP64_LAPACKE`? Ie. why is it exposed to the user? Should the large tensor option be already sufficient?

##########
File path: CMakeLists.txt
##########
@@ -60,6 +60,8 @@ cmake_dependent_option(USE_SSE "Build with x86 SSE instruction support" ON
   "CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL amd64" OFF)
 option(USE_F16C "Build with x86 F16C instruction support" ON) # autodetects support if ON
 option(USE_LAPACK "Build with lapack support" ON)
+option(USE_LAPACKE_INTERFACE "Use LAPACKE interface for lapack support" OFF)

Review comment:
       You're later overwriting this option. Why expose it to the user in the first place?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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