Closed xav12358 closed 6 years ago
Hi ! which version of tensorflow are you compiling ?
Here are more information about my computer:
OS Platform and Distribution : Ubuntu 16.04 TensorFlow installed from source TensorFlow version 1.4.0 Bazel version 0.9
I also try to compile libtensorflow_cc.so (which seems to be the cpp compiled version of tensorflow) but I also get errors:
bazel build --config=android_arm64 -c opt //tensorflow:libtensorflow_cc.so --crosstool_top=//external:android/crosstool --host_crosstool_top=@bazel_tools//tools/cpp:toolchain WARNING: /home/xavier/.cache/bazel/_bazel_xavier/ef54af8645dec4f38c438d8e1c779747/external/protobuf_archive/WORKSPACE:1: Workspace name in /home/xavier/.cache/bazel/_bazel_xavier/ef54af8645dec4f38c438d8e1c779747/external/protobuf_archive/WORKSPACE (@com_google_protobuf) does not match the name given in the repository's definition (@protobuf_archive); this will cause a build error in future versions ERROR: No default_toolchain found for cpu 'arm64-v8a'. Valid cpus are: [ k8, armeabi-v7a, x64_windows, x64_windows_msvc, x64_windows_msys, s390x, ios_x86_64, ] INFO: Elapsed time: 1.217s FAILED: Build did NOT complete successfully (4 packages loaded)
hum, I think you're trying to build a few things that are not "android ready" . In you deps array
deps = [
"//tensorflow/core:framework_internal",
"//tensorflow/core:tensorflow",
"//tensorflow/cc:cc_ops",
"//tensorflow/cc:client_session",
"//tensorflow/cc:scope",
"//tensorflow/c:c_api",
],
you don't depend on //tensorflow/core:android_tensorflow_lib
but //tensorflow/core:tensorflow
which if I remember well has some non android compatible deps...
So the solution is to modify "//tensorflow/core:tensorflow" to "//tensorflow/core:tensorflow_lib" ?
more probably //tensorflow/core:android_tensorflow_lib
but you'll need to figure out if there is all that's needed in here to make the CPP api work in here... there are quite a few parts of the implementation that are swapped out when building for android, you'll need to explore the bazel BUILD files to see what's happening
I don't think this is enough:
`INFO: From Compiling external/protobuf_archive/src/google/protobuf/struct.pb.cc:
external/protobuf_archive/src/google/protobuf/struct.pb.cc:115:3: warning: offset of on non-POD type '::google::protobuf::ValueDefaultTypeInternal' [-Winvalid-offsetof]
offsetof(::google::protobuf::ValueDefaultTypeInternal, nullvalue),
^ ~~~
external/androidndk/ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib64/clang/3.8.275480/include/stddef.h:120:24: note: expanded from macro 'offsetof'
^ ~
external/protobuf_archive/src/google/protobuf/struct.pb.cc:116:3: warning: offset of on non-POD type '::google::protobuf::ValueDefaultTypeInternal' [-Winvalid-offsetof]
offsetof(::google::protobuf::ValueDefaultTypeInternal, numbervalue),
^ ~~~~~
external/androidndk/ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib64/clang/3.8.275480/include/stddef.h:120:24: note: expanded from macro 'offsetof'
^ ~
external/protobuf_archive/src/google/protobuf/struct.pb.cc:117:3: warning: offset of on non-POD type '::google::protobuf::ValueDefaultTypeInternal' [-Winvalid-offsetof]
offsetof(::google::protobuf::ValueDefaultTypeInternal, stringvalue),
^ ~~~~~
external/androidndk/ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib64/clang/3.8.275480/include/stddef.h:120:24: note: expanded from macro 'offsetof'
^ ~
external/protobuf_archive/src/google/protobuf/struct.pb.cc:118:3: warning: offset of on non-POD type '::google::protobuf::ValueDefaultTypeInternal' [-Winvalid-offsetof]
offsetof(::google::protobuf::ValueDefaultTypeInternal, boolvalue),
^ ~~~
external/androidndk/ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib64/clang/3.8.275480/include/stddef.h:120:24: note: expanded from macro 'offsetof'
^ ~
external/protobuf_archive/src/google/protobuf/struct.pb.cc:119:3: warning: offset of on non-POD type '::google::protobuf::ValueDefaultTypeInternal' [-Winvalid-offsetof]
offsetof(::google::protobuf::ValueDefaultTypeInternal, structvalue),
^ ~~~~~
external/androidndk/ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib64/clang/3.8.275480/include/stddef.h:120:24: note: expanded from macro 'offsetof'
^ ~
external/protobuf_archive/src/google/protobuf/struct.pb.cc:120:3: warning: offset of on non-POD type '::google::protobuf::ValueDefaultTypeInternal' [-Winvalid-offsetof]
offsetof(::google::protobuf::ValueDefaultTypeInternal, listvalue),
^ ~~~
external/androidndk/ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib64/clang/3.8.275480/include/stddef.h:120:24: note: expanded from macro 'offsetof'
^ ~
6 warnings generated. ERROR: /home/xavier/.cache/bazel/_bazel_xavier/b4a3d41cf6e18601b16eb0b2e023194f/external/lmdb/BUILD:8:1: C++ compilation of rule '@lmdb//:lmdb' failed (Exit 1): clang failed: error executing command (cd /home/xavier/.cache/bazel/_bazel_xavier/b4a3d41cf6e18601b16eb0b2e023194f/execroot/org_tensorflow && \ exec env - \ LD_LIBRARY_PATH=/opt/ros/kinetic/lib:/usr/local/lib: \ PATH=/opt/ros/kinetic/bin:/home/xavier/Android/Sdk/ndk-bundle/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/aarch64-linux-android/bin/ld:/home/xavier/bin:/home/xavier/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin:/home/xavier/Android/Sdk/platform-tools:/home/xavier/android-ndk-r14b:/home/xavier/Bureau/developpement/androidscreencast/bin:/home/xavier/Bureau/developpement/androidscreencast:/home/xavier/Bureau/developpement/gerrit_tools:/home/xavier/android-studio/bin:/home/xavier/Bureau/developpement:/home/xavier/dev/common.tools/bin:/home/xavier/dev/gcc-arm-none-eabi-6-2017-q2-update/bin:/home/xavier/dev/dump_Cyril:/home/xavier/opt/gnu-mcu-eclipse/openocd/0.10.0-3-20170826-1813-dev/bin \ PWD=/proc/self/cwd \ external/androidndk/ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -gcc-toolchain external/androidndk/ndk/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64 -target aarch64-none-linux-android -ffunction-sections -funwind-tables -fstack-protector-strong -fpic -Wno-invalid-command-line-argument -Wno-unused-command-line-argument -no-canonical-prefixes -O2 -g -DNDEBUG -MD -MF bazel-out/arm64-v8a-opt/bin/external/lmdb/_objs/lmdb/external/lmdb/mdb.d -iquote external/lmdb -iquote bazel-out/arm64-v8a-opt/genfiles/external/lmdb -iquote external/bazel_tools -iquote bazel-out/arm64-v8a-opt/genfiles/external/bazel_tools -isystem external/bazel_tools/tools/cpp/gcc3 -w '--sysroot=external/androidndk/ndk/platforms/android-24/arch-arm64' -isystem external/androidndk/ndk/sources/cxx-stl/gnu-libstdc++/4.9/include -isystem external/androidndk/ndk/sources/cxx-stl/gnu-libstdc++/4.9/libs/arm64-v8a/include -isystem external/androidndk/ndk/sources/cxx-stl/gnu-libstdc++/4.9/include/backward -c external/lmdb/mdb.c -o bazel-out/arm64-v8a-opt/bin/external/lmdb/_objs/lmdb/external/lmdb/mdb.o) external/lmdb/mdb.c:4853:53: error: use of undeclared identifier 'PTHREAD_MUTEX_ROBUST' if (!rc) rc = pthread_mutexattr_setrobust(&mattr, PTHREAD_MUTEX_ROBUST); ^ 1 error generated. Target //tensorflow/contrib/android:libtensorflow_all.so failed to build INFO: Elapsed time: 205.387s, Critical Path: 14.32s FAILED: Build did NOT complete successfully ` It is strange not to find examples of compiled c++ API project on arm64 on internet. Does everybody use C API to use tensorflow on Android?
AFAIK most people use the java api provided by google, at snips we use the C api because we use rust
Are there examples of project who use and load in JNI the graph for image classification?
https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/lite/java/demo
as per the readme here, there is a C++ api bundled in the official tflite package, so you don't need to compile it yourself
Ok thank you I will try it. In the project there is no JNI file?
Anyone ever figure out what to do about PTHREAD_MUTEX_ROBUST on arm64?
PTHREAD_MUTEX_ROBUST issue is from the lmdb module. As per the thread https://www.openldap.org/lists/openldap-devel/201511/msg00010.html, android lacks the robust mutex support. Hence, this can be turned of with -DMDB_USE_ROBUST=0 option.
A defines option can be added under third_party/lmdb.BUILD file to define MDB_USE_ROBUST to 0 in case of android builds through bazel
Somthing like
cc_library( ..., ..., defines = select({ ":android": [ "MDB_USE_ROBUST=0", ], "//conditions:default": [], }), ) Hope this helps
Edit: I also see that android BUILD is not configured for lmdb, so add the following in the file
config_setting( name = "android", values = {"crosstool_top": "//external:android/crosstool"}, )
Hello,
I try to use the compile_android.sh file to be able to compile for arm64-v8a in cpp.
I modify the compile_android.sh file like this:
When I compile it I get that error:
How can I compile it for arm64-v8a in cpp?