From 4d24036948bcb0ca4319c6229b3f31aacb99fa82 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Fri, 22 Apr 2022 02:11:22 -0400 Subject: [PATCH 1/4] update TF installation doc --- doc/install/install-tf.2.3.md | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/doc/install/install-tf.2.3.md b/doc/install/install-tf.2.3.md index b2b7193754..c101d4205f 100644 --- a/doc/install/install-tf.2.3.md +++ b/doc/install/install-tf.2.3.md @@ -1,16 +1,16 @@ # Install TensorFlow's C++ interface -The tensorflow's C++ interface will be compiled from the source code. Firstly one installs bazel. The bazel version 3.1.0 should be used. A full instruction of bazel installation can be found [here](https://docs.bazel.build/versions/master/install.html). +The tensorflow's C++ interface will be compiled from the source code. Firstly one installs bazel. [bazelisk](https://github.com/bazelbuild/bazelisk) can be lanuched to use [bazel](https://github.com/bazelbuild/bazel). + ```bash -cd /some/workspace -wget https://github.com/bazelbuild/bazel/releases/download/3.1.0/bazel-3.1.0-installer-linux-x86_64.sh -chmod +x bazel-3.1.0-installer-linux-x86_64.sh +wget https://github.com/bazelbuild/bazelisk/releases/download/v1.11.0/bazelisk-linux-amd64 -O /some/workspace/bazel/bin/bazel +chmod +x /some/workspace/bazel/bin/bazel ./bazel-3.1.0-installer-linux-x86_64.sh --prefix /some/workspace/bazel export PATH=/some/workspace/bazel/bin:$PATH ``` Firstly get the source code of the TensorFlow ```bash -git clone https://github.com/tensorflow/tensorflow tensorflow -b v2.3.0 --depth=1 +git clone https://github.com/tensorflow/tensorflow tensorflow -b v2.8.0 --depth=1 cd tensorflow ./configure ``` @@ -78,7 +78,7 @@ Now build the shared library of tensorflow: ```bash bazel build -c opt --verbose_failures //tensorflow:libtensorflow_cc.so ``` -You may want to add options `--copt=-msse4.2`, `--copt=-mavx`, `--copt=-mavx2` and `--copt=-mfma` to enable SSE4.2, AVX, AVX2 and FMA SIMD accelerations, respectively. It is noted that these options should be chosen according to the CPU architecture. If the RAM becomes an issue of your machine, you may limit the RAM usage by using `--local_resources 2048,.5,1.0`. +You may want to add options `--copt=-msse4.2`, `--copt=-mavx`, `--copt=-mavx2` and `--copt=-mfma` to enable SSE4.2, AVX, AVX2 and FMA SIMD accelerations, respectively. It is noted that these options should be chosen according to the CPU architecture. If the RAM becomes an issue of your machine, you may limit the RAM usage by using `--local_resources 2048,.5,1.0`. If you want to enable oneDNN optimization, add `--config=mkl`. Now I assume you want to install TensorFlow in directory `$tensorflow_root`. Create the directory if it does not exist ```bash @@ -104,6 +104,11 @@ rsync -avzh --include '*/' --include '*.h' --include '*.inc' --exclude '*' bazel rsync -avzh --include '*/' --include '*.h' --include '*.inc' --exclude '*' bazel-tensorflow/external/com_google_absl/absl/ $tensorflow_root/include/absl/ ``` +If you've enabled oneDNN, also copy `libiomp5.so`: +```bash +cp -d bazel-out/k8-opt/bin/external/llvm_openmp/libiomp5.so $tensorflow_root/lib/ +``` + # Troubleshooting ```bash git: unknown command -C ... From eb572e7e46b5197a92c40c22960185bc7e6e6415 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Fri, 22 Apr 2022 17:36:50 -0400 Subject: [PATCH 2/4] Revert "update TF installation doc" This reverts commit 4d24036948bcb0ca4319c6229b3f31aacb99fa82. --- doc/install/install-tf.2.3.md | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/doc/install/install-tf.2.3.md b/doc/install/install-tf.2.3.md index c101d4205f..b2b7193754 100644 --- a/doc/install/install-tf.2.3.md +++ b/doc/install/install-tf.2.3.md @@ -1,16 +1,16 @@ # Install TensorFlow's C++ interface -The tensorflow's C++ interface will be compiled from the source code. Firstly one installs bazel. [bazelisk](https://github.com/bazelbuild/bazelisk) can be lanuched to use [bazel](https://github.com/bazelbuild/bazel). - +The tensorflow's C++ interface will be compiled from the source code. Firstly one installs bazel. The bazel version 3.1.0 should be used. A full instruction of bazel installation can be found [here](https://docs.bazel.build/versions/master/install.html). ```bash -wget https://github.com/bazelbuild/bazelisk/releases/download/v1.11.0/bazelisk-linux-amd64 -O /some/workspace/bazel/bin/bazel -chmod +x /some/workspace/bazel/bin/bazel +cd /some/workspace +wget https://github.com/bazelbuild/bazel/releases/download/3.1.0/bazel-3.1.0-installer-linux-x86_64.sh +chmod +x bazel-3.1.0-installer-linux-x86_64.sh ./bazel-3.1.0-installer-linux-x86_64.sh --prefix /some/workspace/bazel export PATH=/some/workspace/bazel/bin:$PATH ``` Firstly get the source code of the TensorFlow ```bash -git clone https://github.com/tensorflow/tensorflow tensorflow -b v2.8.0 --depth=1 +git clone https://github.com/tensorflow/tensorflow tensorflow -b v2.3.0 --depth=1 cd tensorflow ./configure ``` @@ -78,7 +78,7 @@ Now build the shared library of tensorflow: ```bash bazel build -c opt --verbose_failures //tensorflow:libtensorflow_cc.so ``` -You may want to add options `--copt=-msse4.2`, `--copt=-mavx`, `--copt=-mavx2` and `--copt=-mfma` to enable SSE4.2, AVX, AVX2 and FMA SIMD accelerations, respectively. It is noted that these options should be chosen according to the CPU architecture. If the RAM becomes an issue of your machine, you may limit the RAM usage by using `--local_resources 2048,.5,1.0`. If you want to enable oneDNN optimization, add `--config=mkl`. +You may want to add options `--copt=-msse4.2`, `--copt=-mavx`, `--copt=-mavx2` and `--copt=-mfma` to enable SSE4.2, AVX, AVX2 and FMA SIMD accelerations, respectively. It is noted that these options should be chosen according to the CPU architecture. If the RAM becomes an issue of your machine, you may limit the RAM usage by using `--local_resources 2048,.5,1.0`. Now I assume you want to install TensorFlow in directory `$tensorflow_root`. Create the directory if it does not exist ```bash @@ -104,11 +104,6 @@ rsync -avzh --include '*/' --include '*.h' --include '*.inc' --exclude '*' bazel rsync -avzh --include '*/' --include '*.h' --include '*.inc' --exclude '*' bazel-tensorflow/external/com_google_absl/absl/ $tensorflow_root/include/absl/ ``` -If you've enabled oneDNN, also copy `libiomp5.so`: -```bash -cp -d bazel-out/k8-opt/bin/external/llvm_openmp/libiomp5.so $tensorflow_root/lib/ -``` - # Troubleshooting ```bash git: unknown command -C ... From b778a487e0b175223f32bd8b305917b211d6c76b Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Fri, 22 Apr 2022 17:37:16 -0400 Subject: [PATCH 3/4] add a seperated doc --- doc/install/install-from-source.md | 2 +- doc/install/install-tf.2.8.md | 116 +++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 doc/install/install-tf.2.8.md diff --git a/doc/install/install-from-source.md b/doc/install/install-from-source.md index a81efd4656..75c3a9be76 100644 --- a/doc/install/install-from-source.md +++ b/doc/install/install-from-source.md @@ -148,7 +148,7 @@ gcc --version The C++ interface of DeePMD-kit was tested with compiler gcc >= 4.8. It is noticed that the I-Pi support is only compiled with gcc >= 4.8. -First the C++ interface of Tensorflow should be installed. It is noted that the version of Tensorflow should be consistent with the python interface. You may follow [the instruction](install-tf.2.3.md) to install the corresponding C++ interface. +First the C++ interface of Tensorflow should be installed. It is noted that the version of Tensorflow should be consistent with the python interface. You may follow [the instruction](install-tf.2.8.md) to install the corresponding C++ interface. ### Install the DeePMD-kit's C++ interface diff --git a/doc/install/install-tf.2.8.md b/doc/install/install-tf.2.8.md new file mode 100644 index 0000000000..d173581428 --- /dev/null +++ b/doc/install/install-tf.2.8.md @@ -0,0 +1,116 @@ +# Install TensorFlow's C++ interface +The tensorflow's C++ interface will be compiled from the source code. Firstly one installs bazel. [bazelisk](https://github.com/bazelbuild/bazelisk) can be lanuched to use [bazel](https://github.com/bazelbuild/bazel). + +```bash +wget https://github.com/bazelbuild/bazelisk/releases/download/v1.11.0/bazelisk-linux-amd64 -O /some/workspace/bazel/bin/bazel +chmod +x /some/workspace/bazel/bin/bazel +./bazel-3.1.0-installer-linux-x86_64.sh --prefix /some/workspace/bazel +export PATH=/some/workspace/bazel/bin:$PATH +``` + +Firstly get the source code of the TensorFlow +```bash +git clone https://github.com/tensorflow/tensorflow tensorflow -b v2.8.0 --depth=1 +cd tensorflow +./configure +``` + +You will answer a list of questions that help configure the building of TensorFlow. You may want to answer the question like the following. If you do not want to add CUDA support, please answer no. + +``` +Please specify the location of python. [Default is xxx]: + +Found possible Python library paths: + xxx +Please input the desired Python library path to use. Default is [xxx] + +Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: +No OpenCL SYCL support will be enabled for TensorFlow. + +Do you wish to build TensorFlow with ROCm support? [y/N]: +No ROCm support will be enabled for TensorFlow. + +Do you wish to build TensorFlow with CUDA support? [y/N]: y +CUDA support will be enabled for TensorFlow. + +Do you wish to build TensorFlow with TensorRT support? [y/N]: +No TensorRT support will be enabled for TensorFlow. + +Found CUDA 10.2 in: + /usr/local/cuda/lib64 + /usr/local/cuda/include +Found cuDNN 7 in: + /usr/local/cuda/lib64 + /usr/local/cuda/include + +Please specify a list of comma-separated CUDA compute capabilities you want to build with. +You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus. +Please note that each additional compute capability significantly increases your build time and binary size, and that TensorFlow only supports compute capabilities >= 3.5 [Default is: 7.5,7.5]: + +Do you want to use clang as CUDA compiler? [y/N]: +nvcc will be used as CUDA compiler. + +Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]: + +Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native -Wno-sign-compare]: + +Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: +Not configuring the WORKSPACE for Android builds. + +Preconfigured Bazel build configs. You can use any of the below by adding "--config=<>" to your build command. See .bazelrc for more details. + --config=mkl # Build with MKL support. + --config=monolithic # Config for mostly static monolithic build. + --config=ngraph # Build with Intel nGraph support. + --config=numa # Build with NUMA support. + --config=dynamic_kernels # (Experimental) Build kernels into separate shared objects. + --config=v2 # Build TensorFlow 2.x instead of 1.x. +Preconfigured Bazel build configs to DISABLE default on features: + --config=noaws # Disable AWS S3 filesystem support. + --config=nogcp # Disable GCP support. + --config=nohdfs # Disable HDFS support. + --config=nonccl # Disable NVIDIA NCCL support. +Configuration finished +``` + +The library path for Python should be set accordingly. + +Now build the shared library of tensorflow: +```bash +bazel build -c opt --verbose_failures //tensorflow:libtensorflow_cc.so +``` +You may want to add options `--copt=-msse4.2`, `--copt=-mavx`, `--copt=-mavx2` and `--copt=-mfma` to enable SSE4.2, AVX, AVX2 and FMA SIMD accelerations, respectively. It is noted that these options should be chosen according to the CPU architecture. If the RAM becomes an issue of your machine, you may limit the RAM usage by using `--local_resources 2048,.5,1.0`. If you want to enable [oneDNN optimization](https://www.oneapi.io/blog/tensorflow-and-onednn-in-partnership/), add `--config=mkl`. + +Now I assume you want to install TensorFlow in directory `$tensorflow_root`. Create the directory if it does not exist +```bash +mkdir -p $tensorflow_root +``` +Now, copy the libraries to the tensorflow's installation directory: +```bash +mkdir -p $tensorflow_root/lib +cp -d bazel-bin/tensorflow/libtensorflow_cc.so* $tensorflow_root/lib/ +cp -d bazel-bin/tensorflow/libtensorflow_framework.so* $tensorflow_root/lib/ +cp -d $tensorflow_root/lib/libtensorflow_framework.so.2 $tensorflow_root/lib/libtensorflow_framework.so +``` +Then copy the headers +```bash +mkdir -p $tensorflow_root/include/tensorflow +rsync -avzh --exclude '_virtual_includes/' --include '*/' --include '*.h' --include '*.inc' --exclude '*' bazel-bin/ $tensorflow_root/include/ +rsync -avzh --include '*/' --include '*.h' --include '*.inc' --exclude '*' tensorflow/cc $tensorflow_root/include/tensorflow/ +rsync -avzh --include '*/' --include '*.h' --include '*.inc' --exclude '*' tensorflow/core $tensorflow_root/include/tensorflow/ +rsync -avzh --include '*/' --include '*' --exclude '*.cc' third_party/ $tensorflow_root/include/third_party/ +rsync -avzh --include '*/' --include '*' --exclude '*.txt' bazel-tensorflow/external/eigen_archive/Eigen/ $tensorflow_root/include/Eigen/ +rsync -avzh --include '*/' --include '*' --exclude '*.txt' bazel-tensorflow/external/eigen_archive/unsupported/ $tensorflow_root/include/unsupported/ +rsync -avzh --include '*/' --include '*.h' --include '*.inc' --exclude '*' bazel-tensorflow/external/com_google_protobuf/src/google/ $tensorflow_root/include/google/ +rsync -avzh --include '*/' --include '*.h' --include '*.inc' --exclude '*' bazel-tensorflow/external/com_google_absl/absl/ $tensorflow_root/include/absl/ +``` + +If you've enabled oneDNN, also copy `libiomp5.so`: +```bash +cp -d bazel-out/k8-opt/bin/external/llvm_openmp/libiomp5.so $tensorflow_root/lib/ +``` + +# Troubleshooting +```bash +git: unknown command -C ... +``` +This may be an issue with your git version issue. Early versions of git do not support this command, in this case upgrading your git to a newer version may resolve any issues. From c11ea7cc1e39d702346f4863b2bf271a24d276d0 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Fri, 22 Apr 2022 17:39:03 -0400 Subject: [PATCH 4/4] fix typo --- doc/install/install-tf.2.8.md | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/install/install-tf.2.8.md b/doc/install/install-tf.2.8.md index d173581428..fec90446f9 100644 --- a/doc/install/install-tf.2.8.md +++ b/doc/install/install-tf.2.8.md @@ -4,7 +4,6 @@ The tensorflow's C++ interface will be compiled from the source code. Firstly on ```bash wget https://github.com/bazelbuild/bazelisk/releases/download/v1.11.0/bazelisk-linux-amd64 -O /some/workspace/bazel/bin/bazel chmod +x /some/workspace/bazel/bin/bazel -./bazel-3.1.0-installer-linux-x86_64.sh --prefix /some/workspace/bazel export PATH=/some/workspace/bazel/bin:$PATH ```