code: def _get_optimal_block_config(
      all_valid_block_configs: List[vapi.NpuShape3D],
  ) -> vapi.NpuShape3D:
      """An internal function to get block config with largest depth
      and then highest volume/area"""
      assert isinstance(all_valid_block_configs, list)
      for block_cfg in all_valid_block_configs:
          assert isinstance(block_cfg, vapi.NpuShape3D)
  
      # Getting the largest volume block for benchmarking
      all_valid_block_configs.sort(
          key=lambda _cfg: _cfg.depth * _cfg.height * _cfg.width,
          reverse=True,
      )
      largest_volume_block_config = all_valid_block_configs[0]
      largest_volume = (
          largest_volume_block_config.depth
          * largest_volume_block_config.height
          * largest_volume_block_config.width
      )
  
      all_valid_block_configs.sort(
          key=lambda _cfg: _cfg.depth, reverse=True
      )
      max_d = all_valid_block_configs[0].depth
      max_depth_block_configs = [
          _cfg
          for _cfg in all_valid_block_configs
          if _cfg.depth == max_d
      ]
      max_depth_block_configs.sort(
          key=lambda _cfg: _cfg.height * _cfg.width, reverse=True
      )
      max_area = (
          max_depth_block_configs[0].height
          * max_depth_block_configs[0].width
      )
      max_area_depth_block_configs = [
          _cfg
          for _cfg in max_depth_block_configs
          if _cfg.height * _cfg.width == max_area
      ]
      # This to get a deterministic anwser everytime
      max_area_depth_block_configs.sort(
          key=lambda _cfg: _cfg.height, reverse=True
      )
      assert len(max_area_depth_block_configs) > 0
      current_volume = (
          max_area_depth_block_configs[0].depth
          * max_area_depth_block_configs[0].height
          * max_area_depth_block_configs[0].width
      )
      logger.info(
          "Using block config=%s", max_area_depth_block_configs[0]
      )
      logger.info(
          "Quality of the block config w.r.t. max volume block config=%s",
          100.0 * (current_volume / largest_volume),
      )
      return max_area_depth_block_configs[0]
  
imports: import logging
  import math
  from typing import List, Optional, Tuple
  import numpy
  from ethosu.vela import api
  from ethosu.vela.architecture_allocator import find_block_config
  from ethosu.vela.architecture_features import Accelerator, create_default_arch
  from ethosu.vela.operation import NpuBlockType
  from ethosu.vela.register_command_stream_generator import resampling_mode_map
  from ethosu.vela.register_command_stream_util import to_kernel
  from ethosu.vela.shape4d import Shape4D
  import tvm
  from tvm.relay.backend.contrib.ethosu import tir_to_cs_translator
  from tvm.relay.backend.contrib.ethosu import util
label_desc: Use image node_id 3 for calling a global function with example usage: _get_optimal_block_config(all_valid_block_configs) and returns: max_area_depth_block_configs