summaryrefslogtreecommitdiff
path: root/python/openvino/demo/ip/intel_ai_ip/verilog/dla_lt_pkg.sv
blob: a7e2e46e9f7b7273885e85e98976e41bfd2077d6 (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Copyright 2020-2024 Intel Corporation.
//
// This software and the related documents are Intel copyrighted materials,
// and your use of them is governed by the express license under which they
// were provided to you ("License"). Unless the License provides otherwise,
// you may not use, modify, copy, publish, distribute, disclose or transmit
// this software or the related documents without Intel's prior written
// permission.
//
// This software and the related documents are provided as is, with no express
// or implied warranties, other than those that are expressly stated in the
// License.


`resetall
`undefineall
`default_nettype none

package dla_lt_pkg;

  import dla_common_pkg::*;

  function int calc_max_partitions;
    input int height, width, channels, stride_height, stride_width, elem_per_ddr;
    static int max_s[1:0] = '{default :'0};
    static int init_s[1:0] = '{default :'0};
    static int distance = 0;
    static int partitions = 0;
    static int s_w = 0;
    static int s_h = 0;
    static int in_w = 0;
    static int in_h = 0;
    static int c = 0;
    static int h = 0;
    static int w = 0;
  begin

    if (elem_per_ddr > height * width * channels)
      elem_per_ddr = height * width * channels - 1;
    for (integer i = 0; i < (height * width * channels); i++)
    begin
      if (i % elem_per_ddr == 0)
      begin
        distance = max_s[0] - init_s[0] + ((max_s[1] - init_s[1]) * (width / stride_width));
        partitions = (distance > partitions) ? distance : partitions;
        init_s[0] = s_w;
        init_s[1] = s_h;
        max_s = init_s;
      end

      if (s_w > max_s[0])
      begin
        max_s[0] = s_w;
      end

      if (s_h > max_s[1])
      begin
        max_s[1] = s_h;
      end

      c += 1;

      if (c >= channels)
      begin
        c = 0;
        w += 1;
        in_w += 1;
      end

      if (w >= width)
      begin
        w = 0;
        in_w = 0;
        s_w = 0;
        h += 1;
        in_h += 1;
      end

      if (h >= height)
      begin
        h = 0;
        s_h = 0;
        in_h = 0;
      end

      if (in_w >= stride_width)
      begin
        in_w = 0;
        s_w += 1;
      end

      if (in_h >= stride_height)
      begin
        in_h = 0;
        s_h += 1;
      end
    end

    calc_max_partitions = (partitions + 1) < 2? 2 : (partitions + 1);
  end
  endfunction

  typedef struct {
    int ENABLE_LT;
    int DATA_ELEMENT_WIDTH;
    int CNT_BITS;
    int DO_U8_CONV;
    int DDR_BYTES;
    int CONFIG_BYTES;
    int MAX_CHANNELS;
    int MAX_FEATURE_HEIGHT;
    int MAX_FEATURE_WIDTH;
    int MAX_FEATURE_DEPTH;
    int MAX_STRIDE_HEIGHT;
    int MAX_STRIDE_WIDTH;
    int MAX_STRIDE_DEPTH;
    int CVEC;
    int MAX_PAD_FRONT;
    int MAX_PAD_LEFT;
    int MAX_PAD_TOP;
    int MAX_FILTER_HEIGHT;
    int MAX_FILTER_WIDTH;
    int MAX_FILTER_DEPTH;
    int MAX_DILATION_WIDTH;
    int MAX_DILATION_HEIGHT;
    int MAX_DILATION_DEPTH;
    device_family_t DEVICE;       // device
  } lt_arch_t;

  enum {VALID, INNER_LINE, CVEC_IDX, STRIDE_IDX, C_STRIDE, NEW_LINE} address_info_e;

  `include "dla_layout_transform_config.svh"

endpackage