Skip to content

Commit 8c828e8

Browse files
committed
enable windows cpu build
Signed-off-by: jiqing-feng <[email protected]>
1 parent 36dad93 commit 8c828e8

File tree

2 files changed

+20
-28
lines changed

2 files changed

+20
-28
lines changed

CMakeLists.txt

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -274,47 +274,22 @@ if (BUILD_CPU)
274274
if (OpenMP_CXX_FOUND)
275275
target_link_libraries(bitsandbytes PRIVATE OpenMP::OpenMP_CXX)
276276
add_definitions(-DHAS_OPENMP)
277-
else()
278-
add_definitions(-DNO_OPENMP)
279277
endif()
280278

281-
if (HOST_ARCH MATCHES "x86_64|amd64")
279+
if ((HOST_ARCH MATCHES "x86_64|amd64") AND (NOT MSVC))
282280
include(CheckCXXCompilerFlag)
283281
check_cxx_compiler_flag(-mavx512f HAS_AVX512F_FLAG)
284282
check_cxx_compiler_flag(-mavx512bf16 HAS_AVX512BF16_FLAG)
285283
if (HAS_AVX512F_FLAG)
286284
target_compile_options(bitsandbytes PRIVATE -mavx512f)
287-
add_definitions(-DHAS_AVX512F)
288285
endif()
289286
if (HAS_AVX512BF16_FLAG)
290287
target_compile_options(bitsandbytes PRIVATE -mavx512bf16)
291-
add_definitions(-DHAS_AVX512BF16)
292-
else()
293-
add_definitions(-DNO_AVX512BF16)
294288
endif()
289+
target_compile_options(bitsandbytes PRIVATE -mprefer-vector-width=256)
295290
endif()
296291
endif()
297292

298-
# --- Windows MSVC specific AVX512BF16 probe (after add_library) ---
299-
if (MSVC AND BUILD_CPU)
300-
include(CheckCXXSourceCompiles)
301-
set(_AVX512BF16_TEST "
302-
#include <immintrin.h>
303-
int main(){
304-
__m512bh a{}, b{};
305-
auto c = _mm512_dpbf16_ps(_mm512_setzero_ps(), a, b);
306-
(void)c;
307-
return 0;
308-
}")
309-
check_cxx_source_compiles("${_AVX512BF16_TEST}" MSVC_HAS_AVX512BF16)
310-
if (MSVC_HAS_AVX512BF16)
311-
# /arch:AVX512;
312-
target_compile_options(bitsandbytes PRIVATE /arch:AVX512)
313-
add_definitions(-DHAS_AVX512BF16)
314-
else()
315-
add_definitions(-DNO_AVX512BF16)
316-
endif()
317-
endif()
318293

319294
if(BUILD_CUDA)
320295
target_include_directories(bitsandbytes PUBLIC ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})

csrc/cpu_ops.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,32 @@ using namespace BinSearch;
1414
#if defined(__AVX512F__)
1515
#include <immintrin.h>
1616

17+
#ifdef _MSC_VER
18+
#include <intrin.h>
19+
static inline bool has_avx512f() {
20+
static bool v = []{
21+
int info[4]; __cpuidex(info, 7, 0);
22+
return (info[1] & (1 << 16)) != 0; // EBX bit16 AVX512F
23+
}();
24+
return v;
25+
}
26+
static inline bool has_avx512bf16() {
27+
static bool v = []{
28+
int info[4]; __cpuidex(info, 7, 1);
29+
return (info[0] & (1 << 5)) != 0; // EAX bit5 AVX512_BF16
30+
}();
31+
return v;
32+
}
33+
#else
1734
bool has_avx512f() {
1835
static const bool supported_avx512f = __builtin_cpu_supports("avx512f");
1936
return supported_avx512f;
2037
}
21-
2238
bool has_avx512bf16() {
2339
static const bool supported_avx512bf16 = __builtin_cpu_supports("avx512bf16");
2440
return supported_avx512bf16;
2541
}
42+
#endif
2643

2744
inline __m256i cvt_fp32_to_fp16(const __m512 src) {
2845
return _mm512_cvtps_ph(src, (_MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC));

0 commit comments

Comments
 (0)