code: def using_device(device_spec):
      """Context manager to apply the thread-local device state.
  
      Args:
          device_spec (object): Device specifier. See :func:`chainer.get_device`
              for details.
  
      .. admonition:: Example
  
          .. testcode::
             :skipif: doctest_helper.skipif_not_enough_cuda_devices(2)
  
             with chainer.using_device('@cupy:1'):
                 a = cupy.empty((3, 2))
  
             assert a.device.id == 1
  
      """
  
      # TODO(niboshi): Set default device (once this concept is introduced in
      # Chainer).
      device = get_device(device_spec)
      return device.create_context()
  
imports: import numpy
  import six
  import chainer
  from chainer.backends import _chainerx
  from chainer.backends import _cpu
  from chainer.backends import cuda
  from chainer.backends import intel64
  import chainerx
  from chainer._backend import Device
  from chainer.backends._chainerx import ChainerxDevice
  from chainer.backends._chainerx import from_chx
  from chainer.backends._chainerx import to_chx
  from chainer.backends._cpu import CpuDevice
  from chainer.backends.cuda import GpuDevice
  from chainer.backends.intel64 import Intel64Device
  from chainer import types
label_desc: Use image node_id 6 for calling a global function with example usage: using_device(device_spec) and returns: device