code: def _array_to_gpu(array, device, stream):
      if array is None:
          return None
  
      if isinstance(array, chainerx.ndarray):
          # TODO(niboshi): Update this logic once both CuPy and ChainerX support
          # the array interface.
          if array.device.backend.name == "cuda":
              # Convert to cupy.ndarray on the same device as source array
              array = chainerx._to_cupy(array)
          else:
              array = chainerx.to_numpy(array)
      elif isinstance(array, (numpy.number, numpy.bool_)):
          array = numpy.asarray(array)
      elif isinstance(array, intel64.mdarray):
          array = numpy.asarray(array)
  
      if isinstance(array, ndarray):
          if array.device == device:
              return array
          is_numpy = False
      elif isinstance(array, numpy.ndarray):
          is_numpy = True
      else:
          raise TypeError(
              "The array sent to gpu must be an array or a NumPy scalar."
              "\nActual type: {0}.".format(type(array))
          )
  
      if stream is not None:
          with device:
              with stream:
                  if is_numpy:
                      return cupy.asarray(array)
                  # Need to make a copy when an array is copied to another device
                  return cupy.array(array, copy=True)
  
      with device:
          if is_numpy:
              return cupy.asarray(array)
          # Need to make a copy when an array is copied to another device
          return cupy.array(array, copy=True)
  
imports: import binascii
  import functools
  import itertools
  import os
  import threading
  import time
  import typing
  import warnings
  import numpy
  import six
  import chainer
  from chainer import _backend
  from chainer.backends import _cpu
  from chainer.backends import intel64
  from chainer.configuration import config
  from chainer import types
  import chainerx
label_desc: Use image node_id 8 for calling a global function with example usage: _array_to_gpu(array, device, stream) and returns: None, cupy, array, cupy, cupy, cupy