How to build tensorflow benchmark_model for android arm64_v8a? - tensorflow

I'm using the following command in the Tensorflow 1.8 folder
bazel build -c opt --cxxopt='--std=c++11' \
//tensorflow/tools/benchmark:benchmark_model \
--crosstool_top=//external:android/crosstool \
--host_crosstool_top=#bazel_tools//tools/cpp:toolchain \
--cpu=arm64-v8a --verbose_failures
It's giving me the error:
ERROR: No default_toolchain found for cpu 'arm64-v8a'. Valid cpus are: [
k8,
local,
armeabi-v7a,
x64_windows,
x64_windows_msvc,
x64_windows_msys,
s390x,
ios_x86_64,
]
INFO: Elapsed time: 0.315s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)
Ubuntu 16.04, Bazel 0.14.1, Tensorflow 1.8

This is because the Android NDK hasn't been configured in the root WORKSPACE file. Download the Android NDK and add the following line to the WORKSPACE:
android_ndk_repository(
name="androidndk",
path="<PATH_TO_NDK>",
)

I figured it out. Using bazel 0.10.1, SDK API level 27, NDK 15, Build tools 27.0.3, tensorflow 1.8.
First run
./configure
Then
bazel build --config=monolithic --cxxopt=--std=c++11 //tensorflow/tools/benchmark:benchmark_model --config=android_arm64 --cpu=arm64-v8a --fat_apk_cpu=arm64-v8a

Related

C++ compilation of rule '//tensorflow/core/kernels:sparse_reduce_op' failed (Exit 1)

I'm trying to build tensorflow from source, it keeps running for several hours then the build fails and I get the following error:
....................................................................................................................................................................................................
ERROR: /home/emadboctor/tensorflow/tensorflow/core/kernels/BUILD:5398:1: C++ compilation of rule '//tensorflow/core/kernels:sparse_reduce_op' failed (Exit 1)
In file included from external/eigen_archive/unsupported/Eigen/CXX11/Tensor:104:0,
from ./third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1,
from ./tensorflow/core/framework/numeric_types.h:20,
from ./tensorflow/core/framework/allocator.h:26,
from ./tensorflow/core/framework/op_kernel.h:24,
from tensorflow/core/kernels/sparse_reduce_op.cc:20:
external/eigen_archive/unsupported/Eigen/CXX11/src/Tensor/TensorReduction.h: In static member function 'static void std::_Function_handler<void(_ArgTypes ...), _Functor>::_M_invoke(const std::_Any_data&, _ArgTypes&& ...) [with _Functor = Eigen::internal::TensorExecutor<Expression, Eigen::ThreadPoolDevice, Vectorizable, Tiling>::run(const Expression&, const Eigen::ThreadPoolDevice&) [with Expression = const Eigen::TensorAssignOp<Eigen::TensorMap<Eigen::TensorFixedSize<std::complex<float>, Eigen::Sizes<>, 1, long int>, 16, Eigen::MakePointer>, const Eigen::TensorReductionOp<Eigen::internal::SumReducer<std::complex<float> >, const Eigen::DimensionList<long int, 1ul>, const Eigen::TensorMap<Eigen::Tensor<std::complex<float>, 1, 1, long int>, 0, Eigen::MakePointer>, Eigen::MakePointer> >; bool Vectorizable = true; Eigen::internal::TiledEvaluation Tiling = (Eigen::internal::TiledEvaluation)0u]::<lambda(Eigen::internal::TensorExecutor<const Eigen::TensorAssignOp<Eigen::TensorMap<Eigen::TensorFixedSize<std::complex<float>, Eigen::Sizes<>, 1, long int>, 16, Eigen::MakePointer>, const Eigen::TensorReductionOp<Eigen::internal::SumReducer<std::complex<float> >, const Eigen::DimensionList<long int, 1ul>, const Eigen::TensorMap<Eigen::Tensor<std::complex<float>, 1, 1, long int>, 0, Eigen::MakePointer>, Eigen::MakePointer> >, Eigen::ThreadPoolDevice, true, (Eigen::internal::TiledEvaluation)0u>::StorageIndex, Eigen::internal::TensorExecutor<const Eigen::TensorAssignOp<Eigen::TensorMap<Eigen::TensorFixedSize<std::complex<float>, Eigen::Sizes<>, 1, long int>, 16, Eigen::MakePointer>, const Eigen::TensorReductionOp<Eigen::internal::SumReducer<std::complex<float> >, const Eigen::DimensionList<long int, 1ul>, const Eigen::TensorMap<Eigen::Tensor<std::complex<float>, 1, 1, long int>, 0, Eigen::MakePointer>, Eigen::MakePointer> >, Eigen::ThreadPoolDevice, true, (Eigen::internal::TiledEvaluation)0u>::StorageIndex)>; _ArgTypes = {long int, long int}]':
external/eigen_archive/unsupported/Eigen/CXX11/src/Tensor/TensorReduction.h:806:9: internal compiler error: in emit_move_insn, at expr.c:3547
values[i] = internal::InnerMostDimReducer<Self, Op>::reduce(*this, firstIndex + i * num_values_to_reduce,
^~~~~~
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-6/README.Bugs> for instructions.
Target //tensorflow/tools/pip_package:build_pip_package failed to build
Use --verbose_failures to see the command lines of failed build steps.
ERROR: /home/emadboctor/tensorflow/tensorflow/tools/pip_package/BUILD:65:1 C++ compilation of rule '//tensorflow/core/kernels:sparse_reduce_op' failed (Exit 1)
INFO: Elapsed time: 8153.055s, Critical Path: 926.03s
INFO: 8566 processes: 8566 local.
FAILED: Build did NOT complete successfully
System information(GCP instance):
Distributor ID: Debian
Description: Debian GNU/Linux 9.12 (stretch)
Release: 9.12
Codename: stretch
gcc version: gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516
g++ version: g++ (Debian 6.3.0-18+deb9u1) 6.3.0 20170516
tensorflow version: 2.1
bazel version: 3.1.0
Steps that led to the problem:
apt update && apt install -y \
build-essential \
libc-ares-dev \
libjpeg-dev \
openjdk-8-jdk \
gcc \
g++ \
python3-pip \
pip3 install six numpy wheel setuptools mock && \
pip3 install keras_applications --no-deps && \
pip3 install keras_preprocessing --no-deps
sudo apt-get update
sudo apt-get -y upgrade
wget https://dl.google.com/go/go1.13.3.linux-amd64.tar.gz
sudo tar -xvf go1.13.3.linux-amd64.tar.gz
sudo mv go /usr/local
export GOROOT=/usr/local/go
export GOPATH=$HOME/Projects/Proj1
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
go get github.com/bazelbuild/bazelisk
mkdir -p ~/bin
ln -s $(go env GOPATH)/bin/bazelisk ~/bin/bazel
export PATH=$HOME/bin:$PATH
git clone https://github.com/tensorflow/tensorflow
cd tensorflow
./configure
Configuration:
emadboctor#reg-build-vm:~/tensorflow$ ./configure
You have bazel 3.0.0 installed.
Please specify the location of python. [Default is /usr/bin/python3]: /usr/bin/python3
Found possible Python library paths:
/usr/local/lib/python3.5/dist-packages
/usr/lib/python3/dist-packages
Please input the desired Python library path to use. Default is [/usr/local/lib/python3.5/dist-packages]
/usr/local/lib/python3.5/dist-packages
Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: n
No OpenCL SYCL support will be enabled for TensorFlow.
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]: y
Clang will be downloaded and used to compile tensorflow.
Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native -Wno-sign-compare]: -config=mkl
Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: n
Not configuring the WORKSPACE for Android builds.
Preconfigured Bazel build configs. You can use any of the below by adding "--config=<>" to your build command. See .bazelrc for more details.
--config=mkl # Build with MKL support.
--config=monolithic # Config for mostly static monolithic build.
--config=ngraph # Build with Intel nGraph support.
--config=numa # Build with NUMA support.
--config=dynamic_kernels # (Experimental) Build kernels into separate shared objects.
--config=v2 # Build TensorFlow 2.x instead of 1.x.
Preconfigured Bazel build configs to DISABLE default on features:
--config=noaws # Disable AWS S3 filesystem support.
--config=nogcp # Disable GCP support.
--config=nohdfs # Disable HDFS support.
--config=nonccl # Disable NVIDIA NCCL support.
Configuration finished
emadboctor#reg-build-vm:~/tensorflow$
Then
bazel build -c opt \
--define=grpc_no_ares=true \
--linkopt="-lrt" \
--linkopt="-lm" \
--host_linkopt="-lrt" \
--host_linkopt="-lm" \
--action_env="LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" \
--copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-mfpmath=both \
--copt=-w \
--jobs=26 \
//tensorflow/tools/pip_package:build_pip_package

Why do I get error 'unrecognized command line option '-fuse-ld=--enable-gold=default' when building Tensorflow?

I am trying to build Tensorflow from source as described at: https://www.tensorflow.org/install/source
I have Bazel 0.29.1 and Python available. I do:
module load bazeltest/0.29.1
module load pythontest/gcc6.3.0/3.7.5tensorflow
./configure
I choose all default options in configure, then:
bazel build //tensorflow/tools/pip_package:build_pip_package
The build proceeds for a while, but fails at:
INFO: Analyzed target //tensorflow/tools/pip_package:build_pip_package (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: /gpfs01/home/cczcb/.cache/bazel/_bazel_cczcb/f0a4604cf88277481621943e2a61f102/external/swig/BUILD.bazel:5:1: Linking of rule '#swig//:swig' failed (Exit 1)
gcc: error: unrecognized command line option '-fuse-ld=--enable-gold=default'
Target //tensorflow/tools/pip_package:build_pip_package failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 18.642s, Critical Path: 10.57s
INFO: 125 processes: 125 local.
FAILED: Build did NOT complete successfully
I have also tried:
bazel build --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" //tensorflow/tools/pip_package:build_pip_package
as I am using GCC 6.3.0 here. The result is the same, as it is when I use GCC 4.9.3.
My O/S is Centos 7.4.
Can anyone advise what might be amiss ?
thanks,
Colin

Changing bazel build output folder on Windows while build tensorflow frm source

I am trying to build Tensorflow 1.14.0-rc1 on
Windows 10
python : 3.6.8
cudatoolkit : 10.1
cudnn : 7.6.1
bazel : 0.25.1
While building bazel gives linking error due to low storage on default location of ~/baze{username}_ so I tried to change output location of build using --output_user_root which gives error
bazel build --config=opt --config=cuda --define=no_tensorflow_py_deps=true //tensorflow/tools/pip_package:build_pip_package output_user_root=/e/build/tensorflow
ERROR: Unrecognized option: --output_user_root=/e/build/tensorflow
when building using
or
E:\tensorflow-1.14.0-rc1>bazel build --config=opt --config=cuda define=no_tensorflow_py_deps=true //tensorflow/tools/pip_package:build_pip_package -output_user_root=E:\build\tensorflow
ERROR: Unrecognized option: --output_user_root=E:\build\tensorflow
--output_user_root is a startup option, so it must go before the command, i.e.:
bazel --output_user_root=<...> build <...>

Build Tensorflow on Intel Atom

I am trying to build Tensorflow on Intel Atom using Bazel 0.15 version.
I followed the instruction here for Build TensorFlow from Source with Intel® MKL.
My bazel command for Intel Atom is
bazel build --config=mkl --cxxopt=-D_GLIBCXX_USE_CXX11_ABI=0 --copt=-march=atom --copt=-mtune=atom
But it didn't success.
What is wrong with the installation?
I am using Intel® Atom ™ E3940.
The error is
~/tensorflow$ bazel build --config=mkl --cxxopt=-D_GLIBCXX_USE_CXX11_ABI=0 --copt=-march=atom --copt=-mtune=atom
Starting local Bazel server and connecting to it...
................................
INFO: Analysed 0 targets (2 packages loaded).
INFO: Found 0 targets...
INFO: Elapsed time: 6.529s, Critical Path: 0.04s
INFO: 0 processes.
INFO: Build completed successfully, 1 total action
How can I solve the issue?
My command is not complete.
The complete command is
bazel build --config=mkl --cxxopt=-D_GLIBCXX_USE_CXX11_ABI=0 --copt=-march=atom --copt=-mtune=atom //tensorflow/tools/pip_package:build_pip_package

tensorflow tools: can't figure out how to build/run summarize_graph

I'm trying to convert my *.pb tensorflow model to coreML. I'm getting stuck on identifying my output node of my model.
In order to obtain my output node, I've attempted to build and run summarize_graph on my *.pb file, but running into issues. How do I build and run summarize_graph after downloading the source?
I've run the following command:
bazel build tensorflow/tools/graph_transforms:summarize_graph
bazel-bin/tensorflow/tools/graph_transforms/summarize_graph --in_graph=tensorflow_inception_graph.pb
and I get the following error:
INFO: Analysed 0 targets (0 packages loaded). INFO: Found 0 targets...
INFO: Elapsed time: 0.389s, Critical Path: 0.01s INFO: Build completed
successfully, 1 total action
bazel-bin/tensorflow/tools/graph_transforms/summarize_graph: No such
file or directory
After issuing the bazel command, a blank bazel-bin directory appears in the location I executed the command.
Note, summarize_graph didn't exist in my tensorflow installation. So I downloaded the source from github tensorflow/tools/graph_transforms and copied it into my tensorflow/tools/graph_transforms directory.
the directory contains the following:
BUILD README.md
init.py
init.pyc add_default_attributes.cc add_default_attributes_test.cc backports.cc backports_test.cc compare_graphs.cc
fake_quantize_training.cc fake_quantize_training_test.cc file_utils.cc
file_utils.h file_utils_test.cc flatten_atrous.cc
flatten_atrous_test.cc fold_batch_norms.cc fold_batch_norms_test.cc
fold_constants_lib.cc fold_constants_lib.h fold_constants_test.cc
fold_old_batch_norms.cc fold_old_batch_norms_test.cc
freeze_requantization_ranges.cc freeze_requantization_ranges_test.cc
fuse_convolutions.cc fuse_convolutions_test.cc insert_logging.cc
insert_logging_test.cc obfuscate_names.cc obfuscate_names_test.cc out
python quantize_nodes.cc quantize_nodes_test.cc quantize_weights.cc
quantize_weights_test.cc remove_attribute.cc remove_attribute_test.cc
remove_device.cc remove_device_test.cc remove_ema.cc
remove_ema_test.cc remove_nodes.cc remove_nodes_test.cc
rename_attribute.cc rename_attribute_test.cc rename_op.cc
rename_op_test.cc round_weights.cc round_weights_test.cc set_device.cc
set_device_test.cc sort_by_execution_order.cc
sort_by_execution_order_test.cc sparsify_gather.cc
sparsify_gather_test.cc strip_unused_nodes.cc
strip_unused_nodes_test.cc summarize_graph_main.cc transform_graph.cc
transform_graph.h transform_graph_main.cc transform_graph_test.cc
transform_utils.cc transform_utils.h transform_utils_test.cc
I'm on a macbook pro
Thanks!
In case anyone is running into the similar problem, I solved it.
Navigate to the root of the tensorflow source directory
cmd> ./configure
cmd> bazel build tensorflow/tools/graph_transforms:summarize_graph
(you may get an error about xcode; if so, run the following)
cmd> xcode-select -s /Applications/Xcode.app/Contents/Developer
cmd> bazel clean --expunge
cmd> bazel build tensorflow/tools/graph_transforms:summarize_graph
CentOS 7 walkthrough:
yum install epel-release
yum update
yum install patch
curl https://copr.fedorainfracloud.org/coprs/vbatts/bazel/repo/epel-7/vbatts-bazel-epel-7.repo -o /etc/yum.repos.d/vbatts-bazel-epel-7.repo
yum install bazel
curl -L -O https://github.com/tensorflow/tensorflow/archive/v1.8.0.tar.gz
cd tensorflow-1.8.0
./configure # interactive!
bazel build tensorflow/tools/graph_transforms:summarize_graph
bazel-bin/tensorflow/tools/graph_transforms/summarize_graph