Skip to content

Commit b5adbd0

Browse files
committed
CFAVML-NONE: Stage the last set of changes
1 parent 2b81c7b commit b5adbd0

File tree

2 files changed

+181
-0
lines changed

2 files changed

+181
-0
lines changed

cfavml-ndarray/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,10 @@ nightly = ["cfavml/nightly"]
2323
[dev-dependencies]
2424
ndarray-rand = "0.15.0"
2525
paste = "1.0.15"
26+
divan = "0.1.14"
27+
28+
mimalloc = { version = "0.1.43", default-features = false }
29+
30+
[[bench]]
31+
name = "bench_arithmetic_ops"
32+
harness = false
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
use std::hint::black_box;
2+
3+
use divan::Bencher;
4+
use divan::counter::ItemsCount;
5+
use ndarray::Array3;
6+
use ndarray_rand::rand_distr::Uniform;
7+
use ndarray_rand::RandomExt;
8+
9+
#[global_allocator]
10+
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
11+
12+
fn main() {
13+
divan::main();
14+
}
15+
16+
17+
#[divan::bench(
18+
sample_count = 32,
19+
sample_size = 25,
20+
counters = [ItemsCount::new(2usize * 10 * 256 * 256)],
21+
)]
22+
fn bench_cfavml_two_array_no_broadcast_no_time_alloc(bencher: Bencher) {
23+
let a = Array3::random((10, 256, 256), Uniform::new(1.0, 10.0));
24+
let b = Array3::random((10, 256, 256), Uniform::new(1.0, 10.0));
25+
26+
bencher
27+
.with_inputs(|| {
28+
a.clone()
29+
})
30+
.bench_local_values(|a| {
31+
cfavml_ndarray::ops::mul(a, black_box(&b))
32+
});
33+
}
34+
35+
#[divan::bench(
36+
sample_count = 32,
37+
sample_size = 25,
38+
counters = [ItemsCount::new(2usize * 10 * 256 * 256)],
39+
)]
40+
fn bench_cfavml_two_array_no_broadcast_time_alloc(bencher: Bencher) {
41+
let a = Array3::random((10, 256, 256), Uniform::new(1.0, 10.0));
42+
let b = Array3::random((10, 256, 256), Uniform::new(1.0, 10.0));
43+
44+
bencher.bench_local(|| {
45+
let a = black_box(&a).clone();
46+
cfavml_ndarray::ops::mul(a, black_box(&b))
47+
});
48+
}
49+
50+
#[divan::bench(
51+
sample_count = 32,
52+
sample_size = 25,
53+
counters = [ItemsCount::new(2usize * 10 * 256 * 256)],
54+
)]
55+
fn bench_cfavml_one_array_broadcast_value_no_time_alloc(bencher: Bencher) {
56+
let a = Array3::random((10, 256, 256), Uniform::new(1.0, 10.0));
57+
58+
bencher
59+
.with_inputs(|| {
60+
a.clone()
61+
})
62+
.bench_local_values(|a| {
63+
cfavml_ndarray::ops::mul(a, black_box(3.0))
64+
});
65+
}
66+
67+
#[divan::bench(
68+
sample_count = 32,
69+
sample_size = 25,
70+
counters = [ItemsCount::new(2usize * 10 * 256 * 256)],
71+
)]
72+
fn bench_cfavml_one_array_broadcast_value_time_alloc(bencher: Bencher) {
73+
let a = Array3::random((10, 256, 256), Uniform::new(1.0, 10.0));
74+
75+
bencher.bench_local(|| {
76+
let a = black_box(&a).clone();
77+
cfavml_ndarray::ops::mul(a, black_box(3.0))
78+
});
79+
}
80+
81+
#[divan::bench(
82+
sample_count = 32,
83+
sample_size = 25,
84+
counters = [ItemsCount::new(2usize * 10 * 256 * 256)],
85+
)]
86+
fn bench_default_two_array_no_broadcast_no_time_alloc(bencher: Bencher) {
87+
let a = Array3::random((10, 256, 256), Uniform::new(1.0, 10.0));
88+
let b = Array3::random((10, 256, 256), Uniform::new(1.0, 10.0));
89+
90+
bencher
91+
.with_inputs(|| {
92+
a.clone()
93+
})
94+
.bench_local_values(|a| {
95+
a * black_box(&b)
96+
});
97+
}
98+
99+
#[divan::bench(
100+
sample_count = 32,
101+
sample_size = 25,
102+
counters = [ItemsCount::new(2usize * 10 * 256 * 256)],
103+
)]
104+
fn bench_default_two_array_no_broadcast_time_alloc(bencher: Bencher) {
105+
let a = Array3::random((10, 256, 256), Uniform::new(1.0, 10.0));
106+
let b = Array3::random((10, 256, 256), Uniform::new(1.0, 10.0));
107+
108+
bencher.bench_local(|| {
109+
let a = black_box(&a).clone();
110+
a * black_box(&b)
111+
});
112+
}
113+
114+
#[divan::bench(
115+
sample_count = 32,
116+
sample_size = 25,
117+
counters = [ItemsCount::new(2usize * 10 * 256 * 256)],
118+
)]
119+
fn bench_default_two_array_no_broadcast_two_views(bencher: Bencher) {
120+
let a = Array3::random((10, 256, 256), Uniform::new(1.0, 10.0));
121+
let b = Array3::random((10, 256, 256), Uniform::new(1.0, 10.0));
122+
123+
bencher.bench_local(|| {
124+
let a = black_box(&a);
125+
let b = black_box(&b);
126+
a * b
127+
});
128+
}
129+
130+
#[divan::bench(
131+
sample_count = 32,
132+
sample_size = 25,
133+
counters = [ItemsCount::new(2usize * 10 * 256 * 256)],
134+
)]
135+
fn bench_default_one_array_broadcast_value_no_time_alloc(bencher: Bencher) {
136+
let a = Array3::random((10, 256, 256), Uniform::new(1.0, 10.0));
137+
138+
bencher
139+
.with_inputs(|| {
140+
a.clone()
141+
})
142+
.bench_local_values(|a| {
143+
a * black_box(3.0)
144+
});
145+
}
146+
147+
#[divan::bench(
148+
sample_count = 32,
149+
sample_size = 25,
150+
counters = [ItemsCount::new(2usize * 10 * 256 * 256)],
151+
)]
152+
fn bench_default_one_array_broadcast_value_time_alloc(bencher: Bencher) {
153+
let a = Array3::random((10, 256, 256), Uniform::new(1.0, 10.0));
154+
155+
bencher.bench_local(|| {
156+
let a = black_box(&a).clone();
157+
a * black_box(3.0)
158+
});
159+
}
160+
161+
#[divan::bench(
162+
sample_count = 32,
163+
sample_size = 25,
164+
counters = [ItemsCount::new(2usize * 10 * 256 * 256)],
165+
)]
166+
fn bench_default_one_array_broadcast_value_with_view(bencher: Bencher) {
167+
let a = Array3::random((10, 256, 256), Uniform::new(1.0, 10.0));
168+
169+
bencher.bench_local(|| {
170+
let a = black_box(&a);
171+
let b = black_box(3.0);
172+
a * b
173+
});
174+
}

0 commit comments

Comments
 (0)