class_docstr: Wrapper runtime module.
  
  This is a thin wrapper of the underlying TVM module.
  you can also directly call set_input, run, and get_output
  of underlying module functions
  
  Parameters
  ----------
  module : tvm.runtime.Module
      The internal tvm module that holds the actual graph functions.
  
  Attributes
  ----------
  module : tvm.runtime.Module
      The internal tvm module that holds the actual graph functions.
  
  Examples
  --------
  
  .. code-block:: python
  
      import tvm
      from tvm import relay
      from tvm.contrib import graph_executor
  
      # build the library using graph executor
      lib = relay.build(...)
      lib.export_library("compiled_lib.so")
      # load it back as a runtime
      lib: tvm.runtime.Module = tvm.runtime.load_module("compiled_lib.so")
      # Call the library factory function for default and create
      # a new runtime.Module, wrap with graph module.
      gmod = graph_executor.GraphModule(lib["default"](dev))
      # use the graph module.
      gmod.set_input("x", data)
      gmod.run()
class_docstr_tok: ["Wrapper","runtime","module",".","This","is","a","thin","wrapper","of","the","underlying","TVM","module",".","you","can","also","directly","call","set_input",",","run",",","and","get_output","of","underlying","module","functions","Parameters","--","--","--","--","--","module",":","tvm.runtime.Module","The","internal","tvm","module","that","holds","the","actual","graph","functions",".","Attributes","--","--","--","--","--","module",":","tvm.runtime.Module","The","internal","tvm","module","that","holds","the","actual","graph","functions",".","Examples","--","--","--","--","..","code-block",":",":","python","import","tvm","from","tvm","import","relay","from","tvm.contrib","import","graph_executor","#","build","the","library","using","graph","executor","lib","=","relay.build","(","...",")","lib.export_library","(","``","compiled_lib.so","''",")","#","load","it","back","as","a","runtime","lib",":","tvm.runtime.Module","=","tvm.runtime.load_module","(","``","compiled_lib.so","''",")","#","Call","the","library","factory","function","for","default","and","create","#","a","new","runtime.Module",",","wrap","with","graph","module",".","gmod","=","graph_executor.GraphModule","(","lib","[","``","default","''","]","(","dev",")",")","#","use","the","graph","module",".","gmod.set_input","(","``","x","''",",","data",")","gmod.run","(",")"]
docstr: Calculate runtime of a function by repeatedly calling it.
  
  Use this function to get an accurate measurement of the runtime of a function. The function
  is run multiple times in order to account for variability in measurements, processor speed
  or other external factors.  Mean, median, standard deviation, min and max runtime are all
  reported.  On GPUs, CUDA and ROCm specifically, special on-device timers are used so that
  synchonization and data transfer operations are not counted towards the runtime. This allows
  for fair comparison of runtimes across different functions and models. The `end_to_end` flag
  switches this behavior to include data transfer operations in the runtime.
  
  The benchmarking loop looks approximately like so:
  
  .. code-block:: python
  
      for r in range(repeat):
          time_start = now()
          for n in range(number):
              func_name()
          time_end = now()
          total_times.append((time_end - time_start)/number)
  
  
  Parameters
  ----------
  func_name : str
      The function to benchmark. This is ignored if `end_to_end` is true.
  
  repeat : int
      Number of times to run the outer loop of the timing code (see above). The output will
      contain `repeat` number of datapoints.
  
  number : int
      Number of times to run the inner loop of the timing code. This inner loop is run in
      between the timer starting and stopping. In order to amortize any timing overhead,
      `number` should be increased when the runtime of the function is small (less than a 1/10
      of a millisecond).
  
  min_repeat_ms : Optional[int]
      If set, the inner loop will be run until it takes longer than `min_repeat_ms`
      milliseconds. This can be used to ensure that the function is run enough to get an
      accurate measurement.
  
  limit_zero_time_iterations : Optional[int]
      The maximum number of repeats when measured time is equal to 0.
      It helps to avoid hanging during measurements.
  
  end_to_end : bool
      If set, include time to transfer input tensors to the device and time to transfer
      returned tensors in the total runtime. This will give accurate timings for end to end
      workloads.
  
  cooldown_interval_ms: Optional[int]
      The cooldown interval in milliseconds between the number of repeats defined by
      `repeats_to_cooldown`.
  
  repeats_to_cooldown: Optional[int]
      The number of repeats before the cooldown is activated.
  
  kwargs : Dict[str, Object]
      Named arguments to the function. These are cached before running timing code, so that
      data transfer costs are not counted in the runtime.
  
  Returns
  -------
  timing_results : BenchmarkResult
      Runtimes of the function. Use `.mean` to access the mean runtime, use `.results` to
      access the individual runtimes (in seconds).
docstr_tok: ["Calculate","runtime","of","a","function","by","repeatedly","calling","it",".","Use","this","function","to","get","an","accurate","measurement","of","the","runtime","of","a","function",".","The","function","is","run","multiple","times","in","order","to","account","for","variability","in","measurements",",","processor","speed","or","other","external","factors",".","Mean",",","median",",","standard","deviation",",","min","and","max","runtime","are","all","reported",".","On","GPUs",",","CUDA","and","ROCm","specifically",",","special","on-device","timers","are","used","so","that","synchonization","and","data","transfer","operations","are","not","counted","towards","the","runtime",".","This","allows","for","fair","comparison","of","runtimes","across","different","functions","and","models",".","The","`","end_to_end","`","flag","switches","this","behavior","to","include","data","transfer","operations","in","the","runtime",".","The","benchmarking","loop","looks","approximately","like","so",":","..","code-block",":",":","python","for","r","in","range","(","repeat",")",":","time_start","=","now","(",")","for","n","in","range","(","number",")",":","func_name","(",")","time_end","=","now","(",")","total_times.append","(","(","time_end","-","time_start",")","\/number",")","Parameters","--","--","--","--","--","func_name",":","str","The","function","to","benchmark",".","This","is","ignored","if","`","end_to_end","`","is","true",".","repeat",":","int","Number","of","times","to","run","the","outer","loop","of","the","timing","code","(","see","above",")",".","The","output","will","contain","`","repeat","`","number","of","datapoints",".","number",":","int","Number","of","times","to","run","the","inner","loop","of","the","timing","code",".","This","inner","loop","is","run","in","between","the","timer","starting","and","stopping",".","In","order","to","amortize","any","timing","overhead",",","`","number","`","should","be","increased","when","the","runtime","of","the","function","is","small","(","less","than","a","1\/10","of","a","millisecond",")",".","min_repeat_ms",":","Optional","[","int","]","If","set",",","the","inner","loop","will","be","run","until","it","takes","longer","than","`","min_repeat_ms","`","milliseconds",".","This","can","be","used","to","ensure","that","the","function","is","run","enough","to","get","an","accurate","measurement",".","limit_zero_time_iterations",":","Optional","[","int","]","The","maximum","number","of","repeats","when","measured","time","is","equal","to","0",".","It","helps","to","avoid","hanging","during","measurements",".","end_to_end",":","bool","If","set",",","include","time","to","transfer","input","tensors","to","the","device","and","time","to","transfer","returned","tensors","in","the","total","runtime",".","This","will","give","accurate","timings","for","end","to","end","workloads",".","cooldown_interval_ms",":","Optional","[","int","]","The","cooldown","interval","in","milliseconds","between","the","number","of","repeats","defined","by","`","repeats_to_cooldown","`",".","repeats_to_cooldown",":","Optional","[","int","]","The","number","of","repeats","before","the","cooldown","is","activated",".","kwargs",":","Dict","[","str",",","Object","]","Named","arguments","to","the","function",".","These","are","cached","before","running","timing","code",",","so","that","data","transfer","costs","are","not","counted","in","the","runtime",".","Returns","--","--","--","-","timing_results",":","BenchmarkResult","Runtimes","of","the","function",".","Use","`",".mean","`","to","access","the","mean","runtime",",","use","`",".results","`","to","access","the","individual","runtimes","(","in","seconds",")","."]
code: def benchmark(
      self,
      device,
      func_name="run",
      repeat=5,
      number=5,
      min_repeat_ms=None,
      limit_zero_time_iterations=100,
      end_to_end=False,
      cooldown_interval_ms=0,
      repeats_to_cooldown=1,
      **kwargs,
  ):
      """Calculate runtime of a function by repeatedly calling it.
  
      Use this function to get an accurate measurement of the runtime of a function. The function
      is run multiple times in order to account for variability in measurements, processor speed
      or other external factors.  Mean, median, standard deviation, min and max runtime are all
      reported.  On GPUs, CUDA and ROCm specifically, special on-device timers are used so that
      synchonization and data transfer operations are not counted towards the runtime. This allows
      for fair comparison of runtimes across different functions and models. The `end_to_end` flag
      switches this behavior to include data transfer operations in the runtime.
  
      The benchmarking loop looks approximately like so:
  
      .. code-block:: python
  
          for r in range(repeat):
              time_start = now()
              for n in range(number):
                  func_name()
              time_end = now()
              total_times.append((time_end - time_start)/number)
  
  
      Parameters
      ----------
      func_name : str
          The function to benchmark. This is ignored if `end_to_end` is true.
  
      repeat : int
          Number of times to run the outer loop of the timing code (see above). The output will
          contain `repeat` number of datapoints.
  
      number : int
          Number of times to run the inner loop of the timing code. This inner loop is run in
          between the timer starting and stopping. In order to amortize any timing overhead,
          `number` should be increased when the runtime of the function is small (less than a 1/10
          of a millisecond).
  
      min_repeat_ms : Optional[int]
          If set, the inner loop will be run until it takes longer than `min_repeat_ms`
          milliseconds. This can be used to ensure that the function is run enough to get an
          accurate measurement.
  
      limit_zero_time_iterations : Optional[int]
          The maximum number of repeats when measured time is equal to 0.
          It helps to avoid hanging during measurements.
  
      end_to_end : bool
          If set, include time to transfer input tensors to the device and time to transfer
          returned tensors in the total runtime. This will give accurate timings for end to end
          workloads.
  
      cooldown_interval_ms: Optional[int]
          The cooldown interval in milliseconds between the number of repeats defined by
          `repeats_to_cooldown`.
  
      repeats_to_cooldown: Optional[int]
          The number of repeats before the cooldown is activated.
  
      kwargs : Dict[str, Object]
          Named arguments to the function. These are cached before running timing code, so that
          data transfer costs are not counted in the runtime.
  
      Returns
      -------
      timing_results : BenchmarkResult
          Runtimes of the function. Use `.mean` to access the mean runtime, use `.results` to
          access the individual runtimes (in seconds).
      """
      min_repeat_ms = 0 if min_repeat_ms is None else min_repeat_ms
      if end_to_end:
          # Have to unpack kwargs into a single list
          args = []
          for k, v in kwargs.items():
              args.append(k)
              args.append(v)
          return self.module.time_evaluator(
              "run_from_inputs",
              device,
              repeat=repeat,
              number=number,
              min_repeat_ms=min_repeat_ms,
              limit_zero_time_iterations=limit_zero_time_iterations,
          )(
              device.device_type % rpc_base.RPC_SESS_MASK,
              device.device_id,
              *args,
          )
      if kwargs:
          self.set_input(**kwargs)
      return self.module.time_evaluator(
          func_name,
          device,
          repeat=repeat,
          number=number,
          min_repeat_ms=min_repeat_ms,
          limit_zero_time_iterations=limit_zero_time_iterations,
          cooldown_interval_ms=cooldown_interval_ms,
          repeats_to_cooldown=repeats_to_cooldown,
      )()
  
imports: import numpy
  import tvm._ffi
  from tvm.rpc import _ffi_api
  from tvm.rpc import base
  from tvm._ffi.base import string_types
  from tvm._ffi.runtime_ctypes import Device
label_desc: Use image node_id 16 for calling the GraphModule obj's underlying member method code with example usage: obj.benchmark(device, func_name, repeat, number, min_repeat_ms, limit_zero_time_iterations, end_to_end, cooldown_interval_ms, repeats_to_cooldown) and returns: self, self