From fc0770d5e32bbc77928c46b2ed3fdc6c6ed7d8bf Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Wed, 25 Mar 2026 19:27:12 +0100 Subject: [PATCH] ethosu: parse optional SRAM size from device spec string The spec format is now GEN-MACS[-SRAM], e.g. "65-256-4096" or "85-256". When the SRAM parameter is omitted it defaults to 0. Part-of: --- src/gallium/drivers/ethosu/ethosu_device.c | 82 ++++++++++------------ 1 file changed, 37 insertions(+), 45 deletions(-) diff --git a/src/gallium/drivers/ethosu/ethosu_device.c b/src/gallium/drivers/ethosu/ethosu_device.c index 57b17cf60ea..ee665ce94fb 100644 --- a/src/gallium/drivers/ethosu/ethosu_device.c +++ b/src/gallium/drivers/ethosu/ethosu_device.c @@ -224,6 +224,30 @@ ethosu_ml_device_create_accel(struct pipe_screen *pscreen) return &screen->ml_device.base; } +static void +set_device_arch(struct ethosu_ml_device *device, bool is_u65) +{ + device->is_u65 = is_u65; + + if (is_u65) { + device->ifm_ublock.width = 2; + device->ifm_ublock.height = 2; + device->ifm_ublock.depth = 8; + device->ofm_ublock.width = 2; + device->ofm_ublock.height = 2; + device->ofm_ublock.depth = 8; + device->max_concurrent_blocks = 3; + } else { + device->ifm_ublock.width = 4; + device->ifm_ublock.height = 4; + device->ifm_ublock.depth = 16; + device->ofm_ublock.width = 4; + device->ofm_ublock.height = 1; + device->ofm_ublock.depth = 8; + device->max_concurrent_blocks = 7; + } +} + static void set_device_callbacks(struct ethosu_ml_device *device) { @@ -256,34 +280,12 @@ ethosu_screen_create(int fd, if (DBG_ENABLED(ETHOSU_DBG_FORCE_U85)) is_u65 = false; - ethosu_screen->ml_device.is_u65 = is_u65; + set_device_arch(ðosu_screen->ml_device, is_u65); ethosu_screen->ml_device.sram_size = ethosu_screen->info.sram_size; if (DBG_ENABLED(ETHOSU_DBG_DISABLE_SRAM)) ethosu_screen->ml_device.sram_size = 0; - if (is_u65) { - ethosu_screen->ml_device.ifm_ublock.width = 2; - ethosu_screen->ml_device.ifm_ublock.height = 2; - ethosu_screen->ml_device.ifm_ublock.depth = 8; - - ethosu_screen->ml_device.ofm_ublock.width = 2; - ethosu_screen->ml_device.ofm_ublock.height = 2; - ethosu_screen->ml_device.ofm_ublock.depth = 8; - - ethosu_screen->ml_device.max_concurrent_blocks = 3; - } else { - ethosu_screen->ml_device.ifm_ublock.width = 4; - ethosu_screen->ml_device.ifm_ublock.height = 4; - ethosu_screen->ml_device.ifm_ublock.depth = 16; - - ethosu_screen->ml_device.ofm_ublock.width = 4; - ethosu_screen->ml_device.ofm_ublock.height = 1; - ethosu_screen->ml_device.ofm_ublock.depth = 8; - - ethosu_screen->ml_device.max_concurrent_blocks = 7; - } - screen->get_screen_fd = ethosu_screen_get_fd; screen->destroy = ethosu_destroy_screen; screen->context_create = ethosu_create_context; @@ -301,35 +303,25 @@ struct pipe_ml_device * ethosu_ml_device_create(const char *spec) { struct ethosu_ml_device *device = NULL; + unsigned gen, macs; + uint32_t sram_size = 0; + int n; - if (strcmp(spec, "65-256") != 0 && strcmp(spec, "85-256") != 0) + /* Parse "GEN-MACS-SRAM" */ + n = sscanf(spec, "%u-%u-%u", &gen, &macs, &sram_size); + if (n != 3) + return NULL; + if (gen != 65 && gen != 85) + return NULL; + if (macs != 256) return NULL; ethosu_debug = debug_get_option_ethosu_debug(); device = rzalloc(NULL, struct ethosu_ml_device); - bool is_u65 = strcmp(spec, "65-256") == 0; - device->is_u65 = is_u65; - device->sram_size = 0; - - if (is_u65) { - device->ifm_ublock.width = 2; - device->ifm_ublock.height = 2; - device->ifm_ublock.depth = 8; - device->ofm_ublock.width = 2; - device->ofm_ublock.height = 2; - device->ofm_ublock.depth = 8; - device->max_concurrent_blocks = 3; - } else { - device->ifm_ublock.width = 4; - device->ifm_ublock.height = 4; - device->ifm_ublock.depth = 16; - device->ofm_ublock.width = 4; - device->ofm_ublock.height = 1; - device->ofm_ublock.depth = 8; - device->max_concurrent_blocks = 7; - } + set_device_arch(device, gen == 65); + device->sram_size = sram_size; set_device_callbacks(device);