Skip to content

[libtorch] create a new port #17199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 90 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from 88 commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
8ee205b
[onnx] feature: foxi
luncliff Sep 11, 2021
d42ca2f
[onnx] force onnx/onnx_proto static in Windows
luncliff Sep 16, 2021
5114b48
[onnx] support windows static triplets
luncliff Sep 16, 2021
28cec17
[onnx] fix wrong LICENSE install
luncliff Sep 16, 2021
f8ec3f5
[onnx] remove feature 'foxi'
luncliff Sep 18, 2021
18d4965
Merge branch 'master' of https://github.com/microsoft/vcpkg into port…
Sep 23, 2021
2a77308
[libtorch] rework patch files
luncliff Sep 11, 2021
1c19e75
[libtorch] config fixup ATen, Torch
luncliff Sep 11, 2021
287b524
[libtorch] make shared only
luncliff Sep 11, 2021
335282e
[libtorch] remove headers after install
luncliff Sep 12, 2021
44ae8f7
Merge branch 'port/onnx' into port/libtorch-1
luncliff Sep 28, 2021
62cd69e
[libtorch] rewrite patches and feature options
luncliff Sep 28, 2021
b1807fb
[libtorch] use eigen3 always
luncliff Sep 28, 2021
5d00ceb
[libtorch] error if BLAS feature collision
luncliff Sep 28, 2021
ecbc08f
[libtorch] remove !static
luncliff Sep 28, 2021
34ec43f
[libtorch] replace vcpkg_find_acquire_program
luncliff Sep 29, 2021
8fd7788
Merge branch 'master' of https://github.com/microsoft/vcpkg into port…
Oct 20, 2021
d3b2cd9
Dependency python3
Oct 20, 2021
835dc6b
Merge branch 'master' into port/libtorch
luncliff Nov 13, 2021
94560c3
[libtorch] migrate works from luncliff/vcpkg-registry
luncliff Nov 13, 2021
06f0a02
[libtorch] misc fix, update version, baseline
luncliff Nov 13, 2021
45944fc
fix merge confict for 'onnx'
luncliff Nov 13, 2021
2c18c57
[libtorch] install pip packages
luncliff Nov 14, 2021
31595af
[libtorch] turn off Metal options
luncliff Nov 14, 2021
929dfc4
[onnx] revert 'onnx' changes
luncliff Nov 14, 2021
080d3e5
Merge branch 'master' into port/libtorch
luncliff Nov 18, 2021
1fb5799
[libtorch] refine patches
luncliff Nov 22, 2021
d44c15e
Merge branch 'master' into port/libtorch
luncliff Dec 5, 2021
d7b3957
[libtorch] link with foxi_loader
luncliff Dec 5, 2021
0ab2fe8
[libtorch] update git-tree
luncliff Dec 5, 2021
b9c4a07
[libtorch] reduce patch size
luncliff Dec 10, 2021
16b5612
Merge branch 'master' into port/libtorch
luncliff Dec 10, 2021
86290b8
[libtorch] find numa and activate USE_NUMA
luncliff Jan 18, 2022
ac8687c
Update ports/libtorch/portfile.cmake
luncliff Jan 19, 2022
a447925
Update ports/libtorch/portfile.cmake
luncliff Jan 19, 2022
7954279
Update ports/libtorch/portfile.cmake
luncliff Jan 19, 2022
65c5545
[libtorch] fix mistype and update version JSON
luncliff Jan 19, 2022
9703ca3
Merge branch 'master' of https://github.com/microsoft/vcpkg into port…
Mar 1, 2022
a04ecfd
Add double quotes
Mar 1, 2022
7156a29
version
Mar 1, 2022
a9a2b2c
Fix support expression
Mar 1, 2022
4424ca4
version
Mar 1, 2022
f9a4d3d
Merge remote-tracking branch 'origin/master' into HEAD
BillyONeal May 18, 2022
478af24
[libtorch] update cpuinfo usage
luncliff May 19, 2022
f11119d
[tensorpipe] fix linux install
luncliff May 27, 2022
b1763bf
[tensorpipe] update versions JSON
luncliff May 27, 2022
bc7c98d
[libtorch] fix feature failures
luncliff May 27, 2022
4afebf9
[libtorch] remove CUDA feature
luncliff May 28, 2022
619e481
[libtorch] giveup 'fbgemm' feature
luncliff Jun 2, 2022
c9d9bcf
[libtorch] use mpi, openmpi in Linux
luncliff Jun 7, 2022
93b2d4f
Merge branch 'master' of https://github.com/microsoft/vcpkg into port…
Jul 5, 2022
dd41633
[libtorch] fix glog link error
luncliff Jul 9, 2022
e198064
Merge branch 'master' into port/libtorch
luncliff Jul 10, 2022
9686405
[tensorpipe] bump port version
luncliff Jul 10, 2022
64d400f
[libtorch] fix patch list
luncliff Jul 10, 2022
c66f133
[libtorch] use official libuv config
luncliff Jul 11, 2022
c6ed667
Update ports/libtorch/portfile.cmake
luncliff Jul 11, 2022
0c9cc66
Update ports/libtorch/portfile.cmake
luncliff Jul 11, 2022
aa94e7e
update versions JSON
luncliff Jul 11, 2022
d8a19cf
revert unnecessary 'nnpack' changes
luncliff Jul 11, 2022
df88c0d
Update ports/libtorch/portfile.cmake
luncliff Jul 17, 2022
dd7c22d
[libtorch] use vcpkg-get-python-packages
luncliff Jul 18, 2022
1339a1b
[libtorch] provide path of python3
luncliff Sep 19, 2022
64495c3
Merge branch 'master' into port/libtorch
luncliff Sep 19, 2022
3317aed
Merge remote-tracking branch 'origin/master' into HEAD
BillyONeal Sep 26, 2022
707d441
Update ports/libtorch/portfile.cmake
luncliff Oct 26, 2022
4947704
Merge remote-tracking branch 'origin/master' into HEAD
BillyONeal Oct 26, 2022
04aeefc
Fix version database.
BillyONeal Oct 26, 2022
4c50475
[libtorch] use openmpi in linux/osx
luncliff Oct 27, 2022
b0e0d81
[libtorch] update to v1.12.1
luncliff Nov 14, 2022
260d530
[libtorch] find_program(python3, python)
luncliff Nov 14, 2022
08637fc
[libtorch] provide PYTHON_EXECUTABLE directly
luncliff Nov 14, 2022
b97c1c5
[xnnpack] update to 2022-02-17
luncliff Nov 14, 2022
26dda6a
[xnnpack] use C11, C++11
luncliff Nov 15, 2022
4085d19
[libtorch] more patches, DISABLE_PARALLEL_CONFIGURE
luncliff Nov 21, 2022
5fd4ef0
[libtorch] allow static torch_cpu build
luncliff Nov 21, 2022
a9dbd78
Revert "[libtorch] allow static torch_cpu build"
luncliff Nov 22, 2022
94bd147
[libtorch] find_package(BLAS)
luncliff Nov 23, 2022
0e63c13
[libtorch] simplify Python3, NumPy option use
luncliff Nov 23, 2022
b8c212e
[libtorch] fix install in Windows
luncliff Nov 23, 2022
981d24d
[libtorch] exclude torch_global_deps in Windows
luncliff Nov 23, 2022
3f43bba
[libtorch] platform of nnpack feature
luncliff Nov 24, 2022
17cd326
[libtorch] fix MPI option in Windows
luncliff Dec 4, 2022
88bb895
[libtorch] fixing LNK1161
luncliff Dec 5, 2022
9598f03
[libtorch] fix some mistypes
luncliff Dec 5, 2022
46e381d
[libtorch] define NOMINMAX for c10
luncliff Dec 10, 2022
62c5081
[libtorch] disable vulkan feature in Windows
luncliff Dec 11, 2022
6566732
ci.baseline.txt: allow libtorch failure
luncliff Dec 18, 2022
027b927
Enable testing port on Windows
vicroms Jan 17, 2023
a3e9e13
[caffe2] redirect to libtorch
luncliff Jan 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions ports/libtorch/fix-c10-glog.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
diff --git a/c10/util/Logging.cpp b/c10/util/Logging.cpp
index fe74e49..06e09d6 100644
--- a/c10/util/Logging.cpp
+++ b/c10/util/Logging.cpp
@@ -4,7 +4,7 @@
#ifdef FBCODE_CAFFE2
#include <folly/synchronization/SanitizeThread.h>
#endif
-
+#include <glog/logging.h>
#include <algorithm>
#include <cstdlib>
#include <cstring>
@@ -192,23 +194,13 @@ C10_DEFINE_int(
google::GLOG_WARNING,
"The minimum log level that caffe2 will output.");

-// Google glog's api does not have an external function that allows one to check
-// if glog is initialized or not. It does have an internal function - so we are
-// declaring it here. This is a hack but has been used by a bunch of others too
-// (e.g. Torch).
-namespace google {
-namespace glog_internal_namespace_ {
-bool IsGoogleLoggingInitialized();
-} // namespace glog_internal_namespace_
-} // namespace google
-
namespace c10 {
namespace {

void initGoogleLogging(char const* name) {
#if !defined(_MSC_VER)
// This trick can only be used on UNIX platforms
- if (!::google::glog_internal_namespace_::IsGoogleLoggingInitialized())
+ if (!::google::IsGoogleLoggingInitialized())
#endif
{
::google::InitGoogleLogging(name);
diff --git a/c10/util/Logging.cpp b/c10/util/Logging.cpp
index 1864f17..b958fa0 100644
--- a/c10/util/Logging.cpp
+++ b/c10/util/Logging.cpp
@@ -154,18 +154,6 @@ void setLogLevelFlagFromEnv();
} // namespace detail
} // namespace c10

-#if defined(C10_USE_GFLAGS) && defined(C10_USE_GLOG)
-// When GLOG depends on GFLAGS, these variables are being defined in GLOG
-// directly via the GFLAGS definition, so we will use DECLARE_* to declare
-// them, and use them in Caffe2.
-// GLOG's minloglevel
-DECLARE_int32(minloglevel);
-// GLOG's verbose log value.
-DECLARE_int32(v);
-// GLOG's logtostderr value
-DECLARE_bool(logtostderr);
-#endif // defined(C10_USE_GFLAGS) && defined(C10_USE_GLOG)
-
#if !defined(C10_USE_GLOG)
// This backward compatibility flags are in order to deal with cases where
// Caffe2 are not built with glog, but some init flags still pass in these
142 changes: 142 additions & 0 deletions ports/libtorch/fix-cmake.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4bf1e85..48b01ae 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -693,7 +693,7 @@ endif()

set(BUILD_ONEDNN_GRAPH OFF)

-include(cmake/Dependencies.cmake)
+include(cmake/vcpkg-dependencies.cmake)

if(USE_CUDA AND (CMAKE_CUDA_COMPILER_VERSION VERSION_LESS 10.2) AND (CMAKE_HOST_SYSTEM_NAME MATCHES "Windows"))
# CUDA < 10.2 doesn't support compiling and extracting header dependencies in
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 48b01ae..8e46275 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -660,7 +660,7 @@ if(NOT CMAKE_BUILD_TYPE)
endif()

# The below means we are cross compiling for arm64 or x86_64 on MacOSX
-if(NOT IOS AND CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_OSX_ARCHITECTURES MATCHES "^(x86_64|arm64)$")
+if(false)
set(CROSS_COMPILING_MACOSX TRUE)
# We need to compile a universal protoc to not fail protobuf build
# We set CMAKE_TRY_COMPILE_TARGET_TYPE to STATIC_LIBRARY (vs executable) to succeed the cmake compiler check for cross-compiling
@@ -678,6 +678,7 @@ if(NOT IOS AND CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_OSX_ARCHITECTURES M
set(PROTOBUF_PROTOC_EXECUTABLE "${PROJECT_SOURCE_DIR}/build_host_protoc/bin/protoc")
set(CAFFE2_CUSTOM_PROTOC_EXECUTABLE "${PROJECT_SOURCE_DIR}/build_host_protoc/bin/protoc")
endif()
+include(cmake/ProtoBuf.cmake)

# ---[ Misc checks to cope with various compiler modes
include(cmake/MiscCheck.cmake)
diff --git a/caffe2/CMakeLists.txt b/caffe2/CMakeLists.txt
index 328210c..c407442 100644
--- a/caffe2/CMakeLists.txt
+++ b/caffe2/CMakeLists.txt
@@ -112,13 +112,8 @@ endif()
# addressed yet.

if(NOT MSVC AND USE_XNNPACK)
- if(NOT TARGET fxdiv)
- set(FXDIV_BUILD_TESTS OFF CACHE BOOL "")
- set(FXDIV_BUILD_BENCHMARKS OFF CACHE BOOL "")
- add_subdirectory(
- "${FXDIV_SOURCE_DIR}"
- "${CMAKE_BINARY_DIR}/FXdiv")
- endif()
+ find_path(FXDIV_INCLUDE_DIRS "fxdiv.h" REQUIRED)
+ include_directories(${FXDIV_INCLUDE_DIRS})
endif()

add_subdirectory(core)
diff --git a/caffe2/CMakeLists.txt b/caffe2/CMakeLists.txt
index c407442..16fa898 100644
--- a/caffe2/CMakeLists.txt
+++ b/caffe2/CMakeLists.txt
@@ -1011,10 +1011,6 @@ if(USE_CUDA OR USE_ROCM)
include(${TORCH_SRC_DIR}/csrc/jit/codegen/cuda/nvfuser.cmake)
endif()

-if(NOT MSVC AND USE_XNNPACK)
- TARGET_LINK_LIBRARIES(torch_cpu PRIVATE fxdiv)
-endif()
-
# ==========================================================
# formerly-libtorch flags
# ==========================================================
diff --git a/c10/CMakeLists.txt b/c10/CMakeLists.txt
index 41b1a1a..3b390ec 100644
--- a/c10/CMakeLists.txt
+++ b/c10/CMakeLists.txt
@@ -110,7 +110,11 @@ endif()
# Note: for now, we will put all export path into one single Caffe2Targets group
# to deal with the cmake deployment need. Inside the Caffe2Targets set, the
# individual libraries like libc10.so and libcaffe2.so are still self-contained.
-install(TARGETS c10 EXPORT Caffe2Targets DESTINATION lib)
+install(TARGETS c10 EXPORT Caffe2Targets
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib
+)
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
DESTINATION include
FILES_MATCHING PATTERN "*.h")
diff --git a/caffe2/CMakeLists.txt b/caffe2/CMakeLists.txt
index 16fa898..7a343f7 100644
--- a/caffe2/CMakeLists.txt
+++ b/caffe2/CMakeLists.txt
@@ -1547,7 +1547,11 @@ endif()

caffe2_interface_library(torch torch_library)

-install(TARGETS torch_cpu torch_cpu_library EXPORT Caffe2Targets DESTINATION "${TORCH_INSTALL_LIB_DIR}")
+install(TARGETS torch_cpu torch_cpu_library EXPORT Caffe2Targets
+ RUNTIME DESTINATION "${TORCH_INSTALL_BIN_DIR}"
+ LIBRARY DESTINATION "${TORCH_INSTALL_LIB_DIR}"
+ ARCHIVE DESTINATION "${TORCH_INSTALL_LIB_DIR}"
+)

if(USE_CUDA)
install(TARGETS torch_cuda torch_cuda_library EXPORT Caffe2Targets DESTINATION "${TORCH_INSTALL_LIB_DIR}")
@@ -1558,7 +1562,11 @@ if(USE_CUDA)
elseif(USE_ROCM)
install(TARGETS torch_hip torch_hip_library EXPORT Caffe2Targets DESTINATION "${TORCH_INSTALL_LIB_DIR}")
endif()
-install(TARGETS torch torch_library EXPORT Caffe2Targets DESTINATION "${TORCH_INSTALL_LIB_DIR}")
+install(TARGETS torch torch_library EXPORT Caffe2Targets
+ RUNTIME DESTINATION "${TORCH_INSTALL_BIN_DIR}"
+ LIBRARY DESTINATION "${TORCH_INSTALL_LIB_DIR}"
+ ARCHIVE DESTINATION "${TORCH_INSTALL_LIB_DIR}"
+)

target_link_libraries(torch PUBLIC torch_cpu_library)

@@ -1688,7 +1696,11 @@ if(BUILD_SHARED_LIBS)
target_link_libraries(torch_global_deps TBB::tbb)
endif()

- install(TARGETS torch_global_deps DESTINATION "${TORCH_INSTALL_LIB_DIR}")
+ install(TARGETS torch_global_deps
+ RUNTIME DESTINATION "${TORCH_INSTALL_BIN_DIR}"
+ LIBRARY DESTINATION "${TORCH_INSTALL_LIB_DIR}"
+ ARCHIVE DESTINATION "${TORCH_INSTALL_LIB_DIR}"
+ )
endif()

# ---[ Caffe2 HIP sources.
diff --git a/caffe2/CMakeLists.txt b/caffe2/CMakeLists.txt
index 7a343f7..3390f9b 100644
--- a/caffe2/CMakeLists.txt
+++ b/caffe2/CMakeLists.txt
@@ -1673,7 +1673,7 @@ target_link_libraries(torch_cpu PRIVATE flatbuffers)
# namespaces, so libtorch is loaded with all its dependencies in a local scope.
# That usually leads to missing symbol errors at run-time, so to avoid a situation like
# this we have to preload those libs in a global namespace.
-if(BUILD_SHARED_LIBS)
+if(BUILD_SHARED_LIBS AND (NOT WIN32))
add_library(torch_global_deps SHARED ${TORCH_SRC_DIR}/csrc/empty.c)
if(HAVE_SOVERSION)
set_target_properties(torch_global_deps PROPERTIES
32 changes: 32 additions & 0 deletions ports/libtorch/fix-fbgemm-include.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
diff --git a/aten/src/ATen/native/quantized/cpu/qembeddingbag_prepack.cpp b/aten/src/ATen/native/quantized/cpu/qembeddingbag_prepack.cpp
index 224a66f..eb42317 100644
--- a/aten/src/ATen/native/quantized/cpu/qembeddingbag_prepack.cpp
+++ b/aten/src/ATen/native/quantized/cpu/qembeddingbag_prepack.cpp
@@ -8,7 +8,10 @@
#include <torch/library.h>

#include <c10/util/irange.h>
-
+#ifdef USE_FBGEMM
+#include <fbgemm/Fbgemm.h>
+#include <fbgemm/FbgemmEmbedding.h>
+#endif
int register_embedding_params();

/*
diff --git a/aten/src/ATen/native/quantized/cpu/qembeddingbag_unpack.cpp b/aten/src/ATen/native/quantized/cpu/qembeddingbag_unpack.cpp
index f94d27b..299b88b 100644
--- a/aten/src/ATen/native/quantized/cpu/qembeddingbag_unpack.cpp
+++ b/aten/src/ATen/native/quantized/cpu/qembeddingbag_unpack.cpp
@@ -4,7 +4,10 @@
#include <ATen/native/quantized/cpu/fbgemm_utils.h>
#include <c10/util/irange.h>
#include <torch/library.h>
-
+#ifdef USE_FBGEMM
+#include <fbgemm/Fbgemm.h>
+#include <fbgemm/FbgemmEmbedding.h>
+#endif
int register_embedding_params();

at::Tensor PackedEmbeddingBagWeight::unpack() {
100 changes: 100 additions & 0 deletions ports/libtorch/fix-windows.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
diff --git a/torch/csrc/jit/tensorexpr/bounds_overlap.h b/torch/csrc/jit/tensorexpr/bounds_overlap.h
index c78884d..baf44bb 100644
--- a/torch/csrc/jit/tensorexpr/bounds_overlap.h
+++ b/torch/csrc/jit/tensorexpr/bounds_overlap.h
@@ -65,6 +65,10 @@ enum OverlapKind { ContainedOrEqual, Contains, PartialOverlap, NoOverlap };
// operator
// NOT_DETERMINED: Some elements satify the given comparison operator and
// some elements not
+#if defined(_WIN32)
+#undef TRUE
+#undef FALSE
+#endif
enum CmpEvalResult { TRUE, FALSE, NOT_DETERMINED };

// Returns the kind of overlap between Bound A and Bound A in a single
diff --git a/caffe2/CMakeLists.txt b/caffe2/CMakeLists.txt
index 3390f9b..578d0bd 100644
--- a/caffe2/CMakeLists.txt
+++ b/caffe2/CMakeLists.txt
@@ -1425,7 +1425,7 @@ target_include_directories(torch_cpu SYSTEM PRIVATE "${Caffe2_DEPENDENCY_INCLUDE
torch_set_target_props(torch_cpu)


-target_compile_options(torch_cpu PRIVATE "-DCAFFE2_BUILD_MAIN_LIB")
+target_compile_definitions(torch_cpu PRIVATE CAFFE2_BUILD_MAIN_LIB)
if(BUILD_SPLIT_CUDA)
target_compile_options(torch_cuda_cu PRIVATE "-DTORCH_CUDA_CU_BUILD_MAIN_LIB")
target_compile_options(torch_cuda_cpp PRIVATE "-DTORCH_CUDA_CPP_BUILD_MAIN_LIB")
@@ -1525,12 +1525,12 @@ if(MSVC AND NOT BUILD_SHARED_LIBS)
#
# NB: This must be target_compile_definitions, not target_compile_options,
# as the latter is not respected by nvcc
- target_compile_definitions(torch_cpu PUBLIC "AT_CORE_STATIC_WINDOWS=1")
+ target_compile_definitions(torch_cpu PUBLIC AT_CORE_STATIC_WINDOWS=1)
endif()
if(MSVC AND BUILD_SHARED_LIBS)
# ONNX is linked statically and needs to be exported from this library
# to be used externally. Make sure that references match the export.
- target_compile_options(torch_cpu PRIVATE "-DONNX_BUILD_MAIN_LIB")
+ target_compile_definitions(torch_cpu PRIVATE ONNX_BUILD_MAIN_LIB)
endif()

caffe2_interface_library(torch_cpu torch_cpu_library)
diff --git a/aten/src/ATen/Parallel.h b/aten/src/ATen/Parallel.h
index 0b494d9..06b5d88 100644
--- a/aten/src/ATen/Parallel.h
+++ b/aten/src/ATen/Parallel.h
@@ -28,13 +28,7 @@ TORCH_API bool in_parallel_region();
namespace internal {

// Initialise num_threads lazily at first parallel call
-inline TORCH_API void lazy_init_num_threads() {
- thread_local bool init = false;
- if (C10_UNLIKELY(!init)) {
- at::init_num_threads();
- init = true;
- }
-}
+TORCH_API void lazy_init_num_threads();

TORCH_API void set_thread_num(int);

diff --git a/aten/src/ATen/ParallelCommon.cpp b/aten/src/ATen/ParallelCommon.cpp
index 068c9d3..b869fde 100644
--- a/aten/src/ATen/ParallelCommon.cpp
+++ b/aten/src/ATen/ParallelCommon.cpp
@@ -17,6 +17,17 @@

namespace at {

+namespace internal {
+/// @see https://github.com/pytorch/pytorch/issues/87957
+void lazy_init_num_threads() {
+ thread_local bool init = false;
+ if (C10_UNLIKELY(!init)) {
+ at::init_num_threads();
+ init = true;
+ }
+}
+} // namespace internal
+
namespace {

const char* get_env_var(
diff --git a/c10/CMakeLists.txt b/c10/CMakeLists.txt
index 3b390ec..7cfa2b0 100644
--- a/c10/CMakeLists.txt
+++ b/c10/CMakeLists.txt
@@ -45,7 +45,10 @@ if(HAVE_SOVERSION)
VERSION ${TORCH_VERSION} SOVERSION ${TORCH_SOVERSION})
endif()
# If building shared library, set dllimport/dllexport proper.
-target_compile_options(c10 PRIVATE "-DC10_BUILD_MAIN_LIB")
+target_compile_definitions(c10 PRIVATE C10_BUILD_MAIN_LIB)
+if(WIN32)
+ target_compile_definitions(c10 PRIVATE NOMINMAX)
+endif()
# Enable hidden visibility if compiler supports it.
if(${COMPILER_SUPPORTS_HIDDEN_VISIBILITY})
target_compile_options(c10 PRIVATE "-fvisibility=hidden")
Loading