Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building TensorFlow Lite - macos_arm64 support using cmake #47437

Merged
merged 3 commits into from
Mar 4, 2021

Conversation

simonmaurer
Copy link
Contributor

@simonmaurer simonmaurer commented Feb 26, 2021

with respect to this issue in the XNNPACK repository: bazel builds for macos_arm64 platform are not yet supported.
however building with cmake works successfully.

this change allows to build the TensorFlow Lite library and the benchmark_model on a macos_arm64 host platform when using -DTFLITE_ENABLE_XNNPACK=ON (default). see instructions.

@google-ml-butler google-ml-butler bot added the size:S CL Change Size: Small label Feb 26, 2021
@google-cla
Copy link

google-cla bot commented Feb 26, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@abattery
Copy link
Contributor

@terryheo could you review this PR?

@simonmaurer
Copy link
Contributor Author

@googlebot I signed it!

@google-cla google-cla bot added cla: yes and removed cla: no labels Feb 26, 2021
@gbaned gbaned self-assigned this Feb 26, 2021
@gbaned gbaned added the comp:lite TF Lite related issues label Feb 26, 2021
@gbaned gbaned added this to Assigned Reviewer in PR Queue via automation Feb 26, 2021
@simonmaurer
Copy link
Contributor Author

oneDNN unit test failed?

@gbaned gbaned added the awaiting review Pull request awaiting review label Mar 1, 2021
@simonmaurer
Copy link
Contributor Author

simonmaurer commented Mar 3, 2021

once this PR is accepted in XNNPACK repo, we can then also proceed with a new PR so TensorFlow Liteand benchmark_modelcan be built for macos_arm64using:

bazel build --config=macos_arm64 -c opt //tensorflow/lite:libtensorflowlite.so
bazel build --config=macos_arm64 -c opt //tensorflow/lite/tools/benchmark:benchmark_model

Copy link
Member

@terryheo terryheo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution.

LGTM

PR Queue automation moved this from Assigned Reviewer to Approved by Reviewer Mar 4, 2021
@google-ml-butler google-ml-butler bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels Mar 4, 2021
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Mar 4, 2021
@terryheo
Copy link
Member

terryheo commented Mar 4, 2021

Oh, are you going to send another PR when google/XNNPACK#1327 is merged?
Otherwise, it might be better to wait?

@simonmaurer
Copy link
Contributor Author

simonmaurer commented Mar 4, 2021

Oh, are you going to send another PR when google/XNNPACK#1327 is merged?
Otherwise, it might be better to wait?

thank you. mainly this PR was for updating the cmake build files for macos_arm64, but you're right.. it might indeed be better to wait for the XNNPACK PR to be accepted. so we can pull in all changes at once.

if you're ok with the PR naming I will wait and add the remaining commits of XNNPACK and pthreadpool too here. would be nice if you could review again to be safe.

there also needs to be a change for cpuinfo. did some testing and pulled the latest master branch in , but the cpuinfo.patch is not compatible so I deactivated applying this patch in WORKSPACE for verification. this went fine for macos_arm64 and host builds on macos_x86-64 but I'm not sure if this is the right way to go.

what do you think?

@terryheo
Copy link
Member

terryheo commented Mar 4, 2021

I see. It might take time to wait for all the XNNPack related changes are merged.
I'm fine with having the second PR so we have can more time to verify all XNNPack related patches.

@gbaned gbaned added ready to pull PR ready for merge process and removed awaiting review Pull request awaiting review ready to pull PR ready for merge process labels Mar 4, 2021
@copybara-service copybara-service bot merged commit 18bbdb4 into tensorflow:master Mar 4, 2021
PR Queue automation moved this from Approved by Reviewer to Merged Mar 4, 2021
@terryheo
Copy link
Member

terryheo commented Mar 5, 2021

This PR is merged and the XNNPack PR got LGTM.

@simonmaurer I have one question. Does the "--config=macos_arm64" option only works on M1 machine?
I can't use it on my Ubuntu desktop and x86 Mac machine.

@simonmaurer
Copy link
Contributor Author

simonmaurer commented Mar 5, 2021

@terryheo thanks. if you're talking about the TensorFlow repo: this accepted PR here only allows the host build for macos_arm64 using cmake as described here.
I'll make the additional PR here to pull in the latest pthreadpool (PR accepted & merged), XNNPACK (PR accepted) and cpuinfo once they are both merged.

however if you're talking about the XNNPACK repo (the PR is indeed accepted, but not yet merged):

bazel build --config=macos_arm64 -c opt :end2end_bench

will work on a host M1 machine. on different platforms (like Linux or even macos x86-64) that does not work (yet) because of missing toolchains
at least I get the following errors when building on a macOS_x86-64 platform for macos_arm64:

ERROR: /private/var/tmp/**/**/external/local_config_cc/BUILD:48:19: in cc_toolchain_suite rule @local_config_cc//:toolchain: cc_toolchain_suite '@local_config_cc//:toolchain' does not contain a toolchain for cpu 'darwin_arm64' INFO: Repository cpuinfo instantiated at: /**/**/**/**/xnnpack_simonmaurer/WORKSPACE:66:13: in <toplevel> Repository rule http_archive defined at: /private/var/tmp/**/**/external/bazel_tools/tools/build_defs/repo/http.bzl:336:31: in <toplevel> ERROR: Analysis of target '//:end2end_bench' failed; build aborted: Analysis of target '@local_config_cc//:toolchain' failed

@simonmaurer
Copy link
Contributor Author

simonmaurer commented Mar 5, 2021

@terryheo another note:
ideally we would want bazel to work like this:

M1 host machine compilation (without specifying the platform):

bazel build -c opt :end2end_bench (XNNPACK)
bazel build -c opt //tensorflow/lite/tools/benchmark:benchmark_model (TF)

Cross compilation on a different platform (e.g. Linux x86):

bazel build -c opt --config=macos_arm64 :end2end_bench (XNNPACK)
bazel build -c opt --config=macos_arm64 //tensorflow/lite/tools/benchmark:benchmark_model (TF)

the pip_package should work already according to this PR, which builds fine on a M1 host but I got errors about missing symbols when importing the tensorflow package in python3

@simonmaurer
Copy link
Contributor Author

simonmaurer commented Mar 6, 2021

the pip_package should work already according to this PR, which builds fine on a M1 host but I got errors about missing symbols when importing the tensorflow package in python3

with this PR the pip package can be built using a native build on M1 host machine. the only dependencies that need manual installation are grpcio/h5py

@simonmaurer
Copy link
Contributor Author

simonmaurer commented Mar 29, 2021

@terryheo / @gbaned also thanks for reviewing #47639. this includes the changes on the follow-up PR we discussed:

once this PR is accepted in XNNPACK repo, we can then also proceed with a new PR so TensorFlow Liteand benchmark_modelcan be built for macos_arm64using:

bazel build --config=macos_arm64 -c opt //tensorflow/lite:libtensorflowlite.so
bazel build --config=macos_arm64 -c opt //tensorflow/lite/tools/benchmark:benchmark_model

that being said, with #47639 we can now also build using bazel for macos_arm64 platform:

Cross compilation on a M1 host or a different platform (e.g. Linux x86):

bazel build -c opt --config=macos_arm64 //tensorflow/lite:libtensorflowlite.so
bazel build -c opt --config=macos_arm64 //tensorflow/lite/tools/benchmark:benchmark_model

and due to the additional changes #47594 by @freedomtan (thanks!) when using a more recent version of bazel (bazel #4928295):

M1 host machine compilation (without specifying the platform):

bazel build -c opt //tensorflow/lite:libtensorflowlite.so
bazel build -c opt //tensorflow/lite/tools/benchmark:benchmark_model

To summarize: TensorFlow Lite library and benchmark_model, but also the full TensorFlow pip package can be built using bazel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes comp:lite TF Lite related issues ready to pull PR ready for merge process size:S CL Change Size: Small
Projects
PR Queue
  
Merged
Development

Successfully merging this pull request may close these issues.

None yet

5 participants