Skip to content

Commit cfc7d42

Browse files
authored
Merge pull request #9 from Human9000-bit/yolo-tuning
Performance tuning for YOLO-like workloads
2 parents ddf5018 + 81cf248 commit cfc7d42

4 files changed

Lines changed: 511 additions & 153 deletions

File tree

apps/bench/src/main.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,19 @@ fn main() {
211211
let _c = yscv_kernels::conv2d_nhwc(&conv_input, &conv_kernel, None, 1, 1).unwrap();
212212
});
213213

214+
let yolo_stem_input = Tensor::zeros(vec![1, 640, 640, 3]).unwrap();
215+
let yolo_stem_kernel = Tensor::zeros(vec![3, 3, 3, 32]).unwrap();
216+
bench_n("conv2d_nhwc_yolo_640x640_3x3_32", 100, || {
217+
let _c =
218+
yscv_kernels::conv2d_nhwc(&yolo_stem_input, &yolo_stem_kernel, None, 1, 1).unwrap();
219+
});
220+
221+
let yolo_p3_input = Tensor::zeros(vec![1, 80, 80, 128]).unwrap();
222+
let yolo_p3_kernel = Tensor::zeros(vec![3, 3, 128, 256]).unwrap();
223+
bench_n("conv2d_nhwc_yolo_p3_80x80_3x3_256", 100, || {
224+
let _c = yscv_kernels::conv2d_nhwc(&yolo_p3_input, &yolo_p3_kernel, None, 1, 1).unwrap();
225+
});
226+
214227
// --- Activations (vs PyTorch) ---
215228
bench_n("sigmoid_1M", 100, || {
216229
let _s = yscv_kernels::sigmoid(&a1m);

crates/yscv-kernels/benches/kernels_cpu_ops.rs

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ use criterion::{Criterion, black_box, criterion_group, criterion_main};
44
use yscv_kernels::{
55
Backend, BatchNorm2dParams, LayerNormLastDimParams, ParallelElementwiseConfig,
66
ParallelMatmulConfig, SeparableConv2dParams, ThreadedCpuBackend, ThreadedCpuBackendConfig, add,
7-
avg_pool2d_nhwc, batch_norm2d_nhwc, conv2d_nhwc, depthwise_conv2d_nhwc, layer_norm_last_dim,
8-
log_softmax_last_dim, logsumexp_last_dim, matmul_2d, matmul_2d_sequential, max_pool2d_nhwc,
9-
relu, separable_conv2d_nhwc, sigmoid, softmax_last_dim,
7+
avg_pool2d_nhwc, batch_norm2d_nhwc, conv2d_nhwc, conv2d_nhwc_indirect_padded,
8+
conv2d_nhwc_padded, depthwise_conv2d_nhwc, layer_norm_last_dim, log_softmax_last_dim,
9+
logsumexp_last_dim, matmul_2d, matmul_2d_sequential, max_pool2d_nhwc, relu,
10+
separable_conv2d_nhwc, sigmoid, softmax_last_dim,
1011
};
1112
use yscv_tensor::Tensor;
1213

@@ -282,6 +283,73 @@ fn bench_conv_modes(c: &mut Criterion) {
282283
group.finish();
283284
}
284285

286+
fn bench_winograd_conv_modes(c: &mut Criterion) {
287+
let small_input = build_tensor(&[1, 32, 32, 8], 0.43);
288+
let small_kernel = build_tensor(&[3, 3, 8, 16], 0.87);
289+
let small_bias = build_tensor(&[16], 0.21);
290+
291+
let yolo_p3_input = build_tensor(&[1, 80, 80, 128], 0.49);
292+
let yolo_p3_kernel = build_tensor(&[3, 3, 128, 256], 0.83);
293+
let yolo_p3_bias = build_tensor(&[256], 0.27);
294+
295+
let mut group = c.benchmark_group("kernels_winograd_conv_modes");
296+
group.bench_function("winograd_3x3_s1_32x32x8_to16", |b| {
297+
b.iter(|| {
298+
let out = conv2d_nhwc_padded(
299+
black_box(&small_input),
300+
black_box(&small_kernel),
301+
Some(black_box(&small_bias)),
302+
1,
303+
1,
304+
0,
305+
0,
306+
0,
307+
0,
308+
yscv_kernels::Activation::Relu,
309+
)
310+
.expect("winograd conv2d small");
311+
black_box(out);
312+
});
313+
});
314+
group.bench_function("winograd_3x3_s1_yolo_p3_80x80x128_to256", |b| {
315+
b.iter(|| {
316+
let out = conv2d_nhwc_padded(
317+
black_box(&yolo_p3_input),
318+
black_box(&yolo_p3_kernel),
319+
Some(black_box(&yolo_p3_bias)),
320+
1,
321+
1,
322+
0,
323+
0,
324+
0,
325+
0,
326+
yscv_kernels::Activation::Relu,
327+
)
328+
.expect("winograd conv2d yolo p3");
329+
black_box(out);
330+
});
331+
});
332+
group.bench_function("indirect_3x3_s1_yolo_p3_80x80x128_to256", |b| {
333+
b.iter(|| {
334+
let out = conv2d_nhwc_indirect_padded(
335+
black_box(&yolo_p3_input),
336+
black_box(&yolo_p3_kernel),
337+
Some(black_box(&yolo_p3_bias)),
338+
1,
339+
1,
340+
0,
341+
0,
342+
0,
343+
0,
344+
yscv_kernels::Activation::Relu,
345+
)
346+
.expect("indirect conv2d yolo p3");
347+
black_box(out);
348+
});
349+
});
350+
group.finish();
351+
}
352+
285353
fn bench_depthwise_conv_modes(c: &mut Criterion) {
286354
let input = build_tensor(&[1, 32, 32, 8], 0.28);
287355
let kernel = build_tensor(&[3, 3, 8, 2], 0.74);
@@ -593,6 +661,7 @@ criterion_group!(
593661
bench_elementwise_modes,
594662
bench_pool_modes,
595663
bench_conv_modes,
664+
bench_winograd_conv_modes,
596665
bench_depthwise_conv_modes,
597666
bench_separable_conv_modes,
598667
bench_batch_norm_modes,

0 commit comments

Comments
 (0)