code: def _repeat(
      func,
      args,
      kwargs,
      n_repeat,
      name,
      n_warmup,
      max_duration,
      devices,
  ):
      events_1 = []
      events_2 = []
  
      for i in devices:
          prev_device = runtime.getDevice()
          try:
              runtime.setDevice(i)
              events_1.append(_cupy.cuda.stream.Event())
              events_2.append(_cupy.cuda.stream.Event())
          finally:
              runtime.setDevice(prev_device)
  
      for i in range(n_warmup):
          func(*args, **kwargs)
  
      for event, device in zip(events_1, devices):
          prev_device = runtime.getDevice()
          try:
              runtime.setDevice(device)
              event.record()
          finally:
              runtime.setDevice(prev_device)
          event.synchronize()
  
      cpu_times = []
      gpu_times = [[] for i in events_1]
      duration = 0
      for i in range(n_repeat):
          for event, device in zip(events_1, devices):
              prev_device = runtime.getDevice()
              try:
                  runtime.setDevice(device)
                  event.record()
              finally:
                  runtime.setDevice(prev_device)
  
          t1 = _time.perf_counter()
  
          func(*args, **kwargs)
  
          t2 = _time.perf_counter()
          cpu_time = t2 - t1
          cpu_times.append(cpu_time)
  
          for event, device in zip(events_2, devices):
              prev_device = runtime.getDevice()
              try:
                  runtime.setDevice(device)
                  event.record()
              finally:
                  runtime.setDevice(prev_device)
          for event, device in zip(events_2, devices):
              prev_device = runtime.getDevice()
              try:
                  runtime.setDevice(device)
                  event.synchronize()
              finally:
                  runtime.setDevice(prev_device)
          for i, (ev1, ev2) in enumerate(zip(events_1, events_2)):
              gpu_time = _cupy.cuda.get_elapsed_time(ev1, ev2) * 1e-3
              gpu_times[i].append(gpu_time)
  
          duration += _time.perf_counter() - t1
          if duration > max_duration:
              break
  
      ts = _numpy.asarray([cpu_times] + gpu_times, dtype=_numpy.float64)
      return _PerfCaseResult(name, ts, devices=devices)
  
file_path: cupy/cupyx/profiler/_time.py
imports: import math
  import time
  import numpy
  import cupy
  from cupy_backends.cuda.api import runtime
label_desc: Use image node_id 2 for calling a global function with example usage: _repeat(func, args, kwargs, n_repeat, name, n_warmup, max_duration, devices) and returns: _PerfCaseResult