Skip to content

[Feature] Resize varshape to constant sized Tensor path#159

Draft
zacharyvincze wants to merge 11 commits into
ROCm:developfrom
zacharyvincze:zv/feature/resize-varshape
Draft

[Feature] Resize varshape to constant sized Tensor path#159
zacharyvincze wants to merge 11 commits into
ROCm:developfrom
zacharyvincze:zv/feature/resize-varshape

Conversation

@zacharyvincze

@zacharyvincze zacharyvincze commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Add variable-shape Resize

Summary

Adds a Resize overload that resizes an ImageBatchVarShape (batch of differently-sized images) into a uniform NHWC output tensor, each image scaled independently. Builds on the varshape image-batch and wrapper infrastructure from the base branch.

Changes

  • op_resize (.hpp / .cpp) — new operator()(stream, ImageBatchVarShape& in, Tensor& out, interp, device). The uniform and varshape paths share a single dispatch_resize_launch; input is non-const because exportData() advances the batch's lazy device-sync state. Validates device, uniform format, dtype [U8, F32], and channels [1,3,4].
  • Resize kernels (device / host) — drop the host-precomputed scaleX/scaleY params; scale is now derived per-batch-index from input.width(batch)/output.width(). For a TensorWrapper this is constant across the batch (identical to before); for an ImageBatchVarShapeWrapper it yields each image's own scale.
  • Validation helpers — new CHECK_IMAGE_BATCH_* macros (device, not-empty, uniform-format, datatypes, channels) mirroring the existing CHECK_TENSOR_* set.
  • Sampleresize_var_shape.cpp demonstrates varshape resize; wired into samples CMake/README.
  • Tests — golden-model coverage for the varshape path in test_op_resize.cpp.

Notes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a variable-shape Resize path that takes an ImageBatchVarShape (heterogeneous input sizes) and produces a uniform NHWC Tensor, while also refactoring the wrapper stack (border/interpolation) to work generically over both uniform (TensorWrapper) and varshape (ImageBatchVarShapeWrapper) inputs. This PR also introduces new core Image / ImageData / ImageBatch*Data types, a varshape descriptor-table implementation, and expands samples/tests accordingly.

Changes:

  • Add Resize::operator()(stream, ImageBatchVarShape&, Tensor&, interp, device) and unify uniform+varshape dispatch via a shared launch helper; resize scale is now derived per-batch-index inside kernels.
  • Introduce Image, ImageBatchVarShape, ImageData*, ImageBatch*Data (and varshape descriptor table) to support varshape batching and exported descriptor snapshots.
  • Update many operators/tests to use TensorWrapper + MakeBorderWrapper/MakeInterpolationWrapper, and add a new varshape resize sample + expanded test coverage.

Reviewed changes

Copilot reviewed 82 out of 82 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/roccv/cpp/src/tests/operators/test_op_warp_perspective.cpp Switch golden path wrappers to TensorWrapper + Make* wrapper factories.
tests/roccv/cpp/src/tests/operators/test_op_warp_affine.cpp Switch golden path wrappers to TensorWrapper + Make* wrapper factories.
tests/roccv/cpp/src/tests/operators/test_op_thresholding.cpp Replace ImageWrapper usage with TensorWrapper in golden model.
tests/roccv/cpp/src/tests/operators/test_op_rotate.cpp Update golden rotate wrapper composition to MakeBorderWrapper/MakeInterpolationWrapper.
tests/roccv/cpp/src/tests/operators/test_op_resize.cpp Add varshape resize correctness tests and extend interpolation coverage (incl. cubic).
tests/roccv/cpp/src/tests/operators/test_op_normalize.cpp Update includes to tensor_wrapper.hpp.
tests/roccv/cpp/src/tests/operators/test_op_histogram.cpp Replace ImageWrapper usage with TensorWrapper in golden model.
tests/roccv/cpp/src/tests/operators/test_op_gamma_contrast.cpp Replace ImageWrapper usage with TensorWrapper in golden model.
tests/roccv/cpp/src/tests/operators/test_op_flip.cpp Replace ImageWrapper usage with TensorWrapper in golden model.
tests/roccv/cpp/src/tests/operators/test_op_cvt_color.cpp Replace ImageWrapper usage with TensorWrapper in golden model.
tests/roccv/cpp/src/tests/operators/test_op_custom_crop.cpp Replace ImageWrapper usage with TensorWrapper in golden model.
tests/roccv/cpp/src/tests/operators/test_op_copy_make_border.cpp Update wrapper composition to MakeBorderWrapper + TensorWrapper.
tests/roccv/cpp/src/tests/operators/test_op_convert_to.cpp Replace ImageWrapper usage with TensorWrapper in golden model.
tests/roccv/cpp/src/tests/operators/test_op_composite.cpp Replace ImageWrapper usage with TensorWrapper in golden model.
tests/roccv/cpp/src/tests/operators/test_op_center_crop.cpp Replace ImageWrapper usage with TensorWrapper in golden model.
tests/roccv/cpp/src/tests/operators/test_op_brightness_contrast.cpp Replace ImageWrapper usage with TensorWrapper in golden model.
tests/roccv/cpp/src/tests/operators/test_op_bnd_box.cpp Replace ImageWrapper usage with TensorWrapper in golden model.
tests/roccv/cpp/src/tests/operators/test_op_bilateral_filter.cpp Update border+output wrappers to new wrapper factories and TensorWrapper.
tests/roccv/cpp/src/tests/core/wrappers/test_tensor_wrapper.cpp Rename/update tests to validate TensorWrapper (formerly ImageWrapper) behavior.
tests/roccv/cpp/src/tests/core/wrappers/test_interpolation_wrapper.cpp Update golden+actual wrapper types to new BorderWrapper/InterpolationWrapper templates.
tests/roccv/cpp/src/tests/core/wrappers/test_border_wrapper.cpp Update border wrapper test to TensorWrapper and new MakeBorderWrapper factory.
tests/roccv/cpp/src/tests/core/image/test_image.cpp New unit tests for Image allocation, exportData, wrap semantics, and lifecycle.
tests/roccv/cpp/src/tests/core/image/test_image_data.cpp New unit tests for ImageData strided variants and cast behavior.
tests/roccv/cpp/src/tests/core/image/test_image_batch_var_shape.cpp New unit tests for ImageBatchVarShape push/pop/export and CPU/GPU behavior.
tests/roccv/cpp/src/tests/core/image/test_image_batch_data.cpp New unit tests for ImageBatch*Data construction and cast behavior.
tests/roccv/cpp/include/test_helpers.hpp Add AsInt/AsAddr/AsSize helpers for safer EXPECT_EQ comparisons.
tests/roccv/cpp/include/image_test_helpers.hpp New shared helpers for image-layer tests (fake buffers, counting allocator).
src/op_warp_perspective.cpp Update operator implementation to TensorWrapper + new wrapper composition API.
src/op_thresholding.cpp Replace ImageWrapper usage with TensorWrapper in operator implementation.
src/op_rotate.cpp Update operator implementation to TensorWrapper + MakeBorder/MakeInterpolation wrappers.
src/op_resize.cpp Add varshape Resize overload, unify dispatch/launch, and remove host-precomputed scale params.
src/op_remap.cpp Update wrappers to TensorWrapper + new wrapper composition API.
src/op_reformat.cpp Replace ImageWrapper usage with TensorWrapper in operator implementation.
src/op_normalize.cpp Replace ImageWrapper usage with TensorWrapper in operator implementation.
src/op_histogram.cpp Replace ImageWrapper usage with TensorWrapper in operator implementation.
src/op_gamma_contrast.cpp Replace ImageWrapper usage with TensorWrapper in operator implementation.
src/op_flip.cpp Replace ImageWrapper usage with TensorWrapper in operator implementation.
src/op_cvt_color.cpp Replace ImageWrapper usage with TensorWrapper in operator implementation.
src/op_custom_crop.cpp Replace ImageWrapper usage with TensorWrapper in operator implementation.
src/op_copy_make_border.cpp Update border/output wrappers to MakeBorderWrapper + TensorWrapper.
src/op_convert_to.cpp Replace ImageWrapper usage with TensorWrapper in operator implementation.
src/op_composite.cpp Replace ImageWrapper usage with TensorWrapper in operator implementation.
src/op_brightness_contrast.cpp Replace ImageWrapper usage with TensorWrapper in operator implementation.
src/op_bnd_box.cpp Replace ImageWrapper usage with TensorWrapper in operator implementation.
src/op_bilateral_filter.cpp Update border/output wrappers and host threading template args to new wrapper types.
src/op_adv_cvt_color.cpp Replace ImageWrapper usage with TensorWrapper in operator implementation.
src/core/tensor_storage.cpp Remove unused hip_assert include.
src/core/image.cpp New Image implementation (requirements, allocation, exportData, wrap).
src/core/image_data.cpp New ImageData implementation (strided variants and compatibility tags).
src/core/image_batch_var_shape.cpp New ImageBatchVarShape implementation with lazy descriptor sync and caches.
src/core/image_batch_data.cpp New ImageBatchData implementation (varshape strided variants and tags).
src/core/detail/var_shape_descriptor_table.cpp New GPU/CPU descriptor table storage + lazy sync implementation.
samples/resize_var_shape.cpp New sample demonstrating varshape resize into uniform tensor.
samples/README.md Document new resize_var_shape sample.
samples/common/utils.hpp Fix WriteRGBITensor to copy each batch image (adds per-image offset).
samples/CMakeLists.txt Add resize_var_shape sample target.
include/op_resize.hpp Declare varshape Resize overload and document constraints.
include/kernels/host/resize_host.hpp Remove explicit scale params; compute scale per image (batch index) in host kernel.
include/kernels/host/reformat_host.hpp Update host kernel signatures to TensorWrapper.
include/kernels/host/convert_to_host.hpp Update includes to TensorWrapper.
include/kernels/host/brightness_contrast_host.hpp Update includes to TensorWrapper.
include/kernels/device/resize_device.hpp Remove explicit scale params; compute scale per image (batch index) in device kernel.
include/kernels/device/reformat_device.hpp Update device kernel signatures to TensorWrapper.
include/kernels/device/copy_make_border_device.hpp Update kernel docstrings to TensorWrapper terminology.
include/kernels/device/convert_to_device.hpp Update includes to TensorWrapper.
include/kernels/device/brightness_contrast_device.hpp Update includes to TensorWrapper.
include/core/wrappers/tensor_wrapper.hpp Rename ImageWrapper -> TensorWrapper and add width(n)/height(n) signature compatibility.
include/core/wrappers/interpolation_wrapper.hpp Retemplate on BorderWrapper type; add MakeInterpolationWrapper factory.
include/core/wrappers/image_batch_var_shape_wrapper.hpp New wrapper providing kernel-friendly access over varshape descriptor snapshots.
include/core/wrappers/border_wrapper.hpp Retemplate on underlying wrapper type; add MakeBorderWrapper factory.
include/core/image.hpp New Image public API.
include/core/image_storage.hpp New refcount target for Image buffer pointer.
include/core/image_format.hpp Add constexpr default ctor, equality operators, and define FMT_NONE.
include/core/image_data.hpp New ImageData API and cast infrastructure.
include/core/image_buffer.hpp New image buffer descriptor structs (planes/strides).
include/core/image_batch_var_shape.hpp New ImageBatchVarShape public API.
include/core/image_batch_data.hpp New ImageBatchData API and cast infrastructure.
include/core/image_batch_buffer.hpp New image batch buffer descriptor structs.
include/core/detail/var_shape_descriptor_table.hpp New internal descriptor-table abstraction.
include/common/validation_helpers.hpp Add ImageBatchVarShape CHECK_* validation macros.

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

Comment thread include/core/image_data.hpp
Comment thread include/core/image_batch_data.hpp
Comment thread include/core/image.hpp
@codecov-commenter

codecov-commenter commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.07453% with 109 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
include/common/validation_helpers.hpp 17.39% 13 Missing and 6 partials ⚠️
src/core/detail/var_shape_descriptor_table.cpp 81.32% 8 Missing and 9 partials ⚠️
src/core/image_batch_var_shape.cpp 85.47% 10 Missing and 7 partials ⚠️
src/op_adv_cvt_color.cpp 63.64% 16 Missing ⚠️
src/op_resize.cpp 74.14% 2 Missing and 13 partials ⚠️
src/core/image.cpp 85.88% 7 Missing and 5 partials ⚠️
include/core/image_batch_var_shape.hpp 33.33% 4 Missing ⚠️
include/core/image_data.hpp 66.67% 3 Missing and 1 partial ⚠️
include/core/image.hpp 57.14% 3 Missing ⚠️
include/core/image_format.hpp 80.00% 0 Missing and 1 partial ⚠️
... and 1 more
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #159      +/-   ##
===========================================
+ Coverage    79.40%   80.43%   +1.02%     
===========================================
  Files           81       93      +12     
  Lines         3544     4041     +497     
  Branches       765      841      +76     
===========================================
+ Hits          2814     3250     +436     
- Misses         368      387      +19     
- Partials       362      404      +42     
Files with missing lines Coverage Δ
include/core/detail/var_shape_descriptor_table.hpp 100.00% <100.00%> (ø)
include/core/image_batch_data.hpp 100.00% <100.00%> (ø)
include/core/image_storage.hpp 100.00% <100.00%> (ø)
include/core/wrappers/border_wrapper.hpp 74.14% <100.00%> (+1.92%) ⬆️
...de/core/wrappers/image_batch_var_shape_wrapper.hpp 100.00% <100.00%> (ø)
include/core/wrappers/interpolation_wrapper.hpp 100.00% <100.00%> (+56.60%) ⬆️
include/kernels/host/brightness_contrast_host.hpp 100.00% <ø> (ø)
include/kernels/host/convert_to_host.hpp 100.00% <ø> (ø)
include/kernels/host/reformat_host.hpp 100.00% <100.00%> (ø)
include/kernels/host/resize_host.hpp 100.00% <100.00%> (ø)
... and 31 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

zacharyvincze and others added 11 commits July 13, 2026 09:54
The LINEAR and CUBIC fast-path bounds checks in InterpolationWrapper::at
called m_desc.width()/height() with the default batch index (n=0), so for
a variable-shape batch every image was tested against image 0's
dimensions. Narrower images then took the no-border at_inbounds path past
their own right/bottom edge instead of clamping (REPLICATE), producing
wrong edge pixels. Pass the batch index n so each image is bounded by its
own width(n)/height(n). Uniform TensorWrapper ignores n, so the uniform
path is unchanged. NEAREST was unaffected (no fast path).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@zacharyvincze
zacharyvincze force-pushed the zv/feature/resize-varshape branch from 6b5eef9 to bfefb18 Compare July 13, 2026 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:precheckin enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants