aboutsummaryrefslogtreecommitdiff
path: root/pseudocode/operators/FULLY_CONNECTED.tosac
blob: fbacccc24f126bbba7cf7eba429a37698fbf3439 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//
// 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 for int8_t
ERROR_IF(weight_t != i8_t && weight_zp != 0);
ERROR_IF(BC != OC && BC != 1);

for_each(0 <= n < N, 0 <= oc < OC) {
    out_t acc = 0;
    for_each(0 <= ic < IC) {
        out_t value  = static_cast<out_t>(tensor_read<in_t>(input, [N,IC], [n,ic]));
        out_t weight = static_cast<out_t>(tensor_read<weight_t>(weight, [OC,IC], [oc,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));
    }
    acc = apply_add_s<out_t>(acc, bias[(BC == 1) ? 0 : oc]);
    tensor_write<out_t>(output, [N,OC], [n,oc], acc);
}