Skip to content

Commit 0fc92f9

Browse files
authored
Merge pull request #2956 from mabel-dev/remove-avx512
remove avx512
2 parents 2b2adb1 + f6dcf85 commit 0fc92f9

20 files changed

Lines changed: 46 additions & 476 deletions

opteryx/__version__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# THIS FILE IS AUTOMATICALLY UPDATED DURING THE BUILD PROCESS
22
# DO NOT EDIT THIS FILE DIRECTLY
33

4-
__build__ = 1947
4+
__build__ = 1951
55
__author__ = "@joocer"
6-
__version__ = "0.26.2-beta.1947"
6+
__version__ = "0.26.2-beta.1951"
77

88
# Store the version here so:
99
# 1) we don't load dependencies by storing it in __init__.py

opteryx/compiled/simd_probe.pyx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
cdef extern from "simd_env.h":
1010
void opteryx_check_simd_env_or_abort()
1111
int opteryx_cpu_supports_avx2()
12-
int opteryx_cpu_supports_avx512()
1312
int opteryx_cpu_supports_neon()
1413

1514
def check_env_or_abort():
@@ -21,18 +20,15 @@ def check_env_or_abort():
2120
def cpu_supports_avx2() -> bool:
2221
return bool(opteryx_cpu_supports_avx2())
2322

24-
def cpu_supports_avx512() -> bool:
25-
return bool(opteryx_cpu_supports_avx512())
26-
2723
def cpu_supports_neon() -> bool:
2824
return bool(opteryx_cpu_supports_neon())
2925

26+
27+
3028
def cpu_architecture() -> list:
3129
architecture = []
3230
if cpu_supports_avx2():
3331
architecture.append("AVX2")
34-
if cpu_supports_avx512():
35-
architecture.append("AVX512")
3632
if cpu_supports_neon():
3733
architecture.append("NEON")
3834
return architecture

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "opteryx"
3-
version = "0.26.2-beta.1947"
3+
version = "0.26.2-beta.1951"
44
description = "Query your data, where it lives"
55
requires-python = '>=3.11'
66
readme = {file = "README.md", content-type = "text/markdown"}

setup.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import glob
66
import os
77
import platform
8-
import subprocess
98
import sys
109

1110
import numpy
@@ -46,32 +45,6 @@ def detect_architecture():
4645
return "x86_64"
4746
return machine
4847

49-
50-
def build_supports_avx512():
51-
"""Check at build time whether the local build machine supports AVX512.
52-
53-
We prefer a lightweight check from /proc/cpuinfo on Linux and use sysctl on
54-
macOS if available. This prevents us from adding global AVX512 compile
55-
flags when the build machine doesn't support them (which can cause
56-
illegal instruction errors if a binary built with those flags runs on a
57-
machine without AVX512).
58-
"""
59-
if is_linux():
60-
try:
61-
with open('/proc/cpuinfo', 'r', encoding='utf8') as cpuinfo_file:
62-
contents = cpuinfo_file.read()
63-
return 'avx512f' in contents and 'avx512bw' in contents
64-
except FileNotFoundError:
65-
return False
66-
if is_mac():
67-
try:
68-
# Attempt to use sysctl to query CPU features
69-
out = subprocess.check_output(['sysctl', '-n', 'machdep.cpu.leaf7_features'], text=True)
70-
return 'AVX512F' in out and 'AVX512BW' in out
71-
except (subprocess.CalledProcessError, FileNotFoundError):
72-
return False
73-
return False
74-
7548
# Compiler flags with SIMD support
7649
arch = detect_architecture()
7750
CPP_FLAGS = ["-O3", "-std=c++17"]
@@ -88,11 +61,6 @@ def build_supports_avx512():
8861
if arch == "x86_64":
8962
# Add SIMD support
9063
CPP_FLAGS.extend(["-msse4.2", "-mavx2"])
91-
# Add AVX512 support only if the build host supports it. This keeps
92-
# compilation portable and prevents the compiler from embedding AVX512 in
93-
# scalar paths when the instruction set isn't available on the test runner.
94-
if build_supports_avx512():
95-
CPP_FLAGS.extend(["-mavx512f", "-mavx512cd", "-mavx512bw", "-mavx512dq", "-mavx512vl"])
9664
elif arch == "arm" and not is_mac():
9765
CPP_FLAGS.append("-mfpu=neon")
9866

src/cpp/cpu_features.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -71,29 +71,6 @@ bool cpu_supports_avx2() {
7171
#endif
7272
}
7373

74-
bool cpu_supports_avx512() {
75-
#if defined(__x86_64__) || defined(__i386__)
76-
#if (defined(__GNUC__) || defined(__clang__))
77-
#ifdef __builtin_cpu_supports
78-
if (__builtin_cpu_supports("avx512f") && __builtin_cpu_supports("avx512bw"))
79-
return true;
80-
#endif
81-
82-
#if defined(__linux__)
83-
std::ifstream f("/proc/cpuinfo");
84-
if (f) {
85-
std::string contents((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
86-
if (contents.find("avx512f") != std::string::npos && contents.find("avx512bw") != std::string::npos)
87-
return true;
88-
}
89-
#endif
90-
#endif
91-
return false;
92-
#else
93-
return false;
94-
#endif
95-
}
96-
9774
bool cpu_supports_neon() {
9875
#if defined(__arm__) || defined(__aarch64__)
9976
// On Linux, check HWCAP

src/cpp/cpu_features.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ extern "C" {
77
#endif
88

99
bool cpu_supports_avx2();
10-
bool cpu_supports_avx512();
1110
bool cpu_supports_neon();
1211

1312
#ifdef __cplusplus

src/cpp/simd_bitops.cpp

Lines changed: 7 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "simd_dispatch.h"
66
#include "cpu_features.h"
77

8-
#if (defined(__AVX512F__) && defined(__AVX512BW__)) || defined(__AVX2__)
8+
#if defined(__AVX2__)
99
#include <immintrin.h>
1010
#endif
1111

@@ -24,19 +24,6 @@ static void simd_and_mask_scalar(uint8_t* dest, const uint8_t* a, const uint8_t*
2424
}
2525
}
2626

27-
#if defined(__AVX512F__) && defined(__AVX512BW__)
28-
static void simd_and_mask_avx512(uint8_t* dest, const uint8_t* a, const uint8_t* b, size_t n) {
29-
size_t i = 0;
30-
for (; i + 64 <= n; i += 64) {
31-
__m512i va = _mm512_loadu_si512(reinterpret_cast<const __m512i*>(a + i));
32-
__m512i vb = _mm512_loadu_si512(reinterpret_cast<const __m512i*>(b + i));
33-
__m512i result = _mm512_and_si512(va, vb);
34-
_mm512_storeu_si512(reinterpret_cast<__m512i*>(dest + i), result);
35-
}
36-
for (; i < n; i++) dest[i] = a[i] & b[i];
37-
}
38-
#endif
39-
4027
#if defined(__AVX2__)
4128
static void simd_and_mask_avx2(uint8_t* dest, const uint8_t* a, const uint8_t* b, size_t n) {
4229
size_t i = 0;
@@ -67,10 +54,8 @@ void simd_and_mask(uint8_t* dest, const uint8_t* a, const uint8_t* b, size_t n)
6754
using fn_t = void(*)(uint8_t*, const uint8_t*, const uint8_t*, size_t);
6855
static std::atomic<fn_t> cache{nullptr};
6956

70-
fn_t fn = simd::select_dispatch<fn_t>(cache, {
71-
#if defined(__AVX512F__) && defined(__AVX512BW__)
72-
{ &cpu_supports_avx512, simd_and_mask_avx512 },
73-
#endif
57+
#if defined(__AVX2__)
58+
fn_t fn = simd::select_dispatch<fn_t>(cache, {
7459
#if defined(__AVX2__)
7560
{ &cpu_supports_avx2, simd_and_mask_avx2 },
7661
#endif
@@ -91,19 +76,6 @@ static void simd_or_mask_scalar(uint8_t* dest, const uint8_t* a, const uint8_t*
9176
for (size_t i = 0; i < n; i++) dest[i] = a[i] | b[i];
9277
}
9378

94-
#if defined(__AVX512F__) && defined(__AVX512BW__)
95-
static void simd_or_mask_avx512(uint8_t* dest, const uint8_t* a, const uint8_t* b, size_t n) {
96-
size_t i = 0;
97-
for (; i + 64 <= n; i += 64) {
98-
__m512i va = _mm512_loadu_si512(reinterpret_cast<const __m512i*>(a + i));
99-
__m512i vb = _mm512_loadu_si512(reinterpret_cast<const __m512i*>(b + i));
100-
__m512i result = _mm512_or_si512(va, vb);
101-
_mm512_storeu_si512(reinterpret_cast<__m512i*>(dest + i), result);
102-
}
103-
for (; i < n; i++) dest[i] = a[i] | b[i];
104-
}
105-
#endif
106-
10779
#if defined(__AVX2__)
10880
static void simd_or_mask_avx2(uint8_t* dest, const uint8_t* a, const uint8_t* b, size_t n) {
10981
size_t i = 0;
@@ -134,10 +106,8 @@ void simd_or_mask(uint8_t* dest, const uint8_t* a, const uint8_t* b, size_t n) {
134106
using fn_t = void(*)(uint8_t*, const uint8_t*, const uint8_t*, size_t);
135107
static std::atomic<fn_t> cache{nullptr};
136108

109+
#if defined(__AVX2__)
137110
fn_t fn = simd::select_dispatch<fn_t>(cache, {
138-
#if defined(__AVX512F__) && defined(__AVX512BW__)
139-
{ &cpu_supports_avx512, simd_or_mask_avx512 },
140-
#endif
141111
#if defined(__AVX2__)
142112
{ &cpu_supports_avx2, simd_or_mask_avx2 },
143113
#endif
@@ -158,19 +128,6 @@ static void simd_xor_mask_scalar(uint8_t* dest, const uint8_t* a, const uint8_t*
158128
for (size_t i = 0; i < n; i++) dest[i] = a[i] ^ b[i];
159129
}
160130

161-
#if defined(__AVX512F__) && defined(__AVX512BW__)
162-
static void simd_xor_mask_avx512(uint8_t* dest, const uint8_t* a, const uint8_t* b, size_t n) {
163-
size_t i = 0;
164-
for (; i + 64 <= n; i += 64) {
165-
__m512i va = _mm512_loadu_si512(reinterpret_cast<const __m512i*>(a + i));
166-
__m512i vb = _mm512_loadu_si512(reinterpret_cast<const __m512i*>(b + i));
167-
__m512i result = _mm512_xor_si512(va, vb);
168-
_mm512_storeu_si512(reinterpret_cast<__m512i*>(dest + i), result);
169-
}
170-
for (; i < n; i++) dest[i] = a[i] ^ b[i];
171-
}
172-
#endif
173-
174131
#if defined(__AVX2__)
175132
static void simd_xor_mask_avx2(uint8_t* dest, const uint8_t* a, const uint8_t* b, size_t n) {
176133
size_t i = 0;
@@ -201,10 +158,8 @@ void simd_xor_mask(uint8_t* dest, const uint8_t* a, const uint8_t* b, size_t n)
201158
using fn_t = void(*)(uint8_t*, const uint8_t*, const uint8_t*, size_t);
202159
static std::atomic<fn_t> cache{nullptr};
203160

161+
#if defined(__AVX2__)
204162
fn_t fn = simd::select_dispatch<fn_t>(cache, {
205-
#if defined(__AVX512F__) && defined(__AVX512BW__)
206-
{ &cpu_supports_avx512, simd_xor_mask_avx512 },
207-
#endif
208163
#if defined(__AVX2__)
209164
{ &cpu_supports_avx2, simd_xor_mask_avx2 },
210165
#endif
@@ -225,19 +180,6 @@ static void simd_not_mask_scalar(uint8_t* dest, const uint8_t* src, size_t n) {
225180
for (size_t i = 0; i < n; i++) dest[i] = ~src[i];
226181
}
227182

228-
#if defined(__AVX512F__) && defined(__AVX512BW__)
229-
static void simd_not_mask_avx512(uint8_t* dest, const uint8_t* src, size_t n) {
230-
size_t i = 0;
231-
__m512i all_ones = _mm512_set1_epi8(static_cast<char>(0xFF));
232-
for (; i + 64 <= n; i += 64) {
233-
__m512i v = _mm512_loadu_si512(reinterpret_cast<const __m512i*>(src + i));
234-
__m512i result = _mm512_xor_si512(v, all_ones);
235-
_mm512_storeu_si512(reinterpret_cast<__m512i*>(dest + i), result);
236-
}
237-
for (; i < n; i++) dest[i] = ~src[i];
238-
}
239-
#endif
240-
241183
#if defined(__AVX2__)
242184
static void simd_not_mask_avx2(uint8_t* dest, const uint8_t* src, size_t n) {
243185
size_t i = 0;
@@ -267,10 +209,8 @@ void simd_not_mask(uint8_t* dest, const uint8_t* src, size_t n) {
267209
using fn_t = void(*)(uint8_t*, const uint8_t*, size_t);
268210
static std::atomic<fn_t> cache{nullptr};
269211

212+
#if defined(__AVX2__)
270213
fn_t fn = simd::select_dispatch<fn_t>(cache, {
271-
#if defined(__AVX512F__) && defined(__AVX512BW__)
272-
{ &cpu_supports_avx512, simd_not_mask_avx512 },
273-
#endif
274214
#if defined(__AVX2__)
275215
{ &cpu_supports_avx2, simd_not_mask_avx2 },
276216
#endif
@@ -330,24 +270,6 @@ static void simd_select_bytes_scalar(uint8_t* dest, const uint8_t* mask,
330270
for (size_t i = 0; i < n; i++) dest[i] = mask[i] ? a[i] : b[i];
331271
}
332272

333-
#if defined(__AVX512F__) && defined(__AVX512BW__)
334-
static void simd_select_bytes_avx512(uint8_t* dest, const uint8_t* mask,
335-
const uint8_t* a, const uint8_t* b, size_t n) {
336-
size_t i = 0;
337-
__m512i zero = _mm512_setzero_si512();
338-
339-
for (; i + 64 <= n; i += 64) {
340-
__m512i vm = _mm512_loadu_si512(reinterpret_cast<const __m512i*>(mask + i));
341-
__m512i va = _mm512_loadu_si512(reinterpret_cast<const __m512i*>(a + i));
342-
__m512i vb = _mm512_loadu_si512(reinterpret_cast<const __m512i*>(b + i));
343-
__mmask64 m = _mm512_cmpneq_epu8_mask(vm, zero);
344-
__m512i result = _mm512_mask_blend_epi8(m, vb, va);
345-
_mm512_storeu_si512(reinterpret_cast<__m512i*>(dest + i), result);
346-
}
347-
for (; i < n; i++) dest[i] = mask[i] ? a[i] : b[i];
348-
}
349-
#endif
350-
351273
#if defined(__AVX2__)
352274
static void simd_select_bytes_avx2(uint8_t* dest, const uint8_t* mask,
353275
const uint8_t* a, const uint8_t* b, size_t n) {
@@ -371,10 +293,8 @@ void simd_select_bytes(uint8_t* dest, const uint8_t* mask,
371293
using fn_t = void(*)(uint8_t*, const uint8_t*, const uint8_t*, const uint8_t*, size_t);
372294
static std::atomic<fn_t> cache{nullptr};
373295

296+
#if defined(__AVX2__)
374297
fn_t fn = simd::select_dispatch<fn_t>(cache, {
375-
#if defined(__AVX512F__) && defined(__AVX512BW__)
376-
{ &cpu_supports_avx512, simd_select_bytes_avx512 },
377-
#endif
378298
#if defined(__AVX2__)
379299
{ &cpu_supports_avx2, simd_select_bytes_avx2 },
380300
#endif

src/cpp/simd_bitops.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ extern "C" {
1010

1111
/**
1212
* SIMD-accelerated bitwise AND operation on byte arrays.
13-
* Processes 64 bytes at once on AVX512, 32 on AVX2, 16 on NEON.
13+
* Processes 32 bytes at a time on AVX2, 16 on NEON.
1414
*
1515
* @param dest Destination buffer (can be same as a or b for in-place)
1616
* @param a First input buffer
@@ -21,7 +21,7 @@ void simd_and_mask(uint8_t* dest, const uint8_t* a, const uint8_t* b, size_t n);
2121

2222
/**
2323
* SIMD-accelerated bitwise OR operation on byte arrays.
24-
* Processes 64 bytes at once on AVX512, 32 on AVX2, 16 on NEON.
24+
* Processes 32 bytes at a time on AVX2, 16 on NEON.
2525
*
2626
* @param dest Destination buffer (can be same as a or b for in-place)
2727
* @param a First input buffer
@@ -32,7 +32,7 @@ void simd_or_mask(uint8_t* dest, const uint8_t* a, const uint8_t* b, size_t n);
3232

3333
/**
3434
* SIMD-accelerated bitwise XOR operation on byte arrays.
35-
* Processes 64 bytes at once on AVX512, 32 on AVX2, 16 on NEON.
35+
* Processes 32 bytes at a time on AVX2, 16 on NEON.
3636
*
3737
* @param dest Destination buffer (can be same as a or b for in-place)
3838
* @param a First input buffer
@@ -43,7 +43,7 @@ void simd_xor_mask(uint8_t* dest, const uint8_t* a, const uint8_t* b, size_t n);
4343

4444
/**
4545
* SIMD-accelerated bitwise NOT operation on byte array.
46-
* Processes 64 bytes at once on AVX512, 32 on AVX2, 16 on NEON.
46+
* Processes 32 bytes at a time on AVX2, 16 on NEON.
4747
*
4848
* @param dest Destination buffer (can be same as src for in-place)
4949
* @param src Source buffer

0 commit comments

Comments
 (0)