Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streamlining transformations for Split and Concat nodes #1189

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 48 additions & 48 deletions src/finn/transformation/fpgadataflow/convert_to_hw_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,63 +585,63 @@ def apply(self, model):

for node in graph.node:
node_ind += 1
successors = model.find_consumers(node.output[0])
if successors is not None and len(successors) >= 2:
output_tensor = node.output[0]
n_outputs = len(successors)
for output_tensor in node.output:
successors = model.find_consumers(output_tensor)
if successors is not None and len(successors) >= 2:
n_outputs = len(successors)

dt = model.get_tensor_datatype(output_tensor)
dt = model.get_tensor_datatype(output_tensor)

# skip conversion for layers with float input
if not dt.is_integer():
continue
# skip conversion for layers with float input
if not dt.is_integer():
continue

# create clone tensors
out_shape = model.get_tensor_shape(output_tensor)
out_tensor_clones = []
for i in range(n_outputs):
clone = helper.make_tensor_value_info(
model.make_new_valueinfo_name(), TensorProto.FLOAT, out_shape
)
model.graph.value_info.append(clone)
out_tensor_clones += [clone.name]
# create clone tensors
out_shape = model.get_tensor_shape(output_tensor)
out_tensor_clones = []
for i in range(n_outputs):
clone = helper.make_tensor_value_info(
model.make_new_valueinfo_name(), TensorProto.FLOAT, out_shape
)
model.graph.value_info.append(clone)
out_tensor_clones += [clone.name]

num_ch = int(out_shape[-1])
vecs = out_shape[:-1]
num_ch = int(out_shape[-1])
vecs = out_shape[:-1]

# create node with no parallelization first
pe = 1
# create node with no parallelization first
pe = 1

dup_node = helper.make_node(
"DuplicateStreams",
[output_tensor],
out_tensor_clones,
domain="finn.custom_op.fpgadataflow",
backend="fpgadataflow",
NumChannels=num_ch,
PE=pe,
inputDataType=dt.name,
numInputVectors=vecs,
NumOutputStreams=n_outputs,
outFIFODepths=[2] * n_outputs,
name="DuplicateStreams_" + node.name,
)
dup_node = helper.make_node(
"DuplicateStreams",
[output_tensor],
out_tensor_clones,
domain="finn.custom_op.fpgadataflow",
backend="fpgadataflow",
NumChannels=num_ch,
PE=pe,
inputDataType=dt.name,
numInputVectors=vecs,
NumOutputStreams=n_outputs,
outFIFODepths=[2] * n_outputs,
name="DuplicateStreams_" + node.name,
)

graph.node.insert(node_ind, dup_node)
graph.node.insert(node_ind, dup_node)

# connect successors to out tensor clone
clone_idx = 0
for successor in successors:
for i, succ_input in enumerate(successor.input):
if succ_input == output_tensor:
successor.input[i] = out_tensor_clones[clone_idx]
clone_idx += 1
# if one node has multiple connections to the same output
# find_direct_successors will return one node per input
# so break the inner loop will result in correct behaviour
break
# connect successors to out tensor clone
clone_idx = 0
for successor in successors:
for i, succ_input in enumerate(successor.input):
if succ_input == output_tensor:
successor.input[i] = out_tensor_clones[clone_idx]
clone_idx += 1
# if one node has multiple connections to the same output
# find_direct_successors will return one node per input
# so break the inner loop will result in correct behaviour
break

graph_modified = True
graph_modified = True

if graph_modified:
model = model.transform(SortGraph())
Expand Down
4 changes: 2 additions & 2 deletions src/finn/transformation/fpgadataflow/insert_fifo.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def apply(self, model):
fifo_input_tensor = oh.make_tensor_value_info(
model.make_new_valueinfo_name(),
n0_tensor_dtype,
n0.get_normal_output_shape(),
n0.get_normal_output_shape(out_ind),
)
graph.value_info.append(fifo_input_tensor)
model.set_tensor_datatype(fifo_input_tensor.name, dtype)
Expand All @@ -294,7 +294,7 @@ def apply(self, model):
graph.node.append(fifo_node)

# set fifo output tensor as new input tensor of second node
final_node.output[0] = fifo_input_tensor.name
final_node.output[out_ind] = fifo_input_tensor.name
else:
warnings.warn(
"""Output FIFO for %s has depth %d and won't
Expand Down
Loading