From 4e8e4ca2fc3f6d92c4271c0f2918785b496d2bb9 Mon Sep 17 00:00:00 2001 From: "Rob Herring (Arm)" Date: Thu, 9 Apr 2026 08:50:36 -0500 Subject: [PATCH] ethosu: Add minimum and maximum operators Signed-off-by: Rob Herring (Arm) Part-of: --- src/gallium/drivers/ethosu/ethosu_cmd.c | 15 +++++++++++++++ src/gallium/drivers/ethosu/ethosu_lower.c | 14 ++++++++++++++ src/gallium/drivers/ethosu/ethosu_ml.c | 2 ++ 3 files changed, 31 insertions(+) diff --git a/src/gallium/drivers/ethosu/ethosu_cmd.c b/src/gallium/drivers/ethosu/ethosu_cmd.c index ba63a2b9ee3..d00076d33b1 100644 --- a/src/gallium/drivers/ethosu/ethosu_cmd.c +++ b/src/gallium/drivers/ethosu/ethosu_cmd.c @@ -724,6 +724,17 @@ simplified_elementwise_add_sub_scale( *out_out_scale = ethosu_quantize_scale(output_rescale_val, out_out_shift, false); } +static void +elementwise_min_max_scale(struct ethosu_subgraph *subgraph) +{ + if (!ethosu_ml_device(subgraph->base.device)->is_u65) { + EMIT1(NPU_SET_OPA_SCALE, 0, 1); + EMIT1(NPU_SET_OPB_SCALE, 0, 1); + + } + EMIT1(NPU_SET_OFM_SCALE, 0, 1); +} + static void elementwise_mul_scale( struct ethosu_subgraph *subgraph, @@ -815,6 +826,10 @@ emit_eltwise(struct ethosu_subgraph *subgraph, struct ethosu_operation *operatio op_to_scale = OP_A; } break; + case ETHOSU_ELTWISE_TYPE_MAX: + case ETHOSU_ELTWISE_TYPE_MIN: + elementwise_min_max_scale(subgraph); + break; default: assert(0); break; diff --git a/src/gallium/drivers/ethosu/ethosu_lower.c b/src/gallium/drivers/ethosu/ethosu_lower.c index d7e84e8767e..2f311115aef 100644 --- a/src/gallium/drivers/ethosu/ethosu_lower.c +++ b/src/gallium/drivers/ethosu/ethosu_lower.c @@ -877,6 +877,20 @@ ethosu_lower_graph(struct ethosu_subgraph *subgraph, break; } + case PIPE_ML_OPERATION_TYPE_MAXIMUM: { + ethosu_lower_eltwise(subgraph, &poperations[i], &operation); + operation.eltwise.type = ETHOSU_ELTWISE_TYPE_MAX; + util_dynarray_append(&subgraph->operations, operation); + break; + } + + case PIPE_ML_OPERATION_TYPE_MINIMUM: { + ethosu_lower_eltwise(subgraph, &poperations[i], &operation); + operation.eltwise.type = ETHOSU_ELTWISE_TYPE_MIN; + util_dynarray_append(&subgraph->operations, operation); + break; + } + case PIPE_ML_OPERATION_TYPE_POOLING: { ethosu_lower_pooling(subgraph, &poperations[i], &operation); util_dynarray_append(&subgraph->operations, operation); diff --git a/src/gallium/drivers/ethosu/ethosu_ml.c b/src/gallium/drivers/ethosu/ethosu_ml.c index a227e35505e..90b8bfaea51 100644 --- a/src/gallium/drivers/ethosu/ethosu_ml.c +++ b/src/gallium/drivers/ethosu/ethosu_ml.c @@ -140,6 +140,8 @@ ethosu_ml_operation_supported(struct pipe_ml_device *pdevice, break; } + case PIPE_ML_OPERATION_TYPE_MAXIMUM: + case PIPE_ML_OPERATION_TYPE_MINIMUM: case PIPE_ML_OPERATION_TYPE_MUL: case PIPE_ML_OPERATION_TYPE_ADD: case PIPE_ML_OPERATION_TYPE_POOLING: