Build error with GPU support when building pip - tensorflow

I've reached the Setting up TensorFlow for Development section of the Tensorflow 0.9 tutorial, and I'm getting an error when trying to add support for GPU.
\> bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package
ERROR: /home/.../tensorflow/tensorflow/core/kernels/BUILD:1489:1:
undeclared inclusion(s) in rule
'//tensorflow/core/kernels:batchtospace_op_gpu': this rule is missing
dependency declarations for the following files included by
'tensorflow/core/kernels/batchtospace_op_gpu.cu.cc'
I do not get this error if I exclude the --config=cuda directive, however.
Setup:
Elementary OS 0.3
tensorflow 0.9
cuda-7.5
cudnn 5.0.5
gcc 4.8.4

try adding
cxx_builtin_include_directory: "/usr/local/cuda-8.0/include"
to
third_party/gpus/crosstool/CROSSTOOL
https://github.com/tensorflow/tensorflow/issues/3431

Related

how to cross compile tensorflow lite for arm64(linux) by using bazel

I'm trying to build the tensorflow lite for 'arm64-v8a' with linux on an amd64 with linux.I follow the guide to build the library libtensorflow-lite.a.but i found there remains a long tail of TensorFlow ops that are not yet natively supported by TensorFlow Lite,so i want Select TensorFlow operators to use in TensorFlow Lite. from the guide i should Recompile the library, I use the command bazel build -c opt //tensorflow/lite:libtensorflowlite.so --cpu=arm64-v8a, I got the following error:
/home/wang/.cache/bazel/_bazel_wang/c72f4772665ac4cb0690414b07635968/external/local_config_cc/BUILD:45:1: in cc_toolchain_suite rule #local_config_cc//:toolchain: cc_toolchain_suite '#local_config_cc//:toolchain' does not contain a toolchain for cpu 'arm64-v8a'
I'm new to bazel and cannot find a detailed walkthrough.what should i do?

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 <...>

How to build tensorflow benchmark_model for android arm64_v8a?

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

error bazel build in tensorflow

At first, I would like to use bazel to help me run tensorflow with SSE and avx so I tried this within work space:
bazel build -c opt --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-mfpmath=both --copt=-msse4.2 --config=cuda -k //tensorflow/tools/pip_package:build_pip_package
but it gives me a new error like following, I wonder what is wrong and what should I do? Thanks for help.
WARNING: Config values are not defined in any .rc file: cuda
ERROR: Skipping '//tensorflow/tools/pip_package:build_pip_package': no such package 'tensorflow/tools/pip_package': BUILD file not found on package path
WARNING: Target pattern parsing failed.
INFO: Analysed 0 targets (2 packages loaded).
INFO: Found 0 targets...
ERROR: command succeeded, but there were errors parsing the target pattern
INFO: Elapsed time: 2.727s, Critical Path: 0.02s
FAILED: Build did NOT complete successfully
You probably have an outdated bazel. I am not sure but you can try to use --config=opt instead of -c opt for initial versions.
You have to run ./configure. That will create a .bazelrc and .tf_configure.bazel file in your Tensorflow workspace.
The --config=cuda Bazel flag refers to entries in those two files (they are both text files). The entries typically look like this: build:cuda --some_bazel_flag.
It was answered here

tensorflow linker_flag in CROSSTOOL

I am working with Tensorflow 1.1.0 with gcc 5.2.0 and bazel 0.4.5
When I do:
./configure
bazel build --verbose_failures --config=opt //tensorflow/tools/pip_package:build_pip_package
I got the following error messages:
ERROR: /remote/us03home4/rogerlo/.cache/bazel/_bazel_rogerlo/c6e718933b1d81ab029d890c5eecbc01/external/protobuf/BUILD:67
9:1: null failed: protoc failed: error executing command
(cd /remote/us03home4/rogerlo/.cache/bazel/_bazel_rogerlo/c6e718933b1d81ab029d890c5eecbc01/execroot/tensorflow && \
exec env - \
bazel-out/host/bin/external/protobuf/protoc '--python_out=bazel-out/local-opt/genfiles/external/protobuf/python' -Iexternal/protobuf/python -Ibazel-out/local-opt/genfiles/external/protobuf/python bazel-out/local-opt/genfiles/external/protobuf/python/google/protobuf/any.proto bazel-out/local-opt/genfiles/external/protobuf/python/google/protobuf/api.proto bazel-out/local-opt/genfiles/external/protobuf/python/google/protobuf/compiler/plugin.proto bazel-out/local-opt/genfiles/external/protobuf/python/google/protobuf/descriptor.proto bazel-out/local-opt/genfiles/external/protobuf/python/google/protobuf/duration.proto bazel-out/local-opt/genfiles/external/protobuf/python/google/protobuf/empty.proto bazel-out/local-opt/genfiles/external/protobuf/python/google/protobuf/field_mask.proto bazel-out/local-opt/genfiles/external/protobuf/python/google/protobuf/source_context.proto bazel-out/local-opt/genfiles/external/protobuf/python/google/protobuf/struct.proto bazel-out/local-opt/genfiles/external/protobuf/python/google/protobuf/timestamp.proto bazel-out/local-opt/genfiles/external/protobuf/python/google/protobuf/type.proto bazel-out/local-opt/genfiles/external/protobuf/python/google/protobuf/wrappers.proto): com.google.devtools.build.lib.shell.BadExitStatusException: Process exited with status 1.
bazel-out/host/bin/external/protobuf/protoc: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by bazel-out/host/bin/external/protobuf/protoc)
bazel-out/host/bin/external/protobuf/protoc: /usr/lib64/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by bazel-out/host/bin/external/protobuf/protoc)
bazel-out/host/bin/external/protobuf/protoc: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.18' not found (required by bazel-out/host/bin/external/protobuf/protoc)
bazel-out/host/bin/external/protobuf/protoc: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by bazel-out/host/bin/external/protobuf/protoc)
____Building complete.
Target //tensorflow/tools/pip_package:build_pip_package failed to build
____Elapsed time: 101.992s, Critical Path: 54.24s
make: *** [tensorflow] Error 1
But if I added this line:
linker_flag: "-Wl,-rpath,/depot/gcc-5.2.0/lib64"
to the file
$TENSORFLOW_ROOT/bazel-tensorflow/external/local_config_cc/CROSSTOOL
Build will pass.
I wonder if I can configure that linker_flag from the configure file or somewhere else?
I did add it to the build option but it doesn't work.
bazel build --verbose_failures --config=opt --linkopt="-Wl,-rpath,/depot/gcc-5.2.0/lib6
4" //tensorflow/tools/pip_package:build_pip_package
EDIT: added bazel version
SOLUTION:
Add the linker option to the configuration of Bazel.
Recompile Bazel.
Compile Tensorflow with the recompiled Bazel will pass.
Investigation
The target is built by external crosstool, so the --linkopt won't work. According to the Bazel official blog, the configuration of external crosstool (C++) is auto detected. It points to the C++ configuration file.
linker_flag rpath is computed by $LD_LIBRARY_PATH. That is, if you have some library paths defined in $LD_LIBRARY_PATH, Bazel will generate their rpath in the linker_flag.
But that dependency is removed because of [issue#2099](github.com/bazelbuild/bazel/issues/2099)
So setting $LD_LIBRARY_PATH doesn't work in [v0.4.5](github.com/bazelbuild/bazel/blob/0.4.5/tools/cpp/cc_configure.bzl#L250)
However, I haven't figure out how to do it correctly (setting env_action or something). So the quick solution is to hardcode it in the configuration file.
(Forgive me about the ugly hyperlinks above. My reputation is not enough to have more than 2 links in a post.)
[Copy my answer here]
SOLUTION:
Add the linker option to the configuration of Bazel.
Recompile Bazel.
Compile Tensorflow with the recompiled Bazel will pass.
Investigation
The target is built by external crosstool, so the --linkopt won't work. According to the Bazel official blog, the configuration of external crosstool (C++) is auto detected. It points to the C++ configuration file.
linker_flag rpath is computed by $LD_LIBRARY_PATH. That is, if you have some library paths defined in $LD_LIBRARY_PATH, Bazel will generate their rpath in the linker_flag.
But that dependency is removed because of [issue#2099](github.com/bazelbuild/bazel/issues/2099)
So setting $LD_LIBRARY_PATH doesn't work in [v0.4.5](github.com/bazelbuild/bazel/blob/0.4.5/tools/cpp/cc_configure.bzl#L250)
However, I haven't figure out how to do it correctly (setting env_action or something). So the quick solution is to hardcode it in the configuration file.
(Forgive me about the ugly hyperlinks above. My reputation is not enough to have more than 2 links in a post.)