anira
anira copied to clipboard
Clang support for libtorch under Windows.
Hi !
I'm trying to work on Windows with a cross-platform toolchain so I'm using Ninja + Clang for my project. Since Clang for MSCV is ABI compatible with MSVC code, everything works fine with the anira binaries except for Clang errors related to the symbols \bigobj
and \EHsc
. Those flags are set in \lib\cmake\Caffe2\Caffe2Targets.cmake
in the pre-built binaries (0.1.2), so it's possible to make it work by changing:
set_target_properties(torch_cpu PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "USE_DISTRIBUTED;USE_C10D_GLOO"
INTERFACE_COMPILE_OPTIONS "\$<\$<COMPILE_LANGUAGE:CXX>:;\$<\$<OR:\$<CONFIG:Debug>,\$<CONFIG:RelWithDebInfo>>:/Z7>;/EHsc;/bigobj>"
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
INTERFACE_LINK_LIBRARIES "protobuf::libprotobuf;c10;caffe2::mkl"
)
into
if (MSVC)
set_target_properties(torch_cpu PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "USE_DISTRIBUTED;USE_C10D_GLOO"
INTERFACE_COMPILE_OPTIONS "\$<\$<COMPILE_LANGUAGE:CXX>:;\$<\$<OR:\$<CONFIG:Debug>,\$<CONFIG:RelWithDebInfo>>:/Z7>;/EHsc;/bigobj>"
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
INTERFACE_LINK_LIBRARIES "protobuf::libprotobuf;c10;caffe2::mkl"
)
else()
set_target_properties(torch_cpu PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "USE_DISTRIBUTED;USE_C10D_GLOO"
INTERFACE_COMPILE_OPTIONS "\$<\$<COMPILE_LANGUAGE:CXX>:;\$<\$<OR:\$<CONFIG:Debug>,\$<CONFIG:RelWithDebInfo>>:/Z7>;-fexceptions>"
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
INTERFACE_LINK_LIBRARIES "protobuf::libprotobuf;c10;caffe2::mkl"
)
endif()
I don't know if this .cmake
file is written as part of your code or if it comes with the libtorch library. In the latter case maybe there's a CMake command that could be used to intercept the MSVC flags and change them before compilation (this way there's no need to change the libtorch code), but I don't know it. If it's part of your code I suggest making the change so that this toolchain is readily enable on Windows.
Best,
Mathis.