1#ifndef __POOL_GRAPH_H__
2#define __POOL_GRAPH_H__
7#include "graph_split.h"
8#include "graph_concat.h"
42template <
template<
typename,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int>
class POOL,
43 typename TT,
int INP_H,
int INP_W,
int INP_W_PAD,
int OUT_H,
int OUT_W,
int B,
int C,
int KH,
int KW,
int STEP_H,
int STEP_W,
44 template<
typename,
int,
int,
int,
int,
int,
int,
int,
int>
class PAD,
45 int H0 = 0,
int H1 = 0,
int W0 = 0,
int W1 = 0>
49 static constexpr int PAD_H = INP_H + H0 + H1;
50 static constexpr int PAD_W = INP_W + W0 + W1;
54 std::vector<adf::kernel> pad;
57 adf::port<input> pin[1];
58 adf::port<output> pout[1];
61 k[0] = adf::kernel::create_object<POOL<TT, PAD_H, PAD_W, OUT_H, OUT_W, B, C, KH, KW, STEP_H, STEP_W>>();
62 adf::source(k[0]) =
"pool.cc";
63 adf::headers(k[0]) = {
"pool.h"};
64 adf::runtime<ratio>(k[0]) = 0.6;
66 adf::connect<adf::window<B*OUT_H*OUT_W*C*
sizeof(TT)>> (k[0].out[0], pout[0]);
68 if (H0+H1+W0+W1 != 0) {
70 adf::kernel::create_object<PAD<TT, B*C, INP_H, INP_W, INP_W_PAD, H0, H1, W0, W1>>());
71 adf::source(pad[0]) =
"pad.cc";
72 adf::headers(pad[0]) = {
"pad.h"};
73 adf::runtime<ratio>(pad[0]) = 0.6;
75 adf::connect<adf::stream> (pin[0], pad[0].in[0]);
76 adf::connect<adf::window<B*PAD_H*PAD_W*C*
sizeof(TT)>> (pad[0].out[0], k[0].in[0]);
78 adf::samples_per_iteration(pad[0].in[0]) = B*C*INP_H*INP_W_PAD;
79 adf::samples_per_iteration(pad[0].out[0]) = B*C*PAD_H*PAD_W;
81 adf::connect<adf::window<B*INP_H*INP_W*C*
sizeof(TT)>> (pin[0], k[0].in[0]);
89 template<
typename,
int,
int,
int,
int>
class SPLIT,
90 template<
typename,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int>
class POOL,
91 template<
typename,
int,
int,
int,
int>
class CONCAT,
93 typename TT,
int INP_H,
int INP_W,
int INP_W_PAD,
int OUT_H,
int OUT_W,
int B,
int C,
int KH,
int KW,
int STEP_H,
int STEP_W,
94 template<
typename,
int,
int,
int,
int,
int,
int,
int,
int>
class PAD,
95 int H0 = 0,
int H1 = 0,
int W0 = 0,
int W1 = 0>
96class PoolChunkCGraph :
public adf::graph {
99 static constexpr int PAD_H = INP_H + H0 + H1;
100 static constexpr int PAD_W = INP_W + W0 + W1;
103 mSplitGraph split_graph;
104 static constexpr int LCNT = mSplitGraph::LCNT;
105 ConcatStreamGraph<CONCAT, TT, LCNT, B, CCHUNK*OUT_H*OUT_W, C*OUT_H*OUT_W> concat_graph;
107 std::vector<adf::kernel> pad;
112 adf::port<input> pin[1];
113 adf::port<output> pout[1];
118 static_assert(LCNT <= 8);
120 for (
int i = 0; i < LCNT; i++) {
121 k[i] = adf::kernel::create_object<POOL<TT, PAD_H, PAD_W, OUT_H, OUT_W, B, CCHUNK, KH, KW, STEP_H, STEP_W>>();
122 adf::source(k[i]) =
"pool.cc";
123 adf::headers(k[i]) = {
"pool.h"};
124 adf::runtime<ratio>(k[i]) = 0.6;
125 adf::repetition_count(k[i]) = repeat_cnt;
127 adf::connect<adf::window<B*CCHUNK*PAD_H*PAD_W*
sizeof(TT)>> (split_graph.pout[i], k[i].in[0]);
128 adf::connect<adf::window<B*CCHUNK*OUT_H*OUT_W*
sizeof(TT)>> (k[i].out[0], concat_graph.pin[i]);
131 adf::connect<adf::stream> (concat_graph.pout[0], pout[0]);
133 if (H0+H1+W0+W1 != 0) {
135 adf::kernel::create_object<PAD<TT, B*C, INP_H, INP_W, INP_W_PAD, H0, H1, W0, W1>>());
136 adf::source(pad[0]) =
"pad.cc";
137 adf::headers(pad[0]) = {
"pad.h"};
138 adf::runtime<ratio>(pad[0]) = 0.6;
139 adf::repetition_count(pad[0]) = repeat_cnt;
141 adf::connect<adf::stream> (pin[0], pad[0].in[0]);
142 adf::connect<adf::stream> (pad[0].out[0], split_graph.pin[0]);
144 adf::samples_per_iteration(pad[0].in[0]) = B*C*INP_H*INP_W_PAD;
145 adf::samples_per_iteration(pad[0].out[0]) = B*C*PAD_H*PAD_W;
147 adf::connect<adf::stream> (pin[0], split_graph.pin[0]);
151 for (
int i = 0; i < LCNT; i++) {
153 adf::location<adf::kernel>(k[i]) = adf::location<adf::kernel>(k[i-1]) + adf::relative_offset({.col_offset=1, .row_offset=1});
154 }
else if ((i&0x3) == 3) {
155 adf::location<adf::kernel>(k[i]) = adf::location<adf::kernel>(k[i-1]) + adf::relative_offset({.col_offset=-1, .row_offset=1});
156 }
else if ((i&0x3) == 2) {
157 adf::location<adf::kernel>(k[i]) = adf::location<adf::kernel>(k[i-1]) + adf::relative_offset({.col_offset=1, .row_offset=0});
159 adf::location<adf::kernel>(k[i]) = adf::location<adf::kernel>(k[i-1]) + adf::relative_offset({.col_offset=-1, .row_offset=0});
161 adf::location<adf::buffer>(k[i].in[0]) = adf::location<adf::kernel>(k[i]);
164 for (
int i = 0; i < concat_graph.k1.size(); i++) {
165 adf::location<adf::kernel>(concat_graph.k1[i]) =
166 adf::location<adf::kernel>(k[2*i]) + adf::relative_offset({.col_offset=0, .row_offset=1});
168 adf::location_constraint cTilePos = adf::location<adf::kernel>(concat_graph.k1[i]);
169 adf::location<adf::buffer>(k[i*2].out[0]) = cTilePos;
170 adf::location<adf::buffer>(k[i*2].out[0]) = {adf::offset(0), adf::offset(8192)};
171 adf::location<adf::stack>(k[i*2]) = cTilePos;
172 adf::location<adf::buffer>(k[i*2+1].out[0]) = cTilePos;
173 adf::location<adf::buffer>(k[i*2+1].out[0]) = {adf::offset(16384), adf::offset(24576)};
174 adf::location<adf::stack>(k[i*2+1]) = cTilePos;
175 adf::location<adf::stack>(concat_graph.k1[i]) = cTilePos;
Single instance graph.
Definition graph_pool.h:46
Graph wrapper for two stream split.
Definition graph_split.h:185