code: def _write_tir_and_build_operator_memory_map(
      src_dir, targets, ir_module_by_target
  ):
      def _eval_shape(param_name, buffer_shape):
          shape = []
          for x in buffer_shape:
              if not isinstance(x, expr.IntImm):
                  raise NonStaticShapeError(
                      f"Parameter {param_name} has shape with non-IntImm elements: {buffer_shape}"
                  )
              shape.append(x.value)
          return shape
  
      memory_map = {}
      for target in targets:
          # TODO(mbs): The device type is not unique, better would be to use target.kind.name
          target_device_type = target.get_target_device_type()
          ir_mod = ir_module_by_target[target]
          printer = get_global_func(
              "relay.ir.ModelLibraryFormatPrinter"
          )(False, None, False)
          with open(
              src_dir / f"tir-{target_device_type}.txt", "w"
          ) as f:
              f.write(printer["print"](ir_mod))
  
          for v in ir_mod.get_global_vars():
              map_entry = []
              for p, b in ir_mod[v.name_hint].buffer_map.items():
                  shape = _eval_shape(p.name, b.shape)
                  buffer_size_bytes = _shape_to_size(
                      shape, str(b.dtype)
                  )
                  # NOTE: cannot tell what is an input or output at this point.
                  map_entry.append(
                      {
                          "size_bytes": buffer_size_bytes,
                          "shape": [int(x) for x in b.shape],
                          "dtype": b.dtype,
                          "input_binding": printer["get_var_name"](p),
                      }
                  )
              memory_map[v.name_hint] = map_entry
  
      return memory_map
  
imports: import datetime
  import json
  import os
  import pathlib
  import re
  import tarfile
  import typing
  import tvm
  from tvm.micro import get_standalone_crt_dir, get_microtvm_template_projects
  from .._ffi import get_global_func
  from ..contrib import utils
  from ..driver import build_module
  from ..relay import param_dict
  from ..relay.backend import executor_factory
  from ..relay.backend.name_transforms import prefix_generated_name, to_c_variable_style
  from ..tir import expr
label_desc: Use image node_id 16 for calling a global function with example usage: _write_tir_and_build_operator_memory_map(src_dir, targets, ir_module_by_target) and returns: memory_map, shape