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

Shared library libtensorflowlite.so cannot be found after building from source #33980

Closed
DocDriven opened this issue Nov 4, 2019 · 4 comments
Assignees
Labels
comp:lite TF Lite related issues type:support Support issues

Comments

@DocDriven
Copy link

DocDriven commented Nov 4, 2019

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): yes
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 18.04 x86 64 bit
  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device:
  • TensorFlow installed from (source or binary): docker image devel-gpu-py3
  • TensorFlow version (use command below):
  • Python version: 3.6
  • Bazel version (if compiling from source): 0.26.1
  • GCC/Compiler version (if compiling from source): 7.4.0
  • CUDA/cuDNN version:
  • GPU model and memory:

Describe the current behavior

Goal is to build TF Lite with the extended runtime to support non-tf-ops. For this I followed the steps from the official guide (https://www.tensorflow.org/lite/guide/ops_select#c). I added the missing flex delegate dependencies to /tensorflow_src/tensorflow/lite/BUILD:

tflite_cc_shared_object(
    name = "libtensorflowlite.so",
    linkopts = select({
        "//tensorflow:macos": [
            "-Wl,-exported_symbols_list,$(location //tensorflow/lite:tflite_exported_symbols.lds)",
            "-Wl,-install_name,@rpath/libtensorflowlite.so",
        ],
        "//tensorflow:windows": [],
        "//conditions:default": [
            "-z defs",
            "-Wl,--version-script,$(location //tensorflow/lite:tflite_version_script.lds)",
        ],
    }),
    deps = [
        ":framework",
        ":tflite_exported_symbols.lds",
        ":tflite_version_script.lds",
        "//tensorflow/lite/kernels:builtin_ops",
        "//tensorflow/lite/delegates/flex:delegate",
    ],
)

I ran the configure script with defaults only and the bazel build command with the mentioned options:

bazel build --config=monolithic --define=with_select_tf_ops=true -c opt //tensorflow/lite:libtensorflowlite.so

This builds without errors. When building my C++ app, it also compiles without errors. But when executing the binary, I get an error:

./myapp: error while loading shared libraries: libtensorflowlite.so: cannot open shared object file: No such file or directory

This is not a path problem because it lies in the same directory as my other .so files. The app works when using the static library generated by the shell scripts in the same directory.

Describe the expected behavior

The app should run just fine with the paths specified.

Other info / logs

.tf_configure.bazel_rc

build --action_env PYTHON_BIN_PATH="/usr/local/bin/python"
build --action_env PYTHON_LIB_PATH="/usr/local/lib/python3.6/dist-packages"
build --python_path="/usr/local/bin/python"
build:xla --define with_xla_support=true
build --config=xla
build --config=tensorrt
build --action_env TF_CUDA_VERSION="10.0"
build --action_env TF_CUDNN_VERSION="7"
build --action_env CUDA_TOOLKIT_PATH="/usr/local/cuda-10.0"
build --action_env TF_CUDA_COMPUTE_CAPABILITIES="3.5,5.2,6.0,6.1,7.0"
build --action_env LD_LIBRARY_PATH="/usr/local/cuda/extras/CUPTI/lib64:/usr/local/cuda/lib64:/usr/local/nvidia/lib:/usr/local/nvidia/lib64"
build --action_env GCC_HOST_COMPILER_PATH="/usr/bin/gcc"
build --config=cuda
build:opt --copt=-march=native
build:opt --copt=-Wno-sign-compare
build:opt --host_copt=-march=native
build:opt --define with_default_optimizations=true
test --flaky_test_attempts=3
test --test_size_filters=small,medium
test --test_tag_filters=-benchmark-test,-no_oss,-oss_serial
test --build_tag_filters=-benchmark-test,-no_oss
test --test_tag_filters=-no_gpu
test --build_tag_filters=-no_gpu
test --test_env=LD_LIBRARY_PATH
build --action_env TF_CONFIGURE_IOS="0"
@oanush oanush self-assigned this Nov 5, 2019
@oanush oanush added comp:lite TF Lite related issues type:support Support issues stat:awaiting tensorflower Status - Awaiting response from tensorflower labels Nov 5, 2019
@freedomtan
Copy link
Contributor

Building a shared library with --config=monolithic, which means to build things static mostly, looks weird. Please remove it and try again.

@oanush oanush assigned jdduke and unassigned oanush Nov 6, 2019
@oanush oanush added stat:awaiting tensorflower Status - Awaiting response from tensorflower and removed stat:awaiting tensorflower Status - Awaiting response from tensorflower labels Nov 6, 2019
@DocDriven
Copy link
Author

@freedomtan
Without the flag, the library cannot be built anymore. Seems this is mandatory if compiling the extended lite runtime.

@jdduke
Copy link
Member

jdduke commented Nov 7, 2019

Right, monolithic is expected here, this looks like #33959. To confirm, would you mind commenting out build --incompatible_remove_legacy_whole_archive in tensorflow/.bazelrc and see if that makes a difference?

@DocDriven
Copy link
Author

DocDriven commented Nov 7, 2019

@jdduke: thanks for the hint. After some testing, I got varying results depending on the docker image used:

Using the devel-gpu-py3 image (even on a non-GPU system) works if you add the current path of the .so to LD_LIBRARY_PATH via export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/custom/path/to/so. This causes a lot of warnings to appear during the execution of the app (missing cuda and libcudnn), but no errors.

Using devel and devel-py3, the linker does not seem to be able to resolve the symbols within the .so file. This can be worked around by using the hack you suggested. For the images I downloaded, however, the file is located in /tensorflow_src/.bazelrc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:lite TF Lite related issues type:support Support issues
Projects
None yet
Development

No branches or pull requests

5 participants