@@ -71,6 +71,28 @@ if(NOT COMPILE_WASM)
71
71
# Setting BUILD_ARCH to native invokes CPU intrinsic detection logic below.
72
72
# Prevent invoking that logic for WASM builds.
73
73
set (BUILD_ARCH native CACHE STRING "Compile for this CPU architecture." )
74
+
75
+ # Unfortunately MSVC supports a limited subset of BUILD_ARCH flags. Instead try to guess
76
+ # what architecture we can compile to reading BUILD_ARCH and mapping it to MSVC values
77
+ # references: https://clang.llvm.org/docs/UsersManual.html https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html https://gcc.gnu.org/onlinedocs/gcc-4.8.5/gcc/i386-and-x86-64-Options.html
78
+ # https://docs.microsoft.com/en-us/cpp/build/reference/arch-x86?redirectedfrom=MSDN&view=vs-2019&view=msvc-170 https://devblogs.microsoft.com/oldnewthing/20201026-00/?p=104397
79
+ # This is by no means an exhaustive list but should match the most common flags Linux programmers expect to parse to MSVC
80
+ if (MSVC )
81
+ if (BUILD_ARCH STREQUAL "native" ) # avx2 is good default for native. Very few desktop systems support avx512
82
+ set (MSVC_BUILD_ARCH "/arch:AVX2" )
83
+ elseif (BUILD_ARCH STREQUAL "skylake-avx512" OR BUILD_ARCH STREQUAL "cannonlake" OR BUILD_ARCH STREQUAL "x86-64-v4" OR BUILD_ARCH STREQUAL "tigerlake" OR BUILD_ARCH STREQUAL "cooperlake" OR BUILD_ARCH STREQUAL "cascadelake" )
84
+ set (MSVC_BUILD_ARCH "/arch:AVX512" )
85
+ elseif (BUILD_ARCH STREQUAL "core-avx2" OR BUILD_ARCH STREQUAL "haswell" OR BUILD_ARCH STREQUAL "x86-64-v3" OR BUILD_ARCH STREQUAL "broadwell" OR BUILD_ARCH STREQUAL "skylake" )
86
+ set (MSVC_BUILD_ARCH "/arch:AVX2" )
87
+ elseif (BUILD_ARCH STREQUAL "sandybridge" OR BUILD_ARCH STREQUAL "corei7-avx" OR BUILD_ARCH STREQUAL "core-avx-i" OR BUILD_ARCH STREQUAL "ivybridge" )
88
+ set (MSVC_BUILD_ARCH "/arch:AVX" )
89
+ elseif (BUILD_ARCH STREQUAL "nehalem" OR BUILD_ARCH STREQUAL "westmere" OR BUILD_ARCH STREQUAL "x86-64-v2" OR BUILD_ARCH STREQUAL "corei7" OR BUILD_ARCH STREQUAL "core2" )
90
+ set (MSVC_BUILD_ARCH "/arch:SSE2" ) # This is MSVC default. We won't go down to SSE because we don't support that hardware at all with intgemm. Marian recommends to only go down to SSE4.1 at most
91
+ else ()
92
+ message (WARNING "Unknown BUILD_ARCH ${BUILD_ARCH} provided. Default to SSE2 for Windows build" )
93
+ set (MSVC_BUILD_ARCH "/arch:SSE2" )
94
+ endif ()
95
+ endif (MSVC )
74
96
endif ()
75
97
76
98
if (USE_THREADS )
@@ -146,7 +168,7 @@ if(MSVC)
146
168
add_definitions (-DUSE_SSE2=1 )
147
169
148
170
# Or maybe use these?
149
- set (INTRINSICS "/arch:AVX2" )
171
+ set (INTRINSICS ${MSVC_BUILD_ARCH} )
150
172
# set(INTRINSICS "/arch:AVX512")
151
173
152
174
set (CMAKE_CXX_FLAGS "/EHsc /DWIN32 /D_WINDOWS /DUNICODE /D_UNICODE /D_CRT_NONSTDC_NO_WARNINGS /D_CRT_SECURE_NO_WARNINGS ${DISABLE_GLOBALLY} " )
0 commit comments