diff options
author | Kevin Petit <kevin.petit@arm.com> | 2024-01-08 15:27:25 +0000 |
---|---|---|
committer | Kevin Petit <kevin.petit@arm.com> | 2024-01-15 10:19:01 +0000 |
commit | a7ac313a13f8f82b4b3ca9730bd746392f6600d9 (patch) | |
tree | 242c97650a951f48a5de96b44e0d5c124ea1c212 /pseudocode/operators/TRANSPOSE_CONV2D.tosac | |
parent | 8754ec288dc491f3a9e936e68a1fd35783c9808e (diff) | |
download | specification-a7ac313a13f8f82b4b3ca9730bd746392f6600d9.tar.gz |
Move operator pseudocode to separate files
This makes it easier to process the pseudocode automatically.
Change-Id: I84394192598e589de07d43a7af60b96788e14f86
Signed-off-by: Kevin Petit <kevin.petit@arm.com>
Diffstat (limited to 'pseudocode/operators/TRANSPOSE_CONV2D.tosac')
-rw-r--r-- | pseudocode/operators/TRANSPOSE_CONV2D.tosac | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/pseudocode/operators/TRANSPOSE_CONV2D.tosac b/pseudocode/operators/TRANSPOSE_CONV2D.tosac new file mode 100644 index 0000000..3aa0e23 --- /dev/null +++ b/pseudocode/operators/TRANSPOSE_CONV2D.tosac @@ -0,0 +1,35 @@ +// +// This confidential and proprietary software may be used only as +// authorised by a licensing agreement from ARM Limited +// (C) COPYRIGHT 2020-2024 ARM Limited +// ALL RIGHTS RESERVED +// The entire notice above must be reproduced on all authorised +// copies and copies may only be made to the extent permitted +// by a licensing agreement from ARM Limited. + +ERROR_IF(in_t != i8_t && input_zp != 0); // Zero point only allowed for int8_t +ERROR_IF(weight_t != i8_t && weight_zp != 0); +ERROR_IF(out_pad_top <= -KH || out_pad_bottom <= -KH); +ERROR_IF(out_pad_left <= -KW || out_pad_right <= -KW); +ERROR_IF(stride_y < 1 || stride_x < 1); +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); + } +} |