code: def get_device(libmod, device):
      """Parse and validate all the device(s).
  
      Parameters
      ----------
      libmod : tvm.runtime.Module
          The module of the corresponding function
  
      device : Device or list of Device
  
      Returns
      -------
      device : list of Device
      num_rpc_dev : Number of rpc devices
      device_type_id : List of device type and device id
      """
  
      if isinstance(device, Device):
          device = [device]
      elif not isinstance(device, (list, tuple)):
          raise ValueError(
              "dev has to be the type of Device or a list of Device"
          )
      for cur_dev in device:
          if not isinstance(cur_dev, Device):
              raise ValueError(
                  "dev has to be the type of Device or a list of Device"
              )
  
      # device_type_id[0], device_type_id[1] are used as the primary/fallback
      # device type and id. All other ones are used as device for
      # heterogeneous execution.
      num_rpc_dev = 0
      device_type_id = []
      for cur_dev in device:
          device_type = cur_dev.device_type
          if device_type >= rpc_base.RPC_SESS_MASK:
              assert libmod.type_key == "rpc"
              assert (
                  _rpc_ffi_api.SessTableIndex(libmod)
                  == cur_dev._rpc_sess._tbl_index
              )
              num_rpc_dev += 1
              device_type = cur_dev.device_type % rpc_base.RPC_SESS_MASK
          device_type_id.append(device_type)
          device_type_id.append(cur_dev.device_id)
  
      if 0 < num_rpc_dev < len(device):
          raise ValueError(
              "Either all or none of the devices should be rpc."
          )
      return device, num_rpc_dev, device_type_id
  
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 2 for calling a global function with example usage: get_device(libmod, device) and returns: device,  num_rpc_dev,  device_type_id