chimera::image::resize is a general-purpose tensor resize. It resizes each channel independently, supports nearest-neighbor and bilinear interpolation, and works on both OCM-resident and DDR-resident tensors. The DDR variants stream channels through OCM and can distribute the work across all cores. The API is provided by image.hpp (included via qil.h); the configuration enums live in image_resize_helpers.hpp.
Specialized overloads are selected at compile time from the ResizeMethod and the tensor locations, so the same call site dispatches to the best implementation for the shapes involved.
Resize Methods & Coordinate Transforms
The template parameters mirror the ONNX Resize attributes:
| Parameter | Applies to | Values | Default |
|---|---|---|---|
resizeMethod | all | NEAREST_NEIGHBORS, BILINEAR_INTERPOLATION | BILINEAR_INTERPOLATION |
coordinateTransform | all | ASYMMETRIC, HALF_PIXEL, ALIGN_CORNERS | HALF_PIXEL (bilinear), ASYMMETRIC (nearest) |
nearestMode | NEAREST_NEIGHBORS only | ROUND_PREFER_FLOOR, ROUND_PREFER_CEIL, FLOOR, CEIL | ROUND_PREFER_FLOOR |
intRoundMethod | BILINEAR_INTERPOLATION only | ROUND, CAST | ROUND |
multicoreMode | DDR overloads only | Single, All | Single |
Note:
BILINEAR_INTERPOLATION_HALF_PIXELandBILINEAR_INTERPOLATION_ASYMMETRICare deprecated. UseBILINEAR_INTERPOLATIONwith the matchingCoordinateTransforminstead.
OCM → OCM Resize
Resizes a planar OCM tensor of shape (1, channels, height, width) into an OCM tensor of shape (1, channels, resized_height, resized_width). The allocator parameter defaults to EmptyType — no scratch OCM is required.
Bilinear interpolation:
With ResizeMethod::NEAREST_NEIGHBORS, a matching overload is selected automatically; it is identical except that coordinateTransform defaults to ASYMMETRIC.
Example:
OcmTensor<std::uint8_t, 1, 3, 224, 224> ocmIn;
OcmTensor<std::uint8_t, 1, 3, 112, 112> ocmOut;
ocmMem.allocate(ocmIn);
ocmMem.allocate(ocmOut);
memCpy(ddrIn, ocmIn);
image::resize<image::ResizeMethod::BILINEAR_INTERPOLATION, image::CoordinateTransform::HALF_PIXEL>(ocmIn, ocmOut);
memCpy(ocmOut, ddrOut);
DDR → DDR Resize
Resizes a DDR tensor of shape (batch, channels, height, width) into a DDR tensor of shape (batch, channels, resized_height, resized_width). Channels are streamed through a double-buffered OCM working set and resized on chip, so a single channel of input plus output must fit within reservedSize bytes of OCM (default: half of OCM). An OCM allocator is required.
As with the OCM overload, ResizeMethod::NEAREST_NEIGHBORS selects a matching overload whose coordinateTransform defaults to ASYMMETRIC.
The DDR overloads also support multicore execution via the multicoreMode parameter. With MultiCoreMode::All, the batch * channels planes are divided evenly across the cores in the kernel group and each core resizes its share; a kGroupSync() is performed before returning. With MultiCoreMode::Single (the default), the calling core processes all channels.
Example (multicore, nearest neighbors):
MemAllocator ocmMem;
DdrInputShape ddrInput(ddrInputPtr);
DdrOutputShape ddrOutput(ddrOutputPtr);
image::resize<image::ResizeMethod::NEAREST_NEIGHBORS,
image::CoordinateTransform::HALF_PIXEL,
image::NearestMode::ROUND_PREFER_FLOOR,
ocm::ocmSizeBytes / 2,
image::IntRoundMethod::CAST,
MultiCoreMode::All>(ddrInput, ddrOutput, ocmMem);
Optimized Paths
The implementation selects an optimized kernel at compile time when the shapes and modes allow it (canOptimizeDownscale / canOptimizeUpscale in image_resize_helpers.hpp). No code changes are needed — the same resize call dispatches automatically.
| Path | Conditions |
|---|---|
| Optimized downscale | Bilinear + HALF_PIXEL, 1-byte element type (int8/uint8), each axis scaled by exactly 1×, 2×, or 4×. Uses packed flows instead of RAU gathers. |
| Optimized 2× upscale | 2× on both axes, 1-byte element type, bilinear + HALF_PIXEL or nearest neighbors with any transform except ALIGN_CORNERS. Streams tiles through flows and computes via neighbor exchange. |
| Optimized 4× upscale | 4× on both axes, 1-byte element type, bilinear + HALF_PIXEL, input larger than coreDim / 4 in at least one axis. |
| General | All other shape/type/mode combinations. Processes a row of output at a time, gathering the 4 source pixels per output pixel through RAU. |
The general bilinear path computes interpolation weights in fixed point (FixedPoint32<31>) and clamps source coordinates at image borders (border replication).
Related
For resizing 3-channel images with fused color conversion, see resizeImage in Image Transformations.
