I did as shown in the tensorflow document: https://www.tensorflow.org/how_tos/adding_an_op/#attrs
- get the source code from https://github.com/tensorflow/tensorflow
- add a
zero_out.cc
file undertensorflow/core/user_ops/
- add a
BUILD
file undertensorflow/core/user_ops/
- run in terminal:
$ bazel build -c opt //tensorflow/core/user_ops:zero_out.so
INFO: Found 1 target...
Target //tensorflow/core/user_ops:zero_out.so up-to-date:
bazel-bin/tensorflow/core/user_ops/zero_out.so
INFO: Elapsed time: 0.125s, Critical Path: 0.00s
But when I run the following code in python, error comes:
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcudnn.so locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcurand.so locally
>>> zero_out_module = tf.load_op_library('zero_out.so')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/yc/tfenv/local/lib/python2.7/site-packages/tensorflow/python/framework/load_library.py", line 64, in load_op_library
None, None, error_msg, error_code)
tensorflow.python.framework.errors_impl.NotFoundError: zero_out.so: cannot open shared object file: No such file or directory
Bazel would generate the op library into the
bazel-bin
folder.As you used bazel to build ot, you should try to load it from there: