1
0
mirror of https://github.com/tensorchord/pgvecto.rs.git synced 2025-07-29 08:21:12 +03:00

chore: move memfd detect to detect crate (#213)

Signed-off-by: usamoi <usamoi@outlook.com>
This commit is contained in:
Usamoi
2023-12-28 19:14:55 +08:00
committed by GitHub
parent 4d34b45b23
commit 2dc6b721f3
11 changed files with 157 additions and 123 deletions

View File

@ -6,3 +6,4 @@ edition.workspace = true
[dependencies]
std_detect = { git = "https://github.com/tensorchord/stdarch.git", branch = "avx512fp16" }
ctor = "0.2.6"
rustix.workspace = true

View File

@ -1 +1,2 @@
pub mod linux;
pub mod x86_64;

View File

@ -0,0 +1,24 @@
#![cfg(target_os = "linux")]
use std::sync::atomic::{AtomicBool, Ordering};
static ATOMIC_MEMFD: AtomicBool = AtomicBool::new(false);
pub fn test_memfd() -> bool {
use rustix::fs::MemfdFlags;
use std::io::ErrorKind;
match rustix::fs::memfd_create(".memfd.VECTORS.SUPPORT", MemfdFlags::empty()) {
Ok(_) => true,
Err(e) if e.kind() == ErrorKind::Unsupported => false,
Err(_) => false,
}
}
#[ctor::ctor]
fn ctor_memfd() {
ATOMIC_MEMFD.store(test_memfd(), Ordering::Relaxed);
}
pub fn detect_memfd() -> bool {
ATOMIC_MEMFD.load(Ordering::Relaxed)
}

View File

@ -80,6 +80,6 @@ fn ctor_v2() {
ATOMIC_V2.store(test_v2(), Ordering::Relaxed);
}
pub fn _detect_v2() -> bool {
pub fn detect_v2() -> bool {
ATOMIC_V2.load(Ordering::Relaxed)
}

View File

@ -0,0 +1,6 @@
#![cfg(target_os = "linux")]
#[test]
fn print() {
assert_eq!(detect::linux::test_memfd(), detect::linux::detect_memfd());
}

View File

@ -0,0 +1,12 @@
#![cfg(target_arch = "x86_64")]
#[test]
fn print() {
assert_eq!(
detect::x86_64::test_avx512fp16(),
detect::x86_64::detect_avx512fp16()
);
assert_eq!(detect::x86_64::test_v4(), detect::x86_64::detect_v4());
assert_eq!(detect::x86_64::test_v3(), detect::x86_64::detect_v3());
assert_eq!(detect::x86_64::test_v2(), detect::x86_64::detect_v2());
}