Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make backend names in JSON reports match burnbench CLI #1375

Merged
merged 3 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Make backend names in JSON reports match burnbench CLI
- add `config_name`  to `Backend` trait
- add `backend_config_name` to  `Benchmark` trait
- fix documentation for JSON reports to use correct unit of time
  • Loading branch information
errordeveloper authored and syl20bnr committed Mar 29, 2024
commit a09edb638942e7f8d1c9c271e923dca1b9c33433
4 changes: 4 additions & 0 deletions backend-comparison/benches/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ impl<B: Backend, const D: usize> Benchmark for BinaryBenchmark<B, D> {
"binary".into()
}

fn backend_config_name(&self) -> Option<String> {
B::config_name(&self.device)
}

fn shapes(&self) -> Vec<Vec<usize>> {
vec![self.shape.dims.into()]
}
Expand Down
4 changes: 4 additions & 0 deletions backend-comparison/benches/custom_gelu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ impl<B: Backend, const D: usize> Benchmark for CustomGeluBenchmark<B, D> {
}
}

fn backend_config_name(&self) -> Option<String> {
B::config_name(&self.device)
}

fn options(&self) -> Option<String> {
Some(format!("{:?}", self.kind))
}
Expand Down
8 changes: 8 additions & 0 deletions backend-comparison/benches/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ impl<B: Backend, const D: usize> Benchmark for ToDataBenchmark<B, D> {
"to_data".into()
}

fn backend_config_name(&self) -> Option<String> {
B::config_name(&self.device)
}

fn shapes(&self) -> Vec<Vec<usize>> {
vec![self.shape.dims.into()]
}
Expand Down Expand Up @@ -46,6 +50,10 @@ impl<B: Backend, const D: usize> Benchmark for FromDataBenchmark<B, D> {
"from_data".into()
}

fn backend_config_name(&self) -> Option<String> {
B::config_name(&self.device)
}

fn shapes(&self) -> Vec<Vec<usize>> {
vec![self.shape.dims.into()]
}
Expand Down
4 changes: 4 additions & 0 deletions backend-comparison/benches/matmul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ impl<B: Backend, const D: usize> Benchmark for MatmulBenchmark<B, D> {
"matmul".into()
}

fn backend_config_name(&self) -> Option<String> {
B::config_name(&self.device)
}

fn shapes(&self) -> Vec<Vec<usize>> {
vec![self.shape_lhs.dims.into(), self.shape_rhs.dims.into()]
}
Expand Down
4 changes: 4 additions & 0 deletions backend-comparison/benches/max_pool2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ impl<B: Backend> Benchmark for MaxPool2dBenchmark<B> {
"max_pool2d".into()
}

fn backend_config_name(&self) -> Option<String> {
B::config_name(&self.device)
}

fn shapes(&self) -> Vec<Vec<usize>> {
vec![self.shape.dims.into()]
}
Expand Down
4 changes: 4 additions & 0 deletions backend-comparison/benches/unary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ impl<B: Backend, const D: usize> Benchmark for UnaryBenchmark<B, D> {
"unary".into()
}

fn backend_config_name(&self) -> Option<String> {
B::config_name(&self.device)
}

fn shapes(&self) -> Vec<Vec<usize>> {
vec![self.shape.dims.into()]
}
Expand Down
7 changes: 6 additions & 1 deletion backend-comparison/src/persistence/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct BenchmarkRecord {
/// [
/// {
/// "backend": "backend name",
/// "backendConfigName": "backend config name as appers in burnbench flag",
/// "device": "device name",
/// "gitHash": "hash",
/// "max": "duration in microseconds",
Expand Down Expand Up @@ -68,7 +69,7 @@ pub fn save<B: Backend>(

let records: Vec<BenchmarkRecord> = benches
.into_iter()
.map(|bench| BenchmarkRecord {
.map(|bench: BenchmarkResult| BenchmarkRecord {
backend: B::name().to_string(),
device: format!("{:?}", device),
system_info: BenchmarkSystemInfo::new(),
Expand Down Expand Up @@ -157,6 +158,7 @@ impl Serialize for BenchmarkRecord {
self,
("backend", &self.backend),
("device", &self.device),
("backendConfigName", &self.results.backend_config_name),
("gitHash", &self.results.git_hash),
("max", &self.results.computed.max.as_micros()),
("mean", &self.results.computed.mean.as_micros()),
Expand Down Expand Up @@ -190,6 +192,7 @@ impl<'de> Visitor<'de> for BenchmarkRecordVisitor {
match key.as_str() {
"backend" => br.backend = map.next_value::<String>()?,
"device" => br.device = map.next_value::<String>()?,
"backendConfigName" => br.results.backend_config_name = Some(map.next_value::<String>()?),
"gitHash" => br.results.git_hash = map.next_value::<String>()?,
"name" => br.results.name = map.next_value::<String>()?,
"max" => {
Expand Down Expand Up @@ -282,6 +285,7 @@ mod tests {
let sample_result = r#"{
"backend": "candle",
"device": "Cuda(0)",
"backendConfigName": "candle-cuda",
"gitHash": "02d37011ab4dc773286e5983c09cde61f95ba4b5",
"name": "unary",
"max": 8858,
Expand Down Expand Up @@ -345,6 +349,7 @@ mod tests {
let record = serde_json::from_str::<BenchmarkRecord>(sample_result).unwrap();
assert!(record.backend == "candle");
assert!(record.device == "Cuda(0)");
assert!(record.results.backend_config_name == "candle-cuda");
assert!(record.results.git_hash == "02d37011ab4dc773286e5983c09cde61f95ba4b5");
assert!(record.results.name == "unary");
assert!(record.results.computed.max.as_micros() == 8858);
Expand Down
7 changes: 7 additions & 0 deletions crates/burn-autodiff/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ impl<B: Backend, C: CheckpointStrategy> Backend for Autodiff<B, C> {
format!("autodiff<{}>", B::name())
}

fn config_name(device: &Self::Device) -> Option<String> {
match B::config_name(device) {
Some(name) => Some(format!("{}-autodiff", name)),
None => None,
}
}

fn seed(seed: u64) {
B::seed(seed)
}
Expand Down
7 changes: 7 additions & 0 deletions crates/burn-candle/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ impl<F: FloatCandleElement, I: IntCandleElement> Backend for Candle<F, I> {
"candle".to_string()
}

fn config_name(device: &Self::Device) -> Option<String> {
match device {
CandleDevice::Cpu => Some(String::from("candle-cpu")),
CandleDevice::Cuda(_) | CandleDevice::Metal(_) => Some(String::from("candle-gpu")),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add candle-cuda and candle-metal in this case.

}
}

fn seed(seed: u64) {
// TODO submit an issue at Candle
panic!("Manual seed not supported by Candle. ")
Expand Down
7 changes: 7 additions & 0 deletions crates/burn-common/src/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ pub trait Benchmark {
/// Name of the benchmark, should be short and it should match the name
/// defined in the crate Cargo.toml
fn name(&self) -> String;

/// Name of the backend as appears in burnbench CLI
fn backend_config_name(&self) -> Option<String>;

/// The options passed to the benchmark.
fn options(&self) -> Option<String> {
None
Expand Down Expand Up @@ -185,6 +189,8 @@ pub struct BenchmarkResult {
pub git_hash: String,
/// Name of the benchmark
pub name: String,
/// Name of the backend as appears in burnbench CLI
pub backend_config_name: Option<String>,
/// Options passed to the benchmark
pub options: Option<String>,
/// Shape dimensions
Expand Down Expand Up @@ -230,6 +236,7 @@ where
computed: BenchmarkComputations::new(&durations),
git_hash,
name: benchmark.name(),
backend_config_name: benchmark.backend_config_name(),
options: benchmark.options(),
shapes: benchmark.shapes(),
timestamp,
Expand Down
4 changes: 4 additions & 0 deletions crates/burn-compute/src/tune/tune_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ impl<S: ComputeServer, C: ComputeChannel<S>> Benchmark for TuneBenchmark<S, C> {
"autotune".to_string()
}

fn backend_config_name(&self) -> Option<String> {
None
}

fn sync(&self) {
self.client.sync();
}
Expand Down
7 changes: 7 additions & 0 deletions crates/burn-fusion/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ impl<B: FusionBackend> Backend for Fusion<B> {
format!("fusion<{}>", B::name())
}

fn config_name(device: &Self::Device) -> Option<String> {
match B::config_name(device) {
Some(name) => Some(format!("{}-fusion", name)),
None => None,
}
}

fn seed(seed: u64) {
B::seed(seed);
}
Expand Down
5 changes: 5 additions & 0 deletions crates/burn-jit/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ impl<R: Runtime> Backend for JitBackend<R> {
format!("jit<{}>", R::name())
}

fn config_name(_device: &Self::Device) -> Option<String> {
// There is currently only one implementation where name returns "wgpu"
Some(format!("{}-jit", R::name()))
}

fn seed(seed: u64) {
let rng = StdRng::seed_from_u64(seed);
let mut seed = SEED.lock().unwrap();
Expand Down
16 changes: 16 additions & 0 deletions crates/burn-ndarray/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ impl Default for NdArrayDevice {
}
}

fn config_name() -> String {
Copy link
Contributor Author

@errordeveloper errordeveloper Mar 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved this one to the top of the file since it seem right to have features config macros up-front, not inside the trait defintion, so this way it seemed more readable to me - no surprises lower-down surprises ;)

if cfg!(feature = "blas-netlib") {
String::from("ndarray-blas-netlib")
} else if cfg!(feature = "blas-openblas") {
String::from("ndarray-blas-openblas")
} else if cfg!(feature = "blas-openblas-system") {
String::from("ndarray-blas-openblas-system")
} else {
String::from("ndarray")
}
}

/// Tensor backend that uses the [ndarray](ndarray) crate for executing tensor operations.
///
/// This backend is compatible with CPUs and can be compiled for almost any platform, including
Expand Down Expand Up @@ -50,6 +62,10 @@ impl<E: FloatNdArrayElement> Backend for NdArray<E> {
String::from("ndarray")
}

fn config_name(_: &Self::Device) -> Option<String> {
Some(config_name())
}

fn seed(seed: u64) {
let rng = StdRng::seed_from_u64(seed);
let mut seed = SEED.lock().unwrap();
Expand Down
9 changes: 9 additions & 0 deletions crates/burn-tch/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ impl<E: TchElement> Backend for LibTorch<E> {
"tch".to_string()
}

fn config_name(device: &Self::Device) -> Option<String> {
match device {
LibTorchDevice::Cpu => Some(String::from("tch-cpu")),
LibTorchDevice::Cuda(_) | LibTorchDevice::Mps | LibTorchDevice::Vulkan => {
Some(String::from("tch-gpu"))
}
}
}

fn sync(device: &Self::Device) {
if let LibTorchDevice::Cuda(index) = device {
tch::Cuda::synchronize(*index as i64);
Expand Down
3 changes: 3 additions & 0 deletions crates/burn-tensor/src/tensor/backend/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ pub trait Backend:
/// Name of the backend.
fn name() -> String;

/// Name of the backend configuration (i.e. as used in burnbench CLI).
fn config_name(device: &Self::Device) -> Option<String>;

/// Seed the backend.
fn seed(seed: u64);

Expand Down