onnx2versal
Loading...
Searching...
No Matches
graph_split.h
1#ifndef __SPLIT_GRAPH_H__
2#define __SPLIT_GRAPH_H__
3
4#include <assert.h>
5#include <adf.h>
6#include "split.h"
7
35template <template<typename, int, int, int, int> class SPLIT,
36 typename TT, int H, int INP_W, int OUT_W, int OVERLAP = 0>
37class SplitGraph : public adf::graph {
38
39 public:
40 static constexpr int LCNT = (INP_W - OUT_W) / (OUT_W - OVERLAP) + 1;
41
42 adf::kernel k[1];
43 adf::port<input> pin[1];
44 adf::port<output> pout[LCNT];
45
46 SplitGraph() {
47 static_assert(LCNT <= 8);
48 k[0] = adf::kernel::create_object<SPLIT<TT, H, INP_W, OUT_W, OVERLAP>>();
49 adf::source(k[0]) = "split.cc";
50 adf::headers(k[0]) = {"split.h"};
51 adf::runtime<ratio>(k[0]) = 0.6;
52
53 adf::connect<adf::stream> (pin[0], k[0].in[0]);
54 adf::samples_per_iteration(k[0].in[0]) = H*INP_W;
55
56 for (int i = 0; i < LCNT; i++) {
57 adf::connect<adf::window<H*OUT_W*sizeof(TT)>> (k[0].out[i], pout[i]);
58 adf::single_buffer(k[0].out[i]);
59 }
60 }
61
62};
63
73template <template<typename, int, int, int, int> class SPLIT,
74 typename TT, int H, int INP_W, int OUT_W, int OVERLAP = 0>
75class SplitTwoStreamGraph : public adf::graph {
76
77 public:
78 static constexpr int LCNT = (INP_W - OUT_W) / (OUT_W - OVERLAP) + 1;
79 adf::kernel k[1];
80 adf::port<input> pin[1];
81 adf::port<output> pout[2];
82
84 k[0] = adf::kernel::create_object<SPLIT<TT, H, INP_W, OUT_W, OVERLAP>>();
85 adf::source(k[0]) = "split.cc";
86 adf::headers(k[0]) = {"split.h"};
87 adf::runtime<ratio>(k[0]) = 0.6;
88
89 adf::connect<adf::stream> (pin[0], k[0].in[0]);
90 adf::connect<adf::stream> (k[0].out[0], pout[0]);
91 adf::connect<adf::stream> (k[0].out[1], pout[1]);
92
93 adf::samples_per_iteration(k[0].in[0]) = H*INP_W;
94 adf::samples_per_iteration(k[0].out[0]) = H*OUT_W* ((LCNT+1)/2);
95 adf::samples_per_iteration(k[0].out[1]) = H*OUT_W* (LCNT/2);
96 }
97
98};
99
100
109template <template<typename, int, int, int, int> class SPLIT,
110 typename TT, int H, int INP_W, int OUT_W, int OVERLAP = 0>
111class SplitFilterStreamGraph : public adf::graph {
112
113 public:
114 static constexpr int LCNT = (INP_W - OUT_W) / (OUT_W - OVERLAP) + 1;
115 adf::kernel k[1];
116 adf::port<input> pin[1];
117 adf::port<output> pout[1];
118
120 int lane_idx
121 ) {
122 k[0] = adf::kernel::create_object<SPLIT<TT, H, INP_W, OUT_W, OVERLAP>>(lane_idx);
123 adf::source(k[0]) = "split.cc";
124 adf::headers(k[0]) = {"split.h"};
125 adf::runtime<ratio>(k[0]) = 0.6;
126
127 adf::connect<adf::stream> (pin[0], k[0].in[0]);
128 adf::connect<adf::stream> (k[0].out[0], pout[0]);
129
130 adf::samples_per_iteration(k[0].in[0]) = H*INP_W;
131 adf::samples_per_iteration(k[0].out[0]) = H*OUT_W;
132 }
133
134};
135
136
145template <template<typename, int, int, int, int> class SPLIT,
146 typename TT, int H, int INP_W, int OUT_W, int OVERLAP = 0>
147class SplitFilterStreamTwiceGraph : public adf::graph {
148
149 public:
150 static constexpr int LCNT = (INP_W - OUT_W) / (OUT_W - OVERLAP) + 1;
151 adf::kernel k[1];
152 adf::port<input> pin[1];
153 adf::port<output> pout[2];
154
156 int lane_idx
157 ) {
158 k[0] = adf::kernel::create_object<SPLIT<TT, H, INP_W, OUT_W, OVERLAP>>(lane_idx);
159 adf::source(k[0]) = "split.cc";
160 adf::headers(k[0]) = {"split.h"};
161 adf::runtime<ratio>(k[0]) = 0.6;
162
163 adf::connect<adf::stream> (pin[0], k[0].in[0]);
164 adf::connect<adf::stream> (k[0].out[0], pout[0]);
165 adf::connect<adf::stream> (k[0].out[1], pout[1]);
166
167 adf::samples_per_iteration(k[0].in[0]) = H*INP_W;
168 adf::samples_per_iteration(k[0].out[0]) = H*OUT_W;
169 adf::samples_per_iteration(k[0].out[1]) = H*OUT_W;
170 }
171
172};
173
174
183template <template<typename, int, int, int, int> class SPLIT,
184 typename TT, int H, int INP_W, int OUT_W, int OVERLAP = 0>
185class SplitFilterPktStreamGraph : public adf::graph {
186
187 public:
188 static constexpr int LCNT = (INP_W - OUT_W) / (OUT_W - OVERLAP) + 1;
189 adf::kernel k[1];
190 adf::port<input> pin[1];
191 adf::port<output> pout[LCNT];
192
193 adf::pktsplit<(LCNT+1)/2> sp0;
194 adf::pktsplit<LCNT/2> sp1;
195
197 k[0] = adf::kernel::create_object<SPLIT<TT, H, INP_W, OUT_W, OVERLAP>>();
198 adf::source(k[0]) = "split.cc";
199 adf::headers(k[0]) = {"split.h"};
200 adf::runtime<ratio>(k[0]) = 0.6;
201
202 adf::connect<adf::stream> (pin[0], k[0].in[0]);
203 adf::samples_per_iteration(k[0].in[0]) = H*INP_W;
204
205 sp0 = adf::pktsplit<(LCNT+1)/2>::create();
206 for (int i = 0; i < (LCNT+1)/2; i++) {
207 adf::connect<adf::pktstream, adf::stream> (sp0.out[i], pout[2*i]);
208 adf::samples_per_iteration(sp0.out[i]) = H*OUT_W;
209 }
210 adf::connect<adf::pktstream> (k[0].out[0], sp0.in[0]);
211
212 sp1 = adf::pktsplit<LCNT/2>::create();
213 for (int i = 0; i < LCNT/2; i++) {
214 adf::connect<adf::pktstream, adf::stream> (sp1.out[i], pout[2*i+1]);
215 adf::samples_per_iteration(sp1.out[i]) = H*OUT_W;
216 }
217 adf::connect<adf::pktstream> (k[0].out[1], sp1.in[0]);
218 }
219
220};
224#endif // __SPLIT_GRAPH_H__
Graph wrapper for two stream split.
Definition graph_split.h:185
Graph wrapper for two stream split.
Definition graph_split.h:111
Graph wrapper for two stream split.
Definition graph_split.h:147
Graph wrapper for arbitrary split kernel implementation and lanes.
Definition graph_split.h:37
Graph wrapper for two stream split.
Definition graph_split.h:75