code: def get_device():
      global _cached_device
      if _cached_device is not None:
          return _cached_device
      # Precedence from high to low
      for device_type in ("XLA_GPU", "GPU", "XLA_CPU", "CPU"):
          devices = config.list_logical_devices(device_type)
          if devices:
              _cached_device = devices[0]
              return _cached_device
      raise ValueError(
          "Cannot find any suitable device. Available devices: %s"
          % config.list_logical_devices()
      )
  
imports: import functools
  from absl.testing import parameterized
  import numpy
  from tensorflow.python.compat import compat
  from tensorflow.python.eager import context
  from tensorflow.python.eager import def_function
  from tensorflow.python.framework import config
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import random_seed
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import array_ops_stack
  from tensorflow.python.ops import gen_stateless_random_ops_v2
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import random_ops
  from tensorflow.python.ops import stateless_random_ops
  from tensorflow.python.platform import test
label_desc: Use image node_id 1 for calling a global function with example usage: get_device() and returns: _cached_device, _cached_device