From e86386df89522d6d7de2ed2d0434fe058cc22d35 Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Wed, 6 Nov 2024 10:26:20 +0100 Subject: [PATCH] etnaviv/nn: Fix use of etna_core_info Right now we were retrieving the properties of the NPU from the etna_core_info of the GPU. Fixes: 92a6f697d589 ("etnaviv: npu: Switch to use etna_core_info") Reviewed-by: Philipp Zabel (cherry picked from commit f9bb9aa7d5ee87069c65ccef26e0f762dadce597) Part-of: --- .pick_status.json | 2 +- src/gallium/drivers/etnaviv/etnaviv_ml.c | 11 +++++++-- src/gallium/drivers/etnaviv/etnaviv_ml.h | 3 +++ src/gallium/drivers/etnaviv/etnaviv_ml_nn.c | 26 ++++++++++----------- src/gallium/drivers/etnaviv/etnaviv_ml_tp.c | 6 ++--- 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 63aa378ff85..1d89ef7b909 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -504,7 +504,7 @@ "description": "etnaviv/nn: Fix use of etna_core_info", "nominated": true, "nomination_type": 2, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "92a6f697d589c926edf712ca40a7742ce7d187d7", "notes": null diff --git a/src/gallium/drivers/etnaviv/etnaviv_ml.c b/src/gallium/drivers/etnaviv/etnaviv_ml.c index bb8a8caedd6..ef3e1ae098b 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_ml.c +++ b/src/gallium/drivers/etnaviv/etnaviv_ml.c @@ -61,6 +61,13 @@ etna_ml_create_tensor(struct etna_ml_subgraph *subgraph, unsigned idx, unsigned ML_DBG("created resource %p for tensor %d with size %d\n", res, idx, size); } +struct etna_core_npu_info * +etna_ml_get_core_info(struct etna_context *context) { + struct etna_screen *screen = context->screen; + struct etna_core_info *info = etna_gpu_get_core_info(screen->npu); + return &info->npu; +} + static bool needs_reshuffle(const struct pipe_ml_operation *poperation) { @@ -237,7 +244,7 @@ etna_ml_subgraph_create(struct pipe_context *pcontext, unsigned count) { struct etna_context *ctx = etna_context(pcontext); - unsigned nn_core_count = ctx->screen->info->npu.nn_core_count; + unsigned nn_core_count = etna_ml_get_core_info(ctx)->nn_core_count; struct etna_ml_subgraph *subgraph; struct list_head operations; unsigned tensor_count; @@ -358,7 +365,7 @@ void etna_ml_subgraph_invoke(struct pipe_context *pctx, struct pipe_ml_subgraph *psubgraph, struct pipe_tensor *input) { struct etna_context *ctx = etna_context(pctx); - unsigned tp_core_count = ctx->screen->info->npu.tp_core_count; + unsigned tp_core_count = etna_ml_get_core_info(ctx)->tp_core_count; struct etna_ml_subgraph *subgraph = (struct etna_ml_subgraph *)(psubgraph); struct etna_cmd_stream *stream = ctx->stream; static bool is_initialized = false; diff --git a/src/gallium/drivers/etnaviv/etnaviv_ml.h b/src/gallium/drivers/etnaviv/etnaviv_ml.h index 1335e36eb22..18a147e1d54 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_ml.h +++ b/src/gallium/drivers/etnaviv/etnaviv_ml.h @@ -8,6 +8,7 @@ #include "pipe/p_state.h" #include "util/u_dynarray.h" +#include "etnaviv_context.h" #define MAX_CONFIG_BOS 4 @@ -94,6 +95,8 @@ unsigned etna_ml_allocate_tensor(struct etna_ml_subgraph *subgraph); struct pipe_resource *etna_ml_get_tensor(struct etna_ml_subgraph *subgraph, unsigned idx); unsigned etna_ml_get_offset(struct etna_ml_subgraph *subgraph, unsigned idx); +struct etna_core_npu_info *etna_ml_get_core_info(struct etna_context *context); + struct pipe_ml_subgraph * etna_ml_subgraph_create(struct pipe_context *context, const struct pipe_ml_operation *operations, diff --git a/src/gallium/drivers/etnaviv/etnaviv_ml_nn.c b/src/gallium/drivers/etnaviv/etnaviv_ml_nn.c index 51c2e45166a..09554e8a069 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_ml_nn.c +++ b/src/gallium/drivers/etnaviv/etnaviv_ml_nn.c @@ -515,8 +515,8 @@ etna_ml_lower_add(struct etna_ml_subgraph *subgraph, static unsigned calc_superblocks(struct etna_context *ctx, const struct etna_operation *operation, unsigned tile_y, unsigned interleave_mode) { - unsigned nn_core_count = ctx->screen->info->npu.nn_core_count; - unsigned nn_accum_buffer_depth = ctx->screen->info->npu.nn_accum_buffer_depth; + unsigned nn_core_count = etna_ml_get_core_info(ctx)->nn_core_count; + unsigned nn_accum_buffer_depth = etna_ml_get_core_info(ctx)->nn_accum_buffer_depth; unsigned output_channels = operation->addition ? 1 : operation->output_channels; unsigned kernels_per_core = DIV_ROUND_UP(output_channels, nn_core_count); unsigned foo = (nn_accum_buffer_depth * interleave_mode) / tile_y; @@ -590,8 +590,8 @@ calc_addition_sizes(unsigned *input_width, unsigned *input_height, unsigned *inp static unsigned calculate_tiling(struct etna_context *ctx, const struct etna_operation *operation, unsigned *tile_width_out, unsigned *tile_height_out) { - unsigned nn_input_buffer_depth = ctx->screen->info->npu.nn_input_buffer_depth; - unsigned nn_accum_buffer_depth = ctx->screen->info->npu.nn_accum_buffer_depth; + unsigned nn_input_buffer_depth = etna_ml_get_core_info(ctx)->nn_input_buffer_depth; + unsigned nn_accum_buffer_depth = etna_ml_get_core_info(ctx)->nn_accum_buffer_depth; unsigned input_width = operation->input_width; unsigned input_height = operation->input_height; unsigned input_channels = operation->input_channels; @@ -639,9 +639,9 @@ create_nn_config(struct etna_ml_subgraph *subgraph, const struct etna_operation { struct pipe_context *context = subgraph->base.context; struct etna_context *ctx = etna_context(context); - unsigned nn_core_count = ctx->screen->info->npu.nn_core_count; + unsigned nn_core_count = etna_ml_get_core_info(ctx)->nn_core_count; unsigned nn_core_version = ctx->screen->specs.nn_core_version; - unsigned oc_sram_size = ctx->screen->info->npu.on_chip_sram_size; + unsigned oc_sram_size = etna_ml_get_core_info(ctx)->on_chip_sram_size; struct etna_bo *bo = etna_bo_new(ctx->screen->dev, sizeof(struct etna_nn_params), DRM_ETNA_GEM_CACHE_WC); @@ -967,7 +967,7 @@ static unsigned write_core_6(struct etna_ml_subgraph *subgraph, uint32_t *map, unsigned core, const struct etna_operation *operation, unsigned zrl_bits) { struct pipe_context *pctx = subgraph->base.context; - unsigned nn_core_count = etna_context(pctx)->screen->info->npu.nn_core_count; + unsigned nn_core_count = etna_ml_get_core_info(etna_context(pctx))->nn_core_count; unsigned input_channels = operation->addition ? 1 : operation->input_channels; unsigned output_channels = operation->addition ? 1 : operation->output_channels; unsigned cores_used = MIN2(output_channels, nn_core_count); @@ -1047,7 +1047,7 @@ static unsigned write_core_interleaved(struct etna_ml_subgraph *subgraph, uint32_t *map, unsigned core, const struct etna_operation *operation, unsigned zrl_bits) { struct pipe_context *pctx = subgraph->base.context; - unsigned nn_core_count = etna_context(pctx)->screen->info->npu.nn_core_count; + unsigned nn_core_count = etna_ml_get_core_info(etna_context(pctx))->nn_core_count; unsigned input_channels = operation->addition ? 1 : operation->input_channels; unsigned output_channels = operation->addition ? 1 : operation->output_channels; unsigned cores_used = MIN2(output_channels, nn_core_count); @@ -1134,7 +1134,7 @@ static unsigned write_core_sequential(struct etna_ml_subgraph *subgraph, uint32_t *map, unsigned core, const struct etna_operation *operation, unsigned zrl_bits) { struct pipe_context *pctx = subgraph->base.context; - unsigned nn_core_count = etna_context(pctx)->screen->info->npu.nn_core_count; + unsigned nn_core_count = etna_ml_get_core_info(etna_context(pctx))->nn_core_count; unsigned output_channels = operation->addition ? 1 : operation->output_channels; unsigned cores_used = MIN2(output_channels, nn_core_count); unsigned kernels_per_core = DIV_ROUND_UP(output_channels, cores_used); @@ -1221,7 +1221,7 @@ calculate_weight_bo_size(struct etna_ml_subgraph *subgraph, const struct etna_op { struct pipe_context *context = subgraph->base.context; struct etna_context *ctx = etna_context(context); - unsigned nn_core_count = ctx->screen->info->npu.nn_core_count; + unsigned nn_core_count = etna_ml_get_core_info(ctx)->nn_core_count; unsigned header_size = ALIGN(nn_core_count * 4, 64); unsigned input_channels = operation->addition ? 1 : operation->input_channels; unsigned output_channels = operation->addition ? 1 : operation->output_channels; @@ -1245,8 +1245,8 @@ calculate_zrl_bits(struct etna_ml_subgraph *subgraph, const struct etna_operatio { struct pipe_context *context = subgraph->base.context; struct etna_context *ctx = etna_context(context); - unsigned nn_core_count = ctx->screen->info->npu.nn_core_count; - unsigned max_zrl_bits = ctx->screen->info->npu.nn_zrl_bits; + unsigned nn_core_count = etna_ml_get_core_info(ctx)->nn_core_count; + unsigned max_zrl_bits = etna_ml_get_core_info(ctx)->nn_zrl_bits; unsigned header_size = ALIGN(nn_core_count * 4, 64); unsigned input_channels = operation->addition ? 1 : operation->input_channels; unsigned output_channels = operation->addition ? 1 : operation->output_channels; @@ -1298,7 +1298,7 @@ create_coefficients_bo(struct etna_ml_subgraph *subgraph, const struct etna_oper { struct pipe_context *context = subgraph->base.context; struct etna_context *ctx = etna_context(context); - unsigned nn_core_count = ctx->screen->info->npu.nn_core_count; + unsigned nn_core_count = etna_ml_get_core_info(ctx)->nn_core_count; unsigned header_size = ALIGN(nn_core_count * 4, 64); unsigned input_channels = operation->addition ? 1 : operation->input_channels; unsigned output_channels = operation->addition ? 1 : operation->output_channels; diff --git a/src/gallium/drivers/etnaviv/etnaviv_ml_tp.c b/src/gallium/drivers/etnaviv/etnaviv_ml_tp.c index 81b01a840da..b68dc554919 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_ml_tp.c +++ b/src/gallium/drivers/etnaviv/etnaviv_ml_tp.c @@ -394,7 +394,7 @@ create_reshuffle_config(struct etna_ml_subgraph *subgraph, const struct etna_ope unsigned tp_core, unsigned tp_cores_used) { struct etna_context *ctx = etna_context(subgraph->base.context); - unsigned tp_core_count = ctx->screen->info->npu.tp_core_count; + unsigned tp_core_count = etna_ml_get_core_info(ctx)->tp_core_count; struct etna_bo *bo = etna_bo_new(ctx->screen->dev, sizeof(struct etna_tp_params), DRM_ETNA_GEM_CACHE_WC); @@ -730,7 +730,7 @@ etna_ml_compile_operation_tp(struct etna_ml_subgraph *subgraph, instruction->configs[0] = create_detranspose_config(subgraph, operation); break; case ETNA_ML_TP_RESHUFFLE: { - unsigned tp_core_count = ctx->screen->info->npu.tp_core_count; + unsigned tp_core_count = etna_ml_get_core_info(ctx)->tp_core_count; unsigned tp_cores_used; tp_cores_used = (operation->input_width > 8 || operation->input_channels > 1) ? tp_core_count : 1; @@ -756,7 +756,7 @@ etna_ml_emit_operation_tp(struct etna_ml_subgraph *subgraph, unsigned idx) { struct etna_context *ctx = etna_context(subgraph->base.context); - unsigned tp_core_count = ctx->screen->info->npu.tp_core_count; + unsigned tp_core_count = etna_ml_get_core_info(ctx)->tp_core_count; struct etna_cmd_stream *stream = ctx->stream; bool more_than_one_tp_job = operation->configs[1] != NULL; bool parallel = DBG_ENABLED(ETNA_DBG_NPU_PARALLEL);