Hide private names in `cupyx.time`
-import math
-import time
+import math as _math
+import time as _time
-import numpy
+import numpy as _numpy
-import cupy
+import cupy as _cupy
from cupy import _util
@@ -51,14 +51,14 @@ class _PerfCaseResult(object):
def repeat(
func, args=(), kwargs={}, n_repeat=10000, *,
- name=None, n_warmup=10, max_duration=math.inf, devices=None):
+ name=None, n_warmup=10, max_duration=_math.inf, devices=None):
_util.experimental('cupyx.time.repeat')
if name is None:
name = func.__name__
if devices is None:
- devices = (cupy.cuda.get_device_id(),)
+ devices = (_cupy.cuda.get_device_id(),)
if not callable(func):
raise ValueError('`func` should be a callable object.')
@@ -86,18 +86,18 @@ def _repeat(
events_2 = []
for i in devices:
- with cupy.cuda.Device(i):
- events_1.append(cupy.cuda.stream.Event())
- events_2.append(cupy.cuda.stream.Event())
+ with _cupy.cuda.Device(i):
+ events_1.append(_cupy.cuda.stream.Event())
+ events_2.append(_cupy.cuda.stream.Event())
- ev1 = cupy.cuda.stream.Event()
- ev2 = cupy.cuda.stream.Event()
+ ev1 = _cupy.cuda.stream.Event()
+ ev2 = _cupy.cuda.stream.Event()
for i in range(n_warmup):
func(*args, **kwargs)
for event, device in zip(events_1, devices):
- with cupy.cuda.Device(device):
+ with _cupy.cuda.Device(device):
event.record()
event.synchronize()
@@ -106,30 +106,30 @@ def _repeat(
duration = 0
for i in range(n_repeat):
for event, device in zip(events_1, devices):
- with cupy.cuda.Device(device):
+ with _cupy.cuda.Device(device):
event.record()
- t1 = time.perf_counter()
+ t1 = _time.perf_counter()
func(*args, **kwargs)
- t2 = time.perf_counter()
+ t2 = _time.perf_counter()
cpu_time = t2 - t1
cpu_times.append(cpu_time)
for event, device in zip(events_2, devices):
- with cupy.cuda.Device(device):
+ with _cupy.cuda.Device(device):
event.record()
for event, device in zip(events_2, devices):
- with cupy.cuda.Device(device):
+ with _cupy.cuda.Device(device):
event.synchronize()
for i, (ev1, ev2) in enumerate(zip(events_1, events_2)):
- gpu_time = cupy.cuda.get_elapsed_time(ev1, ev2) * 1e-3
+ gpu_time = _cupy.cuda.get_elapsed_time(ev1, ev2) * 1e-3
gpu_times[i].append(gpu_time)
- duration += time.perf_counter() - t1
+ duration += _time.perf_counter() - t1
if duration > max_duration:
break
- ts = numpy.asarray([cpu_times] + gpu_times, dtype=numpy.float64)
+ ts = _numpy.asarray([cpu_times] + gpu_times, dtype=_numpy.float64)
return _PerfCaseResult(name, ts, devices=devices)
