Commit 60e5d25a by Ting PAN

Fix the extension compiling issues on win32

Summary:
This commit fixes the two compiling issues on win32:
1. Remove the constexpr in generating protobuf headers.
2. Enforce the "/MT" flag to overwrite the "/MD" always.
1 parent 1ad360e9
[flake8] [flake8]
max-line-length = 120 max-line-length = 120
ignore = E741, # ambiguous variable name ignore = E741, # ambiguous variable name
F403, # ‘from module import *’ used; unable to detect undefined names F403, # 'from module import *' used; unable to detect undefined names
F405, # name may be undefined, or defined from star imports: module F405, # name may be undefined, or defined from star imports: module
F811, # redefinition of unused name from line N F811, # redefinition of unused name from line N
F821, # undefined name F821, # undefined name
......
...@@ -117,8 +117,13 @@ strip_debug_symbol(dragon_python) ...@@ -117,8 +117,13 @@ strip_debug_symbol(dragon_python)
set(_install_dir ${CMAKE_INSTALL_PREFIX}/include) set(_install_dir ${CMAKE_INSTALL_PREFIX}/include)
foreach(_file ${MODULE_INCLUDES}) foreach(_file ${MODULE_INCLUDES})
get_filename_component(_dir ${_file} DIRECTORY) get_filename_component(_dir ${_file} DIRECTORY)
get_filename_component(_ext ${_file} EXT)
file(RELATIVE_PATH _dir ${PROJECT_SOURCE_DIR} ${_dir}) file(RELATIVE_PATH _dir ${PROJECT_SOURCE_DIR} ${_dir})
file(COPY ${_file} DESTINATION ${_install_dir}/dragon/${_dir}) file(COPY ${_file} DESTINATION ${_install_dir}/dragon/${_dir})
if (${_ext} STREQUAL ".pb.h" AND WIN32)
get_filename_component(_name ${_file} NAME)
protobuf_remove_constexpr(${_install_dir}/dragon/${_dir}/${_name})
endif()
endforeach() endforeach()
file(COPY ${THIRD_PARTY_DIR}/cub/cub DESTINATION ${_install_dir}) file(COPY ${THIRD_PARTY_DIR}/cub/cub DESTINATION ${_install_dir})
file(COPY ${THIRD_PARTY_DIR}/eigen/Eigen DESTINATION ${_install_dir}) file(COPY ${THIRD_PARTY_DIR}/eigen/Eigen DESTINATION ${_install_dir})
......
...@@ -93,8 +93,13 @@ strip_debug_symbol(dragonrt) ...@@ -93,8 +93,13 @@ strip_debug_symbol(dragonrt)
set(_install_dir ${CMAKE_INSTALL_PREFIX}/include) set(_install_dir ${CMAKE_INSTALL_PREFIX}/include)
foreach(_file ${MODULE_INCLUDES}) foreach(_file ${MODULE_INCLUDES})
get_filename_component(_dir ${_file} DIRECTORY) get_filename_component(_dir ${_file} DIRECTORY)
get_filename_component(_ext ${_file} EXT)
file(RELATIVE_PATH _dir ${PROJECT_SOURCE_DIR} ${_dir}) file(RELATIVE_PATH _dir ${PROJECT_SOURCE_DIR} ${_dir})
file(COPY ${_file} DESTINATION ${_install_dir}/dragon/${_dir}) file(COPY ${_file} DESTINATION ${_install_dir}/dragon/${_dir})
if (${_ext} STREQUAL ".pb.h" AND WIN32)
get_filename_component(_name ${_file} NAME)
protobuf_remove_constexpr(${_install_dir}/dragon/${_dir}/${_name})
endif()
endforeach() endforeach()
file(COPY dragon_runtime.h DESTINATION ${_install_dir}/dragon) file(COPY dragon_runtime.h DESTINATION ${_install_dir}/dragon)
file(COPY ${THIRD_PARTY_DIR}/cub/cub DESTINATION ${_install_dir}) file(COPY ${THIRD_PARTY_DIR}/cub/cub DESTINATION ${_install_dir})
......
...@@ -206,7 +206,6 @@ class BuildExtension(_build_ext): ...@@ -206,7 +206,6 @@ class BuildExtension(_build_ext):
cflags = self.cflags cflags = self.cflags
else: else:
cflags = [] cflags = []
cflags = COMMON_NVCC_FLAGS + cflags + _get_cuda_arch_flags(cflags) cflags = COMMON_NVCC_FLAGS + cflags + _get_cuda_arch_flags(cflags)
for flag in COMMON_MSVC_FLAGS: for flag in COMMON_MSVC_FLAGS:
cflags = ['-Xcompiler', flag] + cflags cflags = ['-Xcompiler', flag] + cflags
...@@ -218,6 +217,9 @@ class BuildExtension(_build_ext): ...@@ -218,6 +217,9 @@ class BuildExtension(_build_ext):
cflags = COMMON_MSVC_FLAGS + self.cflags cflags = COMMON_MSVC_FLAGS + self.cflags
cmd += cflags cmd += cflags
if '/MD' in cmd:
cmd.remove('/MD')
return original_spawn(cmd) return original_spawn(cmd)
try: try:
...@@ -362,7 +364,7 @@ IS_WINDOWS = _sys.platform == 'win32' ...@@ -362,7 +364,7 @@ IS_WINDOWS = _sys.platform == 'win32'
CUDA_HOME = _find_cuda() CUDA_HOME = _find_cuda()
CUDNN_HOME = _os.environ.get('CUDNN_HOME') or _os.environ.get('CUDNN_PATH') CUDNN_HOME = _os.environ.get('CUDNN_HOME') or _os.environ.get('CUDNN_PATH')
COMMON_CC_FLAGS = ['-Wno-sign-compare', '-Wno-unused-variable', '-Wno-reorder'] COMMON_CC_FLAGS = ['-Wno-sign-compare', '-Wno-unused-variable', '-Wno-reorder']
COMMON_MSVC_FLAGS = ['/EHsc', '/wd4819', '/wd4244', '/wd4251', '/wd4275', '/wd4800', '/wd4996'] COMMON_MSVC_FLAGS = ['/MT', '/EHsc', '/wd4819', '/wd4244', '/wd4251', '/wd4275', '/wd4800', '/wd4996']
COMMON_NVCC_FLAGS = ['-w'] if IS_WINDOWS else ['-std=c++14'] COMMON_NVCC_FLAGS = ['-w'] if IS_WINDOWS else ['-std=c++14']
COMMON_LINK_LIBRARIES = ['protobuf'] if IS_WINDOWS else [] COMMON_LINK_LIBRARIES = ['protobuf'] if IS_WINDOWS else []
DLLIMPORT_STR = '__declspec(dllimport)' if IS_WINDOWS else '' DLLIMPORT_STR = '__declspec(dllimport)' if IS_WINDOWS else ''
...@@ -72,6 +72,7 @@ def configure(): ...@@ -72,6 +72,7 @@ def configure():
# Copy "torchvision" => "dragon.vm.torchvision" # Copy "torchvision" => "dragon.vm.torchvision"
shutil.copytree('../torchvision', 'dragon/vm/torchvision') shutil.copytree('../torchvision', 'dragon/vm/torchvision')
# Copy the pre-built libraries. # Copy the pre-built libraries.
if not os.path.exists('dragon/lib'):
os.makedirs('dragon/lib') os.makedirs('dragon/lib')
for src, dest in find_libraries().items(): for src, dest in find_libraries().items():
if os.path.exists(src): if os.path.exists(src):
......
...@@ -104,7 +104,7 @@ inline int CUDA_NUM_DEVICES() { ...@@ -104,7 +104,7 @@ inline int CUDA_NUM_DEVICES() {
inline int GetCUDADevice() { inline int GetCUDADevice() {
int device_id; int device_id;
cudaGetDevice(&device_id); CUDA_CHECK(cudaGetDevice(&device_id));
return device_id; return device_id;
} }
...@@ -144,7 +144,7 @@ inline bool TENSOR_CORE_AVAILABLE() { ...@@ -144,7 +144,7 @@ inline bool TENSOR_CORE_AVAILABLE() {
class CUDADeviceGuard { class CUDADeviceGuard {
public: public:
explicit CUDADeviceGuard(int new_id) { explicit CUDADeviceGuard(int new_id) {
cudaGetDevice(&prev_id_); CUDA_CHECK(cudaGetDevice(&prev_id_));
if (prev_id_ != new_id) { if (prev_id_ != new_id) {
CUDA_CHECK(cudaSetDevice(new_id)); CUDA_CHECK(cudaSetDevice(new_id));
} }
......
...@@ -159,6 +159,7 @@ class TestOpSpec(unittest.TestCase): ...@@ -159,6 +159,7 @@ class TestOpSpec(unittest.TestCase):
[self.sym1, self.sym1]).shape, None) [self.sym1, self.sym1]).shape, None)
def test_broadcast(self): def test_broadcast(self):
with dragon.graph_mode():
self.assertEqual(dragon.broadcast_to( self.assertEqual(dragon.broadcast_to(
self.sym1, shape=(1,)).shape, None) self.sym1, shape=(1,)).shape, None)
self.assertEqual(dragon.broadcast_to( self.assertEqual(dragon.broadcast_to(
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!