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

Improve slow-path performance for unary ops #223

Merged
merged 1 commit into from
May 31, 2024

Conversation

robertknight
Copy link
Owner

@robertknight robertknight commented May 31, 2024

Replace iterators with a pattern that uses a fixed number of nested loops. The same approach was previously applied to binary and ternary ops.

Part of #192.

Benchmark:

let mut x = Tensor::arange(0., 1024., None).into_shape([32, 32]);
x.clip_dim(1, 2..30);

let start = std::time::Instant::now();
for _ in 0..1000 {
    x.apply(|x| x + 0.001);
}
let elapsed = start.elapsed().as_secs_f64() * 1000.0;
println!("duration {}", elapsed);

Before: 2.95ms
After: 0.5ms
Without the clip_dim call (making it contiguous): 0.22ms

Replace iterators with a pattern that uses a fixed number of nested loops.
The same approach was previously applied to binary and ternary ops.

Part of #192.
@robertknight robertknight marked this pull request as ready for review May 31, 2024 22:16
@robertknight robertknight merged commit 33d25aa into main May 31, 2024
2 checks passed
@robertknight robertknight deleted the better-unary-op-slow-path branch May 31, 2024 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant