class_docstr: Code emitter class.
class_docstr_tok: ["Code","emitter","class","."]
docstr: Compute inputs, outputs, weight, activation sizes
docstr_tok: ["Compute","inputs",",","outputs",",","weight",",","activation","sizes"]
code: def _compute_data_placement(self):
      """Compute inputs, outputs, weight, activation sizes"""
  
      self._inputs = self._arg_nodes.copy()
  
      # weights:
      offset = 0
  
      for key in self._params:
          # First, find the node in graph
          nid = 0
          for node in self._nodes:
              if node["name"] == key:
                  break
              nid += 1
  
          dl_tensor_name = get_input_tensor_name(key)
          tensor = self._get_tensor_from_node(nid, 0)
  
          # Compute the offset
          dltype = tensor["dltype"]
          aligned_offset = _get_aligned_offset(offset, dltype)
          tensor["offset"] = aligned_offset
  
          for idx in self._arg_nodes:
              node = self._nodes[idx]
              node_name = node["name"]
              if node_name == key:
                  self._inputs.remove(idx)
  
          self._weights[dl_tensor_name] = tensor
  
          # Next offset
          offset = aligned_offset + tensor["size"]
  
      self._weights_size = offset
  
      # activations:
      buffer_list_ = {}
  
      nid = 0
      for node in self._nodes:
          if node["op"] == "null":
              nid += 1
              continue
  
          if node["op"] != "tvm_op":
              raise ValueError(f"Only TVM ops are supported")
  
          node_name = node["name"]
          node_attrs = node["attrs"]
          func_name = node_attrs["func_name"]
          num_outputs = int(node_attrs["num_outputs"])
  
          if func_name == "__nop":
              assert (
                  node_name == "reshape_nop"
              ), f"Unsupported __nop operator {node_name}."
              assert num_outputs == 1
              assert not self._tensor_is_output(nid, 0)
              nid += 1
              continue
  
          for idx in range(num_outputs):
              # Do not count the '_outputs'
              if self._tensor_is_output(nid, idx):
                  continue
  
              dl_tensor_name = get_output_tensor_name(node_name, idx)
              tensor = self._get_tensor_from_node(nid, idx)
  
              # Remember this tensor with the storage id
              storage_id = tensor["storage_id"]
              if storage_id not in buffer_list_:
                  buffer_list_[storage_id] = []
              buffer_entry = buffer_list_[storage_id]
              buffer_entry.append(tensor)
  
              self._activations[dl_tensor_name] = tensor
  
          self._nodes_size = self._nodes_size + 1
  
          nid += 1
  
      # Compute '_input_data'
      offset = 0
      for nid in self._inputs:
          node = self._nodes[nid]
          node_name = node["name"]
  
          # Arthur: I suppose that input nodes only have a single
          #         output dependency
          dl_tensor_name = get_input_tensor_name(node_name)
  
          # This tensor is at some index inside '_input_data' dictionary
          # depending on the '_inputs' list order. We refer to this position
          # when generating the XXX.h file.
          tensor = self._get_tensor_from_node(nid, 0)
  
          if self.inputs_static:
              # Remember this tensor with the storage id
              storage_id = tensor["storage_id"]
              if storage_id not in buffer_list_:
                  buffer_list_[storage_id] = []
              buffer_entry = buffer_list_[storage_id]
              buffer_entry.append(tensor)
          else:
              # Compute the offset
              dltype = tensor["dltype"]
              aligned_offset = _get_aligned_offset(offset, dltype)
              tensor["offset"] = aligned_offset
  
          self._input_data[dl_tensor_name] = tensor
  
          # Next offset
          offset = aligned_offset + tensor["size"]
  
      # Compute '_output_data'
      offset = 0
      for output in self._outputs:
          nid = output[0]
          idx = output[1]
  
          node = self._nodes[nid]
          node_name = node["name"]
  
          dl_tensor_name = get_output_tensor_name(node_name, idx)
  
          tensor = self._get_tensor_from_node(nid, idx)
  
          if self.outputs_static:
              # Remember this tensor with the storage id
              storage_id = tensor["storage_id"]
              if storage_id not in buffer_list_:
                  buffer_list_[storage_id] = []
              buffer_entry = buffer_list_[storage_id]
              buffer_entry.append(tensor)
          else:
              # Compute the offset
              dltype = tensor["dltype"]
              aligned_offset = _get_aligned_offset(offset, dltype)
              tensor["offset"] = aligned_offset
  
          self._output_data[dl_tensor_name] = tensor
  
          # Next offset
          offset = aligned_offset + tensor["size"]
  
      # Go over all storage IDs and compute offsets and _activations_size
      offset = 0
      for storage_id in buffer_list_:
          buffer_entry = buffer_list_[storage_id]
  
          new_offset = offset
          for tensor in buffer_entry:
              assert tensor["storage_id"] == storage_id
              dltype = tensor["dltype"]
              aligned_offset = _get_aligned_offset(offset, dltype)
              tensor["offset"] = aligned_offset
              size = tensor["size"]
              if (aligned_offset + size) > new_offset:
                  new_offset = aligned_offset + size
          offset = new_offset
  
      self._activations_size = offset
  
imports: import contextlib
  import json
  import os
  import re
  import shutil
  import tarfile
  import textwrap
  from datetime import datetime
  import numpy
  import tvm
  from tvm.contrib import utils
label_desc: Use image node_id 6 for calling the CodeEmitter obj's underlying member method code with example usage: obj._compute_data_placement() without return types