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



##########
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:
       Yes if openblas.so include both cblas and lapacke then we can 
automatically detect. I originally thought we could support distro's lapacke as 
well but that might over-complicate things.. 




----------------------------------------------------------------
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:
[email protected]


Reply via email to