Skip to content

Commit 0d84df2

Browse files
committed
Fix CPU memory bandwidth benchmark AVX compilation on non-x86 architectures (e.g. ARM64 macOS)
1 parent 9167316 commit 0d84df2

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

cpp_src/benchmarks/SysMemBandwidthBench.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
#include <chrono>
44
#include <cstdlib>
55
#include <cstring>
6-
#ifndef _MSC_VER
6+
#if !defined(_MSC_VER) && (defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || defined(_M_IX86))
7+
#define ENABLE_AVX2 1
8+
#else
9+
#define ENABLE_AVX2 0
10+
#endif
11+
12+
#if ENABLE_AVX2
713
#include <immintrin.h> // AVX2 intrinsics (GCC/Clang only)
814
#endif
915
#include <iostream>
@@ -24,7 +30,7 @@
2430
// Check for AVX2 support.
2531
// __builtin_cpu_supports is a GCC/Clang builtin. MSVC does not support it;
2632
// on MSVC we always disable AVX2 and use the scalar fallback.
27-
#ifndef _MSC_VER
33+
#if ENABLE_AVX2
2834
static bool hasAVX2() { return __builtin_cpu_supports("avx2"); }
2935
#else
3036
static bool hasAVX2() { return false; }
@@ -73,7 +79,7 @@ void SysMemBandwidthBench::Setup(IComputeContext &context,
7379
std::memset(destBuffer, 0, bufferSize); // Touch pages
7480
}
7581

76-
#ifndef _MSC_VER
82+
#if ENABLE_AVX2
7783
// AVX2 kernels
7884
__attribute__((target("avx2"))) void run_read_avx2(const void *src,
7985
size_t size) {
@@ -194,7 +200,7 @@ void SysMemBandwidthBench::Run(uint32_t config_idx) {
194200
std::this_thread::yield();
195201
}
196202

197-
#ifndef _MSC_VER
203+
#if ENABLE_AVX2
198204
if (useAVX2) {
199205
if (config.mode == SysMemTestMode::Read) {
200206
run_read_avx2(tSrc, chunkSize);

0 commit comments

Comments
 (0)