onnx2versal
Loading...
Searching...
No Matches
graph_qlinearpool.h
1#ifndef __QLINEARPOOL_GRAPH_H__
2#define __QLINEARPOOL_GRAPH_H__
3
4#include <adf.h>
5#include "qlinearpool.h"
6#include "graph_concat.h"
7#include "graph_split.h"
8
9
38template <template<typename, int, int, int, int, int, int, int, int> class QLINEARPOOL,
39 typename TT, int INP_H, int INP_W, int OUT_H, int OUT_W, int B, int C, int KH, int KW>
40class QLinearPoolGraph : public adf::graph {
41
42 private:
43 adf::kernel k[1];
44 std::string id;
45
46 public:
47 adf::port<input> pin[1];
48 adf::port<output> pout[1];
49
51 float in_scale,
52 float out_scale,
53 int8_t in_zero,
54 int8_t out_zero
55 ) {
56 k[0] = adf::kernel::create_object<QLINEARPOOL<TT, INP_H, INP_W, OUT_H, OUT_W, B, C, KH, KW>>(
57 in_scale, out_scale, in_zero, out_zero);
58 adf::source(k[0]) = "qlinearpool.cc";
59 adf::headers(k[0]) = {"qlinearpool.h"};
60 adf::runtime<ratio>(k[0]) = 0.6;
61
62 adf::connect<adf::window<B*INP_H*INP_W*C*sizeof(TT)>> (pin[0], k[0].in[0]);
63 adf::connect<adf::stream> (k[0].out[0], pout[0]);
64
65 adf::samples_per_iteration(k[0].out[0]) = B*C*OUT_H*OUT_W;
66 }
67
68};
69
70
79template <
80 template<typename, int, int, int, int> class SPLIT,
81 template<typename, int, int, int, int, int, int, int, int> class QLINEARPOOL,
82 template<typename, int, int, int, int> class CONCAT,
83 int CCHUNK,
84 typename TT, int INP_H, int INP_W, int OUT_H, int OUT_W, int B, int C, int KH, int KW>
85class QLinearPoolChunkCGraph : public adf::graph {
86
87 private:
88 static constexpr int LCNT = C/CCHUNK;
89 ConcatStreamGraph<CONCAT, TT, LCNT, B, CCHUNK*OUT_H*OUT_W, C*OUT_H*OUT_W> concat_graph;
90
91 adf::kernel split[(LCNT+1)/2];
92 adf::kernel k[LCNT];
93 std::string id;
94
95 public:
96 adf::port<input> pin[1];
97 adf::port<output> pout[1];
98
100 float in_scale,
101 float out_scale,
102 int8_t in_zero,
103 int8_t out_zero
104 ) {
105 static_assert(C % CCHUNK == 0);
106 static_assert(LCNT <= 8);
107
108 for (int i = 0; i < LCNT/2; i++) {
109 split[i] = adf::kernel::create_object<SplitFilterInt8StreamTwice<TT, B, C*INP_H*INP_W, CCHUNK*INP_H*INP_W, 0>>(i*2);
110 adf::source(split[i]) = "split.cc";
111 adf::headers(split[i]) = {"split.h"};
112 adf::runtime<ratio>(split[i]) = 0.6;
113
114 adf::connect<adf::stream> (pin[0], split[i].in[0]);
115 adf::samples_per_iteration(split[i].in[0]) = B*C*INP_H*INP_W;
116 adf::samples_per_iteration(split[i].out[0]) = B*CCHUNK*INP_H*INP_W;
117 adf::samples_per_iteration(split[i].out[1]) = B*CCHUNK*INP_H*INP_W;
118 }
119 if ((LCNT & 0x1) == 1) {
120 int i = (LCNT+1)/2 - 1;
121 split[i] = adf::kernel::create_object<SplitFilterInt8Stream<TT, B, C*INP_H*INP_W, CCHUNK*INP_H*INP_W, 0>>(LCNT-1);
122 adf::source(split[i]) = "split.cc";
123 adf::headers(split[i]) = {"split.h"};
124 adf::runtime<ratio>(split[i]) = 0.6;
125
126 adf::connect<adf::stream> (pin[0], split[i].in[0]);
127 adf::samples_per_iteration(split[i].in[0]) = B*C*INP_H*INP_W;
128 adf::samples_per_iteration(split[i].out[0]) = B*CCHUNK*INP_H*INP_W;
129 }
130
131 for (int i = 0; i < LCNT; i++) {
132 k[i] = adf::kernel::create_object<QLINEARPOOL<TT, INP_H, INP_W, OUT_H, OUT_W, B, CCHUNK, KH, KW>>(
133 in_scale, out_scale, in_zero, out_zero);
134 adf::source(k[i]) = "qlinearpool.cc";
135 adf::headers(k[i]) = {"qlinearpool.h"};
136 adf::runtime<ratio>(k[i]) = 0.6;
137
138 adf::connect<adf::window<B*CCHUNK*INP_H*INP_W>> (split[i/2].out[i&0x1], k[i].in[0]);
139 adf::connect<adf::stream> (k[i].out[0], concat_graph.pin[i]);
140 adf::samples_per_iteration(k[i].out[0]) = B*CCHUNK*OUT_H*OUT_W;
141 }
142
143 adf::connect<adf::stream> (concat_graph.pout[0], pout[0]);
144 }
145
146};
147
148
157template <template<typename, int, int, int, int, int, int, int, int> class QLINEARPOOL,
158 typename TT, int INP_H, int INP_W, int OUT_H, int OUT_W, int B, int C, int KH, int KW>
159class QLinearPoolStreamGraph : public adf::graph {
160
161 private:
162 adf::kernel k[1];
163 std::string id;
164
165 public:
166 adf::port<input> pin[1];
167 adf::port<output> pout[1];
168
170 float in_scale,
171 float out_scale,
172 int8_t in_zero,
173 int8_t out_zero
174 ) {
175 k[0] = adf::kernel::create_object<QLINEARPOOL<TT, INP_H, INP_W, OUT_H, OUT_W, B, C, KH, KW>>(
176 in_scale, out_scale, in_zero, out_zero);
177 adf::source(k[0]) = "qlinearpool.cc";
178 adf::headers(k[0]) = {"qlinearpool.h"};
179 adf::runtime<ratio>(k[0]) = 0.6;
180
181 adf::connect<adf::stream> (pin[0], k[0].in[0]);
182 adf::connect<adf::stream> (k[0].out[0], pout[0]);
183
184 adf::samples_per_iteration(k[0].out[0]) = B*C*OUT_H*OUT_W;
185 }
186
187};
191#endif // __QLINEARPOOL_GRAPH_H__
Multi instance graph.
Definition graph_qlinearpool.h:85
Single instance graph.
Definition graph_qlinearpool.h:40
Single instance graph.
Definition graph_qlinearpool.h:159