Unlock this feature

This feature isn’t part of your plan yet

Contact sales to get upgraded to the full DevStudio experience.

Unlock this feature

This feature isn't part of your plan yet.

Image Resize

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

ResizeMethodenum
File: /src/image_resize_helpers.hppLines 25–33

Resize methods.

NEAREST_NEIGHBORS: Nearest neighbor interpolation. BILINEAR_INTERPOLATION: Bilinear interpolation. BILINEAR_INTERPOLATION_MULTISTEP: Pyramid method using a series of bilinear interpolations. Downscales by 2 at a time. Reduces aliasing for large downscaling. BILINEAR_INTERPOLATION_HALF_PIXEL: Bilinear interpolation with half pixel offset. Deprecated in favor of using ResizeMethod::BILINEAR_INTERPOLATION with CoordinateTranform::HALF_PIXEL BILINEAR_INTERPOLATION_ASYMMETRIC: Bilinear interpolation without offset. Deprecated in favor of using ResizeMethod::BILINEAR_INTERPOLATION with CoordinateTranform::ASYMMETRIC

enum class ResizeMethod { NEAREST_NEIGHBORS = 0, BILINEAR_INTERPOLATION, BILINEAR_INTERPOLATION_MULTISTEP, BILINEAR_INTERPOLATION_HALF_PIXEL QUADRIC_DEPRECATED_FUNCTION( "Use BILINEAR_INTERPOLATION with CoordinateTransform mode HALF_PIXEL instead.", "2026-02-24", "26.04"), BILINEAR_INTERPOLATION_ASYMMETRIC QUADRIC_DEPRECATED_FUNCTION( "Use BILINEAR_INTERPOLATION with CoordinateTransform mode ASYMMETRIC instead.", "2026-02-24", "26.04"), }

The template parameters mirror the ONNX Resize attributes:

ParameterApplies toValuesDefault
resizeMethodallNEAREST_NEIGHBORS, BILINEAR_INTERPOLATIONBILINEAR_INTERPOLATION
coordinateTransformallASYMMETRIC, HALF_PIXEL, ALIGN_CORNERSHALF_PIXEL (bilinear), ASYMMETRIC (nearest)
nearestModeNEAREST_NEIGHBORS onlyROUND_PREFER_FLOOR, ROUND_PREFER_CEIL, FLOOR, CEILROUND_PREFER_FLOOR
intRoundMethodBILINEAR_INTERPOLATION onlyROUND, CASTROUND
multicoreModeDDR overloads onlySingle, AllSingle

Note: BILINEAR_INTERPOLATION_HALF_PIXEL and BILINEAR_INTERPOLATION_ASYMMETRIC are deprecated. Use BILINEAR_INTERPOLATION with the matching CoordinateTransform instead.

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:

resizefunction
File: /src/image.hppLines 2471–2489

General purpose tensor resize.

Input tensor shape must be of form (1, channels, height, width). Output tensor shape must be of form (1, channels, resized_height, resized_width)

template <ResizeMethod resizeMethod = ResizeMethod::BILINEAR_INTERPOLATION,
          CoordinateTransform coordinateTransform = CoordinateTransform::HALF_PIXEL,
          NearestMode nearestMode = NearestMode::ROUND_PREFER_FLOOR,
          IntRoundMethod intRoundMethod = IntRoundMethod::ROUND,
          typename OcmAllocatorType = EmptyType,
          typename OcmInputShape,
          typename OcmOutputShape,
          std::enable_if_t<resizeMethod != ResizeMethod::BILINEAR_INTERPOLATION_MULTISTEP &&
            resizeMethod != ResizeMethod::NEAREST_NEIGHBORS &&
            OcmInputShape::location == TensorLocation::OCM, int> = 0>
INLINE void resize(OcmInputShape& ocmInput,
                   OcmOutputShape& ocmOutput,
                   const OcmAllocatorType& ocmMemAlloc = EmptyType())
NameTypeDefaultDescription
resizeMethodResizeMethodResizeMethod::BILINEAR_INTERPOLATIONSelection of resize method.
coordinateTransformCoordinateTransformCoordinateTransform::HALF_PIXELSelection of coordinate transform method.
nearestModeNearestModeNearestMode::ROUND_PREFER_FLOORSelection of internal rounding method. Only applicable for NEAREST_NEIGHBORS.
intRoundMethodIntRoundMethodIntRoundMethod::ROUND
OcmAllocatorTypetypenameEmptyTypeType of ocm allocator.
OcmInputShapetypenameThe shape of the input tensor.
OcmOutputShapetypenameThe shape of the output tensor.
NameTypeDescription
ocmInputOcmInputShape&The input tensor.
ocmOutputOcmOutputShape&The output tensor.
ocmMemAllocconst OcmAllocatorType&ocm allocator to be used locally.

INLINE void — void

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.

resizefunction
File: /src/image.hppLines 2531–2642

General purpose tensor resize for Ddr -> Ddr.

Input tensor shape must be of form (batch, channels, height, width). Output tensor shape must be of form (batch, channels, resized_height, resized_width)

template <ResizeMethod resizeMethod = ResizeMethod::BILINEAR_INTERPOLATION,
          CoordinateTransform coordinateTransform = CoordinateTransform::HALF_PIXEL,
          NearestMode nearestMode = NearestMode::ROUND_PREFER_FLOOR,
          std::int32_t reservedSize = ocm::ocmSizeBytes / 2,
          IntRoundMethod intRoundMethod = IntRoundMethod::ROUND,
          MultiCoreMode multicoreMode = MultiCoreMode::Single,
          typename OcmAllocatorType,
          typename DdrInputShape,
          typename DdrOutputShape,
          std::enable_if_t<resizeMethod != ResizeMethod::BILINEAR_INTERPOLATION_MULTISTEP &&
            resizeMethod != ResizeMethod::NEAREST_NEIGHBORS &&
            DdrInputShape::location == TensorLocation::DDR, int> = 0>
INLINE void resize(DdrInputShape& ddrInput,
                   DdrOutputShape& ddrOutput,
                   OcmAllocatorType& ocmMemAlloc)
NameTypeDefaultDescription
resizeMethodResizeMethodResizeMethod::BILINEAR_INTERPOLATIONSelection of resize method.
coordinateTransformCoordinateTransformCoordinateTransform::HALF_PIXELSelection of coordinate transform method.
nearestModeNearestModeNearestMode::ROUND_PREFER_FLOORSelection of internal rounding method. Only applicable for NEAREST_NEIGHBORS.
reservedSizestd::int32_tocm::ocmSizeBytes / 2Amount of reserved ocm storage that can be used in this function.
intRoundMethodIntRoundMethodIntRoundMethod::ROUND
multicoreModeMultiCoreModeMultiCoreMode::SingleSelection for multicore processing mode.
OcmAllocatorTypetypenameType of ocm allocator.
DdrInputShapetypenameThe Ddr region shape of the input tensor.
DdrOutputShapetypenameThe Ddr region shape of the output tensor.
NameTypeDescription
ddrInputDdrInputShape&The input tensor.
ddrOutputDdrOutputShape&The output tensor.
ocmMemAllocOcmAllocatorType&ocm allocator to be used locally.

INLINE void — void

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.

PathConditions
Optimized downscaleBilinear + 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× upscale2× 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× upscale4× on both axes, 1-byte element type, bilinear + HALF_PIXEL, input larger than coreDim / 4 in at least one axis.
GeneralAll 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).

For resizing 3-channel images with fused color conversion, see resizeImage in Image Transformations.

Sign in to your account

Don't have an account? 
By signing in, you are agreeing to our Terms of Use and Privacy Policy.
Quadric // One architecture. Every algorithm.

Develop.

Simulate.

Profile.

Collaborate.