Outils pour utilisateurs

Outils du site


linux_compiler_tensorflow_avec_bazel

Ceci est une ancienne révision du document !


Linux Compiler Tensorflow avec Bazel

L'objectif est de compiler Tensorflow avec les options AVX2 et FMA !

Ressources

Installation de Bazel

Bazel est le compilateur de Google.

# Bazel
sudo apt install apt-transport-https curl gnupg
curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor > bazel.gpg
sudo mv bazel.gpg /etc/apt/trusted.gpg.d/
echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
sudo apt update
sudo apt install bazel-4.2.1

Sans GPU sur Debian

Désinstaller les packages python protobuf et tensorflow si ils sont installés.

Installation du nécessaire:

python3 -m pip install numpy wheel
python3 -m pip install keras_preprocessing --no-deps

Récupération des sources de tensorflow:

cd /votre/dossier/src
git clone https://github.com/tensorflow/tensorflow 
./configure

Mes réponses

Make sure you are running at least bazel 4.2.1
Please specify the location of python. [Default is /usr/bin/python3]: 
Found possible Python library paths:
  /usr/lib/python3/dist-packages
  /usr/local/lib/python3.9/dist-packages
Please input the desired Python library path to use.  Default is [/usr/lib/python3/dist-packages]
Do you wish to build TensorFlow with ROCm support? [y/N]: n
No ROCm support will be enabled for TensorFlow.
Do you wish to build TensorFlow with CUDA support? [y/N]: n
No CUDA support will be enabled for TensorFlow.
Do you wish to download a fresh release of clang? (Experimental) [y/N]: n
Clang will not be downloaded.
Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -Wno-sign-compare]: -march=native
Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: n
Not configuring the WORKSPACE for Android builds.

Compilation de tensorflow

bazel build //tensorflow/tools/pip_package:build_pip_package
./bazel-bin/tensorflow/tools/pip_package/build_pip_package /media/data/tensorflow_pkg

Installation

cd /media/data/3D/projets/grande_echelle_move
source mon_env/bin/activate
python3 -m pip uninstall tensorflow
python3 -m pip install /media/data/src/tensorflow-2.8.0-cp38-cp38-linux_x86_64.whl

Avec GPU sur Ubuntu qui ne marche pas !

Ubuntu Mate 20.04, python 3.8, venv

Cuda

CudNN

sudo apt install libcudnn8 libcudnn8-dev

TensorRT

sudo apt install libnvinfer8 libnvinfer8-dev

Tensorflow

# Dépendances
python3 -m pip install numpy wheel
python3 -m pip install keras_preprocessing --no-deps
 
# Récupération des sources de tensorflow
mkdir src
cd src/
git clone https://github.com/tensorflow/tensorflow.git
cd tensorflow
./configure

Le plus abcons: Configurer la compilation

  • non à ROCm (non à Rocky)
  • non à TensorRT sinon ça plante
  • non à clang
  • non à download a fresh release of clang ça plante
  • oui à GCC
  • Pour 1060 GTX –> 6.1, Pour GTX 850m –> 5.0

Comment compiler avec AVX2 et FMA: répondre -march=native

Reset de la config

bazel clean

Compilation Création du package pip Installation

Parce que en plus bazel exige la bonne version:

sudo apt update && sudo apt install bazel-4.2.1
bazel build //tensorflow/tools/pip_package:build_pip_package

Après 5 heures de travail d'un I7 à fond!
INFO: Build completed successfully, 32129 total actions

./bazel-bin/tensorflow/tools/pip_package/build_pip_package /media/data/tensorflow_pkg
python3 -m pip install /media/data/src/tensorflow-2.8.0-cp38-cp38-linux_x86_64.whl

Test

  • Ne marche pas !
linux_compiler_tensorflow_avec_bazel.1639229247.txt.gz · Dernière modification : 2021/12/11 13:27 de serge