how to build the tensorflow_cc.so(tensorflow c++ interface) on the xavier

hi!
I want to build the tensorflow_cc.so from source on my xavier,for c++ interface.

I successfully installed JetPack 4.1 on xavier, andxavier can connect the Internet with no problem.
I tried to install Tensorflow using “Installing from sources”,
but when i build it ,
sudo bazel build --config=opt --config=cuda //tensorflow:libtensorflow_cc.so
i get this error:

ERROR:/home/nvidia/Downloads/tensorflow/tensorflow/BUILD:499:1: Linking of rule '//tensorflow:libtensorflow_cc.so’failed (Exit 1)

some versions and software i have installed :
1、lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.1 LTS
Release: 18.04
Codename: bionic

2、CUDA versions:nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2018 NVIDIA Corporation
Built on Sun_Aug_12_21:08:25_CDT_2018
Cuda compilation tools, release 10.0, V10.0.117

3、cuDNN7.3.0

4、Create a 8G swapfile

5、installed Eigen 3

6、installed bazel 0.15.0

7、installed Protobuf 3.5.0

Can anyone tell me how to installTensorflow 1.12.0 C++ Interface on Xavier? Thanks!

Hi,

Could you test the patch shared in this link:
[url]TensorFlow 1.8.0-rc1 fails on aarch64 platforms · Issue #18643 · tensorflow/tensorflow · GitHub

Thanks.

hi AastaLLL
Thank you for your reply.
But that doesn`t work for me.
Now there are new mistakes.

sudo bazel build --config=opt --copt=-DPNG_ARM_NEON_OPT=0 //tensorflow:libtensorflow_cc.so
Starting local Bazel server and connecting to it...
.
ERROR: /home/nvidia/Downloads/tensorflow/tensorflow/core/kernels/BUILD:6589:1: no such package '@icu//': java.io.IOException: thread interrupted and referenced by '//tensorflow/core/kernels:unicode_script_op'
ERROR: Analysis of target '//tensorflow:libtensorflow_cc.so' failed; build aborted: Analysis failed
INFO: Elapsed time: 155.021s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (133 packages loaded)

Can anyone install Tensorflow 1.12.0 from source on xavier? thanks!

sudo bazel build --config=opt --copt=-DPNG_ARM_NEON_OPT=0 //tensorflow:libtensorflow_cc.so
[sudo] password for nvidia: 
WARNING: /home/nvidia/.cache/bazel/_bazel_root/4b0c904fc7955dd9a6eeb72442db8616/external/grpc/BUILD:1992:1: in srcs attribute of cc_library rule @grpc//:grpc_nanopb: please do not import '@grpc//third_party/nanopb:pb_common.c' directly. You should either move the file to this package or depend on an appropriate rule there. Since this rule was created by the macro 'grpc_generate_one_off_targets', the error might have been caused by the macro implementation in /home/nvidia/.cache/bazel/_bazel_root/4b0c904fc7955dd9a6eeb72442db8616/external/grpc/bazel/grpc_build_system.bzl:172:12
WARNING: /home/nvidia/.cache/bazel/_bazel_root/4b0c904fc7955dd9a6eeb72442db8616/external/grpc/BUILD:1992:1: in srcs attribute of cc_library rule @grpc//:grpc_nanopb: please do not import '@grpc//third_party/nanopb:pb_decode.c' directly. You should either move the file to this package or depend on an appropriate rule there. Since this rule was created by the macro 'grpc_generate_one_off_targets', the error might have been caused by the macro implementation in /home/nvidia/.cache/bazel/_bazel_root/4b0c904fc7955dd9a6eeb72442db8616/external/grpc/bazel/grpc_build_system.bzl:172:12
WARNING: /home/nvidia/.cache/bazel/_bazel_root/4b0c904fc7955dd9a6eeb72442db8616/external/grpc/BUILD:1992:1: in srcs attribute of cc_library rule @grpc//:grpc_nanopb: please do not import '@grpc//third_party/nanopb:pb_encode.c' directly. You should either move the file to this package or depend on an appropriate rule there. Since this rule was created by the macro 'grpc_generate_one_off_targets', the error might have been caused by the macro implementation in /home/nvidia/.cache/bazel/_bazel_root/4b0c904fc7955dd9a6eeb72442db8616/external/grpc/bazel/grpc_build_system.bzl:172:12
ERROR: /home/nvidia/Downloads/tensorflow/tensorflow/core/kernels/BUILD:6589:1: no such package '@icu//': java.io.IOException: Error downloading [https://mirror.bazel.build/github.com/unicode-org/icu/archive/release-62-1.tar.gz, https://github.com/unicode-org/icu/archive/release-62-1.tar.gz] to /home/nvidia/.cache/bazel/_bazel_root/4b0c904fc7955dd9a6eeb72442db8616/external/icu/release-62-1.tar.gz: Checksum was 848fc9c71b690ecd84fe65637f3948098dd1b2995f4259b4d556adad3e998d6c but wanted 03a3928d143de7eb5bc2d2cafd036867aa71d1c7d4c433bf16c8c30e952e21d8 and referenced by '//tensorflow/core/kernels:unicode_script_op'
ERROR: Analysis of target '//tensorflow:libtensorflow_cc.so' failed; build aborted: Analysis failed
INFO: Elapsed time: 612.957s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (3 packages loaded)
nvidia@jetson-0423218009492:~/Downloads/tensorflow$ sudo bazel build --config=opt --verbose_failures --copt=-DPNG_ARM_NEON_OPT=0 //tensorflow:libtensorflow_cc.so
WARNING: /home/nvidia/.cache/bazel/_bazel_root/4b0c904fc7955dd9a6eeb72442db8616/external/grpc/BUILD:1992:1: in srcs attribute of cc_library rule @grpc//:grpc_nanopb: please do not import '@grpc//third_party/nanopb:pb_common.c' directly. You should either move the file to this package or depend on an appropriate rule there. Since this rule was created by the macro 'grpc_generate_one_off_targets', the error might have been caused by the macro implementation in /home/nvidia/.cache/bazel/_bazel_root/4b0c904fc7955dd9a6eeb72442db8616/external/grpc/bazel/grpc_build_system.bzl:172:12
WARNING: /home/nvidia/.cache/bazel/_bazel_root/4b0c904fc7955dd9a6eeb72442db8616/external/grpc/BUILD:1992:1: in srcs attribute of cc_library rule @grpc//:grpc_nanopb: please do not import '@grpc//third_party/nanopb:pb_decode.c' directly. You should either move the file to this package or depend on an appropriate rule there. Since this rule was created by the macro 'grpc_generate_one_off_targets', the error might have been caused by the macro implementation in /home/nvidia/.cache/bazel/_bazel_root/4b0c904fc7955dd9a6eeb72442db8616/external/grpc/bazel/grpc_build_system.bzl:172:12
WARNING: /home/nvidia/.cache/bazel/_bazel_root/4b0c904fc7955dd9a6eeb72442db8616/external/grpc/BUILD:1992:1: in srcs attribute of cc_library rule @grpc//:grpc_nanopb: please do not import '@grpc//third_party/nanopb:pb_encode.c' directly. You should either move the file to this package or depend on an appropriate rule there. Since this rule was created by the macro 'grpc_generate_one_off_targets', the error might have been caused by the macro implementation in /home/nvidia/.cache/bazel/_bazel_root/4b0c904fc7955dd9a6eeb72442db8616/external/grpc/bazel/grpc_build_system.bzl:172:12
INFO: Analysed target //tensorflow:libtensorflow_cc.so (0 packages loaded).
INFO: Found 1 target...
ERROR: /home/nvidia/Downloads/tensorflow/tensorflow/BUILD:449:1: Linking of rule '//tensorflow:libtensorflow_cc.so' failed (Exit 1): crosstool_wrapper_driver_is_not_gcc failed: error executing command 
  (cd /home/nvidia/.cache/bazel/_bazel_root/4b0c904fc7955dd9a6eeb72442db8616/execroot/org_tensorflow && \
  exec env - \
    CUDA_TOOLKIT_PATH=/usr/local/cuda-10.0 \
    CUDNN_INSTALL_PATH=/usr/local/cuda-10.0 \
    GCC_HOST_COMPILER_PATH=/usr/bin/gcc \
    LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64: \
    NCCL_HDR_PATH=/usr/local/lib/../include \
    NCCL_INSTALL_PATH=/usr/local/lib \
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin \
    PWD=/proc/self/cwd \
    PYTHON_BIN_PATH=/usr/bin/python \
    PYTHON_LIB_PATH=/usr/local/lib/python2.7/dist-packages \
    TENSORRT_INSTALL_PATH=/usr/lib/aarch64-linux-gnu \
    TF_CUDA_CLANG=0 \
    TF_CUDA_COMPUTE_CAPABILITIES=7.0 \
    TF_CUDA_VERSION=10.0 \
    TF_CUDNN_VERSION=7 \
    TF_NCCL_VERSION=2 \
    TF_NEED_CUDA=1 \
    TF_NEED_OPENCL_SYCL=0 \
    TF_NEED_ROCM=0 \
    TF_TENSORRT_VERSION=5 \
  external/local_config_cuda/crosstool/clang/bin/crosstool_wrapper_driver_is_not_gcc -shared -o bazel-out/arm-opt/bin/tensorflow/libtensorflow_cc.so '-Wl,-rpath,$ORIGIN/../_solib_local/_U_S_Stensorflow_Clibtensorflow_Ucc.so___Utensorflow' '-Wl,-rpath,$ORIGIN/../_solib_local/_U@local_Uconfig_Ucuda_S_Scuda_Ccublas___Uexternal_Slocal_Uconfig_Ucuda_Scuda_Scuda_Slib' '-Wl,-rpath,$ORIGIN/../_solib_local/_U@local_Uconfig_Ucuda_S_Scuda_Ccusolver___Uexternal_Slocal_Uconfig_Ucuda_Scuda_Scuda_Slib' '-Wl,-rpath,$ORIGIN/../_solib_local/_U@local_Uconfig_Ucuda_S_Scuda_Ccudart___Uexternal_Slocal_Uconfig_Ucuda_Scuda_Scuda_Slib' -Lbazel-out/arm-opt/bin/_solib_local/_U_S_Stensorflow_Clibtensorflow_Ucc.so___Utensorflow -Lbazel-out/arm-opt/bin/_solib_local/_U@local_Uconfig_Ucuda_S_Scuda_Ccublas___Uexternal_Slocal_Uconfig_Ucuda_Scuda_Scuda_Slib -Lbazel-out/arm-opt/bin/_solib_local/_U@local_Uconfig_Ucuda_S_Scuda_Ccusolver___Uexternal_Slocal_Uconfig_Ucuda_Scuda_Scuda_Slib -Lbazel-out/arm-opt/bin/_solib_local/_U@local_Uconfig_Ucuda_S_Scuda_Ccudart___Uexternal_Slocal_Uconfig_Ucuda_Scuda_Scuda_Slib -z defs -Wl,--version-script tensorflow/tf_version_script.lds '-Wl,-rpath,$ORIGIN/' -Wl,-soname,libtensorflow_cc.so -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -Wl,-z,muldefs -pthread -Wl,-rpath,../local_config_cuda/cuda/lib64 -Wl,-rpath,../local_config_cuda/cuda/extras/CUPTI/lib64 -Wl,-no-as-needed -Wl,-z,relro,-z,now '-Wl,--build-id=md5' '-Wl,--hash-style=gnu' -no-canonical-prefixes -B/usr/bin -Wl,--gc-sections -Wl,@bazel-out/arm-opt/bin/tensorflow/libtensorflow_cc.so-2.params)
bazel-out/arm-opt/bin/external/aws/libaws.pic.a(AWSCredentialsProvider.pic.o): In function `Aws::Auth::EnvironmentAWSCredentialsProvider::GetAWSCredentials()':
AWSCredentialsProvider.cpp:(.text._ZN3Aws4Auth33EnvironmentAWSCredentialsProvider17GetAWSCredentialsEv+0x48): undefined reference to `Aws::Environment::GetEnv[abi:cxx11](char const*)'
AWSCredentialsProvider.cpp:(.text._ZN3Aws4Auth33EnvironmentAWSCredentialsProvider17GetAWSCredentialsEv+0x1d8): undefined reference to `Aws::Environment::GetEnv[abi:cxx11](char const*)'
AWSCredentialsProvider.cpp:(.text._ZN3Aws4Auth33EnvironmentAWSCredentialsProvider17GetAWSCredentialsEv+0x21c): undefined reference to `Aws::Environment::GetEnv[abi:cxx11](char const*)'
bazel-out/arm-opt/bin/external/aws/libaws.pic.a(AWSCredentialsProvider.pic.o): In function `Aws::Auth::ProfileConfigFileAWSCredentialsProvider::GetConfigProfileFilename[abi:cxx11]()':
AWSCredentialsProvider.cpp:(.text._ZN3Aws4Auth39ProfileConfigFileAWSCredentialsProvider24GetConfigProfileFilenameB5cxx11Ev+0x34): undefined reference to `Aws::FileSystem::GetHomeDirectory[abi:cxx11]()'
bazel-out/arm-opt/bin/external/aws/libaws.pic.a(AWSCredentialsProvider.pic.o): In function `Aws::Auth::ProfileConfigFileAWSCredentialsProvider::GetCredentialsProfileFilename[abi:cxx11]()':
AWSCredentialsProvider.cpp:(.text._ZN3Aws4Auth39ProfileConfigFileAWSCredentialsProvider29GetCredentialsProfileFilenameB5cxx11Ev+0x3c): undefined reference to `Aws::Environment::GetEnv[abi:cxx11](char const*)'
AWSCredentialsProvider.cpp:(.text._ZN3Aws4Auth39ProfileConfigFileAWSCredentialsProvider29GetCredentialsProfileFilenameB5cxx11Ev+0xb4): undefined reference to `Aws::FileSystem::GetHomeDirectory[abi:cxx11]()'
bazel-out/arm-opt/bin/external/aws/libaws.pic.a(AWSCredentialsProvider.pic.o): In function `Aws::Auth::ProfileConfigFileAWSCredentialsProvider::ProfileConfigFileAWSCredentialsProvider(long)':
AWSCredentialsProvider.cpp:(.text._ZN3Aws4Auth39ProfileConfigFileAWSCredentialsProviderC2El+0x174): undefined reference to `Aws::Environment::GetEnv[abi:cxx11](char const*)'
bazel-out/arm-opt/bin/external/aws/libaws.pic.a(AWSCredentialsProviderChain.pic.o): In function `Aws::Auth::DefaultAWSCredentialsProviderChain::DefaultAWSCredentialsProviderChain()':
AWSCredentialsProviderChain.cpp:(.text._ZN3Aws4Auth34DefaultAWSCredentialsProviderChainC2Ev+0x1d8): undefined reference to `Aws::Environment::GetEnv[abi:cxx11](char const*)'
bazel-out/arm-opt/bin/external/aws/libaws.pic.a(ClientConfiguration.pic.o): In function `Aws::Client::ComputeUserAgentString()':
ClientConfiguration.cpp:(.text._ZN3Aws6ClientL22ComputeUserAgentStringEv+0x178): undefined reference to `Aws::OSVersionInfo::ComputeOSVersionString[abi:cxx11]()'
bazel-out/arm-opt/bin/external/aws/libaws.pic.a(DateTimeCommon.pic.o): In function `Aws::Utils::DateTime::ConvertTimestampStringToTimePoint(char const*, Aws::Utils::DateFormat)':
DateTimeCommon.cpp:(.text._ZN3Aws5Utils8DateTime33ConvertTimestampStringToTimePointEPKcNS0_10DateFormatE+0x54): undefined reference to `Aws::Time::TimeGM(tm*)'
bazel-out/arm-opt/bin/external/aws/libaws.pic.a(DateTimeCommon.pic.o): In function `Aws::Utils::DateTime::ConvertTimestampToLocalTimeStruct() const':
DateTimeCommon.cpp:(.text._ZNK3Aws5Utils8DateTime33ConvertTimestampToLocalTimeStructEv+0x2c): undefined reference to `Aws::Time::LocalTime(tm*, long)'
bazel-out/arm-opt/bin/external/aws/libaws.pic.a(DateTimeCommon.pic.o): In function `Aws::Utils::DateTime::ConvertTimestampToGmtStruct() const':
DateTimeCommon.cpp:(.text._ZNK3Aws5Utils8DateTime27ConvertTimestampToGmtStructEv+0x2c): undefined reference to `Aws::Time::GMTime(tm*, long)'
bazel-out/arm-opt/bin/external/aws/libaws.pic.a(TempFile.pic.o): In function `Aws::Utils::TempFile::~TempFile()':
TempFile.cpp:(.text._ZN3Aws5Utils8TempFileD1Ev+0x38): undefined reference to `Aws::FileSystem::RemoveFileIfExists(char const*)'
bazel-out/arm-opt/bin/external/aws/libaws.pic.a(TempFile.pic.o): In function `Aws::Utils::ComputeTempFileName(char const*, char const*)':
TempFile.cpp:(.text._ZN3Aws5UtilsL19ComputeTempFileNameEPKcS2_+0xa8): undefined reference to `Aws::FileSystem::CreateTempFilePath[abi:cxx11]()'
collect2: error: ld returned 1 exit status
Target //tensorflow:libtensorflow_cc.so failed to build
INFO: Elapsed time: 33.964s, Critical Path: 31.58s
INFO: 0 processes.
FAILED: Build did NOT complete successfully

Hi,

Could you share the selection when executing ‘source ./configure’?
You can check this page for reference:
https://github.com/AastaNV/JEP/blob/master/script/TensorFlow_1.6/tf1.6_build_from_source.sh

Not all TensorFlow options are available for Jetson.
We want to check your setting is good first.

Thanks.

hi !
this is my configure
is it right?

nvidia@jetson-0423218009492:~/Downloads/tensorflow$ ./configure 
WARNING: ignoring LD_PRELOAD in environment.
WARNING: --batch mode is deprecated. Please instead explicitly shut down your Bazel server using the command "bazel shutdown".
You have bazel 0.15.0- (@non-git) installed.
Please specify the location of python. [Default is /usr/bin/python]: 


Found possible Python library paths:
  /usr/local/lib/python2.7/dist-packages
  /usr/lib/python2.7/dist-packages
Please input the desired Python library path to use.  Default is [/usr/local/lib/python2.7/dist-packages]

Do you wish to build TensorFlow with Apache Ignite support? [Y/n]: y
Apache Ignite support will be enabled for TensorFlow.

Do you wish to build TensorFlow with XLA JIT support? [Y/n]: y
XLA JIT support will be enabled for TensorFlow.

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]: y
CUDA support will be enabled for TensorFlow.

Please specify the CUDA SDK version you want to use. [Leave empty to default to CUDA 9.0]: 10.0


Please specify the location where CUDA 10.0 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: /usr/local/cuda-10.0


Please specify the cuDNN version you want to use. [Leave empty to default to cuDNN 7]: 7.3.0


Please specify the location where cuDNN 7 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda-10.0]: 


Do you wish to build TensorFlow with TensorRT support? [y/N]: y
TensorRT support will be enabled for TensorFlow.

Please specify the location where TensorRT is installed. [Default is /usr/lib/aarch64-linux-gnu]:/usr/src/tensorrt


Please specify the NCCL version you want to use. If NCCL 2.2 is not installed, then you can use version 1.3 that can be fetched automatically but it may have worse performance with multiple GPUs. [Default is 2.2]: 2.3.7


Please specify the location where NCCL 2 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda-10.0]:/usr/local/lib


NCCL found at /usr/local/lib/libnccl.so.2
Assuming NCCL header path is /usr/local/lib/../include/nccl.h
Please specify a list of comma-separated Cuda compute capabilities you want to build with.
You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
Please note that each additional compute capability significantly increases your build time and binary size. [Default is: 3.5,7.0]: 7.0


Do you want to use clang as CUDA compiler? [y/N]: n
nvcc will be used as CUDA compiler.

Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]: 


Do you wish to build TensorFlow with MPI support? [y/N]: n
No MPI support will be enabled for TensorFlow.

Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native]: 


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 tools/bazel.rc for more details.
	--config=mkl         	# Build with MKL support.
	--config=monolithic  	# Config for mostly static monolithic build.
	--config=gdr         	# Build with GDR support.
	--config=verbs       	# Build with libverbs support.
	--config=ngraph      	# Build with Intel nGraph support.
Configuration finished
nvidia@jetson-0423218009492:~/Downloads/tensorflow$

Hi,

The built error shared in comment #5 is caused by AWS library.
Try to turn off it in the configure.

By the way, it’s recommended to turn off NCCL since it is a feature for discrete GPU.
Thanks.

hi AastaLLL
Thank you for your reply.
But How should I turn off the aws library in the configure ? there is no AWS select.

Hi,

Check your BUILD script:

It should like this:
https://github.com/tensorflow/tensorflow/blob/eea816869a0a85ab5d9427060a8b113fe709c623/tensorflow/BUILD

config_setting(
    name = "no_aws_support",
    define_values = {"no_aws_support": "true"},
    visibility = ["//visibility:public"],
)

Thanks.

Hi,
I have the same problem with Xavier,
Do you solve this problem?

Hi,
For the first time I build the tensorflow_cc.so with Tensorflow 1.12.0-rc2
sudo bazel build --config=opt --config=cuda //tensorflow:libtensorflow_cc.so
I got the same problem with
… …
“undefined reference to ‘Aws::Environment::GetEnv[abi:cxx11](char const*)’”
… …

Follow the advice from AastaLLL, I gedit the BUILD
gedit home/nvidia/tensorflow-1.12.0-rc2/tensorflow/BUILD
Add the content
config_setting(
name = “no_aws_support”,
define_values = {“no_aws_support”: “true”},
visibility = [“//visibility:public”],
)

Then I source the config again and rebuild with the commond (there is no AWS select still)
sudo bazel build --config=opt --config=cuda //tensorflow:libtensorflow_cc.so

Finally I have the same problem with Aws as
… …
“undefined reference to ‘Aws::Environment::GetEnv[abi:cxx11](char const*)’”
… …

Which step was wrong? Thank U! @AastaLLL @wangshuchao

I can`t turn off the AWS build option in configure file as comment #10 said.

Me too.
I add content with “home/nvidia/tensorflow-1.12.0-rc2/tensorflow/BUILD” as #10 said.
While in compilation process,I get the same problem with Aws. It seems useless.

How to turn off the AWS build option? Thank U. @AastaLLL @wangchuchao

Hi,

Could you try the workaround shared in this post?
[url]https://github.com/tensorflow/serving/issues/832[/url]

Thanks.