Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] TensorFlow support #189

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,9 @@ if(MSVC)
target_compile_options(redner PRIVATE /W3 /wd4244 /wd4146 /wd4244 /wd4305 /wd4334 /wd4996)
endif()

if(NOT WIN32)
find_package(TensorFlow)
if(TensorFlow_FOUND)
add_subdirectory(pyredner_tensorflow/custom_ops)
else()
message(INFO " Building without TensorFlow support (not found)")
endif()
find_package(TensorFlow)
if(TensorFlow_FOUND)
add_subdirectory(pyredner_tensorflow/custom_ops)
else()
message(INFO " Building without TensorFlow support (not found)")
endif()
11 changes: 9 additions & 2 deletions pyredner_tensorflow/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
import tensorflow as tf
try:
import redner
Expand Down Expand Up @@ -29,10 +30,16 @@
import os.path

if tf.__cxx11_abi_flag__ == 0:
__data_ptr_module = tf.load_op_library(os.path.join(os.path.dirname(redner.__file__), 'libredner_tf_data_ptr_no_cxx11_abi.so'))
if sys.platform != 'win32':
__data_ptr_module = tf.load_op_library(os.path.join(os.path.dirname(redner.__file__), 'libredner_tf_data_ptr_no_cxx11_abi.so'))
else:
__data_ptr_module = tf.load_op_library(os.path.join(os.path.dirname(redner.__file__), 'redner_tf_data_ptr_no_cxx11_abi.dll'))
else:
assert(tf.__cxx11_abi_flag__ == 1)
__data_ptr_module = tf.load_op_library(os.path.join(os.path.dirname(redner.__file__), 'libredner_tf_data_ptr_cxx11_abi.so'))
if sys.platform != 'win32':
__data_ptr_module = tf.load_op_library(os.path.join(os.path.dirname(redner.__file__), 'libredner_tf_data_ptr_cxx11_abi.so'))
else:
__data_ptr_module = tf.load_op_library(os.path.join(os.path.dirname(redner.__file__), 'redner_tf_data_ptr_cxx11_abi.dll'))

def data_ptr(tensor):
addr_as_uint64 = __data_ptr_module.data_ptr(tensor)
Expand Down
8 changes: 8 additions & 0 deletions pyredner_tensorflow/custom_ops/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ include_directories(SYSTEM ${TensorFlow_INCLUDE_DIR})

# Compile two versions of the library
add_library(redner_tf_data_ptr_cxx11_abi SHARED data_ptr.cc)
if(WIN32)
# ignore C4596
target_compile_options(redner_tf_data_ptr_cxx11_abi PRIVATE /W3)
endif()
set_target_properties(redner_tf_data_ptr_cxx11_abi PROPERTIES COMPILE_FLAGS -D_GLIBCXX_USE_CXX11_ABI=1)
set_target_properties(redner_tf_data_ptr_cxx11_abi PROPERTIES LINK_FLAGS -D_GLIBCXX_USE_CXX11_ABI=1)
if(APPLE)
Expand All @@ -20,6 +24,10 @@ endif()
target_link_libraries(redner_tf_data_ptr_cxx11_abi ${TensorFlow_LIBRARY})

add_library(redner_tf_data_ptr_no_cxx11_abi SHARED data_ptr.cc)
if(WIN32)
# ignore C4596
target_compile_options(redner_tf_data_ptr_no_cxx11_abi PRIVATE /W3)
endif()
set_target_properties(redner_tf_data_ptr_no_cxx11_abi PROPERTIES COMPILE_FLAGS -D_GLIBCXX_USE_CXX11_ABI=0)
set_target_properties(redner_tf_data_ptr_no_cxx11_abi PROPERTIES LINK_FLAGS -D_GLIBCXX_USE_CXX11_ABI=0)
if(APPLE)
Expand Down
5 changes: 5 additions & 0 deletions pyredner_tensorflow/custom_ops/data_ptr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
#include <stdint.h>
#include <climits>

#define EXPAND(x) x

#define TF_NEW_ID_FOR_INIT_2(m, c, ...) EXPAND(m(c, __VA_ARGS__)) // L145 selective_registration.h
#define TF_EXTRACT_KERNEL_NAME_IMPL(m, ...) EXPAND(m(__VA_ARGS__)) // L1431 op_kernel.h

using namespace tensorflow;

/* Tensorflow custom ops does not allow parameter types of list of
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def build_extension(self, ext):
import torch
if torch.cuda.is_available():
build_with_cuda = True
if tf_spec is not None and sys.platform != 'win32':
if tf_spec is not None:
packages.append('pyredner_tensorflow')
if not build_with_cuda:
import tensorflow as tf
Expand Down
2 changes: 1 addition & 1 deletion tests_tensorflow/test_g_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
pyredner.imwrite(normal, 'results/test_g_buffer/target_normal.png', normalize = True)
# Read the target image we just saved.
target_depth = pyredner.imread('results/test_g_buffer/target_depth.exr')
target_depth = target_depth[:, :, 0]
# target_depth = target_depth[:, :, 0]
target_normal = pyredner.imread('results/test_g_buffer/target_normal.exr')

with tf.device(pyredner.get_device_name()):
Expand Down