aboutsummaryrefslogtreecommitdiff
path: root/pseudocode/operators/TRANSPOSE_CONV2D.tosac
diff options
context:
space:
mode:
authorEric Kunze <eric.kunze@arm.com>2024-02-14 16:33:31 -0800
committerEric Kunze <eric.kunze@arm.com>2024-03-13 16:31:19 -0700
commit0afe61f88ce3d2f445c5f01ae5567cb1b0b7f303 (patch)
treebfa03c381634090e9074d3e1167c3256a31f3c84 /pseudocode/operators/TRANSPOSE_CONV2D.tosac
parent6dd341093507157aabbea00b90ca8902509cfd4f (diff)
downloadspecification-0afe61f88ce3d2f445c5f01ae5567cb1b0b7f303.tar.gz
Modify convolution operators to improve bias handling
Accumulator size moves to an enumerated attribute, out_t for floating-point changes to be the size of the input. Bias for floating-point also becomes the bit width of the input type. Signed-off-by: Eric Kunze <eric.kunze@arm.com> Change-Id: I7369417adbb1106ce34a1978e7f511a30272c318
Diffstat (limited to 'pseudocode/operators/TRANSPOSE_CONV2D.tosac')
-rw-r--r--pseudocode/operators/TRANSPOSE_CONV2D.tosac34
1 files changed, 19 insertions, 15 deletions
diff --git a/pseudocode/operators/TRANSPOSE_CONV2D.tosac b/pseudocode/operators/TRANSPOSE_CONV2D.tosac
index ab61348..6713b30 100644
--- a/pseudocode/operators/TRANSPOSE_CONV2D.tosac
+++ b/pseudocode/operators/TRANSPOSE_CONV2D.tosac
@@ -16,20 +16,24 @@ ERROR_IF(OH != (IH - 1) * stride_y + out_pad_top + out_pad_bottom + KH);
ERROR_IF(OW != (IW - 1) * stride_x + out_pad_left + out_pad_right + KW);
ERROR_IF(BC != OC && BC != 1);
-for_each(index in [N, OH, OW, OC]) {
- tensor_write<out_t>(output, [N,OH,OW,OC], index, bias[(BC == 1) ? 0 : index[3]]);
-}
-for_each(0 <= n < N, 0 <= iy < IH, 0 <= ix < IW, 0 <= oc < OC,
- 0 <= ic < IC, 0 <= ky < KH, 0 <= kx < KW) {
- index_t oy = iy * stride_y + out_pad_top + ky;
- index_t ox = ix * stride_x + out_pad_left + kx;
- if (oy >= 0 && oy < OH && ox >= 0 && ox < OW) {
- out_t acc = static_cast<out_t>(tensor_read<out_t>(output, [N,OH,OW,OC], [n,oy,ox,oc]));
- out_t value = static_cast<out_t>(tensor_read<in_t>(input, [N,IH,IW,IC], [n,iy,ix,ic]));
- out_t weight = static_cast<out_t>(tensor_read<weight_t>(weight, [OC,KH,KW,IC], [oc,ky,kx,ic]));
- value = apply_sub_s<out_t>(value, static_cast<out_t>(input_zp));
- weight = apply_sub_s<out_t>(weight, static_cast<out_t>(weight_zp));
- acc = apply_add_s<out_t>(acc, apply_mul_s<out_t>(value, weight));
- tensor_write<out_t>(output, [N,OH,OW,OC], [n,oy,ox,oc], acc);
+for_each(0 <= n < N, 0 <= iy < IH, 0 <= ix < IW, 0 <= dy < stride_y, 0 <= dx < stride_x, 0 <= oc < OC) {
+ acc_t acc = 0;
+ index_t oy = iy * stride_y + dy + out_pad_top;
+ index_t ox = ix * stride_x + dx + out_pad_left;
+
+ for_each(0 <= sy * stride_y < KY - dy, 0 <= sx * stride_x < KX - dx, 0 <= ic < IC) {
+ index_t y = iy - sy;
+ index_t x = ix - sx;
+ index_t ky = dy + sy * stride_y;
+ index_t kx = dx + sx * stride_x;
+ acc_t value = static_cast<acc_t>(tensor_read<in_t>(input, [N,IH,IW,IC], [n,y,x,ic]));
+ acc_t weight_value = static_cast<acc_t>(tensor_read<weight_t>(weight, [OH,KH,KW,IC], [oc,ky,kx,ic]));
+ value = apply_sub_s<acc_t>(value, static_cast<acc_t>(input_zp));
+ weight_value = apply_sub_s<acc_t>(weight_value, static_cast<acc_t>(weight_zp));
+ acc = apply_add_s<acc_t>(acc, apply_mul_s<acc_t>(value, weight_value));
}
+
+ out_t out = static_cast<out_t>(acc);
+ out = apply_add_s<out_t>(out, bias[(BC == 1) ? 0 : oc]);
+ tensor_write<out_t>(output, [N,OH,OW,OC], [n,oy,ox,oc], out);
}