diff --git a/CMakeLists.txt b/CMakeLists.txt index a42480de..845f10f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/pyredner_tensorflow/__init__.py b/pyredner_tensorflow/__init__.py index 97166073..3fd3751d 100644 --- a/pyredner_tensorflow/__init__.py +++ b/pyredner_tensorflow/__init__.py @@ -1,3 +1,4 @@ +import sys import tensorflow as tf try: import redner @@ -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) diff --git a/pyredner_tensorflow/custom_ops/CMakeLists.txt b/pyredner_tensorflow/custom_ops/CMakeLists.txt index f7d12a1a..14d5bdbc 100644 --- a/pyredner_tensorflow/custom_ops/CMakeLists.txt +++ b/pyredner_tensorflow/custom_ops/CMakeLists.txt @@ -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) @@ -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) diff --git a/pyredner_tensorflow/custom_ops/data_ptr.cc b/pyredner_tensorflow/custom_ops/data_ptr.cc index d84ae0d8..e9007a01 100755 --- a/pyredner_tensorflow/custom_ops/data_ptr.cc +++ b/pyredner_tensorflow/custom_ops/data_ptr.cc @@ -13,6 +13,11 @@ #include #include +#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 diff --git a/setup.py b/setup.py index fb2893f6..544eca3c 100644 --- a/setup.py +++ b/setup.py @@ -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 diff --git a/tests_tensorflow/test_g_buffer.py b/tests_tensorflow/test_g_buffer.py index 27cdc46d..79596d84 100644 --- a/tests_tensorflow/test_g_buffer.py +++ b/tests_tensorflow/test_g_buffer.py @@ -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()):