Skip to content

[Perf] Interpolate optimizations #3077

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

Merged
merged 5 commits into from
Apr 25, 2025
Merged

Conversation

wingertge
Copy link
Contributor

@wingertge wingertge commented Apr 24, 2025

Pull Request Template

Checklist

  • Confirmed that run-checks all script has been executed.
  • Made sure the book is up to date with changes in this PR.

Related Issues/PRs

Also fixes #3076

Changes

Refactors interpolation to use NHWC layout to allow for potential vectorization when used with NHWC layout tensors (i.e. from convolution), as well as other perf optimizations. Also fixes a bug in is_contiguous and a clippy warning for slices.

Testing

All tests pass

Copy link

codecov bot commented Apr 24, 2025

Codecov Report

Attention: Patch coverage is 44.57364% with 143 lines in your changes missing coverage. Please review.

Project coverage is 81.15%. Comparing base (e096b0c) to head (4878d8f).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...ates/burn-cubecl/src/kernel/interpolate/bicubic.rs 17.24% 48 Missing ⚠️
...tes/burn-cubecl/src/kernel/interpolate/bilinear.rs 18.51% 44 Missing ⚠️
...-cubecl/src/kernel/interpolate/nearest_backward.rs 28.57% 25 Missing ⚠️
...ates/burn-cubecl/src/kernel/interpolate/nearest.rs 37.83% 23 Missing ⚠️
...ecl/src/kernel/conv/conv2d/implicit_gemm/launch.rs 66.66% 1 Missing ⚠️
...burn-cubecl/src/kernel/pool/avg_pool2d_backward.rs 66.66% 1 Missing ⚠️
crates/burn-cubecl/src/kernel/utils.rs 92.30% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3077      +/-   ##
==========================================
- Coverage   81.16%   81.15%   -0.01%     
==========================================
  Files         815      816       +1     
  Lines      117201   117265      +64     
==========================================
+ Hits        95121    95163      +42     
- Misses      22080    22102      +22     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@laggui laggui left a comment

Choose a reason for hiding this comment

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

LGTM!

Tested locally and with the super-resolution model code (ESRGAN) which prompted this PR.

Just a minor comment on the contiguous checks

Comment on lines +474 to +475
} else if *stride != 1 {
return false;
Copy link
Member

Choose a reason for hiding this comment

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

We should probably add more tests (e.g., your tensor of shape [1, 1, 1, 9] with strides [72, 1, 72, 8] which prompted this fix). Better illustrates what is expected to be contiguous or not, even in more complex cases.

Also @nathanielsimard I just realized we seem to have another is_contiguous fn in fusion, but the implementations are slightly diverging with the latest changes

pub(crate) fn is_contiguous(shape: &[usize], strides: &[usize]) -> bool {
if shape.is_empty() {
return true;
}
if shape.len() == 1 {
return strides[0] == 1;
}
let mut prev_stride = 1;
let mut current_num_elems_shape = 1;
for (i, (stride, shape)) in strides.iter().zip(shape).rev().enumerate() {
if i > 0 {
if current_num_elems_shape != *stride {
return false;
}
if prev_stride >= *stride {
return false;
}
}
current_num_elems_shape *= shape;
prev_stride = *stride;
}
true
}

The definition of contiguous should probably match 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a test, but leaving this unresolved because of the fusion thing

Copy link
Member

Choose a reason for hiding this comment

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

Unrelated to this PR, so I'll merge but will open a small PR to use the same is_contiguous fn across the crates.

@laggui laggui merged commit 6d0db87 into tracel-ai:main Apr 25, 2025
11 checks passed
@wingertge wingertge deleted the perf/interpolate branch April 25, 2025 19:49
@laggui laggui mentioned this pull request Apr 25, 2025
1 task
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.

2 participants