Skip to content

Commit

Permalink
fix: remove ctor (#339)
Browse files Browse the repository at this point in the history
Signed-off-by: usamoi <usamoi@outlook.com>
  • Loading branch information
usamoi authored Feb 2, 2024
1 parent 7ec3c88 commit 4eb1f87
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 26 deletions.
11 changes: 0 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crates/c/tests/x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#[test]
fn test_v_f16_cosine() {
detect::initialize();
const EPSILON: f32 = f16::EPSILON.to_f32_const();
use half::f16;
unsafe fn v_f16_cosine(a: *const u16, b: *const u16, n: usize) -> f32 {
Expand Down Expand Up @@ -46,6 +47,7 @@ fn test_v_f16_cosine() {

#[test]
fn test_v_f16_dot() {
detect::initialize();
const EPSILON: f32 = 1.0f32;
use half::f16;
unsafe fn v_f16_dot(a: *const u16, b: *const u16, n: usize) -> f32 {
Expand Down Expand Up @@ -86,6 +88,7 @@ fn test_v_f16_dot() {

#[test]
fn test_v_f16_sl2() {
detect::initialize();
const EPSILON: f32 = 1.0f32;
use half::f16;
unsafe fn v_f16_sl2(a: *const u16, b: *const u16, n: usize) -> f32 {
Expand Down
1 change: 0 additions & 1 deletion crates/detect/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ edition.workspace = true

[dependencies]
std_detect = { git = "https://github.com/tensorchord/stdarch.git", branch = "avx512fp16" }
ctor = "0.2.6"
rustix.workspace = true
17 changes: 17 additions & 0 deletions crates/detect/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
#[cfg(target_os = "linux")]
pub mod linux;

#[cfg(target_arch = "x86_64")]
pub mod x86_64;

pub fn initialize() {
#[cfg(target_os = "linux")]
{
self::linux::ctor_memfd();
}
#[cfg(target_arch = "x86_64")]
{
self::x86_64::ctor_avx512fp16();
self::x86_64::ctor_v2();
self::x86_64::ctor_v3();
self::x86_64::ctor_v4();
}
}
5 changes: 1 addition & 4 deletions crates/detect/src/linux.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![cfg(target_os = "linux")]

use std::sync::atomic::{AtomicBool, Ordering};

static ATOMIC_MEMFD: AtomicBool = AtomicBool::new(false);
Expand All @@ -14,8 +12,7 @@ pub fn test_memfd() -> bool {
}
}

#[ctor::ctor]
fn ctor_memfd() {
pub fn ctor_memfd() {
ATOMIC_MEMFD.store(test_memfd(), Ordering::Relaxed);
}

Expand Down
14 changes: 4 additions & 10 deletions crates/detect/src/x86_64.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![cfg(target_arch = "x86_64")]

use std::sync::atomic::{AtomicBool, Ordering};

static ATOMIC_AVX512FP16: AtomicBool = AtomicBool::new(false);
Expand All @@ -8,8 +6,7 @@ pub fn test_avx512fp16() -> bool {
std_detect::is_x86_feature_detected!("avx512fp16") && test_v4()
}

#[ctor::ctor]
fn ctor_avx512fp16() {
pub fn ctor_avx512fp16() {
ATOMIC_AVX512FP16.store(test_avx512fp16(), Ordering::Relaxed);
}

Expand All @@ -28,8 +25,7 @@ pub fn test_v4() -> bool {
&& test_v3()
}

#[ctor::ctor]
fn ctor_v4() {
pub fn ctor_v4() {
ATOMIC_V4.store(test_v4(), Ordering::Relaxed);
}

Expand All @@ -52,8 +48,7 @@ pub fn test_v3() -> bool {
&& test_v2()
}

#[ctor::ctor]
fn ctor_v3() {
pub fn ctor_v3() {
ATOMIC_V3.store(test_v3(), Ordering::Relaxed);
}

Expand All @@ -75,8 +70,7 @@ pub fn test_v2() -> bool {
&& std_detect::is_x86_feature_detected!("ssse3")
}

#[ctor::ctor]
fn ctor_v2() {
pub fn ctor_v2() {
ATOMIC_V2.store(test_v2(), Ordering::Relaxed);
}

Expand Down
1 change: 1 addition & 0 deletions crates/detect/tests/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

#[test]
fn print() {
detect::initialize();
assert_eq!(detect::linux::test_memfd(), detect::linux::detect_memfd());
}
1 change: 1 addition & 0 deletions crates/detect/tests/x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#[test]
fn print() {
detect::initialize();
assert_eq!(
detect::x86_64::test_avx512fp16(),
detect::x86_64::detect_avx512fp16()
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ unsafe extern "C" fn _PG_init() {
SessionError::BadInit.friendly();
}
unsafe {
detect::initialize();
self::gucs::init();
self::index::init();
self::ipc::init();
Expand Down

0 comments on commit 4eb1f87

Please sign in to comment.