(M, K, weight_num, BM, BY, bm, by, weight, final_weight)
| 618 | final_weight.append(func_weight) |
| 619 | |
| 620 | def preprocess_three_weights_tl2(M, K, weight_num, BM, BY, bm, by, weight, final_weight): |
| 621 | weight = np.reshape(weight, (weight_num // 3, 3)) |
| 622 | split_weights = np.split(weight, 3, axis=1) |
| 623 | first_weight = np.multiply(split_weights[0], 9) |
| 624 | second_weight = np.multiply(split_weights[1], 3) |
| 625 | third_weight = split_weights[2] |
| 626 | |
| 627 | weight = np.reshape((first_weight + second_weight + third_weight), weight_num // 3) |
| 628 | sign_weight = np.sign(weight) + 2 |
| 629 | sign_weight = np.where(sign_weight > 1, 0, sign_weight) |
| 630 | weight = np.abs(weight) |
| 631 | |
| 632 | # row-major index |
| 633 | weight = np.reshape(weight, (M, K // 3)).astype(np.uint8) |
| 634 | sign_weight = np.reshape(sign_weight, (M, K // 3)).astype(np.uint8) |
| 635 | # print(weight) |
| 636 | |
| 637 | # split in row with size of BM (160) |
| 638 | outer_BM_weights = np.split(weight, (M // BM), axis=0) |
| 639 | for outer_BM_weight in outer_BM_weights: |
| 640 | # split in col with size of by (32index * 3 == 96nums) |
| 641 | outer_BY_weights = np.split(outer_BM_weight, (K // BY), axis=1) |
| 642 | for outer_BY_weight in outer_BY_weights: |
| 643 | # split in row with size of bm (32) |
| 644 | inner_bm_weights = np.split(outer_BY_weight, (BM // bm), axis=0) |
| 645 | for inner_bm_weight in inner_bm_weights: |
| 646 | # split in col with size of by (2index * 3 == 6nums) |
| 647 | inner_by_weights = np.split(inner_bm_weight, (BY // by), axis=1) |
| 648 | for inner_by_weight in inner_by_weights: |
| 649 | func_weights = np.split(inner_by_weight, 2, axis=1) |
| 650 | |
| 651 | left_weight = func_weights[0] |
| 652 | left_sub_weights = np.split(left_weight, 4, axis=0) |
| 653 | new_left_weight = np.reshape( |
| 654 | np.concatenate([left_sub_weights[0], left_sub_weights[2], |
| 655 | left_sub_weights[1], left_sub_weights[3]], axis=0, dtype=np.uint8), |
| 656 | (bm)) |
| 657 | |
| 658 | right_weight = func_weights[1] |
| 659 | right_sub_weights = np.split(right_weight, 4, axis=0) |
| 660 | |
| 661 | new_right_weight = np.reshape( |
| 662 | np.concatenate([right_sub_weights[0], right_sub_weights[2], |
| 663 | right_sub_weights[1], right_sub_weights[3]], axis=0, dtype=np.uint8), |
| 664 | (bm)) |
| 665 | hi_weight = new_left_weight.astype(np.uint8) << 4 |
| 666 | lo_weight = new_right_weight |
| 667 | func_weight = hi_weight + lo_weight |
| 668 | func_weight = np.reshape(func_weight, bm * by // 6) |
| 669 | final_weight.append(func_weight) |
| 670 | |
| 671 | sign_weight_list = [] |
| 672 | sign_outer_BM_weights = np.split(sign_weight, (M // BM), axis=0) |
| 673 | for sign_outer_BM_weight in sign_outer_BM_weights: |
| 674 | # split in col with size of by (32index * 3 == 96nums) |
| 675 | sign_outer_BY_weights = np.split(sign_outer_BM_weight, (K // BY), axis=1) |
| 676 | for sign_outer_BY_weight in sign_outer_BY_weights: |
| 677 | # split in row with size of bm (32) |
no test coverage detected