Skip to content

Unable to compile custom ops #1044

@VishalBalaji321

Description

@VishalBalaji321

Hi,

I am trying to compile custom ops as mentioned in README.md but I am running into errors.
Initially there was a platform mismatch, so I commented out the windows flag in keras_cv/custom_ops/BUILD file. The modified BUILD file looks like this:

licenses(["notice"])  # Apache 2.0

package(default_visibility = ["//visibility:public"])

# config_setting(
#     name = "windows",
#     constraint_values = ["@bazel_tools//platforms:windows"],
# )

cc_library(
    name = "box_util",
    srcs = ["box_util.cc"],
    hdrs = ["box_util.h"],
    deps = [
        "@local_config_tf//:libtensorflow_framework",
        "@local_config_tf//:tf_header_lib",
    ],
    copts = select({
        # ":windows": ["/DEIGEN_STRONG_INLINE=inline", "-DTENSORFLOW_MONOLITHIC_BUILD", "/DPLATFORM_WINDOWS", "/DEIGEN_HAS_C99_MATH", "/DTENSORFLOW_USE_EIGEN_THREADPOOL", "/DEIGEN_AVOID_STL_ARRAY", "/Iexternal/gemmlowp", "/wd4018", "/wd4577", "/DNOGDI", "/UTF_COMPILE_LIBRARY"],
        "//conditions:default": ["-pthread", "-std=c++17"],
    }),
)

cc_binary(
    name = '_keras_cv_custom_ops.so',
    srcs = [
        "kernels/pairwise_iou_kernel.cc",
        "ops/pairwise_iou_op.cc"
    ],
    linkshared = 1,
    deps = [
        "@local_config_tf//:libtensorflow_framework",
        "@local_config_tf//:tf_header_lib",
        ":box_util",
    ],
    features = select({
        #":windows": ["windows_export_all_symbols"],
        "//conditions:default": [],
    }),
    copts = select({
        #":windows": ["/DEIGEN_STRONG_INLINE=inline", "-DTENSORFLOW_MONOLITHIC_BUILD", "/DPLATFORM_WINDOWS", "/DEIGEN_HAS_C99_MATH", "/DTENSORFLOW_USE_EIGEN_THREADPOOL", "/DEIGEN_AVOID_STL_ARRAY", "/Iexternal/gemmlowp", "/wd4018", "/wd4577", "/DNOGDI", "/UTF_COMPILE_LIBRARY"],
        "//conditions:default": ["-pthread", "-std=c++17"],
    }),
)

Now I am able to compile the custom ops and build the wheel file, but I am getting errors when I import keras_cv package:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/code/additional_build/keras-cv/keras_cv/__init__.py", line 25, in <module>
    from keras_cv import models
  File "/code/additional_build/keras-cv/keras_cv/models/__init__.py", line 51, in <module>
    from keras_cv.models.object_detection.faster_rcnn import FasterRCNN
  File "/code/additional_build/keras-cv/keras_cv/models/object_detection/faster_rcnn.py", line 23, in <module>
    from keras_cv.layers.object_detection.roi_sampler import _ROISampler
  File "/code/additional_build/keras-cv/keras_cv/layers/object_detection/roi_sampler.py", line 19, in <module>
    from keras_cv.ops import box_matcher
  File "/code/additional_build/keras-cv/keras_cv/ops/__init__.py", line 16, in <module>
    from keras_cv.ops.point_cloud import _box_area
  File "/code/additional_build/keras-cv/keras_cv/ops/point_cloud.py", line 20, in <module>
    custom_ops = load_library.load_op_library(
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/framework/load_library.py", line 54, in load_op_library
    lib_handle = py_tf.TF_LoadLibrary(library_filename)
tensorflow.python.framework.errors_impl.NotFoundError: /code/additional_build/keras-cv/keras_cv/ops/../custom_ops/_keras_cv_custom_ops.so: undefined symbol: _ZN10tensorflow7strings6StrCatB5cxx11ERKNS0_8AlphaNumES3_

Tried in python3.10 and python3.8, with TF 2.9 and TF 2.11 with the latest BAZEL build version (v7). Getting same issue in all the configurations.

I want IoU3D operation for my tf project. If there is a simpler way to compile just IoU3D op, I would be really happy to know about it 😁

Cheers,
Vishal Balaji

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions