custom-op icon indicating copy to clipboard operation
custom-op copied to clipboard

Problem inserting external library to custom-ops when building a pip package

Open JonathanGoorBlink opened this issue 5 years ago • 1 comments

Hi all, I'm working on a project and I'd like to use the external C++ library in my TF custom ops. In order for me to do this I've tried the following:

I've added the following to the custom-ops WORKSPACE:

load("//tf:tf_configure.bzl", "tf_configure")
load("//gpu:cuda_configure.bzl", "cuda_configure")

tf_configure(name = "local_config_tf")

cuda_configure(name = "local_config_cuda")

new_local_repository(
    name = "custom_ops_logic",
    path = "../custom_ops_logic/",
    build_file = "custom_ops_logic.BUILD",
)

I've also added custom_ops_logic.BUILD in the custom-ops dir:

cc_import(
    name = "custom_ops_logic/zero_out",
    hdrs = ["zero_out_logic/zero_out_logic.h"],
    shared_library = "build/zero_out_logic/libzero_out_logic.so",
    visibility = ["//visibility:public"],
)

Finally, I've added custom_ops_logic/zero_out into the BUILD file of the zero_out custom op. Now, I've succeeded to build the following:

bazel build :build_pip_pkg
bazel-bin/build_pip_pkg artifacts
pip install artifacts/*.whl

But when I try to run the test pip package: python -c "import tensorflow as tf;import tensorflow_zero_out;print(tensorflow_zero_out.zero_out([[1,2], [3,4]]))"'

I get the following error:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/tensorflow_zero_out/__init__.py", line 19, in <module>
    from tensorflow_zero_out.python.ops.zero_out_ops import zero_out
  File "/usr/local/lib/python2.7/dist-packages/tensorflow_zero_out/python/ops/zero_out_ops.py", line 25, in <module>
    resource_loader.get_path_to_datafile('_zero_out_ops.so'))
  File "/usr/local/lib/python2.7/dist-packages/tensorflow_core/python/framework/load_library.py", line 57, in load_op_library
    lib_handle = py_tf.TF_LoadLibrary(library_filename)
tensorflow.python.framework.errors_impl.NotFoundError: libzero_out_logic.so: cannot open shared object file: No such file or directory

I'm new to bazel so there's something I probably don't get (tried changing the BUILD files with no success).

Thanks

JonathanGoorBlink avatar Jul 02 '20 06:07 JonathanGoorBlink

Did you include your new directory in the Manifest.in?

schellmi42 avatar Jul 02 '20 14:07 schellmi42