@@ -20,13 +20,19 @@ namespace ion {
20
20
* Port class is used to create dynamic i/o for each node.
21
21
*/
22
22
class Port {
23
+ public:
24
+ using Channel = std::tuple<std::string, std::string>;
23
25
26
+ private:
24
27
struct Impl {
25
- std::string pred_id;
26
- std::string pred_name;
28
+ // std::string pred_id;
29
+ // std::string pred_name;
30
+
31
+ // std::string succ_id;
32
+ // std::string succ_name;
27
33
28
- std::string succ_id ;
29
- std::string succ_name ;
34
+ Channel pred_chan ;
35
+ std::set<Channel> succ_chans ;
30
36
31
37
Halide::Type type;
32
38
int32_t dimensions;
@@ -36,10 +42,10 @@ class Port {
36
42
37
43
Impl () {}
38
44
39
- Impl (const std::string& pid, const std::string& pn, const std::string& sid, const std::string& sn, const Halide::Type& t, int32_t d)
40
- : pred_id( pid), pred_name(pn), succ_id(sid), succ_name(sn) , type(t), dimensions(d)
45
+ Impl (const std::string& pid, const std::string& pn, const Halide::Type& t, int32_t d)
46
+ : pred_chan{. node_id = pid, . name =pn}, succ_chans{} , type(t), dimensions(d)
41
47
{
42
- params[0 ] = Halide::Internal::Parameter (type, dimensions != 0 , dimensions, argument_name (pid, pn, sid, sn, 0 ));
48
+ params[0 ] = Halide::Internal::Parameter (type, dimensions != 0 , dimensions, argument_name (pid, pn, 0 ));
43
49
}
44
50
};
45
51
@@ -48,42 +54,41 @@ class Port {
48
54
friend class Node ;
49
55
friend class nlohmann ::adl_serializer<Port>;
50
56
51
- Port () : impl_(new Impl(" " , " " , " " , " " , Halide::Type(), 0 )), index_(-1 ) {}
57
+ Port () : impl_(new Impl(" " , " " , Halide::Type(), 0 )), index_(-1 ) {}
52
58
Port (const std::shared_ptr<Impl>& impl) : impl_(impl), index_(-1 ) {}
53
59
54
60
/* *
55
61
* Construct new port for scalar value.
56
62
* @arg k: The key of the port which should be matched with BuildingBlock Input/Output name.
57
63
* @arg t: The type of the value.
58
64
*/
59
- Port (const std::string& n, Halide::Type t) : impl_(new Impl(" " , " " , " " , n, t, 0 )), index_(-1 ) {}
65
+ Port (const std::string& n, Halide::Type t) : impl_(new Impl(" " , n, t, 0 )), index_(-1 ) {}
60
66
61
67
/* *
62
68
* Construct new port for vector value.
63
69
* @arg k: The key of the port which should be matched with BuildingBlock Input/Output name.
64
70
* @arg t: The type of the element value.
65
71
* @arg d: The dimension of the port. The range is 1 to 4.
66
72
*/
67
- Port (const std::string& n, Halide::Type t, int32_t d) : impl_(new Impl(" " , " " , " " , n, t, d)), index_(-1 ) {}
73
+ Port (const std::string& n, Halide::Type t, int32_t d) : impl_(new Impl(" " , n, t, d)), index_(-1 ) {}
68
74
69
- const std::string& pred_name () const { return impl_->pred_name ; }
70
- const std::string& succ_name () const { return impl_->succ_name ; }
75
+ const std::string& pred_id () const { return std::get< 0 >( impl_->pred_chan ) ; }
76
+ const std::string& pred_name () const { return std::get< 1 >( impl_->pred_chan ) ; }
71
77
72
78
const Halide::Type& type () const { return impl_->type ; }
73
79
74
80
int32_t dimensions () const { return impl_->dimensions ; }
75
81
76
- const std::string& pred_id () const { return impl_->pred_id ; }
77
-
78
- const std::string& succ_id () const { return impl_->succ_id ; }
82
+ // const std::string& succ_id() const { return impl_->succ_id; }
79
83
80
84
int32_t size () const { return impl_->params .size (); }
81
85
82
86
int32_t index () const { return index_; }
83
87
84
- bool has_pred () const { return !pred_id ( ).empty (); }
88
+ bool has_pred () const { return !std::get< 0 >(impl_-> pred_chan ).empty (); }
85
89
86
- bool has_succ () const { return !succ_id ().empty (); }
90
+ bool has_succ () const { return !impl_->succ_chans .empty (); }
91
+ bool has_succ (const Channel& c) const { return impl_->succ_chans .count (c); }
87
92
88
93
void set_index (int index) { index_ = index; }
89
94
@@ -100,9 +105,9 @@ class Port {
100
105
void bind (T *v) {
101
106
auto i = index_ == -1 ? 0 : index_;
102
107
if (has_pred ()) {
103
- impl_->params [i] = Halide::Internal::Parameter{Halide::type_of<T>(), false , 0 , argument_name (pred_id (), pred_name (), succ_id (), succ_name (), i)};
108
+ impl_->params [i] = Halide::Internal::Parameter{Halide::type_of<T>(), false , 0 , argument_name (pred_id (), pred_name (), i)};
104
109
} else {
105
- impl_->params [i] = Halide::Internal::Parameter{type (), false , dimensions (), argument_name (pred_id (), pred_name (), succ_id (), succ_name (), i)};
110
+ impl_->params [i] = Halide::Internal::Parameter{type (), false , dimensions (), argument_name (pred_id (), pred_name (), i)};
106
111
}
107
112
108
113
impl_->instances [i] = v;
@@ -113,9 +118,9 @@ class Port {
113
118
void bind (const Halide::Buffer<T>& buf) {
114
119
auto i = index_ == -1 ? 0 : index_;
115
120
if (has_pred ()) {
116
- impl_->params [i] = Halide::Internal::Parameter{buf.type (), true , buf.dimensions (), argument_name (pred_id (), pred_name (), succ_id (), succ_name (), i)};
121
+ impl_->params [i] = Halide::Internal::Parameter{buf.type (), true , buf.dimensions (), argument_name (pred_id (), pred_name (), i)};
117
122
} else {
118
- impl_->params [i] = Halide::Internal::Parameter{type (), true , dimensions (), argument_name (pred_id (), pred_name (), succ_id (), succ_name (), i)};
123
+ impl_->params [i] = Halide::Internal::Parameter{type (), true , dimensions (), argument_name (pred_id (), pred_name (), i)};
119
124
}
120
125
121
126
impl_->instances [i] = buf.raw_buffer ();
@@ -125,9 +130,9 @@ class Port {
125
130
void bind (const std::vector<Halide::Buffer<T>>& bufs) {
126
131
for (size_t i=0 ; i<bufs.size (); ++i) {
127
132
if (has_pred ()) {
128
- impl_->params [i] = Halide::Internal::Parameter{bufs[i].type (), true , bufs[i].dimensions (), argument_name (pred_id (), pred_name (), succ_id (), succ_name (), i)};
133
+ impl_->params [i] = Halide::Internal::Parameter{bufs[i].type (), true , bufs[i].dimensions (), argument_name (pred_id (), pred_name (), i)};
129
134
} else {
130
- impl_->params [i] = Halide::Internal::Parameter{type (), true , dimensions (), argument_name (pred_id (), pred_name (), succ_id (), succ_name (), i)};
135
+ impl_->params [i] = Halide::Internal::Parameter{type (), true , dimensions (), argument_name (pred_id (), pred_name (), i)};
131
136
}
132
137
133
138
impl_->instances [i] = bufs[i].raw_buffer ();
@@ -148,7 +153,7 @@ class Port {
148
153
/* *
149
154
* This port is created from another node
150
155
*/
151
- Port (const std::string& pid, const std::string& pn, const std::string& sid, const std::string& sn ) : impl_(new Impl(pid, pn, sid, sn , Halide::Type(), 0 )), index_(-1 ) {}
156
+ Port (const std::string& pid, const std::string& pn) : impl_(new Impl(pid, pn, Halide::Type(), 0 )), index_(-1 ) {}
152
157
153
158
154
159
std::vector<Halide::Argument> as_argument () const {
@@ -158,7 +163,7 @@ class Port {
158
163
args.resize (i+1 , Halide::Argument ());
159
164
}
160
165
auto kind = dimensions () == 0 ? Halide::Argument::InputScalar : Halide::Argument::InputBuffer;
161
- args[i] = Halide::Argument (argument_name (pred_id (), pred_name (), succ_id (), succ_name (), i), kind, type (), dimensions (), Halide::ArgumentEstimates ());
166
+ args[i] = Halide::Argument (argument_name (pred_id (), pred_name (), i), kind, type (), dimensions (), Halide::ArgumentEstimates ());
162
167
}
163
168
return args;
164
169
}
@@ -184,7 +189,7 @@ class Port {
184
189
if (es.size () <= i) {
185
190
es.resize (i+1 , Halide::Expr ());
186
191
}
187
- es[i] = Halide::Internal::Variable::make (type (), argument_name (pred_id (), pred_name (), succ_id (), succ_name (), i), param);
192
+ es[i] = Halide::Internal::Variable::make (type (), argument_name (pred_id (), pred_name (), i), param);
188
193
}
189
194
return es;
190
195
}
@@ -205,7 +210,7 @@ class Port {
205
210
args.push_back (Halide::Var::implicit (i));
206
211
args_expr.push_back (Halide::Var::implicit (i));
207
212
}
208
- Halide::Func f (param.type (), param.dimensions (), argument_name (pred_id (), pred_name (), succ_id (), succ_name (), i) + " _im" );
213
+ Halide::Func f (param.type (), param.dimensions (), argument_name (pred_id (), pred_name (), i) + " _im" );
209
214
f (args) = Halide::Internal::Call::make (param, args_expr);
210
215
fs[i] = f;
211
216
}
0 commit comments