|
| 1 | +import dpnp |
| 2 | +import numpy as np |
| 3 | +from dpnp.dpnp_utils import get_usm_allocations |
| 4 | +from dpnp.tests.helper import generate_random_numpy_array |
| 5 | +import time |
| 6 | +from IPython import get_ipython |
| 7 | + |
| 8 | +ipython = get_ipython() |
| 9 | +if ipython is None: |
| 10 | + from IPython.terminal.interactiveshell import TerminalInteractiveShell |
| 11 | + ipython = TerminalInteractiveShell() |
| 12 | + |
| 13 | +# dtypes = ['c8', 'c16'] |
| 14 | +dtypes = ['f4', 'f8', 'c8', 'c16'] |
| 15 | + |
| 16 | +n = 8192 * 8192 * 10 |
| 17 | + |
| 18 | +for dtype in dtypes: |
| 19 | + print(f"\n=== dtype: {dtype} ===") |
| 20 | + |
| 21 | + a = generate_random_numpy_array((n,), dtype=dtype, seed_value=81) |
| 22 | + b = generate_random_numpy_array((n,), dtype=dtype, seed_value=76) |
| 23 | + |
| 24 | + atol = 1e-5 |
| 25 | + rtol = 1e-3 |
| 26 | + equal_nan = False |
| 27 | + |
| 28 | + # dpnp arrays on GPU |
| 29 | + a_dp = dpnp.array(a, device='cpu') |
| 30 | + b_dp = dpnp.array(b, device='cpu') |
| 31 | + |
| 32 | + a_dp = a_dp[::-1] |
| 33 | + b_dp = b_dp[::-1] |
| 34 | + _, exec_q = get_usm_allocations([a_dp, b_dp]) |
| 35 | + |
| 36 | + # Cold run |
| 37 | + # _ = np.isclose(a, b, rtol=rtol, atol=atol, equal_nan=equal_nan) |
| 38 | + _ = dpnp.isclose(a_dp, b_dp, rtol=rtol, atol=atol, equal_nan=equal_nan) |
| 39 | + # _ = dpnp.isclose(a_dp, b_dp, rtol=rtol, atol=atol, equal_nan=equal_nan, new=True) |
| 40 | + exec_q.wait() |
| 41 | + |
| 42 | + # time.sleep(1) |
| 43 | + # print("NumPy:") |
| 44 | + # ipython.run_line_magic('timeit', 'np.isclose(a, b, rtol=rtol, atol=atol, equal_nan=equal_nan)') |
| 45 | + |
| 46 | + time.sleep(1) |
| 47 | + print("DPNP (GPU, New):") |
| 48 | + ipython.run_line_magic('timeit', 'dpnp.isclose(a_dp, b_dp, rtol=rtol, atol=atol, equal_nan=equal_nan); exec_q.wait()') |
0 commit comments