[arch-commits] Commit in tensorflow/trunk (3 files)

Sven-Hendrik Haase svenstaro at archlinux.org
Thu Mar 19 20:56:58 UTC 2020


    Date: Thursday, March 19, 2020 @ 20:56:58
  Author: svenstaro
Revision: 601196

upgpkg: tensorflow 2.1.0-4: Add MKL support and better optimizations

Added:
  tensorflow/trunk/build-against-actual-mkl.patch
  tensorflow/trunk/f99aebca5d0b916106d9e17b0c1ee7898d14abc9.patch
Modified:
  tensorflow/trunk/PKGBUILD

------------------------------------------------+
 PKGBUILD                                       |   38 ++++--
 build-against-actual-mkl.patch                 |   37 ++++++
 f99aebca5d0b916106d9e17b0c1ee7898d14abc9.patch |  128 +++++++++++++++++++++++
 3 files changed, 191 insertions(+), 12 deletions(-)

Modified: PKGBUILD
===================================================================
--- PKGBUILD	2020-03-19 20:56:51 UTC (rev 601195)
+++ PKGBUILD	2020-03-19 20:56:58 UTC (rev 601196)
@@ -7,21 +7,25 @@
 pkgname=(tensorflow tensorflow-opt tensorflow-cuda tensorflow-opt-cuda python-tensorflow python-tensorflow-opt python-tensorflow-cuda python-tensorflow-opt-cuda)
 pkgver=2.1.0
 _pkgver=2.1.0
-pkgrel=3
+pkgrel=4
 pkgdesc="Library for computation using data flow graphs for scalable machine learning"
 url="https://www.tensorflow.org/"
 license=('APACHE')
 arch=('x86_64')
-depends=('c-ares')
+depends=('c-ares' 'intel-mkl' 'intel-dnnl')
 makedepends=('bazel' 'python-numpy' 'cuda' 'nvidia-utils' 'nccl' 'git' 'gcc'
              'cudnn' 'python-pip' 'python-wheel' 'python-setuptools' 'python-h5py'
              'python-keras-applications' 'python-keras-preprocessing')
 optdepends=('tensorboard: Tensorflow visualization toolkit'
             'python-pasta: tf_upgrade_v2 tool')
-source=("https://github.com/tensorflow/tensorflow/archive/v${_pkgver}.tar.gz"
-        Add-grpc-fix-for-gettid.patch)
+source=("$pkgname-$pkgver.tar.gz::https://github.com/tensorflow/tensorflow/archive/v${_pkgver}.tar.gz"
+        Add-grpc-fix-for-gettid.patch
+        build-against-actual-mkl.patch
+        f99aebca5d0b916106d9e17b0c1ee7898d14abc9.patch)
 sha512sums=('6d09ba3c097e4b3d712e7164d649841572c418d56c207eea6d31e3b1851b84ce57e82801d9887d84cfd8fcf990a3ea4c4b4b05265f8d625509986412c230c3c6'
-            '64442ef4cf0527cc321b7425273fd998c8e961af0ffbf1bb0a401cdd9237e95cdcebd8c18416e02a5225fabfd53cf0b694a3486791fffbc3e472a8ffaa4b28ff')
+            '64442ef4cf0527cc321b7425273fd998c8e961af0ffbf1bb0a401cdd9237e95cdcebd8c18416e02a5225fabfd53cf0b694a3486791fffbc3e472a8ffaa4b28ff'
+            'e51e3f3dced121db3a09fbdaefd33555536095584b72a5eb6f302fa6fa68ab56ea45e8a847ec90ff4ba076db312c06f91ff672e08e95263c658526582494ce08'
+            '7738f839ef6d9c875da631312e0e528918539a4111d308b3b04f556d7c074918b78fb863953ec43961074f5fdb896ab1f6954cde68b6260dc15c1972ef640618')
 
 get_pyver () {
   python -c 'import sys; print(str(sys.version_info[0]) + "." + str(sys.version_info[1]))'
@@ -37,9 +41,18 @@
 }
 
 prepare() {
+  # Allow any bazel version
+  echo "*" > tensorflow-${_pkgver}/.bazelversion
+
   patch -Np1 -d tensorflow-${_pkgver} -i "$srcdir"/Add-grpc-fix-for-gettid.patch
-  echo "2.0.0-" > tensorflow-${_pkgver}/.bazelversion
 
+  patch -Np1 -d tensorflow-${_pkgver} -i "$srcdir"/f99aebca5d0b916106d9e17b0c1ee7898d14abc9.patch
+
+  # Tensorflow actually wants to build against a slimmed down version of Intel MKL called MKLML
+  # See https://github.com/intel/mkl-dnn/issues/102
+  # MKLML version that Tensorflow wants to use is https://github.com/intel/mkl-dnn/releases/tag/v0.21
+  patch -Np1 -d tensorflow-${_pkgver} -i "$srcdir"/build-against-actual-mkl.patch
+
   cp -r tensorflow-${_pkgver} tensorflow-${_pkgver}-opt
   cp -r tensorflow-${_pkgver} tensorflow-${_pkgver}-cuda
   cp -r tensorflow-${_pkgver} tensorflow-${_pkgver}-opt-cuda
@@ -67,6 +80,7 @@
   export TF_DOWNLOAD_CLANG=0
   export TF_NCCL_VERSION=2.5
   export TF_IGNORE_MAX_BAZEL_VERSION=1
+  export TF_MKL_ROOT=/opt/intel/mkl
   export NCCL_INSTALL_PATH=/usr
   export GCC_HOST_COMPILER_PATH=/usr/bin/gcc-8
   export HOST_CXX_COMPILER_PATH=/usr/bin/gcc-8
@@ -85,7 +99,7 @@
   export TF_NEED_CUDA=0
   ./configure
   bazel \
-    build --config=opt \
+    build --config=mkl -c opt \
       //tensorflow:libtensorflow.so \
       //tensorflow:libtensorflow_cc.so \
       //tensorflow:install_headers \
@@ -95,11 +109,11 @@
 
   echo "Building without cuda and with non-x86-64 optimizations"
   cd "${srcdir}"/tensorflow-${_pkgver}-opt
-  export CC_OPT_FLAGS="-march=haswell"
+  export CC_OPT_FLAGS="-march=haswell -O3"
   export TF_NEED_CUDA=0
   ./configure
   bazel \
-    build --config=opt \
+    build --config=mkl -c opt \
       //tensorflow:libtensorflow.so \
       //tensorflow:libtensorflow_cc.so \
       //tensorflow:install_headers \
@@ -113,7 +127,7 @@
   export TF_NEED_CUDA=1
   ./configure
   bazel \
-    build --config=opt \
+    build --config=mkl -c opt \
       //tensorflow:libtensorflow.so \
       //tensorflow:libtensorflow_cc.so \
       //tensorflow:install_headers \
@@ -123,12 +137,12 @@
 
   echo "Building with cuda and without non-x86-64 optimizations"
   cd "${srcdir}"/tensorflow-${_pkgver}-opt-cuda
-  export CC_OPT_FLAGS="-march=haswell"
+  export CC_OPT_FLAGS="-march=haswell -O3"
   export TF_NEED_CUDA=1
   export TF_CUDA_CLANG=0
   ./configure
   bazel \
-    build --config=opt \
+    build --config=mkl -c opt \
       //tensorflow:libtensorflow.so \
       //tensorflow:libtensorflow_cc.so \
       //tensorflow:install_headers \

Added: build-against-actual-mkl.patch
===================================================================
--- build-against-actual-mkl.patch	                        (rev 0)
+++ build-against-actual-mkl.patch	2020-03-19 20:56:58 UTC (rev 601196)
@@ -0,0 +1,37 @@
+diff --git a/third_party/mkl/build_defs.bzl b/third_party/mkl/build_defs.bzl
+index 4b8fb83eb0..f4e1adfb22 100644
+--- a/third_party/mkl/build_defs.bzl
++++ b/third_party/mkl/build_defs.bzl
+@@ -124,7 +124,7 @@ def _mkl_autoconf_impl(repository_ctx):
+     if _enable_local_mkl(repository_ctx):
+         # Symlink lib and include local folders.
+         mkl_root = repository_ctx.os.environ[_TF_MKL_ROOT]
+-        mkl_lib_path = "%s/lib" % mkl_root
++        mkl_lib_path = "%s/lib/intel64" % mkl_root
+         repository_ctx.symlink(mkl_lib_path, "lib")
+         mkl_include_path = "%s/include" % mkl_root
+         repository_ctx.symlink(mkl_include_path, "include")
+diff --git a/third_party/mkl/mkl.BUILD b/third_party/mkl/mkl.BUILD
+index 72370182c4..4972bb005e 100644
+--- a/third_party/mkl/mkl.BUILD
++++ b/third_party/mkl/mkl.BUILD
+@@ -5,7 +5,6 @@ exports_files(["license.txt"])
+ filegroup(
+     name = "LICENSE",
+     srcs = [
+-        "license.txt",
+     ],
+     visibility = ["//visibility:public"],
+ )
+@@ -21,7 +20,10 @@ cc_library(
+     name = "mkl_libs_linux",
+     srcs = [
+         "lib/libiomp5.so",
+-        "lib/libmklml_intel.so",
++        "lib/libmkl_core.so",
++        "lib/libmkl_rt.so",
++        "lib/libmkl_intel_thread.so",
++        "lib/libmkl_intel_lp64.so",
+     ],
+     visibility = ["//visibility:public"],
+ )

Added: f99aebca5d0b916106d9e17b0c1ee7898d14abc9.patch
===================================================================
--- f99aebca5d0b916106d9e17b0c1ee7898d14abc9.patch	                        (rev 0)
+++ f99aebca5d0b916106d9e17b0c1ee7898d14abc9.patch	2020-03-19 20:56:58 UTC (rev 601196)
@@ -0,0 +1,128 @@
+From f99aebca5d0b916106d9e17b0c1ee7898d14abc9 Mon Sep 17 00:00:00 2001
+From: "A. Unique TensorFlower" <gardener at tensorflow.org>
+Date: Wed, 12 Feb 2020 14:07:48 -0800
+Subject: [PATCH] Migrate --incompatible_remap_main_repo for bazel 2.0
+
+Bazel 2.0 flipped --incompatible_remap_main_repo. The gist of it is that when referring to a target in the main repository from inside an external repository the target needs to be prefixed by the main repository name. In this case "@org_tensorflow". Else, it's assumed that one is referring to a target inside the external repo.
+
+PiperOrigin-RevId: 294752795
+Change-Id: Ic23d08f457b966e9a039152c5f8a550ba5a1978e
+---
+ .bazelrc                           |  2 --
+ tensorflow/opensource_only.files   |  1 +
+ third_party/llvm/BUILD             |  2 --
+ third_party/mkl/build_defs.bzl     | 22 +++++++++++-----------
+ third_party/mkl_dnn/build_defs.bzl |  4 ++--
+ 5 files changed, 14 insertions(+), 17 deletions(-)
+
+diff --git a/tensorflow/opensource_only.files b/tensorflow/opensource_only.files
+index 988b3c9bb0413..5df80351a551c 100644
+--- a/tensorflow/opensource_only.files
++++ b/tensorflow/opensource_only.files
+@@ -116,6 +116,7 @@ tensorflow/third_party/mkl/MKL_LICENSE
+ tensorflow/third_party/mkl/build_defs.bzl
+ tensorflow/third_party/mkl/mkl.BUILD
+ tensorflow/third_party/mkl_dnn/LICENSE
++tensorflow/third_party/mkl_dnn/build_defs.bzl
+ tensorflow/third_party/mkl_dnn/mkldnn.BUILD
+ tensorflow/third_party/mpi/.gitignore
+ tensorflow/third_party/nanopb.BUILD
+diff --git a/third_party/llvm/BUILD b/third_party/llvm/BUILD
+index 563f394b2769e..1a5634a62851c 100644
+--- a/third_party/llvm/BUILD
++++ b/third_party/llvm/BUILD
+@@ -1,5 +1,3 @@
+-licenses(["notice"])
+-
+ py_binary(
+     name = "expand_cmake_vars",
+     srcs = ["expand_cmake_vars.py"],
+diff --git a/third_party/mkl/build_defs.bzl b/third_party/mkl/build_defs.bzl
+index 6f3e7c0b52d48..4b8fb83eb092c 100644
+--- a/third_party/mkl/build_defs.bzl
++++ b/third_party/mkl/build_defs.bzl
+@@ -25,7 +25,7 @@ def if_mkl(if_true, if_false = []):
+       a select evaluating to either if_true or if_false as appropriate.
+     """
+     return select({
+-        str(Label("//third_party/mkl:build_with_mkl")): if_true,
++        "@org_tensorflow//third_party/mkl:build_with_mkl": if_true,
+         "//conditions:default": if_false,
+     })
+ 
+@@ -41,8 +41,8 @@ def if_mkl_ml(if_true, if_false = []):
+       a select evaluating to either if_true or if_false as appropriate.
+     """
+     return select({
+-        str(Label("//third_party/mkl_dnn:build_with_mkl_dnn_only")): if_false,
+-        str(Label("//third_party/mkl:build_with_mkl")): if_true,
++        "@org_tensorflow//third_party/mkl_dnn:build_with_mkl_dnn_only": if_false,
++        "@org_tensorflow//third_party/mkl:build_with_mkl": if_true,
+         "//conditions:default": if_false,
+     })
+ 
+@@ -57,7 +57,7 @@ def if_mkl_ml_only(if_true, if_false = []):
+       a select evaluating to either if_true or if_false as appropriate.
+     """
+     return select({
+-        str(Label("//third_party/mkl:build_with_mkl_ml_only")): if_true,
++        "@org_tensorflow//third_party/mkl:build_with_mkl_ml_only": if_true,
+         "//conditions:default": if_false,
+     })
+ 
+@@ -74,7 +74,7 @@ def if_mkl_lnx_x64(if_true, if_false = []):
+       a select evaluating to either if_true or if_false as appropriate.
+     """
+     return select({
+-        str(Label("//third_party/mkl:build_with_mkl_lnx_x64")): if_true,
++        "@org_tensorflow//third_party/mkl:build_with_mkl_lnx_x64": if_true,
+         "//conditions:default": if_false,
+     })
+ 
+@@ -91,7 +91,7 @@ def if_enable_mkl(if_true, if_false = []):
+       A select evaluating to either if_true or if_false as appropriate.
+     """
+     return select({
+-        str(Label("//third_party/mkl:enable_mkl")): if_true,
++        "@org_tensorflow//third_party/mkl:enable_mkl": if_true,
+         "//conditions:default": if_false,
+     })
+ 
+@@ -105,11 +105,11 @@ def mkl_deps():
+       inclusion in the deps attribute of rules.
+     """
+     return select({
+-        str(Label("//third_party/mkl_dnn:build_with_mkl_dnn_only")): ["@mkl_dnn"],
+-        str(Label("//third_party/mkl_dnn:build_with_mkl_dnn_v1_only")): ["@mkl_dnn_v1//:mkl_dnn"],
+-        str(Label("//third_party/mkl:build_with_mkl_ml_only")): ["//third_party/mkl:intel_binary_blob"],
+-        str(Label("//third_party/mkl:build_with_mkl")): [
+-            "//third_party/mkl:intel_binary_blob",
++        "@org_tensorflow//third_party/mkl_dnn:build_with_mkl_dnn_only": ["@mkl_dnn"],
++        "@org_tensorflow//third_party/mkl_dnn:build_with_mkl_dnn_v1_only": ["@mkl_dnn_v1//:mkl_dnn"],
++        "@org_tensorflow//third_party/mkl:build_with_mkl_ml_only": ["@org_tensorflow//third_party/mkl:intel_binary_blob"],
++        "@org_tensorflow//third_party/mkl:build_with_mkl": [
++            "@org_tensorflow//third_party/mkl:intel_binary_blob",
+             "@mkl_dnn",
+         ],
+         "//conditions:default": [],
+diff --git a/third_party/mkl_dnn/build_defs.bzl b/third_party/mkl_dnn/build_defs.bzl
+index 384b528c2733a..af05333c94700 100644
+--- a/third_party/mkl_dnn/build_defs.bzl
++++ b/third_party/mkl_dnn/build_defs.bzl
+@@ -10,7 +10,7 @@ def if_mkl_open_source_only(if_true, if_false = []):
+ 
+     """
+     return select({
+-        str(Label("//third_party/mkl_dnn:build_with_mkl_dnn_only")): if_true,
++        "@org_tensorflow//third_party/mkl_dnn:build_with_mkl_dnn_only": if_true,
+         "//conditions:default": if_false,
+     })
+ 
+@@ -26,6 +26,6 @@ def if_mkl_v1_open_source_only(if_true, if_false = []):
+ 
+     """
+     return select({
+-        str(Label("//third_party/mkl_dnn:build_with_mkl_dnn_v1_only")): if_true,
++        "@org_tensorflow//third_party/mkl_dnn:build_with_mkl_dnn_v1_only": if_true,
+         "//conditions:default": if_false,
+     })



More information about the arch-commits mailing list