code: def device(dev_type, dev_id=0):
      """Construct a TVM device with given device type and id.
  
      Parameters
      ----------
      dev_type: int or str
          The device type mask or name of the device.
  
      dev_id : int, optional
          The integer device id
  
      Returns
      -------
      dev: tvm.runtime.Device
          The corresponding device.
  
      Examples
      --------
      Device can be used to create reflection of device by
      string representation of the device type.
  
      .. code-block:: python
  
        assert tvm.device("cpu", 1) == tvm.cpu(1)
        assert tvm.device("cuda", 0) == tvm.cuda(0)
      """
      if not isinstance(dev_id, int):
          raise ValueError(f"Invalid device id: {dev_id}")
  
      if isinstance(dev_type, string_types):
          dev_type = dev_type.split()[0]
          if dev_type.count(":") == 0:
              pass
          elif dev_type.count(":") == 1:
              # It will override the dev_id passed by the user.
              dev_type, dev_id = dev_type.split(":")
              if not dev_id.isdigit():
                  raise ValueError(f"Invalid device id: {dev_id}")
              dev_id = int(dev_id)
          else:
              raise ValueError(f"Invalid device string: {dev_type}")
  
          if dev_type not in Device.STR2MASK:
              raise ValueError(f"Unknown device type: {dev_type}")
  
          return Device(Device.STR2MASK[dev_type], dev_id)
      return Device(dev_type, dev_id)
  
imports: import ctypes
  import warnings
  import numpy
  import tvm._ffi
  from tvm._ffi.base import _LIB, check_call, c_array, string_types, _FFI_MODE
  from tvm._ffi.runtime_ctypes import DataType, Device, TVMArray, TVMArrayHandle
  from tvm._ffi.runtime_ctypes import DataTypeCode, tvm_shape_index_t
  from .None import _ffi_api
label_desc: Use image node_id 1 for calling a global function with example usage: device(dev_type, dev_id) and returns: Device, Device