code: def run_pipeline(device, num_dim, replace=False, layout=None):
      @pipeline_def
      def pipeline():
          arg = fn.external_source(input_batch(num_dim), layout=layout)
          if device == "gpu":
              arg = arg.gpu()
          return fn.per_frame(arg, replace=replace, device=device)
  
      pipe = pipeline(
          num_threads=4, batch_size=max_batch_size, device_id=0
      )
      pipe.build()
      expected_layout = (
          "F" + "*" * (num_dim - 1)
          if layout is None
          else "F" + layout[1:]
      )
      for baseline in input_batch(num_dim):
          (out,) = pipe.run()
          check_batch(
              out,
              baseline,
              len(baseline),
              expected_layout=expected_layout,
          )
  
file_path: DALI/dali/test/python/operator_1/test_per_frame.py
imports: import numpy
  from nvidia.dali import pipeline_def
  import nvidia.dali.fn
  from test_utils import check_batch
  from nose_utils import raises
label_desc: Use image node_id 2 for calling a global function with example usage: run_pipeline(device, num_dim, replace, layout) and returns: fn