diff --git a/src/finn/custom_op/fpgadataflow/__init__.py b/src/finn/custom_op/fpgadataflow/__init__.py index 7930915daf18219c465ca50c3f29b61f3fd0f22b..a0a6903ed879ef2594cace9238e82c82d43e96f9 100644 --- a/src/finn/custom_op/fpgadataflow/__init__.py +++ b/src/finn/custom_op/fpgadataflow/__init__.py @@ -37,33 +37,6 @@ class HLSCustomOp(CustomOp): """ self.code_gen_dict = {} - def execute_node(self, node, context, graph): - in_ind = 0 - temp_files = [] - for inputs in node.input: - np.save("input_{}.npy".format(in_ind), context[inputs]) - temp_files.append("input_{}.npy".format(in_ind)) - in_ind += 1 - self.code_generation(node) - temp_files.append("execute_{}.cpp".format(node.op_type)) - bash_compile = """g++ -o execute_{} execute_{}.cpp - /workspace/cnpy/cnpy.cpp -I/workspace/cnpy/ - -I/workspace/finn-hlslib -I/workspace/vivado-hlslib - --std=c++11 -lz""".format( - node.op_type, node.op_type - ) - process_compile = subprocess.Popen(bash_compile.split(), stdout=subprocess.PIPE) - process_compile.communicate() - bash_execute = "./execute_{}".format(node.op_type) - process_execute = subprocess.Popen(bash_execute.split(), stdout=subprocess.PIPE) - process_execute.communicate() - temp_files.append("execute_{}".format(node.op_type)) - temp_files.append("output.npy") - output = np.load("output.npy") - context[node.output[0]] = output - # deleting temporary files - for temp_file in temp_files: - os.remove(temp_file) @abstractmethod def get_attributes(self, node): diff --git a/src/finn/custom_op/fpgadataflow/streamingfclayer_batch.py b/src/finn/custom_op/fpgadataflow/streamingfclayer_batch.py index 5a767724663ec7e19f6e30881fd87d8d4c449f7e..da147722f4c6af7ee1fc05b2596117d8d3a3799f 100644 --- a/src/finn/custom_op/fpgadataflow/streamingfclayer_batch.py +++ b/src/finn/custom_op/fpgadataflow/streamingfclayer_batch.py @@ -9,6 +9,35 @@ class StreamingFCLayer_Batch(HLSCustomOp): def infer_node_datatype(self, node, model): pass + def execute_node(self, node, context, graph): + in_ind = 0 + temp_files = [] + for inputs in node.input: + np.save("input_{}.npy".format(in_ind), context[inputs]) + temp_files.append("input_{}.npy".format(in_ind)) + in_ind += 1 + self.code_generation(node) + temp_files.append("execute_{}.cpp".format(node.op_type)) + bash_compile = """g++ -o execute_{} execute_{}.cpp + /workspace/cnpy/cnpy.cpp -I/workspace/cnpy/ + -I/workspace/finn-hlslib -I/workspace/vivado-hlslib + --std=c++11 -lz""".format( + node.op_type, node.op_type + ) + process_compile = subprocess.Popen(bash_compile.split(), stdout=subprocess.PIPE) + process_compile.communicate() + bash_execute = "./execute_{}".format(node.op_type) + process_execute = subprocess.Popen(bash_execute.split(), stdout=subprocess.PIPE) + process_execute.communicate() + temp_files.append("execute_{}".format(node.op_type)) + temp_files.append("output.npy") + output = np.load("output.npy") + context[node.output[0]] = output + # deleting temporary files + for temp_file in temp_files: + os.remove(temp_file) + + def get_attributes(self, node): self.resType = get_by_name(node.attribute, "resType").s.decode("utf-8") self.MW = get_by_name(node.attribute, "MW").i diff --git a/src/finn/custom_op/fpgadataflow/streamingmaxpool.py b/src/finn/custom_op/fpgadataflow/streamingmaxpool.py index acdf0a181bbab397c75088d50623d14da55a78bc..0d27a789b00cda4f4d24be6c7cac57e3dc4bb90f 100644 --- a/src/finn/custom_op/fpgadataflow/streamingmaxpool.py +++ b/src/finn/custom_op/fpgadataflow/streamingmaxpool.py @@ -1,3 +1,8 @@ +import os +import numpy as np +import subprocess + + from finn.core.utils import get_by_name from finn.custom_op.fpgadataflow import HLSCustomOp @@ -9,6 +14,35 @@ class StreamingMaxPool(HLSCustomOp): def infer_node_datatype(self, node, model): pass + def execute_node(self, node, context, graph): + in_ind = 0 + temp_files = [] + for inputs in node.input: + np.save("input_{}.npy".format(in_ind), context[inputs]) + temp_files.append("input_{}.npy".format(in_ind)) + in_ind += 1 + self.code_generation(node) + temp_files.append("execute_{}.cpp".format(node.op_type)) + bash_compile = """g++ -o execute_{} execute_{}.cpp + /workspace/cnpy/cnpy.cpp -I/workspace/cnpy/ + -I/workspace/finn-hlslib -I/workspace/vivado-hlslib + --std=c++11 -lz""".format( + node.op_type, node.op_type + ) + process_compile = subprocess.Popen(bash_compile.split(), stdout=subprocess.PIPE) + process_compile.communicate() + bash_execute = "./execute_{}".format(node.op_type) + process_execute = subprocess.Popen(bash_execute.split(), stdout=subprocess.PIPE) + process_execute.communicate() + temp_files.append("execute_{}".format(node.op_type)) + temp_files.append("output.npy") + output = np.load("output.npy") + context[node.output[0]] = output + # deleting temporary files + for temp_file in temp_files: + os.remove(temp_file) + + def get_attributes(self, node): self.ImgDim = get_by_name(node.attribute, "ImgDim").i self.PoolDim = get_by_name(node.attribute, "PoolDim").i diff --git a/src/finn/custom_op/fpgadataflow/streamingmaxpool_batch.py b/src/finn/custom_op/fpgadataflow/streamingmaxpool_batch.py index 90edf06268942ac59ac9129217b3face1401dd69..556406657315d3e7eb0a3ed81f5e851536f8317e 100644 --- a/src/finn/custom_op/fpgadataflow/streamingmaxpool_batch.py +++ b/src/finn/custom_op/fpgadataflow/streamingmaxpool_batch.py @@ -1,3 +1,7 @@ +import os +import numpy as np +import subprocess + from finn.core.utils import get_by_name from finn.custom_op.fpgadataflow import HLSCustomOp @@ -8,6 +12,35 @@ class StreamingMaxPool_Batch(HLSCustomOp): def infer_node_datatype(self, node, model): pass + + def execute_node(self, node, context, graph): + in_ind = 0 + temp_files = [] + for inputs in node.input: + np.save("input_{}.npy".format(in_ind), context[inputs]) + temp_files.append("input_{}.npy".format(in_ind)) + in_ind += 1 + self.code_generation(node) + temp_files.append("execute_{}.cpp".format(node.op_type)) + bash_compile = """g++ -o execute_{} execute_{}.cpp + /workspace/cnpy/cnpy.cpp -I/workspace/cnpy/ + -I/workspace/finn-hlslib -I/workspace/vivado-hlslib + --std=c++11 -lz""".format( + node.op_type, node.op_type + ) + process_compile = subprocess.Popen(bash_compile.split(), stdout=subprocess.PIPE) + process_compile.communicate() + bash_execute = "./execute_{}".format(node.op_type) + process_execute = subprocess.Popen(bash_execute.split(), stdout=subprocess.PIPE) + process_execute.communicate() + temp_files.append("execute_{}".format(node.op_type)) + temp_files.append("output.npy") + output = np.load("output.npy") + context[node.output[0]] = output + # deleting temporary files + for temp_file in temp_files: + os.remove(temp_file) + def get_attributes(self, node): self.ImgDim = get_by_name(node.attribute, "ImgDim").i