Skip to content

Commit 6bdefca

Browse files
qwe
1 parent 9af0901 commit 6bdefca

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

perf.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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()')

test.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import dpnp
2+
from dpnp.tests.helper import generate_random_numpy_array
3+
import numpy
4+
5+
a = generate_random_numpy_array((16,16), 'c8', hermitian=True, seed_value=64, low=-5, high=5)
6+
a_dp = dpnp.array(a)
7+
8+
B_dp = dpnp.linalg.pinv(a_dp, hermitian=True)
9+
reconstructed = dpnp.dot(dpnp.dot(a_dp, B_dp), a_dp)
10+
11+
res = dpnp.isclose(reconstructed, a_dp, rtol=1e-03, atol=1e-03)
12+
13+
print(reconstructed[5][15])
14+
print(a_dp[5][15])
15+
print(res[5][15])
16+
17+
print("DPNP isclose")
18+
print(dpnp.isclose(reconstructed[5][15], a_dp[5][15], rtol=1e-03, atol=1e-03))
19+
20+
print("Numpy isclose")
21+
print(numpy.isclose(dpnp.asnumpy(reconstructed[5][15]), dpnp.asnumpy(a_dp[5][15]), rtol=1e-03, atol=1e-03))
22+
23+
# print(res[])

0 commit comments

Comments
 (0)