Skip to content

Commit

Permalink
Python - tiling all layers
Browse files Browse the repository at this point in the history
  • Loading branch information
Aba committed Oct 26, 2023

Verified

This commit was signed with the committer’s verified signature.
onnovisser Onno Visser
1 parent 383f235 commit 6d14263
Showing 5 changed files with 103 additions and 108 deletions.
24 changes: 12 additions & 12 deletions c/model.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#define N_BUNDLES 7
Bundle_t bundles [N_BUNDLES] = {
{.n=8, .l=2, .kw=11, .coe=2, .coe_tl=2, .r_ll=2, .h=10, .w=8, .ci=3, .co=16, .w_kw2=3, .t=8, .p=3, .cm=1, .cm_p0=1, .w_bpt=272, .w_bpt_p0=272, .x_bpt=840, .x_bpt_p0=840, .is_bias=1, .b_offset=0, .b_val_shift=5, .b_bias_shift=0, .ca_nzero=0, .ca_shift=12, .ca_pl_scale=0, .x_header=414341061322735616, .x_header_p0=414341061322735616, .w_header=414587437826703360, .w_header_p0=414341061322735616 },
{.n=8, .l=2, .kw=1, .coe=24, .coe_tl=0, .r_ll=2, .h=10, .w=8, .ci=16, .co=16, .w_kw2=8, .t=1, .p=1, .cm=20, .cm_p0=16, .w_bpt=392, .w_bpt_p0=392, .x_bpt=13320, .x_bpt_p0=13320, .is_bias=0, .b_offset=16, .b_val_shift=0, .b_bias_shift=0, .ca_nzero=1, .ca_shift=7, .ca_pl_scale=0, .x_header=8700964375684448256, .x_header_p0=8700964375684448256, .w_header=8701210795138088960, .w_header_p0=8700964375684448256 },
{.n=8, .l=2, .kw=7, .coe=3, .coe_tl=4, .r_ll=2, .h=10, .w=8, .ci=16, .co=16, .w_kw2=5, .t=6, .p=8, .cm=2, .cm_p0=2, .w_bpt=344, .w_bpt_p0=344, .x_bpt=1672, .x_bpt_p0=1672, .is_bias=1, .b_offset=16, .b_val_shift=5, .b_bias_shift=0, .ca_nzero=1, .ca_shift=12, .ca_pl_scale=0, .x_header=846686625550303232, .x_header_p0=846686625550303232, .w_header=846933027824074752, .w_header_p0=846686625550303232 },
{.n=8, .l=2, .kw=5, .coe=4, .coe_tl=4, .r_ll=2, .h=10, .w=8, .ci=16, .co=16, .w_kw2=6, .t=4, .p=4, .cm=4, .cm_p0=4, .w_bpt=488, .w_bpt_p0=488, .x_bpt=3336, .x_bpt_p0=3336, .is_bias=0, .b_offset=34, .b_val_shift=0, .b_bias_shift=0, .ca_nzero=1, .ca_shift=10, .ca_pl_scale=3, .x_header=1927550536119222272, .x_header_p0=1927550536119222272, .w_header=1927796989932601344, .w_header_p0=1927550536119222272 },
{.n=8, .l=2, .kw=3, .coe=8, .coe_tl=8, .r_ll=2, .h=10, .w=8, .ci=16, .co=24, .w_kw2=7, .t=3, .p=3, .cm=6, .cm_p0=4, .w_bpt=440, .w_bpt_p0=296, .x_bpt=5000, .x_bpt_p0=3336, .is_bias=1, .b_offset=34, .b_val_shift=5, .b_bias_shift=0, .ca_nzero=0, .ca_shift=12, .ca_pl_scale=0, .x_header=3008414446688141312, .x_header_p0=1855492942081294336, .w_header=3008660883321651200, .w_header_p0=1855492942081294336 },
{.n=8, .l=2, .kw=1, .coe=24, .coe_tl=2, .r_ll=2, .h=10, .w=8, .ci=24, .co=50, .w_kw2=8, .t=3, .p=2, .cm=20, .cm_p0=4, .w_bpt=488, .w_bpt_p0=104, .x_bpt=16648, .x_bpt_p0=3336, .is_bias=0, .b_offset=58, .b_val_shift=0, .b_bias_shift=0, .ca_nzero=1, .ca_shift=10, .ca_pl_scale=3, .x_header=11006807384898142208, .x_header_p0=1783435348043366400, .w_header=11007053838711521280, .w_header_p0=1783435348043366400 },
{.n=1, .l=1, .kw=1, .coe=24, .coe_tl=0, .r_ll=8, .h=8, .w=1, .ci=4000, .co=10, .w_kw2=1, .t=1, .p=200, .cm=20, .cm_p0=20, .w_bpt=488, .w_bpt_p0=488, .x_bpt=138, .x_bpt_p0=138, .is_bias=1, .b_offset=58, .b_val_shift=5, .b_bias_shift=0, .ca_nzero=1, .ca_shift=15, .ca_pl_scale=3, .x_header=10952754293765046272, .x_header_p0=10952754293765046272, .w_header=10952754456973803520, .w_header_p0=10952754293765046272 }
{.n=8, .l=3, .kw=11, .coe=2, .coe_tl=2, .r_ll=2, .h=18, .w=8, .ci=3, .co=16, .w_kw2=3, .t=8, .p=3, .cm=1, .cm_p0=1, .w_bpt=272, .w_bpt_p0=272, .x_bpt=1256, .x_bpt_p0=1256, .is_bias=1, .conv2dense=0, .b_offset=0, .b_val_shift=5, .b_bias_shift=0, .ca_nzero=0, .ca_shift=12, .ca_pl_scale=0, .x_header=414349857415757824, .x_header_p0=414349857415757824, .w_header=414596233919725568, .w_header_p0=414349857415757824 },
{.n=8, .l=3, .kw=1, .coe=24, .coe_tl=0, .r_ll=2, .h=18, .w=8, .ci=16, .co=16, .w_kw2=8, .t=1, .p=1, .cm=20, .cm_p0=16, .w_bpt=392, .w_bpt_p0=392, .x_bpt=19976, .x_bpt_p0=19976, .is_bias=0, .conv2dense=0, .b_offset=16, .b_val_shift=0, .b_bias_shift=0, .ca_nzero=1, .ca_shift=7, .ca_pl_scale=0, .x_header=8700973171777470464, .x_header_p0=8700973171777470464, .w_header=8701219591231111168, .w_header_p0=8700973171777470464 },
{.n=8, .l=3, .kw=7, .coe=3, .coe_tl=4, .r_ll=2, .h=18, .w=8, .ci=16, .co=16, .w_kw2=5, .t=6, .p=8, .cm=2, .cm_p0=2, .w_bpt=344, .w_bpt_p0=344, .x_bpt=2504, .x_bpt_p0=2504, .is_bias=1, .conv2dense=0, .b_offset=16, .b_val_shift=5, .b_bias_shift=0, .ca_nzero=1, .ca_shift=12, .ca_pl_scale=0, .x_header=846695421643325440, .x_header_p0=846695421643325440, .w_header=846941823917096960, .w_header_p0=846695421643325440 },
{.n=8, .l=3, .kw=5, .coe=4, .coe_tl=4, .r_ll=2, .h=18, .w=8, .ci=16, .co=16, .w_kw2=6, .t=4, .p=4, .cm=4, .cm_p0=4, .w_bpt=488, .w_bpt_p0=488, .x_bpt=5000, .x_bpt_p0=5000, .is_bias=0, .conv2dense=0, .b_offset=34, .b_val_shift=0, .b_bias_shift=0, .ca_nzero=1, .ca_shift=10, .ca_pl_scale=3, .x_header=1927559332212244480, .x_header_p0=1927559332212244480, .w_header=1927805786025623552, .w_header_p0=1927559332212244480 },
{.n=8, .l=3, .kw=3, .coe=8, .coe_tl=8, .r_ll=2, .h=18, .w=8, .ci=16, .co=24, .w_kw2=7, .t=3, .p=3, .cm=6, .cm_p0=4, .w_bpt=440, .w_bpt_p0=296, .x_bpt=7496, .x_bpt_p0=5000, .is_bias=1, .conv2dense=0, .b_offset=34, .b_val_shift=5, .b_bias_shift=0, .ca_nzero=0, .ca_shift=12, .ca_pl_scale=0, .x_header=3008423242781163520, .x_header_p0=1855501738174316544, .w_header=3008669679414673408, .w_header_p0=1855501738174316544 },
{.n=8, .l=3, .kw=1, .coe=24, .coe_tl=2, .r_ll=2, .h=18, .w=8, .ci=24, .co=50, .w_kw2=8, .t=3, .p=2, .cm=20, .cm_p0=4, .w_bpt=488, .w_bpt_p0=104, .x_bpt=24968, .x_bpt_p0=5000, .is_bias=0, .conv2dense=1, .b_offset=58, .b_val_shift=0, .b_bias_shift=0, .ca_nzero=1, .ca_shift=10, .ca_pl_scale=3, .x_header=11006816180991164416, .x_header_p0=1783444144136388608, .w_header=11007062634804543488, .w_header_p0=1783444144136388608 },
{.n=1, .l=1, .kw=1, .coe=24, .coe_tl=0, .r_ll=8, .h=8, .w=1, .ci=7200, .co=10, .w_kw2=1, .t=1, .p=360, .cm=20, .cm_p0=20, .w_bpt=488, .w_bpt_p0=488, .x_bpt=138, .x_bpt_p0=138, .is_bias=1, .conv2dense=0, .b_offset=58, .b_val_shift=5, .b_bias_shift=0, .ca_nzero=1, .ca_shift=15, .ca_pl_scale=3, .x_header=10952754293765046272, .x_header_p0=10952754293765046272, .w_header=10952754456973803520, .w_header_p0=10952754293765046272 }
};

#define X_BITS_L2 2
@@ -16,11 +16,11 @@ Bundle_t bundles [N_BUNDLES] = {
#define PE_ROWS 8
#define PE_COLS 24

#define WB_BYTES 134308
#define W_BYTES 134144
#define X_BYTES 2520
#define X_BYTES_ALL 103480
#define Y_BYTES 294920
#define WB_BYTES 212388
#define W_BYTES 212224
#define X_BYTES 3768
#define X_BYTES_ALL 163416
#define Y_BYTES 442376
#define B_TYPE signed short
#define B_WORDS 82
#define DATA_DIR "D:/dnn-engine/test/vectors"
2 changes: 1 addition & 1 deletion c/runtime.h
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
typedef struct {
const int n, l, kw, coe, coe_tl, r_ll, h, w, ci, co, w_kw2, t, p, cm, cm_p0;
const int w_bpt, w_bpt_p0, x_bpt, x_bpt_p0; // bytes per transfer
const char is_bias;
const char is_bias, conv2dense;
const int b_offset, b_val_shift, b_bias_shift;
const signed char ca_nzero, ca_shift, ca_pl_scale;
const unsigned long long x_header, x_header_p0, w_header, w_header_p0; // 64 bits (at least)
4 changes: 2 additions & 2 deletions test/py/bundle.py
Original file line number Diff line number Diff line change
@@ -420,7 +420,7 @@ def clog2(x):
c = namedtuple('Compile', params)(**params)
return c

def export (self, c):
def export (self, c, is_last):

if self.core['type'] != 'conv':
print('Conv -> Dense Reshape')
@@ -458,7 +458,7 @@ def export (self, c):
self.xe = self.reorder_x_q2e_conv(x_int, c, r)
self.ye_exp = self.reorder_y_q2e_conv(y_int, c, r)
self.o_int = o_int
self.oe_exp = self.reorder_y_q2e_conv(o_int, c, r)
self.oe_exp = o_int if is_last else self.reorder_y_q2e_conv(o_int, c, r)
print(f"x reshape: [int]:{self.inp['int'].shape}, int:{x_int.shape}. xe:{self.xe[0].shape}")

'''
8 changes: 4 additions & 4 deletions test/py/param_test.py
Original file line number Diff line number Diff line change
@@ -189,7 +189,7 @@ class Config:
def test_dnn_engine(COMPILE):
c = make_compile_params(COMPILE)

input_shape = (8,10,8,3) # (XN, XH, XW, CI)
input_shape = (8,18,8,3) # (XN, XH, XW, CI)
model_config = [
Config(11, 16, True , f'quantized_relu({c.X_BITS},0,negative_slope=0)'),
Config(1 , 16, False, f'quantized_bits({c.X_BITS},0,False,False,1)'),
@@ -240,10 +240,10 @@ def test_dnn_engine(COMPILE):
'''
Export
'''
for b in bundles:
for ib, b in enumerate(bundles):
print(f'-----------------{b.idx}-----------------------')
b.process(inp if b.idx==0 else None, c)
b.export(c)
b.export(c, ib==len(bundles)-1)



@@ -280,7 +280,7 @@ def test_dnn_engine(COMPILE):

ca_nzero, ca_shift, ca_pl_scale = b.core['act']['non_zero'], b.core['act']['shift_bits'], b.core['act']['plog_slope']

ch.write(f" {{.n={b.r.XN}, .l={b.r.L}, .kw={b.r.KW}, .coe={y_coe}, .coe_tl={y_coe_tl}, .r_ll={y_r_ll}, .h={b.r.XH}, .w={b.r.XW}, .ci={b.r.CI}, .co={b.r.CO}, .w_kw2={b.r.XW-b.r.KW//2}, .t={b.r.IT}, .p={b.r.CP}, .cm={b.r.CM}, .cm_p0={b.r.CM_0}, .w_bpt={w_bpt}, .w_bpt_p0={w_bpt_p0}, .x_bpt={x_bpt}, .x_bpt_p0={x_bpt_p0}, .is_bias={1*(b.b is not None)}, .b_offset={b_words}, .b_val_shift={b.bias_val_shift}, .b_bias_shift={b.bias_b_shift}, .ca_nzero={ca_nzero}, .ca_shift={ca_shift}, .ca_pl_scale={ca_pl_scale}, .x_header={b.r.x_header_be_p[-1][0]}, .x_header_p0={b.r.x_header_be_p[0][0]}, .w_header={b.r.w_header_be_p[-1][0]}, .w_header_p0={b.r.x_header_be_p[0][0]} }}")
ch.write(f" {{.n={b.r.XN}, .l={b.r.L}, .kw={b.r.KW}, .coe={y_coe}, .coe_tl={y_coe_tl}, .r_ll={y_r_ll}, .h={b.r.XH}, .w={b.r.XW}, .ci={b.r.CI}, .co={b.r.CO}, .w_kw2={b.r.XW-b.r.KW//2}, .t={b.r.IT}, .p={b.r.CP}, .cm={b.r.CM}, .cm_p0={b.r.CM_0}, .w_bpt={w_bpt}, .w_bpt_p0={w_bpt_p0}, .x_bpt={x_bpt}, .x_bpt_p0={x_bpt_p0}, .is_bias={1*(b.b is not None)}, .conv2dense={1*b.flatten}, .b_offset={b_words}, .b_val_shift={b.bias_val_shift}, .b_bias_shift={b.bias_b_shift}, .ca_nzero={ca_nzero}, .ca_shift={ca_shift}, .ca_pl_scale={ca_pl_scale}, .x_header={b.r.x_header_be_p[-1][0]}, .x_header_p0={b.r.x_header_be_p[0][0]}, .w_header={b.r.w_header_be_p[-1][0]}, .w_header_p0={b.r.x_header_be_p[0][0]} }}")

b_words += b.be.size if b.b else 0
if b.idx != len(bundles)-1:
Loading

0 comments on commit 6d14263

Please sign in to comment.