three registers and a zero command
MODIFY
extra/cherry.py
extra/cherry.py
@@ -46,7 +46,6 @@ SLOT = lambda x: x*SLOTSIZE
from enum import Enum
class Reg(Enum):
- ZERO = 0
# can the ALU use the same registers?
MATMUL_INPUT = 1
MATMUL_WEIGHTS = 2
@@ -175,12 +174,14 @@ def riski_matmul():
regfile[Reg.MATMUL_WEIGHTS]
@count
-def riski_mov(tout, tin, transpose=False):
+def riski_mov(tout, tin):
ret = regfile[tin]
- if transpose:
- ret = ret.T
regfile[tout] = np.copy(ret)
+@count
+def riski_zero(tout):
+ regfile[tout][:, :] = 0
+
load_log = open("/tmp/risk_load_log", "w") if os.getenv("LOAD_LOG") else None
@count
@@ -444,7 +445,7 @@ def cherry_matmul(x, w, transpose_x=False, transpose_w=False):
for c in range(cnt):
for m in range(0, M, SZ):
for n in range(0, N, SZ):
- riski_mov(Reg.MATMUL_OUTPUT, Reg.ZERO)
+ riski_zero(Reg.MATMUL_OUTPUT)
for k in range(0, K, SZ):
if transpose_x:
riski_load(Reg.MATMUL_INPUT, SLOT(0)+c*M*K + k*M+m, 1, M, min(SZ, M-m), min(SZ, K-k))

MODIFY
extra/ops_cherry.py
extra/ops_cherry.py
@@ -186,7 +186,7 @@ class Conv2D(Function):
for Y in range(0, oy):
for X in range(0, ox, SZ):
IY,IX = Y*ys,X*xs
- riski_mov(Reg.MATMUL_OUTPUT, Reg.ZERO)
+ riski_zero(Reg.MATMUL_OUTPUT)
for y in range(IY, IY+H):
for x in range(IX, IX+W):
riski_load(Reg.MATMUL_INPUT,
@@ -212,7 +212,7 @@ class Conv2D(Function):
assert yx == iy*ix
for YX in range(0, oy*ox, SZ): # these are next to each other
# inner conv
- riski_mov(Reg.MATMUL_OUTPUT, Reg.ZERO)
+ riski_zero(Reg.MATMUL_OUTPUT)
for ci in range(0, cin, SZ):
riski_load(Reg.MATMUL_INPUT,
SLOT(0) + B*groups*cin*yx + g*cin*yx + ci*yx + YX,
@@ -234,7 +234,7 @@ class Conv2D(Function):
IY,IX = Y*ys,X*xs
# inner conv
- riski_mov(Reg.MATMUL_OUTPUT, Reg.ZERO)
+ riski_zero(Reg.MATMUL_OUTPUT)
for ci in range(0, cin, SZ):
# not a loop in 1x1 convs, 9 in 3x3, 25 in 5x5
for y in range(IY, IY+H):

three registers and a zero command