This is an automated email from the ASF dual-hosted git repository.

manuseth pushed a commit to branch v1.x
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git


The following commit(s) were added to refs/heads/v1.x by this push:
     new 2d891d9  [v1.x] Use ArmPL as BLAS for MXNet AArch64 wheels (#20342)
2d891d9 is described below

commit 2d891d993b8fbe440829f9dc50c56b2ff8627862
Author: Manu Seth <[email protected]>
AuthorDate: Thu Jun 17 11:45:15 2021 -0700

    [v1.x] Use ArmPL as BLAS for MXNet AArch64 wheels (#20342)
    
    * use armpl as blas for mxnet
    
    * link libgfortran
    
    * fix CPATH
    
    * rectify if condition
    
    * update armpl macro
    
    * remove lapacke.h as duplicate of cblas.h
---
 3rdparty/mshadow/mshadow/base.h             |  8 +++
 cmake/ChooseBlas.cmake                      |  8 +++
 cmake/Modules/FindArmPL.cmake               | 79 +++++++++++++++++++++++++++++
 config/distribution/linux_aarch64_cpu.cmake |  1 +
 src/operator/c_lapack_api.h                 | 16 +++---
 tools/staticbuild/build.sh                  |  6 ++-
 tools/staticbuild/build_lib_cmake.sh        |  4 +-
 7 files changed, 113 insertions(+), 9 deletions(-)

diff --git a/3rdparty/mshadow/mshadow/base.h b/3rdparty/mshadow/mshadow/base.h
index 9f53857..a6bf0ef 100755
--- a/3rdparty/mshadow/mshadow/base.h
+++ b/3rdparty/mshadow/mshadow/base.h
@@ -106,6 +106,10 @@ typedef unsigned __int64 uint64_t;
 #ifndef MSHADOW_USE_MKL
   #define MSHADOW_USE_MKL   1
 #endif
+/*! \brief use ArmPL for BLAS */
+#ifndef MSHADOW_USE_ARMPL
+  #define MSHADOW_USE_ARMPL 0
+#endif
 
 /*!
  * \brief use CUDA support, must ensure that the cuda include path is correct,
@@ -178,6 +182,10 @@ typedef unsigned __int64 uint64_t;
 
 #if MSHADOW_USE_CBLAS
 extern "C" {
+    #if MSHADOW_USE_ARMPL
+        #define armpl_singlecomplex_t float _Complex
+        #define armpl_doublecomplex_t double _Complex
+    #endif
     #include <cblas.h>
 }
 #elif MSHADOW_USE_MKL
diff --git a/cmake/ChooseBlas.cmake b/cmake/ChooseBlas.cmake
index 3848a3c..24ba7ea 100644
--- a/cmake/ChooseBlas.cmake
+++ b/cmake/ChooseBlas.cmake
@@ -103,4 +103,12 @@ elseif(BLAS STREQUAL "apple")
   add_definitions(-DMSHADOW_USE_MKL=0)
   add_definitions(-DMSHADOW_USE_CBLAS=1)
   add_definitions(-DMXNET_USE_BLAS_APPLE=1)
+elseif(BLAS STREQUAL "armpl" OR BLAS STREQUAL "ArmPL")
+  find_package(ArmPL REQUIRED)
+  include_directories(SYSTEM ${ArmPL_INCLUDE_DIR})
+  list(APPEND mshadow_LINKER_LIBS ${ArmPL_LIBRARIES})
+  add_definitions(-DMSHADOW_USE_CBLAS=1)
+  add_definitions(-DMSHADOW_USE_MKL=0)
+  add_definitions(-DMSHADOW_USE_ARMPL=1)
+  add_definitions(-DMXNET_USE_LAPACK=1)
 endif()
diff --git a/cmake/Modules/FindArmPL.cmake b/cmake/Modules/FindArmPL.cmake
new file mode 100644
index 0000000..5ff4e44
--- /dev/null
+++ b/cmake/Modules/FindArmPL.cmake
@@ -0,0 +1,79 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Find the ARM Performance Libraries
+#
+# The following are set after configuration is done:
+#  ArmPL_FOUND
+#  ArmPL_INCLUDE_DIR
+#  ArmPL_LIBRARIES
+
+file(TO_CMAKE_PATH "$ENV{ArmPL_HOME}" ArmPL_HOME)
+
+SET(ArmPL_INCLUDE_SEARCH_PATHS
+        /opt/arm/armpl_21.0_gcc-8.2/include_lp64_mp
+        ${ArmPL_HOME}/include_lp64_mp
+)
+
+SET(ArmPL_LIB_SEARCH_PATHS
+       /opt/arm/armpl_21.0_gcc-8.2/lib
+        ${ArmPL_HOME}/lib
+)
+
+FIND_PATH(ArmPL_INCLUDE_DIR NAMES armpl.h PATHS ${ArmPL_INCLUDE_SEARCH_PATHS})
+FIND_LIBRARY(ArmPL_LIB NAMES armpl_lp64_mp PATHS ${ArmPL_LIB_SEARCH_PATHS})
+FIND_LIBRARY(MATH_LIB NAMES amath PATHS ${ArmPL_LIB_SEARCH_PATHS})
+FIND_LIBRARY(STRING_LIB NAMES astring PATHS ${ArmPL_LIB_SEARCH_PATHS})
+SET(ArmPL_LIBRARIES
+       ${ArmPL_LIB}
+       ${MATH_LIB}
+       ${STRING_LIB}
+       /usr/local/gcc-8.5.0/lib64/libgfortran.so
+       /usr/lib/aarch64-linux-gnu/libm.so
+)
+
+SET(ArmPL_FOUND ON)
+
+#    Check include files
+IF(NOT ArmPL_INCLUDE_DIR)
+    SET(ArmPL_FOUND OFF)
+    MESSAGE(STATUS "Could not find ArmPL include. Turning ArmPL_FOUND off")
+ENDIF()
+
+#    Check libraries
+IF(NOT ArmPL_LIBRARIES)
+    SET(ArmPL_FOUND OFF)
+    MESSAGE(STATUS "Could not find ArmPL lib. Turning ArmPL_FOUND off")
+ENDIF()
+
+IF (ArmPL_FOUND)
+  IF (NOT ArmPL_FIND_QUIETLY)
+         MESSAGE(STATUS "Found ArmPL libraries: ${ArmPL_LIBRARIES}")
+    MESSAGE(STATUS "Found ArmPL include: ${ArmPL_INCLUDE_DIR}")
+  ENDIF (NOT ArmPL_FIND_QUIETLY)
+ELSE (ArmPL_FOUND)
+  IF (ArmPL_FIND_REQUIRED)
+    MESSAGE(FATAL_ERROR "Could not find ArmPL")
+  ENDIF (ArmPL_FIND_REQUIRED)
+ENDIF (ArmPL_FOUND)
+
+MARK_AS_ADVANCED(
+    ArmPL_FOUND
+    ArmPL_INCLUDE_DIR
+    ArmPL_LIBRARIES
+)
+
diff --git a/config/distribution/linux_aarch64_cpu.cmake 
b/config/distribution/linux_aarch64_cpu.cmake
index f413451..22d4fbc 100644
--- a/config/distribution/linux_aarch64_cpu.cmake
+++ b/config/distribution/linux_aarch64_cpu.cmake
@@ -19,6 +19,7 @@ set(CMAKE_BUILD_TYPE "Distribution" CACHE STRING "Build type")
 set(CFLAGS "-march=armv8-a+crc+crypto -moutline-atomics" CACHE STRING "CFLAGS")
 set(CXXFLAGS "-march=armv8-a" CACHE STRING "CXXFLAGS")
 
+set(USE_BLAS ArmPL CACHE STRING "BLAS")
 set(USE_CUDA OFF CACHE BOOL "Build with CUDA support")
 set(USE_OPENCV ON CACHE BOOL "Build with OpenCV support")
 set(USE_OPENMP ON CACHE BOOL "Build with Openmp support")
diff --git a/src/operator/c_lapack_api.h b/src/operator/c_lapack_api.h
index 8b07265..698822b 100644
--- a/src/operator/c_lapack_api.h
+++ b/src/operator/c_lapack_api.h
@@ -70,8 +70,8 @@
 
 using namespace mshadow;
 
-// Will cause clash with MKL fortran layer headers
-#if MSHADOW_USE_MKL == 0
+// Will cause clash with MKL/ArmPL fortran layer headers
+#if (!MSHADOW_USE_MKL && !MSHADOW_USE_ARMPL)
 
 extern "C" {
 
@@ -199,7 +199,7 @@ extern "C" {
   MXNET_LAPACK_FSIG_GEEV(dgeev, double)
 }
 
-#endif  // MSHADOW_USE_MKL == 0
+#endif  // (!MSHADOW_USE_MKL && !MSHADOW_USE_ARMPL)
 
 
 #define CHECK_LAPACK_UPLO(a) \
@@ -228,11 +228,13 @@ inline void flip(int m, int n, DType *b, int ldb, DType 
*a, int lda) {
 }
 
 
-#if (MSHADOW_USE_MKL && MXNET_USE_LAPACK)
+#if (MXNET_USE_LAPACK && (MSHADOW_USE_MKL || MSHADOW_USE_ARMPL))
 
-  // We interface with the C-interface of MKL
-  // as this is the preferred way.
-  #include <mkl_lapacke.h>
+  #if (MSHADOW_USE_MKL)
+    // We interface with the C-interface of MKL
+    // as this is the preferred way.
+    #include <mkl_lapacke.h>
+  #endif
 
   #define MXNET_LAPACK_ROW_MAJOR LAPACK_ROW_MAJOR
   #define MXNET_LAPACK_COL_MAJOR LAPACK_COL_MAJOR
diff --git a/tools/staticbuild/build.sh b/tools/staticbuild/build.sh
index e5ce595..1306dce 100755
--- a/tools/staticbuild/build.sh
+++ b/tools/staticbuild/build.sh
@@ -59,7 +59,11 @@ else
     export 
PKG_CONFIG_PATH=$DEPS_PATH/lib/pkgconfig:$DEPS_PATH/lib64/pkgconfig:$DEPS_PATH/lib/x86_64-linux-gnu/pkgconfig:$PKG_CONFIG_PATH
 fi
 export FC="gfortran"
-export CPATH=$DEPS_PATH/include:$CPATH
+if [[ $ARCH == 'aarch64' ]]; then
+    export CPATH=/opt/arm/armpl_21.0_gcc-8.2/include_lp64_mp:$CPATH
+else
+    export CPATH=$DEPS_PATH/include:$CPATH
+fi
 
 if [[ $PLATFORM == 'linux' && $VARIANT == cu* ]]; then
     source tools/setup_gpu_build_tools.sh $VARIANT $DEPS_PATH
diff --git a/tools/staticbuild/build_lib_cmake.sh 
b/tools/staticbuild/build_lib_cmake.sh
index ade6b7a..a29c393 100755
--- a/tools/staticbuild/build_lib_cmake.sh
+++ b/tools/staticbuild/build_lib_cmake.sh
@@ -39,8 +39,10 @@ cd -
 rm -rf lib; mkdir lib;
 if [[ $PLATFORM == 'linux' ]]; then
     cp -L build/libmxnet.so lib/libmxnet.so
-    cp -L staticdeps/lib/libopenblas.so lib/libopenblas.so.0
     cp -L $(ldd lib/libmxnet.so | grep libgfortran | awk '{print $3}') lib/
+    if [[ ! $ARCH == 'aarch64' ]]; then
+        cp -L staticdeps/lib/libopenblas.so lib/libopenblas.so.0
+    fi
 elif [[ $PLATFORM == 'darwin' ]]; then
     cp -L build/libmxnet.dylib lib/libmxnet.dylib
 fi

Reply via email to