-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Metal: Activate bfloat affine and add benchmark (#1543)
* Use cfg to seperate benchmark results based on features * Add bfloat affine and benchmarks * Fix flops calculation * Remove allow pragma * Avoid some unnecessary returns. * Improve benchmarks layout --------- Co-authored-by: Laurent <laurent.mazare@gmail.com> Co-authored-by: Nicolas Patry <patry.nicolas@protonmail.com>
- Loading branch information
1 parent
e90bcdc
commit a3d92ab
Showing
5 changed files
with
54 additions
and
8 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
mod benchmarks; | ||
|
||
use criterion::criterion_main; | ||
criterion_main!(benchmarks::matmul::benches, benchmarks::where_cond::benches); | ||
criterion_main!(benchmarks::matmul::benches, benchmarks::affine::benches, benchmarks::where_cond::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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use crate::benchmarks::{BenchDevice, BenchDeviceHandler}; | ||
use candle_core::{DType, Device, Tensor}; | ||
use criterion::{black_box, criterion_group, Criterion, Throughput}; | ||
use std::time::Instant; | ||
|
||
fn run(a: &Tensor) { | ||
a.affine(12.34, 56.78).unwrap(); | ||
} | ||
|
||
fn run_affine_benchmark(c: &mut Criterion, device: &Device, dtype: DType, name: &str) { | ||
let b = 1; | ||
let m = 1024; | ||
let k = 1024; | ||
|
||
let tensor = Tensor::zeros((b, m, k), dtype, &device).unwrap(); | ||
|
||
let flops = b * m * k * dtype.size_in_bytes(); | ||
|
||
let mut group = c.benchmark_group(device.bench_name(name)); | ||
group.throughput(Throughput::Bytes(flops as u64)); | ||
group.bench_function("iter", move |b| { | ||
b.iter_custom(|iters| { | ||
let start = Instant::now(); | ||
for _i in 0..iters { | ||
run(black_box(&tensor)); | ||
} | ||
device.sync().unwrap(); | ||
start.elapsed() | ||
}) | ||
}); | ||
group.finish(); | ||
} | ||
|
||
fn criterion_benchmark(c: &mut Criterion) { | ||
let handler = BenchDeviceHandler::new().unwrap(); | ||
for device in handler.devices { | ||
run_affine_benchmark(c, &device, DType::F32, "affine_f32"); | ||
run_affine_benchmark(c, &device, DType::F16, "affine_f16"); | ||
run_affine_benchmark(c, &device, DType::BF16, "affine_bf16"); | ||
} | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); |
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,3 +1,4 @@ | ||
pub(crate) mod affine; | ||
pub(crate) mod matmul; | ||
pub(crate) mod where_cond; | ||
|
||
|
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