Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't bazel build benchmark_model with quantization deps due to -lpthread linking error #4529

Closed
dwightcrow opened this issue Sep 22, 2016 · 2 comments
Assignees

Comments

@dwightcrow
Copy link

dwightcrow commented Sep 22, 2016

Trying to build //tensorflow/tools/benchmark:benchmark_model per instructions at this stackoveflow post http://stackoverflow.com/questions/37953369/tensorflow-quantized-graph-for-android. Am getting error that cannot find -lpthread despite my belief that lib is unneeded and best efforts to remove it.

external/androidndk/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lpthread
collect2: error: ld returned 1 exit status

//tensorflow/tools/benchmark/BUILD cc_binary

deps = [":benchmark_model_lib",
        "//tensorflow/contrib/quantization/kernels:quantized_ops",
            ],

//tensorflow/contrib/quantization/kernels/BUILD:

deps = [
    "//tensorflow/contrib/quantization:cc_array_ops",
    "//tensorflow/contrib/quantization:cc_math_ops",
    "//tensorflow/contrib/quantization:cc_nn_ops",
    #"//tensorflow/core",
    #"//tensorflow/core:framework",
    #"//tensorflow/core:lib",
    #"//tensorflow/core/kernels:concat_lib_hdrs",
    #"//tensorflow/core/kernels:conv_ops",
    #"//tensorflow/core/kernels:eigen_helpers",
    #"//tensorflow/core/kernels:ops_util",
    #"//tensorflow/core/kernels:pooling_ops",
    "//third_party/eigen3",
    "@gemmlowp//:eight_bit_int_gemm",
],

Then run:
bazel build -c opt --cxxopt='-std=gnu++11'--crosstool_top=//external:android/crosstool --cpu=armeabi-v7a --host_crosstool_top=@bazel_tools//tools/cpp:toolchain tensorflow/tools/benchmark:benchmark_model --verbose_failures

Which (with following all other instructions in linked post) succeeds with the exception that it fails to link against pthread.

I've tried removing -lpthread in tensorflow/tensorflow.bzl, tensorflow/tools/proto_text/BUILD, tensorflow/tools/proto_text/BUILD, and tensorflow/cc/BUILD but this still results in -lpthread being linked to in final compilation.

I've also looked at the fixes such as this one #419 which either remove -lpthread from google protobuf or link to the dummy lib but these seem to only apply to earlier versions of TensorFlow.

Apologies if this is a basic config error, I'm new to Bazel and am pretty stuck. benchmark_model and quantize_graph both compile well independently but not yet for me when combined.

What related GitHub issues or StackOverflow threads have you found by searching the web for your problem?

http://stackoverflow.com/questions/37953369/tensorflow-quantized-graph-for-android
#419
protocolbuffers/protobuf#1373

Environment info

Operating System: Ubuntu 14.04

Installed version of CUDA and cuDNN:
(ml) socialh@socialh:~$ echo $LD_LIBRARY_PATH
/home/socialh/cuda/lib64:/usr/local/cuda/lib64:

(ml) socialh@socialh:~/otf$ ll /usr/local/cuda/lib/libcud*
-rw-r--r-- 1 root root 189170 Aug 31 15:22 /usr/local/cuda/lib/libcudadevrt.a
lrwxrwxrwx 1 root root 16 Aug 31 15:22 /usr/local/cuda/lib/libcudart.so -> libcudart.so.7.5*
lrwxrwxrwx 1 root root 19 Aug 31 15:22 /usr/local/cuda/lib/libcudart.so.7.5 -> libcudart.so.7.5.18*
-rwxr-xr-x 1 root root 311596 Aug 31 15:22 /usr/local/cuda/lib/libcudart.so.7.5.18*
-rw-r--r-- 1 root root 558020 Aug 31 15:22 /usr/local/cuda/lib/libcudart_static.a

(ml) socialh@socialh:~$ ll /home/socialh/cuda/lib64/
lrwxrwxrwx 1 socialh socialh 13 Jun 10 01:20 libcudnn.so -> libcudnn.so.5*
lrwxrwxrwx 1 socialh socialh 17 Jun 10 01:20 libcudnn.so.5 -> libcudnn.so.5.1.3*
-rwxr-xr-x 1 socialh socialh 60696704 Jun 10 01:18 libcudnn.so.5.1.3*
-rw-r--r-- 1 socialh socialh 59715990 Jun 10 01:18 libcudnn_static.a

If installed from source, provide
git rev-parse head
640353d
bazel version
Build target: bazel-out/local-fastbuild/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Thu Jan 01 00:00:00 1970 (0)
Build timestamp: Thu Jan 01 00:00:00 1970 (0)
Build timestamp as int: 0

If possible, provide a minimal reproducible example (We usually don't have time to read hundreds of lines of your code)

bazel build -c opt --cxxopt '-std=gnu++11' --crosstool_top=//external:android/crosstool --cpu=armeabi-v7a --host_crosstool_top=@bazel_tools//tools/cpp:toolchain tensorflow/tools/benchmark:benchmark_model --verbose_failures
with other steps taken in first StackOverflow example

What other attempted solutions have you tried?

Tried removing all -lpthreads references, also tried removing lpthreads in bazel-out files but did not help.

Logs or other output that would be helpful

(If logs are large, please upload as attachment or provide link).

@andrewharp andrewharp self-assigned this Sep 22, 2016
@andrewharp
Copy link
Contributor

andrewharp commented Sep 22, 2016

To work around the pthread issue, use the @gemmlowp//:eight_bit_int_gemm_sources filegroup in your srcs rather than the cc_library target as a dep.

e.g.:

cc_library(
    name = "android_tensorflow_lib",
    srcs = if_android([":android_op_registrations_and_gradients",
        "//tensorflow/contrib/quantization:android_ops",
        "//tensorflow/contrib/quantization/kernels:android_ops",
        "@gemmlowp//:eight_bit_int_gemm_sources"]),
    copts = tf_copts() + ["-Iexternal/gemmlowp"],
    linkopts = ["-lz"],
    tags = [
        "manual",
        "notap",
    ],
    visibility = ["//visibility:public"],
    deps = [
        ":android_tensorflow_lib_lite",
        ":protos_cc",
        "//tensorflow/core/kernels:android_tensorflow_kernels",
        "//third_party/eigen3",
    ],
    alwayslink = 1,
)

@dwightcrow
Copy link
Author

Worked great, thanks so much @andrewharp!!!!

Really appreciate prompt reply, transcribed answer (along with git pull --recurse-submodules and removing all earlier "fixes") to StackOverflow so hopefully will prevent other n00bs hitting you with same question.

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants