Unverified Commit 7d872968 authored by peterjc123's avatar peterjc123 Committed by GitHub
Browse files

Fix cmake cuda build for Windows & Enable cmake windows gpu build (#2754)



* Fix cmake cuda build for Windows

* add gpu test jobs

* Update .circleci/regenerate.py
Co-authored-by: default avatarFrancisco Massa <fvsmassa@gmail.com>
parent c542137c
......@@ -1145,6 +1145,10 @@ workflows:
cu_version: cpu
name: cmake_windows_cpu
python_version: '3.8'
- cmake_windows_gpu:
cu_version: cu101
name: cmake_windows_gpu
python_version: '3.8'
- cmake_macos_cpu:
cu_version: cpu
name: cmake_macos_cpu
......
......@@ -191,8 +191,8 @@ def cmake_workflows(indentation=6):
jobs = []
python_version = '3.8'
for os_type in ['linux', 'windows', 'macos']:
# Right now CMake builds are failling on Windows (GPU)
device_types = ['cpu', 'gpu'] if os_type == 'linux' else ['cpu']
# Skip OSX CUDA
device_types = ['cpu', 'gpu'] if os_type != 'macos' else ['cpu']
for device in device_types:
job = {
'name': f'cmake_{os_type}_{device}',
......@@ -200,7 +200,7 @@ def cmake_workflows(indentation=6):
}
job['cu_version'] = 'cu101' if device == 'gpu' else 'cpu'
if device == 'gpu':
if device == 'gpu' and os_type == 'linux':
job['wheel_docker_image'] = 'pytorch/manylinux-cuda101'
jobs.append({f'cmake_{os_type}_{device}': job})
return indent(indentation, jobs)
......
......@@ -9,6 +9,7 @@ if(WITH_CUDA)
enable_language(CUDA)
add_definitions(-D__CUDA_NO_HALF_OPERATORS__)
add_definitions(-DWITH_CUDA)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-relaxed-constexpr")
endif()
find_package(Python3 COMPONENTS Development)
......@@ -17,6 +18,15 @@ find_package(Torch REQUIRED)
find_package(PNG REQUIRED)
find_package(JPEG REQUIRED)
function(CUDA_CONVERT_FLAGS EXISTING_TARGET)
get_property(old_flags TARGET ${EXISTING_TARGET} PROPERTY INTERFACE_COMPILE_OPTIONS)
if(NOT "${old_flags}" STREQUAL "")
string(REPLACE ";" "," CUDA_flags "${old_flags}")
set_property(TARGET ${EXISTING_TARGET} PROPERTY INTERFACE_COMPILE_OPTIONS
"$<$<BUILD_INTERFACE:$<COMPILE_LANGUAGE:CXX>>:${old_flags}>$<$<BUILD_INTERFACE:$<COMPILE_LANGUAGE:CUDA>>:-Xcompiler=${CUDA_flags}>"
)
endif()
endfunction()
file(GLOB HEADERS torchvision/csrc/*.h)
# Image extension
......@@ -29,6 +39,26 @@ endif()
file(GLOB MODELS_HEADERS torchvision/csrc/models/*.h)
file(GLOB MODELS_SOURCES torchvision/csrc/models/*.h torchvision/csrc/models/*.cpp)
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4819")
if(WITH_CUDA)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler=/wd4819")
foreach(diag cc_clobber_ignored integer_sign_change useless_using_declaration
set_but_not_used field_without_dll_interface
base_class_has_different_dll_interface
dll_interface_conflict_none_assumed
dll_interface_conflict_dllexport_assumed
implicit_return_from_non_void_function
unsigned_compare_with_zero
declared_but_not_referenced
bad_friend_decl)
string(APPEND CMAKE_CUDA_FLAGS " -Xcudafe --diag_suppress=${diag}")
endforeach()
CUDA_CONVERT_FLAGS(torch_cpu)
CUDA_CONVERT_FLAGS(torch_cuda)
endif()
endif()
add_library(${PROJECT_NAME} SHARED ${MODELS_SOURCES} ${OPERATOR_SOURCES} ${IMAGE_SOURCES})
target_link_libraries(${PROJECT_NAME} PRIVATE ${TORCH_LIBRARIES} ${PNG_LIBRARY} ${JPEG_LIBRARIES} Python3::Python)
set_target_properties(${PROJECT_NAME} PROPERTIES EXPORT_NAME TorchVision)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment