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

[Code Generation - IP] Added .cpp template to __init__() and added additional...

[Code Generation - IP] Added .cpp template to __init__() and added additional function, filled the functions in convinputgenerator.py
parent 19ce3752
No related branches found
No related tags found
No related merge requests found
......@@ -38,14 +38,50 @@ class HLSCustomOp(CustomOp):
"""
self.code_gen_dict = {}
self.ipgen_template= """
#include "bnn-library.h"
// includes for network parameters
$GLOBALS$
// defines for network parameters
$DEFINES$
$BLACKBOXFUNCTION$
{
$PRAGMAS$
$DOCOMPUTE$
}
"""
def get_nodeattr_types(self):
return {
"backend": ("s", True, "fpgadataflow"),
"code_gen_dir_npysim": ("s", False, ""),
"code_gen_dir_ipgen": ("s", False, ""),
"executable_path": ("s", False, ""),
}
def code_generation_ipgen(self, model):
node = self.onnx_node
self.global_includes()
self.defines()
self.blackboxfunction()
self.pragmas()
self.docompute()
template = self.ipgen_template
for key in self.code_gen_dict:
# transform list into long string separated by '\n'
code_gen_line = "\n".join(self.code_gen_dict[key])
template = template.replace(key, code_gen_line)
code_gen_dir = self.get_nodeattr("code_gen_dir_ipgen")
f = open(os.path.join(code_gen_dir, "top_{}.cpp".format(node.op_type)), "w")
f.write(template)
f.close()
self.code_gen_dict.clear()
def code_generation_npysim(self, model):
node = self.onnx_node
self.generate_params(model)
......@@ -67,6 +103,7 @@ class HLSCustomOp(CustomOp):
f = open(os.path.join(code_gen_dir, "execute_{}.cpp".format(node.op_type)), "w")
f.write(template)
f.close()
self.code_gen_dict.clear()
def compile_singlenode_code(self):
code_gen_dir = self.get_nodeattr("code_gen_dir_npysim")
......@@ -161,3 +198,10 @@ compilation transformations?
@abstractmethod
def save_as_npy(self):
pass
def blackboxfunction(self):
pass
def pragmas(self):
pass
......@@ -168,3 +168,18 @@ class ConvolutionInputGenerator(HLSCustomOp):
def save_as_npy(self):
self.code_gen_dict["$SAVEASCNPY$"] = []
def blackboxfunction(self):
self.code_gen_dict["$BLACKBOXFUNCTION$"] = [
"""void {}(hls::stream<ap_uint<SIMD1*Input_precision1>> &in,
hls::stream<ap_uint<SIMD1*Input_precision1>> &out)""".format(
self.onnx_node.name
)
]
def pragmas(self):
self.code_gen_dict["$PRAGMAS$"] = ["#pragma HLS INTERFACE axis port=in"]
self.code_gen_dict["$PRAGMAS$"].append("#pragma HLS INTERFACE axis port=out")
self.code_gen_dict["$PRAGMAS$"].append(
"#pragma HLS INTERFACE ap_ctrl_none port=return"
)
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