Skip to content

Instantly share code, notes, and snippets.

@Sergio0694
Last active June 22, 2018 15:24
Show Gist options
  • Save Sergio0694/28a1e197e3f05e933286c0927c2f5752 to your computer and use it in GitHub Desktop.
Save Sergio0694/28a1e197e3f05e933286c0927c2f5752 to your computer and use it in GitHub Desktop.
Test .cmake file to build a custom op
# 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/core/user_ops/add_one.cc"
)
set(tf_ackermann_gpu_srcs
"${tensorflow_source_dir}/tensorflow/core/user_ops/add_one_kernel.cu.cc"
)
# TODO: target_dir should be under ${CMAKE_CURRENT_BINARY_DIR}
set(target_dir
"${tensorflow_source_dir}/tensorflow/core/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.dll")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment