Last active
September 13, 2019 16:11
-
-
Save guschmue/2908e4411edc2faef6ddfe87a2ce4a1d to your computer and use it in GitHub Desktop.
example how to build a user_op for windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# example how to build a user_op for windows | |
# | |
# 1. save this file as tensorflow/contrib/cmake/tf_user_ops.cmake | |
# 2. append "include(tf_user_ops.cmake)" to CMakeLists.txt | |
# 3. call cmake (see tensorflow/contrib/cmake/README.md), ie: | |
# cmake %cmake_dir% -A x64 -DCMAKE_BUILD_TYPE=RelWithDebInfo -DPYTHON_EXECUTABLE=%PY%\python.exe | |
# -DPYTHON_LIBRARIES=%PY%\libs\python35.lib -DSWIG_EXECUTABLE=c:\local\swigwin-3.0.10\swig.exe | |
# -Dtensorflow_BUILD_PYTHON_TESTS=ON | |
# 4. you need to build the source tree once to generate all header files needed, ie: | |
# MSBuild /p:Configuration=RelWithDebInfo tf_python_build_pip_package.vcxproj | |
# 5. build your user_ops | |
# MSBuild /p:Configuration=RelWithDebInfo ackermann_ops.vcxproj | |
# or if you know what you are doing you can skip checking dependencies: | |
# MSBuild /p:Configuration=RelWithDebInfo /p:BuildProjectReferences=false ackermann_ops.vcxproj | |
# | |
set(tf_ackermanm_srcs | |
"${tensorflow_source_dir}/tensorflow/user_ops/ackermann_op.cc" | |
) | |
set(tf_ackermann_gpu_srcs | |
) | |
# TODO: target_dir should be under ${CMAKE_CURRENT_BINARY_DIR} | |
set(target_dir | |
"${tensorflow_source_dir}/tensorflow/user_ops" | |
) | |
AddUserOps(TARGET ackermann_ops | |
SOURCES ${tf_ackermanm_srcs} | |
GPUSOURCES ${tf_ackermann_gpu_srcs} | |
DEPENDS pywrap_tensorflow_internal tf_python_ops | |
DISTCOPY ${target_dir}) | |
add_custom_command(TARGET ackermann_ops POST_BUILD | |
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:ackermann_ops> "${target_dir}/ackermann_op.so") |
@guyeng0 please check the file name 'ackermann_op.so', in windows the postfix should be '.dll'
Hi, I encountered an error when config the cMake, it shows ‘unknown cMake command ‘AddUserOps’. Any ideas How to solve this? thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello and thank you for these instructions.
I tried following these, built and installed tensorflow but when running python and then loading the dll using:
tf.load_op_library(r'<my_path>\tensorflow\tensorflow\user_ops\ackermann_op.so')
I get the following error:
If I remove the
OP_REQUIRES_OK(context, context->allocate_output(0, TensorShape(), &output_tensor));
line but instead call context->allocate_output(0, TensorShape(), &output_tensor) directly the dll manages to load.
I've looked at the dll using dependency walker and it seems to me that CtxFailureWithWarning is in the dll so I have no idea why loading the dll returns this error.
I'll appreciate any help you might have.
Thank you,
Guy