Help Cross Compiling TensorFlow Using a Custom Toolchain

1,407 views
Skip to first unread message

jstrouth

unread,
Dec 13, 2017, 2:31:49 PM12/13/17
to bazel-discuss
Hi, 

I am currently trying to cross compile TensorFlow for arm64 using gcc (musl instead of glibc) and I am new to Bazel. I have created a toolchain according to this project: https://github.com/richfelker/musl-cross-make for aarch64-linux-musl. The toolchain is located locally on my build machine which is x86_64 running Alpine 3.7. I am having trouble setting up the BUILD files and CROSSTOOL files, I have been following https://github.com/bazelbuild/bazel/wiki/Building-with-a-custom-toolchain, but I run into the error: 

No toolchain found for cpu 'k8'. Valid cpus are: [
  arm64,
]

I have attached copies of my BUILD, WORKSPACE, and CROSSTOOL files.
Any help or pointers would be greatly appreciated.

Thanks,
Jonathan
BUILD
CROSSTOOL
WORKSPACE
aarch64-linux-musl-gcc_6.4.0.BUILD

Austin Schuh

unread,
Dec 13, 2017, 7:51:05 PM12/13/17
to jstrouth, bazel-discuss
Do you have a toolchain for the host?  That sounds like you are trying to build something for your host machine as a tool to use to do code-gen (protobuf comes to mind) and Bazel can't find the compiler to use to do that.

Austin

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/fa99a9e4-e2ae-41e6-a567-81a0653cf1a1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jstrouth

unread,
Dec 14, 2017, 8:08:01 AM12/14/17
to bazel-discuss
Yes, the toolchain I am using was built on the host according to this project. The project builds a toolchain on the host that compiles for another target architecture (x86_64 to arm64 in this case). I think this issue is related to my BUILD and CROSSTOOL files being setup incorrectly for this toolchain.

Austin Schuh

unread,
Dec 14, 2017, 12:51:35 PM12/14/17
to jstrouth, bazel-discuss
You are misunderstanding me.  I've done what you are trying to do.

For something like tensorflow, Bazel needs 2 toolchains.  1) your shiny new arm64 compiler.  2) A host compiler to build things like protobuf so they can be used to generate code to be built with (1).  In bazel terminology, these are "tools", and "tools" are built for the "host" configuration, not the "data" configuration (your target, ie arm64).

Your error says to me that Bazel can't fine 2).  Do you have a host compiler configured for k8?

Austin

On Thu, Dec 14, 2017 at 5:08 AM jstrouth <jcst...@gmail.com> wrote:
Yes, the toolchain I am using was built on the host according to this project. The project builds a toolchain on the host that compiles for another target architecture (x86_64 to arm64 in this case). I think this issue is related to my BUILD and CROSSTOOL files being setup incorrectly for this toolchain.

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.

jstrouth

unread,
Dec 20, 2017, 1:43:28 PM12/20/17
to bazel-discuss
Thanks for the explanation about Bazel tools. I have resolved that particular issue, I had to configure a local toolchain for k8 in my CROSSTOOL file.

I have attempted a few builds and overcome various bugs along the way. I am now currently trying to fix this error:

ERROR: /root/.cache/bazel/_bazel_root/efb88f6336d9c4a18216fb94287b8d97/external/protobuf_archive/BUILD:656:1: undeclared inclusion(s) in rule '@protobuf_archive//:python/google/protobuf/internal/_api_implementation.so':
this rule is missing dependency declarations for the following files included by 'external/protobuf_archive/python/google/protobuf/internal/api_implementation.cc':
  '/usr/include/python3.6m/Python.h'
  '/usr/include/python3.6m/patchlevel.h'
  '/usr/include/python3.6m/pyconfig.h'
  '/usr/include/python3.6m/pymacconfig.h'
  '/usr/include/python3.6m/pyport.h'
  '/usr/include/python3.6m/pymacro.h'
  '/usr/include/python3.6m/pyatomic.h'
  '/usr/include/python3.6m/pymath.h'
  '/usr/include/python3.6m/pytime.h'
  '/usr/include/python3.6m/object.h'
  '/usr/include/python3.6m/pymem.h'
  '/usr/include/python3.6m/objimpl.h'
  '/usr/include/python3.6m/typeslots.h'
  '/usr/include/python3.6m/pyhash.h'
  '/usr/include/python3.6m/pydebug.h'
  '/usr/include/python3.6m/bytearrayobject.h'
  '/usr/include/python3.6m/bytesobject.h'
  '/usr/include/python3.6m/unicodeobject.h'
  '/usr/include/python3.6m/longobject.h'
  '/usr/include/python3.6m/longintrepr.h'
  '/usr/include/python3.6m/boolobject.h'
  '/usr/include/python3.6m/floatobject.h'
  '/usr/include/python3.6m/complexobject.h'
  '/usr/include/python3.6m/rangeobject.h'
  '/usr/include/python3.6m/memoryobject.h'
  '/usr/include/python3.6m/tupleobject.h'
  '/usr/include/python3.6m/listobject.h'
  '/usr/include/python3.6m/dictobject.h'
  '/usr/include/python3.6m/odictobject.h'
  '/usr/include/python3.6m/enumobject.h'
  '/usr/include/python3.6m/setobject.h'
  '/usr/include/python3.6m/methodobject.h'
  '/usr/include/python3.6m/moduleobject.h'
  '/usr/include/python3.6m/funcobject.h'
  '/usr/include/python3.6m/classobject.h'
  '/usr/include/python3.6m/fileobject.h'
  '/usr/include/python3.6m/pycapsule.h'
  '/usr/include/python3.6m/traceback.h'
  '/usr/include/python3.6m/pystate.h'
  '/usr/include/python3.6m/sliceobject.h'
  '/usr/include/python3.6m/cellobject.h'
  '/usr/include/python3.6m/iterobject.h'
  '/usr/include/python3.6m/genobject.h'
  '/usr/include/python3.6m/descrobject.h'
  '/usr/include/python3.6m/warnings.h'
  '/usr/include/python3.6m/weakrefobject.h'
  '/usr/include/python3.6m/structseq.h'
  '/usr/include/python3.6m/namespaceobject.h'
  '/usr/include/python3.6m/codecs.h'
  '/usr/include/python3.6m/pyerrors.h'
  '/usr/include/python3.6m/pyarena.h'
  '/usr/include/python3.6m/modsupport.h'
  '/usr/include/python3.6m/pythonrun.h'
  '/usr/include/python3.6m/pylifecycle.h'
  '/usr/include/python3.6m/ceval.h'
  '/usr/include/python3.6m/sysmodule.h'
  '/usr/include/python3.6m/osmodule.h'
  '/usr/include/python3.6m/intrcheck.h'
  '/usr/include/python3.6m/import.h'
  '/usr/include/python3.6m/abstract.h'
  '/usr/include/python3.6m/bltinmodule.h'
  '/usr/include/python3.6m/compile.h'
  '/usr/include/python3.6m/code.h'
  '/usr/include/python3.6m/eval.h'
  '/usr/include/python3.6m/pyctype.h'
  '/usr/include/python3.6m/pystrtod.h'
  '/usr/include/python3.6m/pystrcmp.h'
  '/usr/include/python3.6m/dtoa.h'
  '/usr/include/python3.6m/fileutils.h'
  '/usr/include/python3.6m/pyfpe.h'.
Target //tensorflow/tools/pip_package:build_pip_package failed to build

Could you offer any advice?

Thanks,
Jonathan


Austin Schuh

unread,
Dec 20, 2017, 2:56:09 PM12/20/17
to jstrouth, bazel-discuss
Awesome!  That's progress :)

Without looking too deep, you either need to do a new local repository pointing to /usr/include/python3.6m/ to add those to the include path, or add /usr/include/python3.6m to cxx_builtin_include_directory in your crosstool.  I'm not sure if tensorflow has something already with the python dependencies.  If they do, I'd go with the former option, otherwise I'd do the latter.

Austin

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages