Skip to content
Snippets Groups Projects
Commit f39dfea0 authored by auphelia's avatar auphelia
Browse files

[Code Generation] Changed get_layer_attribute function so that it now takes a...

[Code Generation] Changed get_layer_attribute function so that it now takes a single node as input, started to work on the function for the computation commands
parent 3c09a8d1
No related merge requests found
def get_layer_attributes(node):
def extract_layer_attributes(model):
# Layer attributes # Layer attributes
j = -1 num_attr = len(node.attribute)
L_PE = {} for k in range(num_attr):
L_SIMD = {} if node.attribute[k].name == "PE":
L_MH = {} L_PE = node.attribute[k].i
L_MW = {} if node.attribute[k].name == "SIMD":
L_resDataType = {} L_SIMD = node.attribute[k].i
L_resType = {} if node.attribute[k].name == "MH":
for node in model.graph.node: L_MH = node.attribute[k].i
num_attr = len(node.attribute) if node.attribute[k].name == "MW":
j += 1 L_MW = node.attribute[k].i
if node.op_type == "StreamingFCLayer_Batch": if node.attribute[k].name == "resDataType":
for k in range(num_attr): L_resDataType = node.attribute[k].i
if node.attribute[k].name == "PE": if node.attribute[k].name == "resType":
L_PE[j] = node.attribute[k].i L_resType = node.attribute[k].i
if node.attribute[k].name == "SIMD":
L_SIMD[j] = node.attribute[k].i
if node.attribute[k].name == "MH":
L_MH[j] = node.attribute[k].i
if node.attribute[k].name == "MW":
L_MW[j] = node.attribute[k].i
if node.attribute[k].name == "resDataType":
L_resDataType[j] = node.attribute[k].i
if node.attribute[k].name == "resType":
L_resType[j] = node.attribute[k].i
return [L_PE, L_SIMD, L_MH, L_MW, L_resDataType, L_resType] return [L_PE, L_SIMD, L_MH, L_MW, L_resDataType, L_resType]
...@@ -55,6 +44,37 @@ def strm_prgm(model, code_gen_dict): ...@@ -55,6 +44,37 @@ def strm_prgm(model, code_gen_dict):
) )
def computation_cmds(model, code_gen_dict):
code_gen_dict["Computation commands"] = []
for node in model.graph.node:
if node.op_type == "StreamingFCLayer_Batch":
inp = node.input[0]
weights = node.input[1]
thresholds = node.input[2]
outp = node.output[0]
# get layer attributes
[PE, SIMD, MH, MW, resDataType, resType] = get_layer_attributes(node)
print(str(resDataType))
print(resType)
code_gen_dict["Computation commands"].append(
"{}<{}, {}, {}, {}, {}>({}, {}, {}, {}, numReps, {});".format(
node.op_type,
MW,
MH,
SIMD,
PE,
resDataType,
inp,
outp,
weights,
thresholds,
resType,
)
)
def code_generation(model): def code_generation(model):
code_gen_dict = {} code_gen_dict = {}
...@@ -65,8 +85,7 @@ def code_generation(model): ...@@ -65,8 +85,7 @@ def code_generation(model):
# stream pragmas # stream pragmas
strm_prgm(model, code_gen_dict) strm_prgm(model, code_gen_dict)
# print(code_gen_dict) # computation commands
computation_cmds(model, code_gen_dict)
[L_PE, L_SIMD, L_MH, L_MW, L_resDataType, L_resType] = extract_layer_attributes( print(code_gen_dict)
model
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment