code: def run_through_rpc(
      measure_input,
      build_result,
      number,
      repeat,
      min_repeat_ms,
      cooldown_interval,
      remote_kwargs,
      ref_input,
      enable_cpu_cache_flush=False,
      module_loader=None,
  ):
      """Run a generated library through rpc
  
      Parameters
      ----------
      measure_input: MeasureInput
          The raw measure input
      build_result: BuildResult
          The result returned from Builder. This contains the path to the generated library.
      number: int
          The number of times to run the generated code for taking average.
          We call these runs as one `repeat` of measurement.
      repeat : int, optional
          The number of times to repeat the measurement.
          In total, the generated code will be run (1 + number x repeat) times,
          where the first one is warm up and will be discarded.
          The returned result contains `repeat` costs,
          each of which is an average of `number` costs.
      min_repeat_ms: int, optional
          The minimum duration of one `repeat` in milliseconds.
          By default, one `repeat` contains `number` runs. If this parameter is set,
          the parameters `number` will be dynamically adjusted to meet the
          minimum duration requirement of one `repeat`.
          i.e., When the run time of one `repeat` falls below this time, the `number` parameter
          will be automatically increased.
      cooldown_interval: float
          The cool down interval between two measurements
      remote_kwargs: dict
          Passed to module_loader(). Ultimately, keyword args to request_remote().
      ref_input: List of np.ndarray
          The reference input used for tuning. Empty for randomly filled input.
      enable_cpu_cache_flush: bool
          Whether to flush cache on CPU between repeated measurements.
          Flushing cache can make the measured latency of one operator closer to
          its actual latency during end-to-end inference.
          To make this option effective, the argument `number` should also be set to 1.
          This is only has effect on CPU task.
      module_loader: ModuleLoader
          A function that returns a ContextManager used to establish and teardown the remote session.
      """
      if isinstance(build_result, MeasureResult):
          return build_result
  
      tic = time.time()
      errno = MeasureErrorNo.NO_ERROR
      try:
          # upload built module
          with module_loader(remote_kwargs, build_result) as (
              remote,
              mod,
          ):
              dev = remote.device(str(measure_input.target), 0)
  
              # Limitation:
              # We can not get PackFunction directly in the remote mode as it is wrapped
              # under the std::function. We could lift the restriction later once we fold
              # the PackedFunc as an object. Currently, we pass function name to work
              # around it.
              f_prepare = (
                  "cache_flush_cpu_non_first_arg"
                  if enable_cpu_cache_flush
                  else ""
              )
              time_f = mod.time_evaluator(
                  mod.entry_name,
                  dev,
                  number=number,
                  repeat=repeat,
                  min_repeat_ms=min_repeat_ms,
                  f_preproc=f_prepare,
              )
  
              if ref_input:
                  args = [nd.array(x, device=dev) for x in ref_input]
              else:
                  try:
                      random_fill = remote.get_function(
                          "tvm.contrib.random.random_fill"
                      )
                  except AttributeError:
                      raise AttributeError(
                          "Please make sure USE_RANDOM is ON in the config.cmake "
                          "on the remote devices"
                      )
                  args = [
                      nd.empty(x[0], x[1], dev)
                      for x in build_result.arg_info
                  ]
                  if "scatter" not in measure_input.task.name:
                      # the index tensor of scatter op cannot be randomly initialized
                      for arg in args:
                          random_fill(arg)
                  dev.sync()
  
              costs = time_f(*args).results
  
          if (
              len(costs) > 2
          ):  # remove largest and smallest value to reduce variance
              costs = list(costs)
              costs.sort()
              costs = tuple(costs[1:-1])
      except TVMError as exc:
          msg = str(exc)
          if "Stack trace returned" in msg:
              msg = msg[: msg.index("Stack trace returned")]
          if "CUDA Source" in msg:
              msg = msg[: msg.index("CUDA Source")]
          costs = (traceback.format_exc(), RuntimeError(msg[:1024]))
          errno = MeasureErrorNo.RUNTIME_DEVICE
      tstamp = time.time()
      time.sleep(cooldown_interval)
      return MeasureResult(
          costs, errno, tstamp - tic + build_result.time_cost, tstamp
      )
  
imports: import contextlib
  import logging
  import os
  import shutil
  import tempfile
  import threading
  import time
  import traceback
  import typing
  import warnings
  from collections import namedtuple
  from random import getrandbits
  import tvm._ffi
  import tvm.ir.transform
  from tvm import nd
  from tvm import rpc
  from tvm.autotvm.env import AutotvmGlobalScope, reset_global_scope
  from tvm.contrib import ndk, stackvm, tar
  from tvm.contrib.popen_pool import PopenPoolExecutor
  from tvm.driver import build
  from tvm.error import TVMError
  from tvm.target import Target
  from ..env import AutotvmGlobalScope
  from ..task.space import InstantiationError
  from ..utils import get_const_tuple
  from .measure import Builder, MeasureErrorNo, MeasureResult, Runner
label_desc: Use image node_id 2 for calling a global function with example usage: run_through_rpc(measure_input, build_result, number, repeat, min_repeat_ms, cooldown_interval, remote_kwargs, ref_input, enable_cpu_cache_flush, module_loader) and returns: MeasureResult, build_result