diff options
Diffstat (limited to 'tensorflow/contrib/cmake/tf_python.cmake')
-rwxr-xr-x[-rw-r--r--] | tensorflow/contrib/cmake/tf_python.cmake | 107 |
1 files changed, 99 insertions, 8 deletions
diff --git a/tensorflow/contrib/cmake/tf_python.cmake b/tensorflow/contrib/cmake/tf_python.cmake index 2c21154217..2ecc08f421 100644..100755 --- a/tensorflow/contrib/cmake/tf_python.cmake +++ b/tensorflow/contrib/cmake/tf_python.cmake @@ -623,12 +623,7 @@ add_custom_command( COMMENT "Running SWIG to generate Python wrappers" VERBATIM ) -# pywrap_tensorflow_internal is a shared library containing all of the -# TensorFlow runtime and the standard ops and kernels. These are installed into -# tf_python/tensorflow/python/. -# TODO(mrry): Refactor this to expose a framework library that -# facilitates `tf.load_op_library()`. -add_library(pywrap_tensorflow_internal SHARED +set (pywrap_tensorflow_internal_src "${tensorflow_source_dir}/tensorflow/python/client/tf_session_helper.h" "${tensorflow_source_dir}/tensorflow/python/client/tf_session_helper.cc" "${tensorflow_source_dir}/tensorflow/python/framework/cpp_shape_inference.h" @@ -652,6 +647,55 @@ add_library(pywrap_tensorflow_internal SHARED "${tensorflow_source_dir}/tensorflow/c/tf_status_helper.cc" "${tensorflow_source_dir}/tensorflow/c/tf_status_helper.h" "${CMAKE_CURRENT_BINARY_DIR}/pywrap_tensorflow_internal.cc" +) + +if(WIN32) + # Windows: build a static library with the same objects as tensorflow.dll. + # This can be used to build for a standalone exe and also helps us to + # find all symbols that need to be exported from the dll which is needed + # to provide the tensorflow c/c++ api in tensorflow.dll. + # From the static library we create the def file with all symbols that need to + # be exported from tensorflow.dll. Because there is a limit of 64K sybmols + # that can be exported, we filter the symbols with a python script to the namespaces + # we need. + # + add_library(pywrap_tensorflow_internal_static STATIC + ${pywrap_tensorflow_internal_src} + $<TARGET_OBJECTS:tf_core_lib> + $<TARGET_OBJECTS:tf_core_cpu> + $<TARGET_OBJECTS:tf_core_framework> + $<TARGET_OBJECTS:tf_core_ops> + $<TARGET_OBJECTS:tf_core_direct_session> + $<TARGET_OBJECTS:tf_tools_transform_graph_lib> + $<$<BOOL:${tensorflow_ENABLE_GRPC_SUPPORT}>:$<TARGET_OBJECTS:tf_core_distributed_runtime>> + $<TARGET_OBJECTS:tf_core_kernels> + $<$<BOOL:${tensorflow_ENABLE_GPU}>:$<TARGET_OBJECTS:tf_core_kernels_cpu_only>> + $<$<BOOL:${tensorflow_ENABLE_GPU}>:$<TARGET_OBJECTS:tf_stream_executor>> + ) + target_include_directories(pywrap_tensorflow_internal_static PUBLIC + ${PYTHON_INCLUDE_DIR} + ${NUMPY_INCLUDE_DIR} + ) + target_link_libraries(pywrap_tensorflow_internal_static + tf_protos_cc + tf_python_protos_cc + ) + set(pywrap_tensorflow_deffile "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/pywrap_tensorflow.def") + set_source_files_properties(${pywrap_tensorflow_deffile} PROPERTIES GENERATED TRUE) + + add_custom_command(TARGET pywrap_tensorflow_internal_static POST_BUILD + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/create_def_file.py + --input $<TARGET_FILE:pywrap_tensorflow_internal_static> + --output ${pywrap_tensorflow_deffile} + ) +endif(WIN32) + + +# pywrap_tensorflow_internal is a shared library containing all of the +# TensorFlow runtime and the standard ops and kernels. These are installed into +# tf_python/tensorflow/python/. +add_library(pywrap_tensorflow_internal SHARED + ${pywrap_tensorflow_internal_src} $<TARGET_OBJECTS:tf_core_lib> $<TARGET_OBJECTS:tf_core_cpu> $<TARGET_OBJECTS:tf_core_framework> @@ -662,7 +706,13 @@ add_library(pywrap_tensorflow_internal SHARED $<TARGET_OBJECTS:tf_core_kernels> $<$<BOOL:${tensorflow_ENABLE_GPU}>:$<TARGET_OBJECTS:tf_core_kernels_cpu_only>> $<$<BOOL:${tensorflow_ENABLE_GPU}>:$<TARGET_OBJECTS:tf_stream_executor>> + ${pywrap_tensorflow_deffile} ) + +if(WIN32) + add_dependencies(pywrap_tensorflow_internal pywrap_tensorflow_internal_static) +endif(WIN32) + target_include_directories(pywrap_tensorflow_internal PUBLIC ${PYTHON_INCLUDE_DIR} ${NUMPY_INCLUDE_DIR} @@ -675,6 +725,44 @@ target_link_libraries(pywrap_tensorflow_internal ${PYTHON_LIBRARIES} ) +if(WIN32) + # include contrib/rnn as .so + # + set(tf_gru_srcs + "${tensorflow_source_dir}/tensorflow/contrib/rnn/kernels/blas_gemm.cc" + "${tensorflow_source_dir}/tensorflow/contrib/rnn/kernels/blas_gemm.h" + "${tensorflow_source_dir}/tensorflow/contrib/rnn/kernels/gru_ops.cc" + "${tensorflow_source_dir}/tensorflow/contrib/rnn/kernels/gru_ops.h" + "${tensorflow_source_dir}/tensorflow/contrib/rnn/ops/gru_ops.cc" + ) + set(tf_gru_gpu_srcs + "${tensorflow_source_dir}/tensorflow/contrib/rnn/kernels/gru_ops_gpu.cu.cc" + ) + + set(tf_lstm_srcs + "${tensorflow_source_dir}/tensorflow/contrib/rnn/kernels/blas_gemm.cc" + "${tensorflow_source_dir}/tensorflow/contrib/rnn/kernels/blas_gemm.h" + "${tensorflow_source_dir}/tensorflow/contrib/rnn/kernels/lstm_ops.cc" + "${tensorflow_source_dir}/tensorflow/contrib/rnn/kernels/lstm_ops.h" + "${tensorflow_source_dir}/tensorflow/contrib/rnn/ops/lstm_ops.cc" + ) + set(tf_lstm_gpu_srcs + "${tensorflow_source_dir}/tensorflow/contrib/rnn/kernels/lstm_ops_gpu.cu.cc" + ) + + AddUserOps(TARGET _gru_ops + SOURCES "${tf_gru_srcs}" + GPUSOURCES ${tf_gru_gpu_srcs} + DEPENDS pywrap_tensorflow_internal tf_python_ops + DISTCOPY ${CMAKE_CURRENT_BINARY_DIR}/tf_python/tensorflow/contrib/rnn/python/ops/) + + AddUserOps(TARGET _lstm_ops + SOURCES "${tf_lstm_srcs}" + GPUSOURCES ${tf_lstm_gpu_srcs} + DEPENDS pywrap_tensorflow_internal tf_python_ops + DISTCOPY ${CMAKE_CURRENT_BINARY_DIR}/tf_python/tensorflow/contrib/rnn/python/ops/) +endif(WIN32) + ############################################################ # Build a PIP package containing the TensorFlow runtime. ############################################################ @@ -684,14 +772,17 @@ add_dependencies(tf_python_build_pip_package tensorboard_copy_dependencies tf_python_copy_scripts_to_destination tf_python_touchup_modules - tf_python_ops) + tf_python_ops + tf_extension_ops) add_custom_command(TARGET tf_python_build_pip_package POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${tensorflow_source_dir}/tensorflow/tools/pip_package/setup.py ${CMAKE_CURRENT_BINARY_DIR}/tf_python/) if(WIN32) add_custom_command(TARGET tf_python_build_pip_package POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/pywrap_tensorflow_internal.dll - ${CMAKE_CURRENT_BINARY_DIR}/tf_python/tensorflow/python/_pywrap_tensorflow_internal.pyd) + ${CMAKE_CURRENT_BINARY_DIR}/tf_python/tensorflow/python/_pywrap_tensorflow_internal.pyd + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/pywrap_tensorflow_internal.lib + ${CMAKE_CURRENT_BINARY_DIR}/tf_python/tensorflow/python/) else() add_custom_command(TARGET tf_python_build_pip_package POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/libpywrap_tensorflow_internal.so |