Skip to content

Commit 8ab1e0b

Browse files
committed
Panic if AVX or FMA is missing
Our compilation on x86 enables fma and avx in target-feature. We should panic if the running CPU is actually missing the feature because otherwise the behavior is undefined and in practice we've seen segfaults. The panic will be translated to a Postgres error.
1 parent 4834ced commit 8ab1e0b

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

pgvectorscale/src/access_method/distance.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ compile_error!(
55
"On x86, the AVX2 feature must be enabled. Set RUSTFLAGS=\"-C target-feature=+avx2,+fma\""
66
);
77

8+
pub fn init() {
9+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
10+
if (!is_x86_feature_detected!("avx2") || !is_x86_feature_detected!("fma")) {
11+
panic!("On x86, pgvectorscale requires the CPU to support AVX2 and FMA. See https://github.com/timescale/pgvectorscale/issues/115");
12+
}
13+
}
14+
815
#[inline]
916
pub fn distance_l2(a: &[f32], b: &[f32]) -> f32 {
1017
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]

pgvectorscale/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ mod util;
88
#[allow(non_snake_case)]
99
#[pg_guard]
1010
pub unsafe extern "C" fn _PG_init() {
11+
access_method::distance::init();
1112
access_method::options::init();
1213
access_method::guc::init();
1314
}

0 commit comments

Comments
 (0)