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

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?

Related

Precompiled Tensorflow is faster than TF built from the source CPU optimized, how to reproduce precompiled?

I have a trained tensorflow.keras model. I'm loading my model and doing inference from my C code on CPU on Ubuntu 18.04. For performance reasons, I'm comparing different builts of Tensorflow.
The first built I have is the precompiled version that I downloaded from https://www.tensorflow.org/install/lang_c.
https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-2.4.0.tar.gz
Then I built the tensorflow 2.4 from the source following the installation procedure here. I used the defaults in ./configure. Then I ran,
bazel build --config=opt //tensorflow/tools/lib_package:libtensorflow
Then I untar the generated file below and do the necessary exports (I didn't untar into /usr/local),
~/tensorflow/bazel-bin/tensorflow/tools/lib_package/libtensorflow.tar.gz
Lastly, I rebuilt the tensorflow 2.4 from the source, again used the defaults in ./configure. Then I ran,
bazel build --config=mkl --config=noaws --config=nogcp --config=nohdfs -c opt --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-mfpmath=both --copt=-msse4.1 --copt=-msse4.2 //tensorflow/tools/lib_package:libtensorflow
From what I read, this command should build tensorflow with intel-mkl support and with avx, avx2, fma, sse4.1 and sse4.2 instruction sets. I checked that my CPU supports those instructions. Then I untar the generated file and did the exports.
The performance results show that precompiled library is nearly twice as fast than the ones I built from the source. What am I doing wrong here, I couldn't find any other way other than using
--config=mkl -c opt --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-mfpmath=both --copt=-msse4.1 --copt=-msse4.2
Building with these options didn't show any change in performance. Is there a way to learn with which flags the precompiled versions were built, how can I reproduce it?
Thanks,

GPU error: Sagemaker mp.p2.xlarge instance using tensorflow==2.3.0

I got the following error when trying to train my tensorflow model on sagemaker ml.p2.xlarge instance. I use tensorflow==2.3.0. I wonder whether this is because of the tensorflow version incompatibility with cuda. sagemaker ml.p2.xlarge seems to use cuda 10.0
GPU error:
2020-08-31 08:46:46.429756: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcudart.so.10.1'; dlerror: libcudart.so.10.1: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/local/openmpi/lib:/usr/local/nvidia/lib:/usr/local/nvidia/lib64
2020-08-31 08:47:02.170819: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcudart.so.10.1'; dlerror: libcudart.so.10.1: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/local/openmpi/lib:/usr/local/nvidia/lib:/usr/local/nvidia/lib64
2020-08-31 08:47:02.764874: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1753] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...
This question is probably old, but it falls back on an open issue found at the beginning of choosing which versions of frameworks to use.
The problem does not depend on the type of instance that you specified (which has NVidia GPU).
From the official documentation "Available Deep Learning Containers Images", to date 20/10/2022, precompiled versions higher than 2.2 do not seem to be usable:
Framework
Job Type
Horovod Options
CPU/GPU
Python Version Options
Example URL
TensorFlow 2.2 (Cuda 10.2)
training
Yes
GPU
3.7 (py37)
763104351884.dkr.ecr.us-east-1.amazonaws.com/tensorflow-training:2.2.0-gpu-py37-cu102-ubuntu18.04
TensorFlow 2.2
inference
No
GPU
3.7 (py37)
763104351884.dkr.ecr.us-east-1.amazonaws.com/tensorflow-inference:2.2.0-gpu-py37-cu102-ubuntu18.04
Within the dockerfile that is used to use the container is the instruction to install the libraries that your custom version is missing:
RUN apt-get update && apt-get install -y --no-install-recommends --allow-unauthenticated \
python3-dev \
python3-pip \
python3-setuptools \
ca-certificates \
cuda-command-line-tools-10-1 \
cuda-cudart-dev-10-1 \
cuda-cufft-dev-10-1 \
cuda-curand-dev-10-1 \
cuda-cusolver-dev-10-1 \
cuda-cusparse-dev-10-1 \
curl \
libcudnn7=7.6.2.24-1+cuda10.1 \
# TensorFlow doesn't require libnccl anymore but Open MPI still depends on it
libnccl2=2.4.7-1+cuda10.1 \
libgomp1 \
libnccl-dev=2.4.7-1+cuda10.1 \
....
Then you can install the required libraries from your custom version directly with a requirements.txt file or run the install command directly in the training script.
If there are no special project requirements, I recommend using the precompiled versions of sagemaker. Otherwise, build a docker image from scratch instead of installing libraries this way..

maxpooling error in Tenssoflow ;Check failed: dnnPoolingCreateForward_F32(.<parameter list>.) == E_SUCCESS (-127 vs. 0)

I am learning tesnorflow from this blog:
http://www.wildml.com/2015/12/implementing-a-cnn-for-text-classification-in-tensorflow/
The code i am running is :
https://github.com/dennybritz/cnn-text-classification-tf/blob/master/train.py
I have installed tensorflow from sourcse in a virtual enviroment,in CPU only enviroment using followinbg bazel build command: bazel build --config=mkl ...
here is the exact error:
"2018-01-16 03:15:27.783040: F tensorflow/core/kernels/mkl_maxpooling_op.cc:157] Check failed: dnnPoolingCreateForward_F32( &prim_pooling_fwd, primAttr, algorithm, lt_user_input, params.kernel_size, params.kernel_stride, params.in_offset, dnnBorderZerosAsymm) == E_SUCCESS (-127 vs. 0)
Aborted
"
I have debugged error to the line where sess.run is written, i have beleived it has something to do it mkl_maxpooling, as i had installed tensorflow with mkl optimization of INTEL cpu's
Given below are the steps that I followed:
Build tensorflow 1.4 from source with mkl as mentioned in the question
Cloned the git repo "https://github.com/dennybritz/cnn-text-classification-tf.git"
Ran "python train.py" from "cnn-text-classification-tf" directory(created from git clone)
Code ran without any errors. So it seems like the tensorflow was not properly built from the source. Please confirm that there were no errors while building tensorflow from source.

The TensorFlow library wasn't compiled to use AVX - AVX2

I'm new to Tensorflow.
I am using a 64 bit version of Windows 10 and I would like to install Tensorflow for the CPU.
I don't remember the exact steps that I followed to install it, however when I checked for the installation using:
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
I have the following output:
2017-10-18 09:56:21.656601: W C:\tf_jenkins\home\workspace\rel-win\M\windows\PY\36\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2017-10-18 09:56:21.656984: W C:\tf_jenkins\home\workspace\rel-win\M\windows\PY\36\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
b'Hello, TensorFlow!'
I am running python in Sublime Text 3 using the package SublimeREPL.
I tried to search these errors and found out that it means that the tensorflow is built without these instructions which could improve performances for the CPU. I also found the code to hide these warnings, but I actually I want to use these instructions.
The code that I found that enables this is:
bazel build -c opt --copt=-mavx --copt=-mavx2 --copt=-msse4.2 --copt=-msse4.1 --copt=-msse3 --copt=-mfma -k //tensorflow/tools/pip_package:build_pip_package
but I got this output:
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. Continuing anyway.
INFO: Found 0 targets...
ERROR: command succeeded, but there were errors parsing the target pattern.
INFO: Elapsed time: 8,147s, Critical Path: 0,02s
How can I solve this problem?
Lastly, I don't understand what pip, wheel and bazel are so I need a step by step instructions.
Thank you a lot!
if you want to download TensorFlow source, compile+install, use this link. If you want to download binaries, then use this link.

Build error with GPU support when building pip

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