-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix conditional compilation, so that everything builds on machine wit…
…hout AVX512
- Loading branch information
1 parent
1d1ab21
commit 20ddb7b
Showing
8 changed files
with
132 additions
and
70 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,75 @@ | ||
use std::{mem, arch::x86_64::*}; | ||
use std::{mem, arch::x86_64::*, simd::u64x8}; | ||
|
||
use criterion::{measurement::Measurement, Criterion, Throughput, black_box, BenchmarkId}; | ||
use rand::Rng; | ||
use rand_core::{RngCore, SeedableRng}; | ||
use rand_xoshiro::Xoshiro256Plus; | ||
use simd_rand::specific::avx512::{U64x8, SimdRand, Xoshiro256PlusX8}; | ||
use simd_rand::portable::*; | ||
use simd_rand::specific; | ||
use packed_simd_2::u64x8 as ps_u64x8; | ||
|
||
#[inline(always)] | ||
fn execute_rand<RNG: RngCore>(rng: &mut RNG, data: &mut U64x8, i: usize) { | ||
for _ in 0..i { | ||
for i in 0..8 { | ||
black_box(&mut *data)[i] = rng.next_u64(); | ||
} | ||
#[inline(never)] | ||
fn execute_rand<RNG: RngCore>(rng: &mut RNG, data: &mut u64x8) { | ||
for i in 0..8 { | ||
data[i] = rng.next_u64(); | ||
} | ||
} | ||
|
||
#[inline(always)] | ||
fn execute_rand_vectorized<RNG: RngCore>(rng: &mut RNG, data: &mut ps_u64x8, i: usize) { | ||
for _ in 0..i { | ||
*black_box(&mut *data) = rng.gen::<ps_u64x8>(); | ||
} | ||
#[inline(never)] | ||
fn execute_rand_vectorized<RNG: RngCore>(rng: &mut RNG, data: &mut ps_u64x8) { | ||
*data = rng.gen::<ps_u64x8>(); | ||
} | ||
|
||
#[inline(always)] | ||
fn execute_vectorized<RNG: SimdRand>(rng: &mut RNG, data: &mut __m512i, i: usize) { | ||
for _ in 0..i { | ||
*black_box(&mut *data) = rng.next_m512i(); | ||
} | ||
#[inline(never)] | ||
fn execute_vectorized_portable<RNG: SimdRandX8>(rng: &mut RNG, data: &mut u64x8) { | ||
*data = rng.next_u64x8(); | ||
} | ||
|
||
pub fn add_top_benchmark<M: Measurement, const ITERATIONS: usize>(c: &mut Criterion<M>) { | ||
let mut group = c.benchmark_group("top"); | ||
#[cfg(all(target_arch = "x86_64", target_feature = "avx512f", target_feature = "avx512dq"))] | ||
#[inline(never)] | ||
fn execute_vectorized_specific<RNG: specific::avx512::SimdRand>(rng: &mut RNG, data: &mut __m512i) { | ||
*data = rng.next_m512i(); | ||
} | ||
|
||
let iterations: Vec<_> = (0..8).map(|v| (v + 1) * ITERATIONS).collect(); | ||
pub fn add_top_benchmark<M: Measurement, const ITERATIONS: usize>(c: &mut Criterion<M>) { | ||
let mut group = c.benchmark_group("Top"); | ||
|
||
for iterations in iterations { | ||
group.throughput(Throughput::Bytes((iterations * mem::size_of::<__m512i>()) as u64)); | ||
group.throughput(Throughput::Bytes(mem::size_of::<u64x8>() as u64)); | ||
|
||
let name = BenchmarkId::new(format!("Rand/Xoshiro256+"), iterations); | ||
group.bench_with_input(name, &iterations, |b, i| { | ||
let mut rng = Xoshiro256Plus::seed_from_u64(0x0DDB1A5E5BAD5EEDu64); | ||
let mut data = Default::default(); | ||
let name = BenchmarkId::new(format!("Rand/Xoshiro256+"), 1); | ||
|
||
b.iter(|| execute_rand(&mut rng, black_box(&mut data), black_box(*i))) | ||
}); | ||
group.bench_with_input(name, &1, |b, i| { | ||
let mut rng = Xoshiro256Plus::seed_from_u64(0x0DDB1A5E5BAD5EEDu64); | ||
let mut data = Default::default(); | ||
|
||
let name = BenchmarkId::new(format!("RandVectorized/Xoshiro256+"), iterations); | ||
group.bench_with_input(name, &iterations, |b, i| { | ||
let mut rng = Xoshiro256Plus::seed_from_u64(0x0DDB1A5E5BAD5EEDu64); | ||
let mut data = Default::default(); | ||
b.iter(|| execute_rand(&mut rng, black_box(&mut data))) | ||
}); | ||
|
||
b.iter(|| execute_rand_vectorized(&mut rng, black_box(&mut data), black_box(*i))) | ||
}); | ||
|
||
let name = BenchmarkId::new(format!("AVX512/Xoshiro256+"), iterations); | ||
group.bench_with_input(name, &iterations, |b, i| unsafe { | ||
let mut rng = Xoshiro256PlusX8::seed_from_u64(0x0DDB1A5E5BAD5EEDu64); | ||
let mut data: __m512i = _mm512_setzero_si512(); | ||
let name = BenchmarkId::new(format!("RandVectorized/Xoshiro256+"), 1); | ||
group.bench_with_input(name, &1, |b, i| { | ||
let mut rng = Xoshiro256Plus::seed_from_u64(0x0DDB1A5E5BAD5EEDu64); | ||
let mut data = Default::default(); | ||
|
||
b.iter(|| execute_vectorized(&mut rng, black_box(&mut data), black_box(*i))) | ||
}); | ||
} | ||
b.iter(|| execute_rand_vectorized(&mut rng, black_box(&mut data))) | ||
}); | ||
|
||
let name = BenchmarkId::new(format!("Portable/Xoshiro256+X8"), 1); | ||
group.bench_with_input(name, &1, |b, i| { | ||
let mut rng = Xoshiro256PlusX8::seed_from_u64(0x0DDB1A5E5BAD5EEDu64); | ||
let mut data = Default::default(); | ||
|
||
b.iter(|| execute_vectorized_portable(&mut rng, black_box(&mut data))) | ||
}); | ||
|
||
#[cfg(all(target_arch = "x86_64", target_feature = "avx512f", target_feature = "avx512dq"))] | ||
let name = BenchmarkId::new(format!("Specific/Xoshiro256+X8"), iterations); | ||
#[cfg(all(target_arch = "x86_64", target_feature = "avx512f", target_feature = "avx512dq"))] | ||
group.bench_with_input(name, &iterations, |b, i| unsafe { | ||
let mut rng = specific::avx512::Xoshiro256PlusX8::seed_from_u64(0x0DDB1A5E5BAD5EEDu64); | ||
let mut data: __m512i = _mm512_setzero_si512(); | ||
|
||
b.iter(|| execute_vectorized_specific(&mut rng, black_box(&mut data))) | ||
}); | ||
|
||
group.finish(); | ||
} |
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