Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
BhavyeMathur committed Jan 12, 2025
2 parents 240b4fe + 4695f63 commit bda2c64
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ path = "benches/fill_f32.rs"
name = "fill_f32_slice"
path = "benches/fill_f32_slice.rs"

[[bin]]
name = "ones_f32"
path = "benches/ones_f32.rs"


[dependencies]
cpu-time = "1.0.0"
bitflags = "2.6.0"
Expand Down
25 changes: 25 additions & 0 deletions benches/ones_f32.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import numpy as np
import torch

from perfprofiler import *

class TensorOnes(TimingSuite):
def __init__(self, n):
self.n = n

@measure_performance("NumPy")
def run(self):
np.ones(self.n, dtype="float32")

@measure_performance("PyTorch CPU")
def run(self):
torch.ones(self.n, dtype=torch.float32)

@measure_rust_performance("Chela CPU", target="ones_f32")
def run(self, executable):
return self.run_rust(executable, self.n)

if __name__ == "__main__":
sizes = [2 ** n for n in range(9, 25)]
results = TensorOnes.profile_each(sizes, n=10)
plot_results(sizes, results, "tensor.ones() CPU time vs length")
16 changes: 16 additions & 0 deletions benches/ones_f32.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use chela::*;
use std::env;
use cpu_time::ProcessTime;

fn profile(size: usize) -> u128 {
let start = ProcessTime::now();
let tensor: Tensor<f32> = Tensor::ones(size);
start.elapsed().as_nanos()
}

fn main() {
let args: Vec<String> = env::args().collect();
let size = args[1].parse::<usize>().unwrap();

println!("{}", profile(size));
}
1 change: 0 additions & 1 deletion benches/perfprofiler/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,4 @@ def wrapper(self, *args, **kwargs):

return decorator


__all__ = ["measure_performance", "measure_rust_performance"]
1 change: 0 additions & 1 deletion benches/perfprofiler/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def compile_rust(target: str) -> str:
out = out.split(b"\n")[-3]
return json.loads(out)["executable"]


def get_method_class(method) -> str:
return method.__qualname__.split(".")[0]

Expand Down

0 comments on commit bda2c64

Please sign in to comment.