aboutsummaryrefslogtreecommitdiff
path: root/ethosu/vela/graph_optimiser.py
diff options
context:
space:
mode:
authorPatrik Gustavsson <patrik.gustavsson@arm.com>2020-11-20 15:08:44 +0100
committertim.hall <tim.hall@arm.com>2020-11-20 14:56:58 +0000
commit43f8f6424cb942f27599258607ea36c9a852f5ef (patch)
tree36c2101bd448c90611220c817200d770f1b5af71 /ethosu/vela/graph_optimiser.py
parentb4fc087ac427e26bd37543ed705cf1c4fbf55872 (diff)
downloadethos-u-vela-43f8f6424cb942f27599258607ea36c9a852f5ef.tar.gz
Revert "MLMBED-3450: Do not convert batched fully connected to conv"2.0.0.rc2
This reverts commit 15a8e803844b286fe9533e1cf703c76a77b090a8. Signed-off-by: Patrik Gustavsson <patrik.gustavsson@arm.com> Change-Id: I64169443f473c9ba42551281ad6ac4b45856f420
Diffstat (limited to 'ethosu/vela/graph_optimiser.py')
-rw-r--r--ethosu/vela/graph_optimiser.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/ethosu/vela/graph_optimiser.py b/ethosu/vela/graph_optimiser.py
index 7401927d..58899054 100644
--- a/ethosu/vela/graph_optimiser.py
+++ b/ethosu/vela/graph_optimiser.py
@@ -317,7 +317,7 @@ def fixup_fully_connected_input(op, arch, nng):
return op
-def convert_batched_fc_shape(op, arch, nng):
+def convert_batched_fc_to_conv(op, arch, nng):
if op.type == Op.FullyConnected:
ifm = op.inputs[0]
ofm = op.outputs[0]
@@ -327,6 +327,19 @@ def convert_batched_fc_shape(op, arch, nng):
batching_split = {4: (2, 2), 8: (2, 4), 16: (4, 4)}
h, w = batching_split.get(n, (1, n))
+ # Convert to convolution
+ op.name += "_conv"
+ op.type = Op.Conv2DBias
+ op.attrs = {
+ "dilation": (1, 1, 1, 1),
+ "dilation_h_factor": 1,
+ "dilation_w_factor": 1,
+ "padding": b"SAME",
+ "stride_h": 1,
+ "stride_w": 1,
+ "strides": (1, 1, 1, 1),
+ }
+
prev_op = ifm.ops[0]
desired_shape = [1, h, w, ifm.shape[-1]]
if len(ifm.consumer_list) == 1 and prev_op is not None and prev_op.type == Op.Reshape:
@@ -367,7 +380,7 @@ def convert_batched_fc_shape(op, arch, nng):
else:
op.outputs[0].set_all_shapes(desired_shape)
else:
- # Add reshape op to the output
+ # Add rehape op to the output
op.set_output_tensor(create_reshape_tensor(ofm, desired_shape, False))
return op
@@ -1082,7 +1095,7 @@ def optimise_graph_a(nng, arch, verbose_graph=False):
convert_conv_to_fc,
convert_softmax,
fixup_fully_connected_input,
- convert_batched_fc_shape,
+ convert_batched_fc_to_conv,
fixup_pack_input,
unfuse_activation_function,
fixup_conv2d_backprop,