Skip to content

[Optimization] Improve border/interpolation wrapper implementations#147

Open
zacharyvincze wants to merge 13 commits intoROCm:developfrom
zacharyvincze:zv/optimization/interp-border-mode-patch
Open

[Optimization] Improve border/interpolation wrapper implementations#147
zacharyvincze wants to merge 13 commits intoROCm:developfrom
zacharyvincze:zv/optimization/interp-border-mode-patch

Conversation

@zacharyvincze
Copy link
Copy Markdown
Contributor

Description

This PR offers improvements to the interpolation, border paths as well as adding a dedicated WarpAffine kernel over using the WarpPerspective operator.

Optimizations to these paths improve geometric transformations which make use of border modes and interpolation (Rotate, Resize, WarpAffine, WarpPerspective, CopyMakeBorder).

Technical Details

  • Uses device intrinsics where possible in border/interpolation wrapper implementations.
  • Coordinate calculations use 32-bit integer math over 64-bit integer math when possible, but will fallback to 64-bit math when not possible.
  • Interpolation implementations such as Bilinear and Bicubic now determine whether their neighborhood falls within image bounds. If they do, then they ignore the border calculations and sample pixels directly.
  • WarpAffine now has a dedicated kernel instead of calling WarpPerspective. This ensures that affine warp doesn't use the bottom row of the 3x3 transformation matrix that a perspective transform uses, which was redundant anyway.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the affine warp path to use a dedicated WarpAffine kernel (instead of delegating to WarpPerspective) and optimizes border/interpolation wrappers with new shared sampling helpers to reduce overhead on common in-bounds sampling cases.

Changes:

  • Added dedicated GPU/CPU WarpAffine kernels and updated WarpAffine::operator() to dispatch directly by dtype/channels/border/interp.
  • Optimized InterpolationWrapper (bilinear/cubic) with in-bounds fast paths to bypass border handling when neighborhoods are fully in-range.
  • Refactored border coordinate math and interpolation index conversion into a new sampling_helpers.hpp helper header.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/op_warp_affine.cpp Replaces WarpPerspective reuse with dedicated WarpAffine dispatch and kernel launches.
include/op_warp_affine.hpp Removes WarpPerspective member dependency; keeps WarpAffine API unchanged.
include/kernels/host/warp_affine_host.hpp Adds host-side affine warp kernel implementation.
include/kernels/device/warp_affine_device.hpp Adds device-side affine warp kernel implementation.
include/core/wrappers/interpolation_wrapper.hpp Adds in-bounds fast paths and refactors nearest/bilinear/cubic sampling math.
include/core/wrappers/border_wrapper.hpp Refactors border coordinate mapping with new helper functions and adds at_inbounds().
include/core/detail/sampling_helpers.hpp New shared host/device helpers for modulo/clamp/abs and interpolation index conversion.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread include/core/wrappers/border_wrapper.hpp
Comment thread include/core/detail/sampling_helpers.hpp
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 16, 2026

Codecov Report

❌ Patch coverage is 59.47137% with 92 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
include/core/wrappers/interpolation_wrapper.hpp 34.43% 39 Missing and 1 partial ⚠️
src/op_warp_affine.cpp 75.82% 6 Missing and 16 partials ⚠️
include/core/detail/sampling_helpers.hpp 58.82% 14 Missing ⚠️
include/core/wrappers/border_wrapper.hpp 56.67% 11 Missing and 2 partials ⚠️
include/kernels/host/warp_affine_host.hpp 72.73% 0 Missing and 3 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #147      +/-   ##
===========================================
- Coverage    74.40%   73.92%   -0.48%     
===========================================
  Files           79       81       +2     
  Lines         3355     3520     +165     
  Branches       738      764      +26     
===========================================
+ Hits          2496     2602     +106     
- Misses         378      416      +38     
- Partials       481      502      +21     
Files with missing lines Coverage Δ
include/kernels/host/warp_affine_host.hpp 72.73% <72.73%> (ø)
include/core/wrappers/border_wrapper.hpp 71.43% <56.67%> (+6.61%) ⬆️
include/core/detail/sampling_helpers.hpp 58.82% <58.82%> (ø)
src/op_warp_affine.cpp 77.08% <75.82%> (-22.92%) ⬇️
include/core/wrappers/interpolation_wrapper.hpp 41.86% <34.43%> (-1.54%) ⬇️

... and 1 file with indirect coverage changes

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants