-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbsg_wormhole_router.rs
194 lines (156 loc) · 6.19 KB
/
bsg_wormhole_router.rs
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
use shakeflow::*;
use shakeflow_std::*;
use super::pkg::bsg_wormhole_router::*;
use super::types::*;
const FLIT_WIDTH_P: usize = 10;
const DIMS_P: usize = 2;
const DIRS_LP: usize = (DIMS_P * 2) + 1;
const CORD_DIMS_P: usize = DIMS_P;
const ROUTING_MATRIX_P: [[usize; DIRS_LP]; 2] = STRICT_XY;
const REVERSE_ORDER_P: usize = 0;
const LEN_WIDTH_LP: usize = 5;
const HOLD_ON_VALID_P: usize = 0;
#[derive(Debug, Clone, Signal)]
pub struct V {
data: Bits<U<FLIT_WIDTH_P>>,
}
#[derive(Debug, Interface)]
pub struct IC {
link: [VrChannel<V>; DIRS_LP],
#[member(name = "my_cord")]
coord: UniChannel<Bits<U<5>>>,
}
#[derive(Debug, Interface)]
pub struct OC {
link: [VrChannel<V>; DIRS_LP],
}
#[derive(Debug, Clone, Signal)]
pub struct DorI {
target_cord: Bits<U<5>>,
my_cord: Bits<U<5>>,
}
pub type DorIC = UniChannel<DorI>;
pub type DorOC = UniChannel<Bits<U<DIRS_LP>>>;
#[derive(Debug, Clone, Signal)]
pub struct WicI {
yumi: Ready,
decoded_dest: Bits<U<DIRS_LP>>,
payload_len: Bits<U<LEN_WIDTH_LP>>,
}
#[derive(Debug, Clone, Signal)]
pub struct WicO {
reqs: Bits<U<DIRS_LP>>,
release: bool,
detected_header: bool,
}
pub type WicIC = UniChannel<Valid<WicI>>;
pub type WicOC = UniChannel<WicO>;
#[derive(Debug, Clone, Signal)]
pub struct WocI {
reqs: bool,
release: bool,
}
#[derive(Debug, Clone, Signal)]
pub struct WocO {
data_sel: Bits<U<DIRS_LP>>,
}
pub type WocIC = [VrChannel<WocI>; DIRS_LP];
pub type WocOC = VrChannel<WocO>;
pub type FeedbackC = UniChannel<Array<Bits<U<DIRS_LP>>, U<DIRS_LP>>>;
impl_custom_inst! {DorIC, DorOC, bsg_wormhole_router_decoder_dor, <dims_p, cord_dims_p, reverse_order_p>, false,}
impl_custom_inst! {WicIC, WicOC, bsg_wormhole_router_input_control, <output_dirs_p, payload_len_bits_p>, true,}
impl_custom_inst! {WocIC, WocOC, bsg_wormhole_router_output_control, <input_dirs_p, hold_on_valid_p>, true,}
pub fn m() -> Module<IC, OC> {
composite::<(IC, FeedbackC), (OC, FeedbackC), _>(
"bsg_wormhole_router",
Some("i"),
Some("o"),
|(input, feedback), k| {
let (in_ch, fifo_data) = input
.link
.array_map_enumerate(|i, link| {
let fifo = link.fifo::<2>(k);
let (fifo, any_yumi) = fifo.fire(k);
let filter = feedback.clone().map(k, move |input| input[i].any());
let fifo = fifo.filter_bwd(k, filter).into_uni(k, true);
let hdr = fifo.clone().map(k, |input| {
let data = input.inner.data;
WormholeRouterHeaderProj {
len: data.clip_const::<U<LEN_WIDTH_LP>>(0),
cord: data.clip_const::<U<5>>(LEN_WIDTH_LP),
}
.into()
});
let decoded_dest_lo = hdr
.clone()
.zip(k, input.coord.clone())
.map(k, |input| {
let (hdr, my_cord) = *input;
DorIProj { target_cord: hdr.cord, my_cord }.into()
})
.bsg_wormhole_router_decoder_dor::<DIMS_P, CORD_DIMS_P, REVERSE_ORDER_P>(
k,
"dor",
Some("i"),
Some("req_o"),
);
let decoded_dest_sparse_lo = decoded_dest_lo
.concentrate::<U<DIRS_LP>>(k, usize_to_bits::<DIRS_LP>(ROUTING_MATRIX_P[0][i]).to_vec());
let wic_i = fifo.clone().zip4(k, any_yumi, hdr, decoded_dest_sparse_lo).map(k, |input| {
let (fifo, any_yumi, hdr, decoded_dest_sparse_lo) = *input;
Expr::<Valid<_>>::new(
fifo.valid,
WicIProj {
yumi: Expr::<Ready>::new(any_yumi),
decoded_dest: decoded_dest_sparse_lo,
payload_len: hdr.len,
}
.into(),
)
});
let wic_o = wic_i.bsg_wormhole_router_input_control::<DIRS_LP, LEN_WIDTH_LP>(
k,
"wic",
Some("fifo_i"),
Some("o"),
);
let woc_i = fifo.clone().zip(k, wic_o).map(k, move |input| {
let (fifo, wic_o) = *input;
Expr::<Valid<_>>::new(
fifo.valid,
WocIProj { reqs: wic_o.reqs[i], release: wic_o.release }.into(),
)
});
let fifo_data_lo = fifo.map(k, |input| input.inner.data);
(woc_i, fifo_data_lo)
})
.unzip();
let fifo_data = fifo_data.concat(k);
let (out_ch, yumis_transpose) = range_map::<DIRS_LP, _, _>(|_| {
// TODO: concentrate/unconcentrate
let (in_ch, yumis_lo) = in_ch.clone().array_map(k, "yumis_lo", |ch, k| ch.into_vr(k).fire(k)).unzip();
let yumis_lo = yumis_lo.concat(k);
let woc_o = in_ch.bsg_wormhole_router_output_control::<DIRS_LP, HOLD_ON_VALID_P>(
k,
"woc",
Some("i"),
Some("o"),
);
let (woc_o, woc_o_fwd) = woc_o.clone_uni(k);
let link_data_o = (fifo_data.clone(), woc_o_fwd.map(k, |input| input.inner.data_sel)).mux_one_hot(k);
(
woc_o.zip_uni(k, link_data_o).map(k, |input| {
let (_, link_data_o) = *input;
VProj { data: link_data_o }.into()
}),
yumis_lo,
)
})
.unzip();
let yumis_transpose = yumis_transpose.transpose(k).concat(k);
(OC { link: out_ch }, yumis_transpose)
},
)
.loop_feedback()
.build()
}