class_docstr: Function hook for measuring memory usage of functions in cupy memory pool.
  
  Example:
      Code example::
  
          from chainer.function_hooks import CupyMemoryProfileHook
          hook = CupyMemoryProfileHook()
          with hook:
              trainer.run()
          hook.print_report()
  
      Output example::
  
                 FunctionName  UsedBytes  AcquiredBytes  Occurrence
               LinearFunction     5.16GB       179.98MB        3900
                         ReLU     0.99GB       458.97MB        2600
          SoftmaxCrossEntropy     0.01GB         5.08MB        1300
                     Accuracy     0.00GB         0.35MB         700
  
      where *FunctionName* is the name of function that calls the hook, and
      *UsedBytes* is the memory bytes the function used from cupy memory
      pool, and *AcquiredBytes* is the actual memory bytes the cupy memory
      pool acquired from GPU device on the function call, and *Occurrence*
      is the number of calls.
  Attributes:
      call_history: List of measurement results. It consists of the name of
          the function that calls this hook, the memory bytes the function
          used from cupy memory pool, and the memory bytes the cupy memory
          pool acquired from GPU device on the function call.
class_docstr_tok: ["Function","hook","for","measuring","memory","usage","of","functions","in","cupy","memory","pool",".","Example",":","Code","example",":",":","from","chainer.function_hooks","import","CupyMemoryProfileHook","hook","=","CupyMemoryProfileHook","(",")","with","hook",":","trainer.run","(",")","hook.print_report","(",")","Output","example",":",":","FunctionName","UsedBytes","AcquiredBytes","Occurrence","LinearFunction","5.16GB","179.98MB","3900","ReLU","0.99GB","458.97MB","2600","SoftmaxCrossEntropy","0.01GB","5.08MB","1300","Accuracy","0.00GB","0.35MB","700","where","*","FunctionName","*","is","the","name","of","function","that","calls","the","hook",",","and","*","UsedBytes","*","is","the","memory","bytes","the","function","used","from","cupy","memory","pool",",","and","*","AcquiredBytes","*","is","the","actual","memory","bytes","the","cupy","memory","pool","acquired","from","GPU","device","on","the","function","call",",","and","*","Occurrence","*","is","the","number","of","calls",".","Attributes",":","call_history",":","List","of","measurement","results",".","It","consists","of","the","name","of","the","function","that","calls","this","hook",",","the","memory","bytes","the","function","used","from","cupy","memory","pool",",","and","the","memory","bytes","the","cupy","memory","pool","acquired","from","GPU","device","on","the","function","call","."]
docstr: Prints a summary report of memory profiling in functions.
  
  Args:
      unit (str): Supplementary units used for used memories.
          `B`, `KB`, `MB`, `GB`, `TB`, `PB`, `EB`, `ZB`, `auto`(default)
          and `auto_foreach` are supported. If `auto`, units of memories
          are aligned to the largest values of 'used_bytes' and
          'acquired_bytes'. If `auto_foreach`, units of memories are
          adjusted for each element.
docstr_tok: ["Prints","a","summary","report","of","memory","profiling","in","functions",".","Args",":","unit","(","str",")",":","Supplementary","units","used","for","used","memories",".","`","B","`",",","`","KB","`",",","`","MB","`",",","`","GB","`",",","`","TB","`",",","`","PB","`",",","`","EB","`",",","`","ZB","`",",","`","auto","`","(","default",")","and","`","auto_foreach","`","are","supported",".","If","`","auto","`",",","units","of","memories","are","aligned","to","the","largest","values","of","'used_bytes","'","and","'acquired_bytes","'",".","If","`","auto_foreach","`",",","units","of","memories","are","adjusted","for","each","element","."]
code: def print_report(self, unit="auto", file=sys.stdout):
      """Prints a summary report of memory profiling in functions.
  
      Args:
          unit (str): Supplementary units used for used memories.
              `B`, `KB`, `MB`, `GB`, `TB`, `PB`, `EB`, `ZB`, `auto`(default)
              and `auto_foreach` are supported. If `auto`, units of memories
              are aligned to the largest values of 'used_bytes' and
              'acquired_bytes'. If `auto_foreach`, units of memories are
              adjusted for each element.
      """
      entries = [
          ["FunctionName", "UsedBytes", "AcquiredBytes", "Occurrence"]
      ]
      if unit == "auto":
          max_used = max(
              record["used_bytes"] for record in self.summary().values()
          )
          max_acquired = max(
              record["acquired_bytes"]
              for record in self.summary().values()
          )
          denomi_used, unit_used = self._choose_unit(max_used)
          denomi_acquired, unit_acquired = self._choose_unit(
              max_acquired
          )
      elif unit != "auto_foreach":
          denomi_used = denomi_acquired = self._table[unit]
          unit_used = unit_acquired = unit
      for function_name, record in self.summary().items():
          used_bytes = record["used_bytes"]
          acquired_bytes = record["acquired_bytes"]
          if unit == "auto_foreach":
              denomi_used, unit_used = self._choose_unit(used_bytes)
              denomi_acquired, unit_acquired = self._choose_unit(
                  acquired_bytes
              )
          used_bytes = "%3.2f%s" % (used_bytes / denomi_used, unit_used)
          acquired_bytes = "%3.2f%s" % (
              acquired_bytes / denomi_acquired,
              unit_acquired,
          )
          occurrence = str(record["occurrence"])
          entries.append(
              [function_name, used_bytes, acquired_bytes, occurrence]
          )
      entry_widths = []
      entry_widths.append(max(len(f) for f, _, _, _ in entries))
      entry_widths.append(max(len(u) for _, u, _, _ in entries))
      entry_widths.append(max(len(a) for _, _, a, _ in entries))
      entry_widths.append(max(len(o) for _, _, _, o in entries))
      template = "  ".join("{:>%d}" % w for w in entry_widths)
      for (
          function_name,
          used_bytes,
          acquired_bytes,
          occurrence,
      ) in entries:
          line = template.format(
              function_name, used_bytes, acquired_bytes, occurrence
          )
          file.write(line)
          file.write("\n")
      if hasattr(file, "flush"):
          file.flush()
  
imports: import collections
  import sys
  import typing
  from chainer.backends import cuda
  from chainer import function_hook
label_desc: Use image node_id 14 for calling the CupyMemoryProfileHook obj's underlying member method code with example usage: obj.print_report(unit, file) without return types