I am trying to build libtensorflow_cc.so for android for arm64-v8a architecture using bazel
Requirement
I am trying to build 'libtensorflow_cc.so' for android for arm64-v8a architecture. I needed it to create and train a model file in Android NDK through C++ at runtime. I was able do so on Desktop using C++ with the help of 'libtensorflow_cc.so' generated by
bazel build -c opt //tensorflow:libtensorflow_cc.so
, but wanted to integrate with Android NDK now and train on mobile.
I tried with 'libtensorflow.so' , but i get below error
tensorflow_jni.cc:359 Non-OK-status: session->Create (graph_def) status: Invalid argument: No OpKernel was registered to support Op 'SparseSoftmaxCrossEntropyWithLogits' with these attrs. Registered devices: [CPU], Registered kernels: [[Node: SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits = SparseSoftmaxCrossEntropyWithLogits[T=DT_FLOAT, Tlabels=DT_INT64](add, Cast)]]
I also tried with 'libtensorflow_inference.so' but I get many undefined reference errors like below
In function tensorflow::TensorShapeRep::~TensorShapeRep()': /home/ashok/AndroidStudioProjects/Android-arm64-v8a-dnn/facerecognitionlibrary/jni-build/jni/include/include1/tensorflow/core/framework/tensor_shape.h:492: undefined reference totensorflow::TensorShapeRep::DestructorOutOfLine()' ./obj/local/arm64-v8a/objs-debug/tensorflow_cc1/tensorflowTrian_jni.o: In function std::pair::~pair()': /home/ashok/Ashok/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/bits/stl_pair.h:96: undefined reference totensorflow::Tensor::~Tensor()' ./obj/local/arm64-v8a/objs-debug/tensorflow_cc1/tensorflowTrian_jni.o: In function std::string* tensorflow::internal::MakeCheckOpString(long const&, int const&, char const*)': /home/ashok/AndroidStudioProjects/Android-arm64-v8a-dnn/facerecognitionlibrary/jni-build/jni/include/include1/tensorflow/core/platform/default/logging.h:184: undefined reference totensorflow::internal::CheckOpMessageBuilder::CheckOpMessageBuilder(char const*)'
Hence building libtensorflow_cc.so for arm64-v8a using below code
Code
bazel build -c opt //tensorflow:libtensorflow_cc.so --crosstool_top=//external:android/crosstool --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --cpu=arm64-v8a
Logs
WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:avgpooling_op.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:bounds_check.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:cwise_ops.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:cwise_ops_common.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:cwise_ops_gradients.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:eigen_activations.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:eigen_attention.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:eigen_backward_cuboid_convolutions.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:eigen_backward_spatial_convolutions.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:eigen_cuboid_convolution.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:eigen_pooling.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:eigen_softmax.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:eigen_spatial_convolutions.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:eigen_volume_patch.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:fifo_queue.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:maxpooling_op.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:ops_util.cc' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:ops_util.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:padding_fifo_queue.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:pooling_ops_common.cc' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:pooling_ops_common.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:queue_base.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:queue_op.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/kernels:typed_queue.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/util/ctc:ctc_beam_entry.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/util/ctc:ctc_beam_scorer.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/util/ctc:ctc_beam_search.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/util/ctc:ctc_decoder.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/util/ctc:ctc_loss_util.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/util/tensor_bundle:naming.cc' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/util/tensor_bundle:naming.h' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/util/tensor_bundle:tensor_bundle.cc' directly. You should either move the file to this package or depend on an appropriate rule there WARNING: /home/ashok/Ashok/tensorflow/tensorflow/core/BUILD:952:12: in srcs attribute of cc_library rule //tensorflow/core:android_tensorflow_lib_lite: please do not import '//tensorflow/core/util/tensor_bundle:tensor_bundle.h' directly. You should either move the file to this package or depend on an appropriate rule there ERROR: /home/ashok/Ashok/tensorflow/tensorflow/c/eager/BUILD:11:1: in deps attribute of cc_library rule //tensorflow/c/eager:c_api: target '//tensorflow/c/eager:c_api_internal' does not exist. Since this rule was created by the macro 'tf_cuda_library', the error might have been caused by the macro implementation in /home/ashok/Ashok/tensorflow/tensorflow/tensorflow.bzl:667:12 ERROR: Analysis of target '//tensorflow:libtensorflow_cc.so' failed; build aborted INFO: Elapsed time: 0.252s FAILED: Build did NOT complete successfully (0 packages loaded)
Please help resolve the issues
You should either move the file to this package or depend on an appropriate rule there- Effective_cellistthis rule is missing dependency declarations for the following files included by 'tensorflow/core/kernels/decode_image_op.cc': './tensorflow/core/lib/jpeg/jpeg_mem.h' './tensorflow/core/platform/jpeg.h'- Effective_cellist