Merge branch 'main' into ivarflakstad/metal-fill

This commit is contained in:
Ivar Flakstad
2024-01-12 07:25:32 +01:00
53 changed files with 1024 additions and 1050 deletions

View File

@ -1,4 +1,4 @@
use crate::benchmarks::{bench_name, device, BenchDevice};
use crate::benchmarks::{BenchDevice, BenchDeviceHandler};
use candle_core::{DType, Device, Tensor};
use criterion::{black_box, criterion_group, Criterion, Throughput};
use std::time::Instant;
@ -7,16 +7,14 @@ fn run(shape: (usize, usize, usize), dtype: DType, device: &Device) {
Tensor::ones(shape, dtype, device).unwrap();
}
fn run_fill_benchmark(c: &mut Criterion, name: &str, dtype: DType) {
fn run_fill_benchmark(c: &mut Criterion, device: &Device, name: &str, dtype: DType) {
let b = 1;
let rows = 4096;
let columns = 4096;
let rows = 1024;
let columns = 1024;
let flops = b * rows * columns * dtype.size_in_bytes();
let device = device().unwrap();
let mut group = c.benchmark_group(bench_name(name));
let mut group = c.benchmark_group(device.bench_name(name));
group.throughput(Throughput::Bytes(flops as u64));
group.bench_function("iter", move |bencher| {
bencher.iter_custom(|iters| {
@ -36,8 +34,11 @@ fn run_fill_benchmark(c: &mut Criterion, name: &str, dtype: DType) {
}
fn criterion_benchmark(c: &mut Criterion) {
run_fill_benchmark(c, "fill_u8", DType::U8);
run_fill_benchmark(c, "fill_f32", DType::F32);
let handler = BenchDeviceHandler::new().unwrap();
for device in handler.devices {
run_fill_benchmark(c, &device, "fill_u8", DType::U8);
run_fill_benchmark(c, &device, "fill_f32", DType::F32);
}
}
criterion_group!(benches, criterion_benchmark);