code: def _test_cross_device(src, dst, use_dali_tensor=False):
      # The use_dali_tensor converts (via the Dlpack) to the DALI native Tensor before feeding the
      # data, to additionally check if the constructor works correctly wrt to device_id.
      # TODO(klecki): [device_id] currently the device_id is not exposed in Python Tensors, so there
      # is no other way we may verify it.
      import nvidia.dali.fn as fn
      import numpy as np
  
      pipe = Pipeline(1, 3, dst)
  
      iter = 0
  
      def get_data():
          nonlocal iter
          with cp.cuda.Device(src):
              data = (
                  cp.array(
                      [[1, 2, 3, 4], [5, 6, 7, 8]], dtype=cp.float32
                  )
                  + iter
              )
              iter += 1
          if use_dali_tensor:
              return TensorGPU(data.toDlpack())
          return data
  
      with pipe:
          pipe.set_outputs(
              fn.external_source(get_data, batch=False, device="gpu")
          )
  
      pipe.build()
      for i in range(10):
          (out,) = pipe.run()
          assert np.array_equal(
              np.array(out[0].as_cpu()),
              np.array([[1, 2, 3, 4], [5, 6, 7, 8]]) + i,
          )
  
file_path: DALI/dali/test/python/test_external_source_cupy.py
imports: from nose.plugins.attrib import attr
  from test_external_source_impl import *
  from test_external_source_impl import use_cupy
  from test_utils import check_output, check_output_pattern
  import nvidia.dali
  from nvidia.dali import Pipeline, pipeline_def
  import nvidia.dali.fn
  from nvidia.dali.tensors import TensorGPU
  import numpy
  import cupy
label_desc: Use image node_id 3 for calling a global function with example usage: _test_cross_device(src, dst, use_dali_tensor) and returns: data, TensorGPU