From 08d93a60f56b8c0c944006ab5aae1b48489ce43b Mon Sep 17 00:00:00 2001 From: "Rob Herring (Arm)" Date: Tue, 10 Mar 2026 20:50:41 -0500 Subject: [PATCH] ethosu: Add quantize operation The quantize operation lowers to a pooling nop operation. Signed-off-by: Rob Herring (Arm) Part-of: --- src/gallium/drivers/ethosu/ethosu_lower.c | 26 +++++++++++++++++++++++ src/gallium/drivers/ethosu/ethosu_ml.c | 1 + 2 files changed, 27 insertions(+) diff --git a/src/gallium/drivers/ethosu/ethosu_lower.c b/src/gallium/drivers/ethosu/ethosu_lower.c index 20b40cdd7c7..ff20bf0f4b7 100644 --- a/src/gallium/drivers/ethosu/ethosu_lower.c +++ b/src/gallium/drivers/ethosu/ethosu_lower.c @@ -582,6 +582,26 @@ ethosu_lower_leakyrelu(struct ethosu_subgraph *subgraph, ethosu_sched_operation(subgraph, operation); } +static void +ethosu_lower_quantize(struct ethosu_subgraph *subgraph, + const struct pipe_ml_operation *poperation, + struct ethosu_operation *operation) +{ + operation->type = ETHOSU_OPERATION_TYPE_POOLING; + operation->round_mode = ETHOSU_ROUNDING_DOUBLE; + operation->pooling.nop = true; + + if (ethosu_ml_device(subgraph->base.device)->is_u65) + operation->pooling.type = ETHOSU_POOLING_TYPE_AVG; + else + operation->pooling.type = ETHOSU_POOLING_TYPE_SUM; + + set_feature_maps(subgraph, poperation->input_tensors[0], poperation->output_tensors[0], operation); + + allocate_feature_maps(subgraph, operation); + ethosu_sched_operation(subgraph, operation); +} + static void ethosu_lower_concatenation(struct ethosu_subgraph *subgraph, const struct pipe_ml_operation *poperation, @@ -914,6 +934,12 @@ ethosu_lower_graph(struct ethosu_subgraph *subgraph, break; } + case PIPE_ML_OPERATION_TYPE_QUANTIZE: { + ethosu_lower_quantize(subgraph, &poperations[i], &operation); + util_dynarray_append(&subgraph->operations, operation); + break; + } + default: DBG("poperation->type %d\n", poperations[i].type); UNREACHABLE("Unsupported ML operation type"); diff --git a/src/gallium/drivers/ethosu/ethosu_ml.c b/src/gallium/drivers/ethosu/ethosu_ml.c index c5721dd21c5..551ab7b0a49 100644 --- a/src/gallium/drivers/ethosu/ethosu_ml.c +++ b/src/gallium/drivers/ethosu/ethosu_ml.c @@ -149,6 +149,7 @@ ethosu_ml_operation_supported(struct pipe_ml_device *pdevice, case PIPE_ML_OPERATION_TYPE_TANH: case PIPE_ML_OPERATION_TYPE_HSWISH: case PIPE_ML_OPERATION_TYPE_LEAKY_RELU: + case PIPE_ML_OPERATION_TYPE_QUANTIZE: supported = true; break; case PIPE_ML_OPERATION_TYPE_RESIZE: {