code: def _test_cross_device(src, dst):
      import nvidia.dali.fn as fn
      import numpy as np
  
      pipe = Pipeline(1, 3, dst)
  
      iter = 0
  
      def get_data():
          nonlocal iter
          data = (
              torch.tensor(
                  [[1, 2, 3, 4], [5, 6, 7, 8]], dtype=torch.float32
              ).cuda(device=src)
              + iter
          )
          iter += 1
          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_pytorch_gpu.py
imports: from nose.plugins.attrib import attr
  from nvidia.dali.pipeline import Pipeline
  import nvidia.dali.fn
  from test_utils import check_output
  import torch
  from test_external_source_impl import use_torch
  import numpy
label_desc: Use image node_id 2 for calling a global function with example usage: _test_cross_device(src, dst) and returns: data