Skip to content

Commit 75a3911

Browse files
committed
SIMD
1 parent 45a072e commit 75a3911

3 files changed

Lines changed: 35 additions & 5 deletions

File tree

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__ = 1943
4+
__build__ = 1944
55
__author__ = "@joocer"
6-
__version__ = "0.26.2-beta.1943"
6+
__version__ = "0.26.2-beta.1944"
77

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

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.1943"
3+
version = "0.26.2-beta.1944"
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: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import os
77
import platform
88
import sys
9+
import subprocess
910

1011
import numpy
1112
from Cython.Build import cythonize
@@ -45,6 +46,32 @@ def detect_architecture():
4546
return "x86_64"
4647
return machine
4748

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+
4875
# Compiler flags with SIMD support
4976
arch = detect_architecture()
5077
CPP_FLAGS = ["-O3", "-std=c++17"]
@@ -61,8 +88,11 @@ def detect_architecture():
6188
if arch == "x86_64":
6289
# Add SIMD support
6390
CPP_FLAGS.extend(["-msse4.2", "-mavx2"])
64-
# Add AVX512 support
65-
CPP_FLAGS.extend(["-mavx512f", "-mavx512cd", "-mavx512bw", "-mavx512dq", "-mavx512vl"])
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"])
6696
elif arch == "arm" and not is_mac():
6797
CPP_FLAGS.append("-mfpu=neon")
6898

0 commit comments

Comments
 (0)