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

[Pre-commit] Add of reformatted files

parent 28eecbba
No related branches found
No related tags found
No related merge requests found
......@@ -194,8 +194,8 @@ def gen_finn_dt_tensor(finn_dt, tensor_shape):
# always use float type as container
return tensor_values.astype(np.float32)
class CallCppCompiler():
class CallCppCompiler:
def __init__(self):
self.include_paths = []
self.cpp_files = []
......@@ -212,11 +212,13 @@ class CallCppCompiler():
raise ValueError(
"""There is no generated code to compile
for node of op type {}""".format(
node.op_type
)
node.op_type
)
)
else:
self.cpp_files.append(str(self.code_gen_dir) + "/execute_" + str(node.op_type) + ".cpp")
self.cpp_files.append(
str(self.code_gen_dir) + "/execute_" + str(node.op_type) + ".cpp"
)
for lib in self.include_paths:
if "cnpy" in lib:
self.cpp_files.append("/workspace/cnpy/cnpy.cpp")
......@@ -227,15 +229,19 @@ class CallCppCompiler():
raise ValueError(
"""There is no generated code to compile
for node of op type {}""".format(
node.op_type
)
node.op_type
)
)
else:
self.executable_path = str(self.code_gen_dir) + "/execute_" + str(node.op_type)
self.executable_path = (
str(self.code_gen_dir) + "/execute_" + str(node.op_type)
)
def build(self, node):
# raise error if includes are empty
self.code_gen_dir = (get_by_name(node.attribute, "code_gen_dir")).s.decode("UTF-8")
self.code_gen_dir = (get_by_name(node.attribute, "code_gen_dir")).s.decode(
"UTF-8"
)
self.prepare_cpp_files(node)
self.set_executable_path(node)
self.compile_components.append("g++ -o " + str(self.executable_path))
......@@ -249,10 +255,8 @@ class CallCppCompiler():
for component in self.compile_components:
bash_compile += str(component) + " "
self.compile_script = str(self.code_gen_dir)+"/compile.sh"
f = open(self.compile_script,"w")
self.compile_script = str(self.code_gen_dir) + "/compile.sh"
f = open(self.compile_script, "w")
f.write("#!/bin/sh \n")
f.write(bash_compile)
f.close()
......@@ -2,8 +2,8 @@ import os
import tempfile as tmp
import finn.custom_op.registry as registry
from finn.transformation import Transformation
from finn.core.utils import get_by_name
from finn.transformation import Transformation
def code_gen_transformation(node, model):
......@@ -67,7 +67,7 @@ class CodeGen(Transformation):
for node in model.graph.node:
if node.domain == "finn":
backend_attribute = get_by_name(node.attribute, "backend")
backend_value = backend_attribute.s.decode('UTF-8')
backend_value = backend_attribute.s.decode("UTF-8")
if backend_value == "fpgadataflow":
code_gen_transformation(node, model)
return (model, False)
import subprocess
import finn.core.utils as util
from finn.transformation import Transformation
from finn.core.utils import CallCppCompiler
from finn.transformation import Transformation
class Compilation(Transformation):
"""Compilation for all nodes in model"""
def __init__(self):
super().__init__()
self.compiler_call = CallCppCompiler()
......@@ -19,14 +20,11 @@ class Compilation(Transformation):
self.compiler_call.append_includes("-I/workspace/vivado-hlslib")
self.compiler_call.append_includes("--std=c++11")
def prepare_bash_command(self, node):
self.get_includes()
self.compiler_call.build(node)
bash_command = "chmod +x " + str(self.compiler_call.compile_script)
process_compile = subprocess.Popen(
bash_command.split(), stdout=subprocess.PIPE
)
process_compile = subprocess.Popen(bash_command.split(), stdout=subprocess.PIPE)
process_compile.communicate()
print(self.compiler_call.code_gen_dir)
......@@ -35,7 +33,7 @@ class Compilation(Transformation):
for node in model.graph.node:
if node.domain == "finn":
backend_attribute = util.get_by_name(node.attribute, "backend")
backend_value = backend_attribute.s.decode('UTF-8')
backend_value = backend_attribute.s.decode("UTF-8")
if backend_value == "fpgadataflow":
self.prepare_bash_command(node)
bash_command = self.compiler_call.compile_script
......@@ -44,6 +42,8 @@ class Compilation(Transformation):
)
process_compile.communicate()
model.set_attribute(node, "executable_path", self.compiler_call.executable_path)
model.set_attribute(
node, "executable_path", self.compiler_call.executable_path
)
return (model, False)
import numpy as np
from onnx import TensorProto, helper
import finn.core.onnx_exec as oxe
import finn.custom_op.xnorpopcount as xp
from finn.core.datatype import DataType
from finn.core.modelwrapper import ModelWrapper
from finn.core.utils import get_by_name
def test_set_attribute():
mw = 8
mh = 8
......@@ -20,7 +18,7 @@ def test_set_attribute():
inp = helper.make_tensor_value_info("inp", TensorProto.FLOAT, [1, sf, simd])
outp = helper.make_tensor_value_info("outp", TensorProto.FLOAT, [1, nf, pe])
node_inp_list = ["inp", "weights"]
FCLayer_node = helper.make_node(
"StreamingFCLayer_Batch",
node_inp_list,
......@@ -50,7 +48,7 @@ def test_set_attribute():
value_to_set = "fpgadataflow"
model.set_attribute(FCLayer_node, "backend", value_to_set)
value = get_by_name(FCLayer_node.attribute, "backend")
assert value.s.decode('UTF-8') == value_to_set
assert value.s.decode("UTF-8") == value_to_set
value_to_set = mw
model.set_attribute(FCLayer_node, "MW", value_to_set)
......@@ -60,8 +58,4 @@ def test_set_attribute():
value_to_set = idt.name
model.set_attribute(FCLayer_node, "inputDataType", value_to_set)
value = get_by_name(FCLayer_node.attribute, "inputDataType")
assert value.s.decode('UTF-8') == value_to_set
assert value.s.decode("UTF-8") == value_to_set
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