Re: [PATCH v5 15/19] accel: ethosu: Validate resize operations
From: Tomeu Vizoso
Date: Sat Nov 28 2026 - 07:32:32 EST
Hi Rob,
On Fri, Nov 20, 2026 at 3:58 PM Rob Herring (Arm) <robh@xxxxxxxxxx> wrote:
>
> Resize input coordinates are controlled by the scale, offset, and step
> registers. Require those values to be explicitly programmed and validate
> their scale and step relationships before calculating feature-map bounds.
>
> KERNEL_WIDTH_M1 and KERNEL_HEIGHT_M1 specify the input dimensions for
> resize, not a convolution footprint to add to each sampling coordinate.
> Compute the final sampling position using the signed resize offset,
> check it against the input dimensions, and include the upper sample
> only for interpolation modes that use it.
>
> Pass zero-based maximum coordinates to feature-map validation, as for
> other operations. Keep the block-step relationship based on the stored
> M1 block dimensions, as required by the hardware.
>
> Signed-off-by: Rob Herring (Arm) <robh@xxxxxxxxxx>
> ---
> v5:
> - Use signed resize offsets and the programmed input dimensions.
> - Account for interpolation mode when including an upper sample.
> - Avoid adding input dimensions to the sampling footprint or converting
> the maximum coordinate to an element count.
> - Do not validate an accumulator input for resize as the accumulator is
> never used for resize.
>
> v3:
> - Fix width and height calculations to account for kernel size reported
> by sashiko
>
> v2:
> - new patch
> ---
> drivers/accel/ethosu/ethosu_device.h | 8 ++
> drivers/accel/ethosu/ethosu_gem.c | 161 ++++++++++++++++++++++++++++++++++-
> 2 files changed, 168 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/accel/ethosu/ethosu_device.h b/drivers/accel/ethosu/ethosu_device.h
> index 368daac25acc..6aa7f035f32c 100644
> --- a/drivers/accel/ethosu/ethosu_device.h
> +++ b/drivers/accel/ethosu/ethosu_device.h
...
> +
> +static int calc_sizes_resize(struct drm_device *ddev,
> + struct ethosu_validated_cmdstream_info *info,
> + struct cmd_state *st, u16 mode)
> +{
> + struct ethosu_device *edev = to_ethosu_device(ddev);
> + u32 ifm_width, ifm_height;
> + u64 len;
> + int ret;
> +
> + if (!cmd_state_reg_is_set(st, NPU_SET_KERNEL_WIDTH_M1) ||
> + !cmd_state_reg_is_set(st, NPU_SET_KERNEL_HEIGHT_M1) ||
> + !cmd_state_reg_is_set(st, NPU_SET_OFM_BLK_WIDTH_M1) ||
> + !cmd_state_reg_is_set(st, NPU_SET_OFM_BLK_HEIGHT_M1) ||
> + !cmd_state_reg_is_set(st, NPU_SET_RESIZE_X_SCALE_N_M1) ||
> + !cmd_state_reg_is_set(st, NPU_SET_RESIZE_Y_SCALE_N_M1) ||
> + !cmd_state_reg_is_set(st, NPU_SET_RESIZE_X_OFFSET) ||
> + !cmd_state_reg_is_set(st, NPU_SET_RESIZE_Y_OFFSET) ||
> + !cmd_state_reg_is_set(st, NPU_SET_RESIZE_X) ||
> + !cmd_state_reg_is_set(st, NPU_SET_RESIZE_Y))
> + return -EINVAL;
> +
> + ret = resize_axis_size(st, 0, st->ofm.width, st->ofm_blk_width,
> + st->ifm.width, mode, &ifm_width);
> + if (ret)
> + return ret;
> + ret = resize_axis_size(st, 1, st->ofm.height[2], st->ofm_blk_height,
> + st->ifm.height[2], mode, &ifm_height);
> + if (ret)
> + return ret;
> +
> + ret = feat_matrix_size(edev, info, st, &st->ifm, FEAT_MATRIX_IFM,
> + ifm_width, ifm_height, st->ifm.depth, false, &len);
If I'm not mistaken, st->ifm.depth contains IFM_DEPTH_M1, but the
pseudocode in the U85 TRM at 3.10.11 shows the hardware using the
depth in OFM_DEPTH_M1 instead. Can you please check?
The same problem seems to happen for depthwise (3.10.3) and for
pooling other than
reduce_sum (3.10.10).
Regards,
Tomeu