You've already forked pgvecto.rs
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:
@ -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
|
||||
|
@ -1 +1,2 @@
|
||||
pub mod linux;
|
||||
pub mod x86_64;
|
||||
|
24
crates/detect/src/linux.rs
Normal file
24
crates/detect/src/linux.rs
Normal 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)
|
||||
}
|
@ -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)
|
||||
}
|
||||
|
6
crates/detect/tests/linux.rs
Normal file
6
crates/detect/tests/linux.rs
Normal file
@ -0,0 +1,6 @@
|
||||
#![cfg(target_os = "linux")]
|
||||
|
||||
#[test]
|
||||
fn print() {
|
||||
assert_eq!(detect::linux::test_memfd(), detect::linux::detect_memfd());
|
||||
}
|
12
crates/detect/tests/x86_64.rs
Normal file
12
crates/detect/tests/x86_64.rs
Normal 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());
|
||||
}
|
Reference in New Issue
Block a user