-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
5 changed files
with
46 additions
and
2 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
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,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") |
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,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)); | ||
} |
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