larroy commented on a change in pull request #14871: Cmake blas
URL: https://github.com/apache/incubator-mxnet/pull/14871#discussion_r286368774
 
 

 ##########
 File path: cmake/Modules/FindOpenBLAS.cmake
 ##########
 @@ -14,78 +14,181 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+#
+# Finds the OpenBLAS library.
+#
+# The following variables are set after configuration is done:
+#
+# - OpenBLAS_FOUND
+# - OpenBLAS_INCLUDE_DIRS
+# - OpenBLAS_LIBRARIES
+#
+# This script will try to find the OpenBLAS library using the following 
RESULT_VARs in this order:
+#
+# 1 - Use find_package(OpenBLAS) in Config mode.
+# 2 - Find the files manually
+#
+# At each step that was just described, in order to guarantee that the library 
was found correctly,
+# this script tries to compile this simple program:
+#
+#   #include <cblas.h>
+#   int main() {
+#     cblas_sasum(0, (float*)0, 0);
+#     return 0;
+#   }
+#
+# If this simple program can't be compiled with the OpenBLAS library 
discovered in the previous
+# step, then it assumes the step failed and moves on to the next step.
+#
+# To control where OpenBLAS should be searched for, one can set the 
environment variable
+# `OpenBLAS_HOME` point to the installation directory of OpenBLAS:
+#
+#   set OpenBLAS_HOME=c:\mxnet
+
+include(CheckCSourceCompiles)
+function(check_openblas_compiles RESULT_VAR)
+  message(STATUS "Testing a simple OpenBLAS program with: (${RESULT_VAR}, "
+                                                          "includes: 
${OpenBLAS_INCLUDE_DIRS}, "
+                                                          "libs: 
${OpenBLAS_LIBRARIES})")
+  set(CMAKE_REQUIRED_INCLUDES "${OpenBLAS_INCLUDE_DIRS}")
+  set(CMAKE_REQUIRED_LIBRARIES "${OpenBLAS_LIBRARIES}")
+
+  check_c_source_compiles("
+      #include <cblas.h>
+      int main() { cblas_sasum(0, (float*)0, 0); return 0; }
+  " OPENBLAS_CAN_COMPILE)
+
+  unset(CMAKE_REQUIRED_INCLUDES CACHE)
+  unset(CMAKE_REQUIRED_LIBRARIES CACHE)
+
+  if (NOT ${CAN_COMPILE})
+    message(WARNING "Couldn't compile a simple program to test for OpenBLAS 
presence using the '${RESULT_VAR}' RESULT_VAR. "
+            "To verify the error from the compiler, run cmake with the flag 
`--debug-trycompile`. "
+            "Check that the include directories are correct and contain the 
'cblas.h' file: ${OpenBLAS_INCLUDE_DIRS} "
+            "Check that the library directory also contains the compiled 
library: '${OpenBLAS_LIBRARIES}'.")
+  else()
+    message(STATUS "Found OpenBLAS via ${RESULT_VAR} (include: 
${OpenBLAS_INCLUDE_DIRS})")
+    message(STATUS "Found OpenBLAS via ${RESULT_VAR} (lib: 
${OpenBLAS_LIBRARIES})")
+  endif()
+
+  set(${RESULT_VAR} ${OPENBLAS_CAN_COMPILE} PARENT_SCOPE)
+  unset(OPENBLAS_CAN_COMPILE CACHE)
+endfunction()
+
+macro(unset_openblas_variables)
+  unset(OpenBLAS_FOUND)
+  unset(OpenBLAS_FOUND CACHE)
+  unset(OpenBLAS_LIBRARIES)
+  unset(OpenBLAS_LIBRARIES CACHE)
+  unset(OpenBLAS_INCLUDE_DIRS)
+  unset(OpenBLAS_INCLUDE_DIRS CACHE)
+endmacro()
+
+# Try config-mode
+find_package(OpenBLAS
+             NO_MODULE  # Forcing Config mode, otherwise this would be an 
infinite loop.
+             PATHS $ENV{OpenBLAS_HOME}
+             )
+if (OpenBLAS_FOUND)
+  check_openblas_compiles(OpenBLAS_CONFIG_MODE)
+  if (OpenBLAS_CONFIG_MODE)
+    return()
+  else()
+    unset_openblas_variables()
+  endif()
+endif()
+
+# Try finding the files manually
+if(CMAKE_CROSSCOMPILING)
+  set(OpenBLAS_INCLUDE_SEARCH_PATHS
+      ${OpenBLAS_INCLUDE_SEARCH_PATHS}
+
+      "$ENV{CROSS_ROOT}"
+      "${CROSS_ROOT}"
+      )
+endif()
+
+set(OpenBLAS_INCLUDE_SEARCH_PATHS
+    ${OpenBLAS_INCLUDE_SEARCH_PATHS}
+
+    "$ENV{OpenBLAS_HOME}"
+    "${OpenBLAS_HOME}"
+    "${OpenBLAS_ROOT}"
+
+    /usr
+    /usr/include/openblas
+    /usr/include/openblas-base
+    /usr/local
+    /usr/local/include/openblas
+    /usr/local/include/openblas-base
+    /opt/OpenBLAS
+    /usr/local/opt/openblas
+
+    "${PROJECT_SOURCE_DIR}/3rdparty/OpenBLAS"
+    "${PROJECT_SOURCE_DIR}/thirdparty/OpenBLAS"
+    )
+
+if(CMAKE_CROSSCOMPILING)
+  set(Open_BLAS_LIB_SEARCH_PATHS
+      ${Open_BLAS_LIB_SEARCH_PATHS}
+
+      "$ENV{CROSS_ROOT}"
+      "${CROSS_ROOT}"
+      )
+endif()
+
+set(OpenBLAS_LIB_SEARCH_PATHS
+    ${OpenBLAS_LIB_SEARCH_PATHS}
+
+    "$ENV{OpenBLAS_HOME}"
+    "${OpenBLAS_HOME}"
 
 Review comment:
   We don't need Openblas_home/include?  Where is this list coming from?

----------------------------------------------------------------
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]


With regards,
Apache Git Services

Reply via email to