1
0
mirror of https://github.com/tensorchord/pgvecto.rs.git synced 2025-07-30 19:23:05 +03:00

C code tests & avx512f f16 implement (#183)

* test: add tests for c code

Signed-off-by: usamoi <usamoi@outlook.com>

* fix: relax EPSILON for tests

Signed-off-by: usamoi <usamoi@outlook.com>

---------

Signed-off-by: usamoi <usamoi@outlook.com>
This commit is contained in:
Usamoi
2023-12-15 16:00:08 +08:00
committed by GitHub
parent 2869fbd44c
commit c50912e87d
13 changed files with 276 additions and 31 deletions

8
crates/detect/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "detect"
version.workspace = true
edition.workspace = true
[dependencies]
std_detect = { git = "https://github.com/tensorchord/stdarch.git", branch = "avx512fp16" }
ctor = "0.2.6"

1
crates/detect/src/lib.rs Normal file
View File

@ -0,0 +1 @@
pub mod x86_64;

View File

@ -0,0 +1,85 @@
#![cfg(target_arch = "x86_64")]
use std::sync::atomic::{AtomicBool, Ordering};
static ATOMIC_AVX512FP16: AtomicBool = AtomicBool::new(false);
pub fn test_avx512fp16() -> bool {
std_detect::is_x86_feature_detected!("avx512fp16") && test_v4()
}
#[ctor::ctor]
fn ctor_avx512fp16() {
ATOMIC_AVX512FP16.store(test_avx512fp16(), Ordering::Relaxed);
}
pub fn detect_avx512fp16() -> bool {
ATOMIC_AVX512FP16.load(Ordering::Relaxed)
}
static ATOMIC_V4: AtomicBool = AtomicBool::new(false);
pub fn test_v4() -> bool {
std_detect::is_x86_feature_detected!("avx512bw")
&& std_detect::is_x86_feature_detected!("avx512cd")
&& std_detect::is_x86_feature_detected!("avx512dq")
&& std_detect::is_x86_feature_detected!("avx512f")
&& std_detect::is_x86_feature_detected!("avx512vl")
&& test_v3()
}
#[ctor::ctor]
fn ctor_v4() {
ATOMIC_V4.store(test_v4(), Ordering::Relaxed);
}
pub fn detect_v4() -> bool {
ATOMIC_V4.load(Ordering::Relaxed)
}
static ATOMIC_V3: AtomicBool = AtomicBool::new(false);
pub fn test_v3() -> bool {
std_detect::is_x86_feature_detected!("avx")
&& std_detect::is_x86_feature_detected!("avx2")
&& std_detect::is_x86_feature_detected!("bmi1")
&& std_detect::is_x86_feature_detected!("bmi2")
&& std_detect::is_x86_feature_detected!("f16c")
&& std_detect::is_x86_feature_detected!("fma")
&& std_detect::is_x86_feature_detected!("lzcnt")
&& std_detect::is_x86_feature_detected!("movbe")
&& std_detect::is_x86_feature_detected!("xsave")
&& test_v2()
}
#[ctor::ctor]
fn ctor_v3() {
ATOMIC_V3.store(test_v3(), Ordering::Relaxed);
}
pub fn detect_v3() -> bool {
ATOMIC_V3.load(Ordering::Relaxed)
}
static ATOMIC_V2: AtomicBool = AtomicBool::new(false);
pub fn test_v2() -> bool {
std_detect::is_x86_feature_detected!("cmpxchg16b")
&& std_detect::is_x86_feature_detected!("fxsr")
&& std_detect::is_x86_feature_detected!("popcnt")
&& std_detect::is_x86_feature_detected!("sse")
&& std_detect::is_x86_feature_detected!("sse2")
&& std_detect::is_x86_feature_detected!("sse3")
&& std_detect::is_x86_feature_detected!("sse4.1")
&& std_detect::is_x86_feature_detected!("sse4.2")
&& std_detect::is_x86_feature_detected!("ssse3")
}
#[ctor::ctor]
fn ctor_v2() {
ATOMIC_V2.store(test_v2(), Ordering::Relaxed);
}
pub fn _detect_v2() -> bool {
ATOMIC_V2.load(Ordering::Relaxed)
}