-
Notifications
You must be signed in to change notification settings - Fork 0
/
PE.py
34 lines (26 loc) · 929 Bytes
/
PE.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
import numpy as np
from PU import PU
class PE:
def __init__(self, M, N_0):
self.M = M
self.N_0 = N_0
self.acc = np.zeros((self.M, self.N_0))
self.PUs = [None] * self.N_0
for i in range(self.N_0):
self.PUs[i] = PU(self.M)
# Send appropriate a value and b value to each PU
def pu_mult(self, a_val, a_row, a_col, B_ji):
a_col = int(a_col)
for i in range(np.shape(B_ji)[1]):
self.PUs[i].cum_multiply(a_val, a_row, B_ji[a_col, i])
self.accum()
# Accumulate partial C across all PUs
def accum(self):
p_sum = np.zeros((self.M, self.N_0))
for i in range(self.N_0):
p_sum[:, i] = self.PUs[i].scratch
self.acc = self.acc + p_sum
# Reset scratch pad of all PUs
def rst_scratch(self):
for i in range(self.N_0):
self.PUs[i].rst()