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]
max-line-length = 120
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
F811, # redefinition of unused name from line N
F821, # undefined name
......
......@@ -117,8 +117,13 @@ strip_debug_symbol(dragon_python)
set(_install_dir ${CMAKE_INSTALL_PREFIX}/include)
foreach(_file ${MODULE_INCLUDES})
get_filename_component(_dir ${_file} DIRECTORY)
get_filename_component(_ext ${_file} EXT)
file(RELATIVE_PATH _dir ${PROJECT_SOURCE_DIR} ${_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()
file(COPY ${THIRD_PARTY_DIR}/cub/cub DESTINATION ${_install_dir})
file(COPY ${THIRD_PARTY_DIR}/eigen/Eigen DESTINATION ${_install_dir})
......
......@@ -93,8 +93,13 @@ strip_debug_symbol(dragonrt)
set(_install_dir ${CMAKE_INSTALL_PREFIX}/include)
foreach(_file ${MODULE_INCLUDES})
get_filename_component(_dir ${_file} DIRECTORY)
get_filename_component(_ext ${_file} EXT)
file(RELATIVE_PATH _dir ${PROJECT_SOURCE_DIR} ${_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()
file(COPY dragon_runtime.h DESTINATION ${_install_dir}/dragon)
file(COPY ${THIRD_PARTY_DIR}/cub/cub DESTINATION ${_install_dir})
......
......@@ -206,7 +206,6 @@ class BuildExtension(_build_ext):
cflags = self.cflags
else:
cflags = []
cflags = COMMON_NVCC_FLAGS + cflags + _get_cuda_arch_flags(cflags)
for flag in COMMON_MSVC_FLAGS:
cflags = ['-Xcompiler', flag] + cflags
......@@ -218,6 +217,9 @@ class BuildExtension(_build_ext):
cflags = COMMON_MSVC_FLAGS + self.cflags
cmd += cflags
if '/MD' in cmd:
cmd.remove('/MD')
return original_spawn(cmd)
try:
......@@ -362,7 +364,7 @@ IS_WINDOWS = _sys.platform == 'win32'
CUDA_HOME = _find_cuda()
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_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_LINK_LIBRARIES = ['protobuf'] if IS_WINDOWS else []
DLLIMPORT_STR = '__declspec(dllimport)' if IS_WINDOWS else ''
......@@ -72,7 +72,8 @@ def configure():
# Copy "torchvision" => "dragon.vm.torchvision"
shutil.copytree('../torchvision', 'dragon/vm/torchvision')
# Copy the pre-built libraries.
os.makedirs('dragon/lib')
if not os.path.exists('dragon/lib'):
os.makedirs('dragon/lib')
for src, dest in find_libraries().items():
if os.path.exists(src):
shutil.copy(src, dest)
......
......@@ -104,7 +104,7 @@ inline int CUDA_NUM_DEVICES() {
inline int GetCUDADevice() {
int device_id;
cudaGetDevice(&device_id);
CUDA_CHECK(cudaGetDevice(&device_id));
return device_id;
}
......@@ -144,7 +144,7 @@ inline bool TENSOR_CORE_AVAILABLE() {
class CUDADeviceGuard {
public:
explicit CUDADeviceGuard(int new_id) {
cudaGetDevice(&prev_id_);
CUDA_CHECK(cudaGetDevice(&prev_id_));
if (prev_id_ != new_id) {
CUDA_CHECK(cudaSetDevice(new_id));
}
......
......@@ -159,14 +159,15 @@ class TestOpSpec(unittest.TestCase):
[self.sym1, self.sym1]).shape, None)
def test_broadcast(self):
self.assertEqual(dragon.broadcast_to(
self.sym1, shape=(1,)).shape, None)
self.assertEqual(dragon.broadcast_to(
self.sym2, shape=(1, 2)).shape, (1, 2))
self.assertEqual(dragon.broadcast_to(
self.sym3, shape=(2,)).shape, self.sym3.shape[:-1] + (2,))
self.assertEqual(dragon.broadcast_to(
self.sym3, shape=(-1, 2, 2)).shape, (1, 2, 2))
with dragon.graph_mode():
self.assertEqual(dragon.broadcast_to(
self.sym1, shape=(1,)).shape, None)
self.assertEqual(dragon.broadcast_to(
self.sym2, shape=(1, 2)).shape, (1, 2))
self.assertEqual(dragon.broadcast_to(
self.sym3, shape=(2,)).shape, self.sym3.shape[:-1] + (2,))
self.assertEqual(dragon.broadcast_to(
self.sym3, shape=(-1, 2, 2)).shape, (1, 2, 2))
def test_cast(self):
with dragon.graph_mode():
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!