Skip to content

Commit

Permalink
test: run bvecf32 test for 10000 times
Browse files Browse the repository at this point in the history
Signed-off-by: usamoi <[email protected]>
  • Loading branch information
usamoi committed Mar 26, 2024
1 parent bc66423 commit 4a360a3
Showing 1 changed file with 48 additions and 72 deletions.
120 changes: 48 additions & 72 deletions crates/base/src/vector/bvecf32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,24 +245,16 @@ fn cosine_v4_avx512vpopcntdq_test() {
println!("test {} ... skipped (v4_avx512vpopcntdq)", module_path!());
return;
}
let lhs = {
let mut x = vec![0; 126];
x.fill_with(|| rand::random());
x[125] &= 1;
BVecf32Owned::new(8001, x)
};
let rhs = {
let mut x = vec![0; 126];
x.fill_with(|| rand::random());
x[125] &= 1;
BVecf32Owned::new(8001, x)
};
let specialized = unsafe { cosine_v4_avx512vpopcntdq(lhs.for_borrow(), rhs.for_borrow()) };
let fallback = unsafe { cosine_fallback(lhs.for_borrow(), rhs.for_borrow()) };
assert!(
(specialized - fallback).abs() < EPSILON,
"specialized = {specialized}, fallback = {fallback}."
);
for _ in 0..10000 {
let lhs = random_bvector();
let rhs = random_bvector();
let specialized = unsafe { cosine_v4_avx512vpopcntdq(lhs.for_borrow(), rhs.for_borrow()) };
let fallback = unsafe { cosine_fallback(lhs.for_borrow(), rhs.for_borrow()) };
assert!(
(specialized - fallback).abs() < EPSILON,
"specialized = {specialized}, fallback = {fallback}."
);
}
}

#[detect::multiversion(v4_avx512vpopcntdq = import, v4, v3, v2, neon, fallback = export)]
Expand Down Expand Up @@ -327,24 +319,16 @@ fn dot_v4_avx512vpopcntdq_test() {
println!("test {} ... skipped (v4_avx512vpopcntdq)", module_path!());
return;
}
let lhs = {
let mut x = vec![0; 126];
x.fill_with(|| rand::random());
x[125] &= 1;
BVecf32Owned::new(8001, x)
};
let rhs = {
let mut x = vec![0; 126];
x.fill_with(|| rand::random());
x[125] &= 1;
BVecf32Owned::new(8001, x)
};
let specialized = unsafe { dot_v4_avx512vpopcntdq(lhs.for_borrow(), rhs.for_borrow()) };
let fallback = unsafe { dot_fallback(lhs.for_borrow(), rhs.for_borrow()) };
assert!(
(specialized - fallback).abs() < EPSILON,
"specialized = {specialized}, fallback = {fallback}."
);
for _ in 0..10000 {
let lhs = random_bvector();
let rhs = random_bvector();
let specialized = unsafe { dot_v4_avx512vpopcntdq(lhs.for_borrow(), rhs.for_borrow()) };
let fallback = unsafe { dot_fallback(lhs.for_borrow(), rhs.for_borrow()) };
assert!(
(specialized - fallback).abs() < EPSILON,
"specialized = {specialized}, fallback = {fallback}."
);
}
}

#[detect::multiversion(v4_avx512vpopcntdq = import, v4, v3, v2, neon, fallback = export)]
Expand Down Expand Up @@ -402,24 +386,16 @@ fn sl2_v4_avx512vpopcntdq_test() {
println!("test {} ... skipped (v4_avx512vpopcntdq)", module_path!());
return;
}
let lhs = {
let mut x = vec![0; 126];
x.fill_with(|| rand::random());
x[125] &= 1;
BVecf32Owned::new(8001, x)
};
let rhs = {
let mut x = vec![0; 126];
x.fill_with(|| rand::random());
x[125] &= 1;
BVecf32Owned::new(8001, x)
};
let specialized = unsafe { sl2_v4_avx512vpopcntdq(lhs.for_borrow(), rhs.for_borrow()) };
let fallback = unsafe { sl2_fallback(lhs.for_borrow(), rhs.for_borrow()) };
assert!(
(specialized - fallback).abs() < EPSILON,
"specialized = {specialized}, fallback = {fallback}."
);
for _ in 0..10000 {
let lhs = random_bvector();
let rhs = random_bvector();
let specialized = unsafe { sl2_v4_avx512vpopcntdq(lhs.for_borrow(), rhs.for_borrow()) };
let fallback = unsafe { sl2_fallback(lhs.for_borrow(), rhs.for_borrow()) };
assert!(
(specialized - fallback).abs() < EPSILON,
"specialized = {specialized}, fallback = {fallback}."
);
}
}

#[detect::multiversion(v4_avx512vpopcntdq = import, v4, v3, v2, neon, fallback = export)]
Expand Down Expand Up @@ -481,24 +457,16 @@ fn jaccard_v4_avx512vpopcntdq_test() {
println!("test {} ... skipped (v4_avx512vpopcntdq)", module_path!());
return;
}
let lhs = {
let mut x = vec![0; 126];
x.fill_with(|| rand::random());
x[125] &= 1;
BVecf32Owned::new(8001, x)
};
let rhs = {
let mut x = vec![0; 126];
x.fill_with(|| rand::random());
x[125] &= 1;
BVecf32Owned::new(8001, x)
};
let specialized = unsafe { jaccard_v4_avx512vpopcntdq(lhs.for_borrow(), rhs.for_borrow()) };
let fallback = unsafe { jaccard_fallback(lhs.for_borrow(), rhs.for_borrow()) };
assert!(
(specialized - fallback).abs() < EPSILON,
"specialized = {specialized}, fallback = {fallback}."
);
for _ in 0..10000 {
let lhs = random_bvector();
let rhs = random_bvector();
let specialized = unsafe { jaccard_v4_avx512vpopcntdq(lhs.for_borrow(), rhs.for_borrow()) };
let fallback = unsafe { jaccard_fallback(lhs.for_borrow(), rhs.for_borrow()) };
assert!(
(specialized - fallback).abs() < EPSILON,
"specialized = {specialized}, fallback = {fallback}."
);
}
}

#[detect::multiversion(v4_avx512vpopcntdq = import, v4, v3, v2, neon, fallback = export)]
Expand Down Expand Up @@ -558,3 +526,11 @@ pub fn l2_normalize<'a>(vector: BVecf32Borrowed<'a>) -> Vecf32Owned {
let l = length(vector);
Vecf32Owned::new(vector.iter().map(|i| F32(i as u32 as f32) / l).collect())
}

#[cfg(all(target_arch = "x86_64", test))]
fn random_bvector() -> BVecf32Owned {
let mut x = vec![0; 126];
x.fill_with(|| rand::random());
x[125] &= 1;
BVecf32Owned::new(8001, x)
}

0 comments on commit 4a360a3

Please sign in to comment.