TensorFlow

This page captures steps to build TensorFlow for windows on arm from source and known issues with the build.

TensorFlow uses Bazel build system so the first step is to compile Bazel for windows on arm.

Build Bazel

Bazel can be either built from scratch or built using Bazel. Building using another Bazel seems to be the easiest option and we have two options for that.

  1. Cross compile from a windows/x64 machine

  2. Build with windows on Arm machine running windows 11 or supporting x64 emulation

Make sure you have Visual Studio 2017/2019 as 2022 is not yet supported.

The steps given below are similar for above both setups.

Checkout Bazel with windows on arm support

Please check out the following repository for Bazel 4.2.1 source code with win/arm64 support

https://github.com/nsait-linaro/bazel/tree/4.2.1-win_arm64

Or apply https://github.com/nsait-linaro/bazel/commit/bcfdf9a891900c3123203b6ee7e8c514462b75c6 to Bazel repository

Download Bazel (x64)

TensorFlow compiles only with Bazel version 4.2.1 or below. To build WoA Bazel 4.2.1 it is recommended to use x64 Bazel 4.2.1.

Download Bazel(x64) 4.2.1: https://github.com/bazelbuild/bazel/releases/download/4.2.1/bazel-4.2.1-windows-x86_64.zip

Add Bazel(x64) to your path and we can use it to build Bazel(arm64).

Install supporting tools for Bazel

You will also need a few other tools for building Bazel. Follow steps given here https://docs.bazel.build/versions/main/install-compile-source.html#bootstrap-windows-bootstrap

You also need to download JDK (win/arm64): https://www.azul.com/downloads/?package=jdk

You should add a few environment variables like the following as mentioned on Bazel build from the source page.

$env:BAZEL_SH="C:\msys64\usr\bin\bash.exe" $env:BAZEL_VC="C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC" $env:JAVA_HOME="C:\Users\niysai01\Downloads\zulu17.30.15-ca-jdk17.0.1-win_aarch64\zulu17.30.15-ca-jdk17.0.1-win_aarch64\"

Compile Bazel (Arm64)

And now you are all set to build Bazel. Please use the following command to build

bazel_x64.exe build --subcommands --cpu=x64_arm64_windows //src:bazel.exe

That will generate you an arm64 bazel.exe binary which we can use for the TensorFlow build.

You can add bazel.exe to your PATH and will use it for the TensorFlow build.

Build TensorFlow

Checkout TensorFlow

See instructions here: https://www.tensorflow.org/install/source

Apply TensorFlow patch to add windows on arm support

Apply the following patch to your TensorFlow repository.

Enable tensorflow build for windows on arm · niyas-sait/tensorflow@91a69d3

Now run python configure.py and default options should work.

Compile TensorFlow

Please use the following command to build TensorFlow

bazel build --subcommands --config=win_arm64 --compilation_mode=fastbuild //tensorflow/tools/pip_package:build_pip_package

Above will generate an executable build_pip_executable.exe which can be used to generate a python binary wheel with the following command.

This will generate the binary python wheel which can be installed with pip install <generated_wheel>.whl

Running TensorFlow Tests

Create a py_test_dir in the TensorFlow directory and add a symlink

Create a shell script with following

Now tests can be run as

TensorFlow Test Results

TensorFlow seems to be working fine with examples from https://www.tensorflow.org/tutorials/quickstart/beginner

And running the test suites (using the steps given in the Running TensorFlow tests section following results are obtained.

Number of tests

 

Number of tests

 

Total

894

Pass

879

Fail

15

 

Known Issues

There are a few known issues with the TensorFlow build.

  1. Empty simple_console_for_windows.zip generated.

Bazel zipper can only handle files < 4 Gb and if the package needs to be generated more than that then an empty zip file is generated as a result of this.

TensorFlow seems to add some redundant zip files and one workaround is to remove them manually and run the zipper manually from bazel-out/x64_arm64_windows-fastbuild/bin/tensorflow/tools/pip_package/simple_console_for_windows.zip-0.params. Grep for `.zip=` and remove the entries and run the zipper command again to generate the simple_console_for_windows.zip

Ensure the generated file is not 0 bytes anymore.

2. TensorFlow pip installation might fail due to tensorflow-io-gcs-filesystem package missing.

tensorflow-io-gcs-filesystem is not yet available for win/arm64 and you will have to manually unpack the wheel file and remove the Tensorflow-io entry from

2. There are few known issues with clang compiler and we can only build TensorFlow in fastbuild mode. Turning ON all optimization will trigger some errors during compilation. LLVM patches are in progress and should be able to build with LLVM 14 release.