-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from jvdd/refactoring
✨ support f16 + 🧹 some minor refactoring
- Loading branch information
Showing
24 changed files
with
710 additions
and
397 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: Test | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
test: | ||
name: argminmax test | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: ['windows-latest', 'macOS-latest', 'ubuntu-latest'] | ||
rust: ['stable', 'beta', 'nightly'] | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install Rust toolchain | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: ${{ matrix.rust }} | ||
components: clippy, rustfmt | ||
|
||
- name: Rust toolchain info | ||
run: | | ||
cargo --version --verbose | ||
rustc --version | ||
cargo clippy --version | ||
cargo fmt --version | ||
- name: Linting | ||
run: | | ||
cargo fmt -- --check | ||
cargo clippy --features half -- -D warnings | ||
- name: Cache Dependencies | ||
uses: Swatinem/rust-cache@v1 | ||
|
||
- name: Run cargo-tarpaulin | ||
uses: actions-rs/tarpaulin@v0.1 | ||
with: | ||
args: '--features half -- --test-threads 1' | ||
|
||
- name: Upload to codecov.io | ||
uses: codecov/codecov-action@v3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#[macro_use] | ||
extern crate criterion; | ||
extern crate dev_utils; | ||
|
||
#[cfg(feature = "half")] | ||
use argminmax::ArgMinMax; | ||
use criterion::{black_box, Criterion}; | ||
use dev_utils::{config, utils}; | ||
|
||
#[cfg(feature = "half")] | ||
use half::f16; | ||
use ndarray::Array1; | ||
|
||
#[cfg(feature = "half")] | ||
fn get_random_f16_array(n: usize) -> Array1<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(); | ||
let arr: Array1<f16> = Array1::from(data); | ||
arr | ||
} | ||
|
||
#[cfg(feature = "half")] | ||
fn minmax_f16_random_array_long(c: &mut Criterion) { | ||
let n = config::ARRAY_LENGTH_LONG; | ||
let data = get_random_f16_array(n); | ||
c.bench_function("simp_random_long_f16", |b| { | ||
b.iter(|| argminmax::scalar_argminmax_f16(black_box(data.view()))) | ||
}); | ||
c.bench_function("simd_random_long_f16", |b| { | ||
b.iter(|| black_box(data.view().argminmax())) | ||
}); | ||
} | ||
|
||
#[cfg(feature = "half")] | ||
fn minmax_f16_random_array_short(c: &mut Criterion) { | ||
let n = config::ARRAY_LENGTH_SHORT; | ||
let data = get_random_f16_array(n); | ||
c.bench_function("simple_random_short_f16", |b| { | ||
b.iter(|| argminmax::scalar_argminmax_f16(black_box(data.view()))) | ||
}); | ||
c.bench_function("simd_random_short_f16", |b| { | ||
b.iter(|| black_box(data.view().argminmax())) | ||
}); | ||
} | ||
|
||
#[cfg(feature = "half")] | ||
fn minmax_f16_worst_case_array_long(c: &mut Criterion) { | ||
let n = config::ARRAY_LENGTH_LONG; | ||
let data = utils::get_worst_case_array::<f16>(n, f16::from_f32(1.)); | ||
c.bench_function("simple_worst_long_f16", |b| { | ||
b.iter(|| argminmax::scalar_argminmax_f16(black_box(data.view()))) | ||
}); | ||
c.bench_function("simd_worst_long_f16", |b| { | ||
b.iter(|| black_box(data.view().argminmax())) | ||
}); | ||
} | ||
|
||
#[cfg(feature = "half")] | ||
fn minmax_f16_worst_case_array_short(c: &mut Criterion) { | ||
let n = config::ARRAY_LENGTH_SHORT; | ||
let data = utils::get_worst_case_array::<f16>(n, f16::from_f32(1.)); | ||
c.bench_function("simple_worst_short_f16", |b| { | ||
b.iter(|| argminmax::scalar_argminmax_f16(black_box(data.view()))) | ||
}); | ||
c.bench_function("simd_worst_short_f16", |b| { | ||
b.iter(|| black_box(data.view().argminmax())) | ||
}); | ||
} | ||
|
||
#[cfg(feature = "half")] | ||
criterion_group!( | ||
benches, | ||
minmax_f16_random_array_long, | ||
minmax_f16_random_array_short, | ||
minmax_f16_worst_case_array_long, | ||
minmax_f16_worst_case_array_short | ||
); | ||
#[cfg(feature = "half")] | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.