forked from intel/pyMIC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmul_performance.py
59 lines (50 loc) · 1.3 KB
/
mul_performance.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import pymic as mic
import numpy as np
import time
import sys
if len(sys.argv) > 1 :
sz = int(sys.argv[1])
m, n, k = sz, sz, sz
else :
sz = 4096
m, n, k = sz, sz, sz
np.random.seed(10)
a = np.random.random(m * k).reshape((m, k))
b = np.random.random(k * n).reshape((k, n))
c = np.zeros((m, n))
device = mic.devices[0]
stream = device.get_default_stream()
offl_a = stream.bind(a)
offl_b = stream.bind(b)
offl_c = stream.bind(c)
pymic_dot_start = time.time()
offl_c = offl_a * offl_b
stream.sync()
pymic_dot_end = time.time()
print("pymic dot :")
print("--------------------------------------")
offl_c.update_host()
print(offl_c)
print("checksum:", np.sum(offl_c.array))
print("Run time:", pymic_dot_end - pymic_dot_start)
print()
print("--------------------------------------")
c[:] = 0.0
offl_c.update_device()
alpha = 1.0
beta = 0.0
library = device.load_library("libdgemm.so")
pymic_dgemm_start = time.time()
stream.invoke(library.dgemm_kernel,
offl_a, offl_b, offl_c,
m, n, k, alpha, beta)
stream.sync()
pymic_dgemm_end = time.time()
print("pymic dgemm :")
print("--------------------------------------")
offl_c.update_host()
print(offl_c)
print("checksum:", np.sum(offl_c.array))
print("Run time:", pymic_dgemm_end - pymic_dgemm_start)
print()
print("--------------------------------------")