-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
🚀 float NaN handling #21
Changes from 48 commits
edd083c
878dbdc
ec9dd42
4c27423
728e310
718a0ee
a046743
97adc4f
b58d0d6
ab36c08
ddad0a5
4cf61d8
599d247
4b81161
1b6231c
c3ddfeb
a3f7c4b
3324014
56c09cd
ccf0f8f
d8da46c
fa86ca8
d8f0896
2cf885b
aa14124
6026ad8
b5390b6
2c2ab4e
87422b7
a52571e
de00a6f
7b12400
4dbd0f4
c2b386a
e65d89b
fd7edfb
30fad1c
1b4bfe6
1d95552
859ac95
14f5070
dd698cf
4fcc780
c493e39
2e28b19
439b58b
049e9d3
84b6518
d53e09c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,21 +22,38 @@ arrow = { version = "*", default-features = false, optional = true} | |
default = ["half"] # TODO: remove this as default feature as soon as https://github.com/CodSpeedHQ/codspeed-rust/issues/1 is fixed | ||
|
||
[dev-dependencies] | ||
# rstest = { version = "0.16", default-features = false} | ||
# rstest_reuse = "0.5" | ||
codspeed-criterion-compat = "1.0.1" | ||
criterion = "0.3.1" | ||
dev_utils = { path = "dev_utils" } | ||
|
||
|
||
[[bench]] | ||
name = "bench_f16" | ||
name = "bench_f16_return_nan" | ||
harness = false | ||
required-features = ["half"] | ||
|
||
# TODO: support this | ||
# [[bench]] | ||
# name = "bench_f16_ignore_nan" | ||
# harness = false | ||
# required-features = ["half"] | ||
Comment on lines
+37
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is currently not supported as we use the |
||
|
||
[[bench]] | ||
name = "bench_f32_return_nan" | ||
harness = false | ||
|
||
[[bench]] | ||
name = "bench_f32_ignore_nan" | ||
harness = false | ||
|
||
[[bench]] | ||
name = "bench_f32" | ||
name = "bench_f64_return_nan" | ||
harness = false | ||
|
||
[[bench]] | ||
name = "bench_f64" | ||
name = "bench_f64_ignore_nan" | ||
harness = false | ||
|
||
[[bench]] | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#![feature(stdsimd)] | ||
|
||
extern crate dev_utils; | ||
|
||
#[cfg(feature = "half")] | ||
use argminmax::ArgMinMax; | ||
use codspeed_criterion_compat::*; | ||
use dev_utils::{config, utils}; | ||
|
||
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] | ||
use argminmax::{SIMDArgMinMax, AVX2, AVX512, SSE}; | ||
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))] | ||
use argminmax::{SIMDArgMinMax, NEON}; | ||
use argminmax::{ScalarArgMinMax, SCALAR}; | ||
|
||
#[cfg(feature = "half")] | ||
use half::f16; | ||
|
||
#[cfg(feature = "half")] | ||
fn get_random_f16_array(n: usize) -> Vec<f16> { | ||
let data = utils::get_random_array::<u16>(n, u16::MIN, u16::MAX); | ||
let data: Vec<f16> = data.iter().map(|&x| f16::from_bits(x)).collect(); | ||
// Replace NaNs and Infs with 0 | ||
let data: Vec<f16> = data | ||
.iter() | ||
.map(|&x| { | ||
if x.is_nan() || x.is_infinite() { | ||
f16::from_bits(0) | ||
} else { | ||
x | ||
} | ||
}) | ||
.collect(); | ||
data | ||
} | ||
|
||
// TODO: rename _random_long_ to _nanargminmax_ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do this in a separate PR (cleaning up the benchmarks; renaming + removing unused benchmarks) |
||
#[cfg(feature = "half")] | ||
fn nanargminmax_f16_random_array_long(c: &mut Criterion) { | ||
let n = config::ARRAY_LENGTH_LONG; | ||
let data: &[f16] = &get_random_f16_array(n); | ||
c.bench_function("scalar_random_long_f16", |b| { | ||
b.iter(|| SCALAR::argminmax(black_box(data))) | ||
}); | ||
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] | ||
if is_x86_feature_detected!("sse4.1") { | ||
c.bench_function("sse_random_long_f16", |b| { | ||
b.iter(|| unsafe { SSE::argminmax(black_box(data)) }) | ||
}); | ||
} | ||
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] | ||
if is_x86_feature_detected!("avx2") { | ||
c.bench_function("avx2_random_long_f16", |b| { | ||
b.iter(|| unsafe { AVX2::argminmax(black_box(data)) }) | ||
}); | ||
} | ||
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] | ||
if is_x86_feature_detected!("avx512bw") { | ||
c.bench_function("avx512_random_long_f16", |b| { | ||
b.iter(|| unsafe { AVX512::argminmax(black_box(data)) }) | ||
}); | ||
} | ||
#[cfg(target_arch = "arm")] | ||
if std::arch::is_arm_feature_detected!("neon") { | ||
c.bench_function("neon_random_long_f16", |b| { | ||
b.iter(|| unsafe { NEON::argminmax(black_box(data)) }) | ||
}); | ||
} | ||
#[cfg(target_arch = "aarch64")] | ||
if std::arch::is_aarch64_feature_detected!("neon") { | ||
c.bench_function("neon_random_long_f16", |b| { | ||
b.iter(|| unsafe { NEON::argminmax(black_box(data)) }) | ||
}); | ||
} | ||
c.bench_function("impl_random_long_f16", |b| { | ||
b.iter(|| black_box(data.nanargminmax())) | ||
}); | ||
} | ||
|
||
#[cfg(feature = "half")] | ||
criterion_group!(benches, nanargminmax_f16_random_array_long,); | ||
#[cfg(feature = "half")] | ||
criterion_main!(benches); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is something I experimented with and will use in a future PR (parameterizing the tests)