forked from esl-epfl/ESL-CGRA-simulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kernels.py
56 lines (41 loc) · 1.47 KB
/
kernels.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
EXT = ".csv"
FILENAME_INSTR = "instructions"
FILENAME_MEM = "memory"
FILENAME_INP = "inputs"
FILENAME_OUP = "outputs"
FILENAME_MEM_O = "memory_out"
WORD_SIZE = 4
def kernel_new( name, dim=4 ):
import os, csv
filedir = "./"+name+"/"
if os.path.isdir(filedir):
print("Kernel", name, "already exists!")
return
os.makedirs(os.path.dirname(filedir), exist_ok=True)
with open(filedir + FILENAME_INP + EXT,"w+") as f:
csv.writer(f).writerow([""]*dim)
with open(filedir + FILENAME_MEM + EXT,"w+") as f:
csv.writer(f).writerow(["Address", "Data"])
csv.writer(f).writerow(["0", "0"])
print("Kernel", name, "created successfuly!")
def kernel_clear_memory( name ):
import csv
filedir = "./"+name+"/"
with open(filedir + FILENAME_MEM + EXT,"w+") as f:
csv.writer(f).writerow(["Address", "Data"])
csv.writer(f).writerow(["0", "0"])
def kernel_add_memory_region( name, start, vals ):
import csv
mem = []
region = []
filedir = "./"+name+"/"
for i in range(len(vals)):
region.append([ start + i*WORD_SIZE,vals[i]])
try:
with open(filedir + FILENAME_MEM + EXT) as f:
for row in csv.reader(f): mem.append(row)
for row in region: mem.append(row)
with open(filedir + FILENAME_MEM + EXT,"w") as f:
for row in mem: csv.writer(f).writerow(row)
except:
print("Could not open memory file")