Coder Social home page Coder Social logo

tensorflow-multiarch's Introduction

TENSORFLOW-MULTIARCH

This is my attempt to build a recent Tensorflow wheel and Docker image compatible with multiple architectures and processors.

It's currently using Tensorflow v2.16.1

It supports the following architectures:

  • ARM32
  • AARCH64
  • X86_64 processors without AVX extensions.

The wheels are in the release section

The docker images are docker.io/snowzach/tensorflow-multiarch here

The default/latest docker images includes arm32, arm64 and amd64-noavx

Compiling Tensorflow Wheel

I checked out the Tensorflow source at version 2.16.1 and I had to edit the file tensorflow/tools/ci_build/pi/build_raspberry_pi.sh and insert on line 99 to add an ARMHF target.

elif [[ $1 == "ARMHF" ]]; then
  PI_COPTS="--config=elinux_armhf
  --copt=-std=gnu11
  --copt=-O3"
  WHEEL_ARCH=linux_armv7l

I also removed the --config=monolithic option from the bazel build command around line 126. After that I was able to cross compile the aarch64 and armv7l wheels with the commands:

$ tensorflow/tools/ci_build/ci_build.sh PI-PYTHON38 \
    tensorflow/tools/ci_build/pi/build_raspberry_pi.sh AARCH64
$ tensorflow/tools/ci_build/ci_build.sh PI-PYTHON38 \
    tensorflow/tools/ci_build/pi/build_raspberry_pi.sh ARMHF

After running the command there was working python whl and library in the output-artifacts directory.

I renamed the armhf output wheel from tensorflow-2.16.1-cp38-none-linux_armhf.whl to tensorflow-2.16.1-cp38-none-linux_armv7l.whl to ensure it matched the hardware architecture and would be installed by python.

Tensorflow IO

Tensorflow IO is required in order to install the Tensorflow wheel. There seems to be a chicken-egg problem with creating a Tensorflow IO wheel. The Tensorflow Wheel won't install without TensorflowIO but TensorflowIO won't compile without Tensorflow installed.

I was able to work around this by installing just the python portion of Tensorflow IO. I had to actually run this on ARM devices to get Tensorflow IO to compile. (QEMU segfaulted)

$ git clone https://github.com/tensorflow/io.git
$ cd io
$ git checkout v0.23.1
$ python3 setup.py install # Install just the python code
$ python3 -m pip install tensorflow-2.16.1-cp38-none-linux_<arch>.whl # Install tensorflow wheel

From there I compiled Tensorflow IO with

$ export SETUPTOOLS_USE_DISTUTILS=stdlib # Needed to overcome some strange error with python deps
# ./configure
$ bazel build -s --verbose_failures --local_ram_resources=HOST_RAM*.4 --local_cpu_resources=2 //tensorflow_io/... //tensorflow_io_gcs_filesystem/...
$ python3 setup.py bdist_wheel --data bazel-bin
$ python3 setup.py --project tensorflow_io_gcs_filesystem bdist_wheel --data bazel-bin

These wheels are included in this repo as well with other dependancies.

Docker Image

The Dockerfiles for aarch64 and armv7l are slightly different as each had packages the other architecture didn't.

I build them with docker buildx with these commands:

# Setup QEMU
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes

# Build the docker images
docker buildx build --push --platform linux/arm/v7 -f Dockerfile.armv7l --tag docker.io/snowzach/tensorflow-multiarch:2.16.1-armv7l .
docker buildx build --push --platform linux/arm64/v8 -f Dockerfile.aarch64 --tag docker.io/snowzach/tensorflow-multiarch:2.16.1-aarch64 .
docker buildx build --push --platform linux/amd64 -f Dockerfile.amd64-noavx --tag docker.io/snowzach/tensorflow-multiarch:2.16.1-amd64-noavx .

# Tag the releases as 2.16.1
docker manifest push --purge docker.io/snowzach/tensorflow-multiarch:2.16.1
docker manifest create docker.io/snowzach/tensorflow-multiarch:2.16.1 docker.io/snowzach/tensorflow-multiarch:2.16.1-armv7l docker.io/snowzach/tensorflow-multiarch:2.16.1-aarch64 docker.io/snowzach/tensorflow-multiarch:2.16.1-amd64-noavx
docker manifest push docker.io/snowzach/tensorflow-multiarch:2.16.1

# Tag the releases as latest
docker manifest push --purge docker.io/snowzach/tensorflow-multiarch:latest
docker manifest create docker.io/snowzach/tensorflow-multiarch:latest docker.io/snowzach/tensorflow-multiarch:2.16.1-armv7l docker.io/snowzach/tensorflow-multiarch:2.16.1-aarch64 docker.io/snowzach/tensorflow-multiarch:2.16.1-amd64-noavx
docker manifest push docker.io/snowzach/tensorflow-multiarch:latest

tensorflow-multiarch's People

Contributors

snowzach avatar

Stargazers

toz avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.