21 #ifndef NVHLS_PACKET_H
22 #define NVHLS_PACKET_H
25 #include <nvhls_types.h>
26 #include <nvhls_marshaller.h>
27 #include <nvhls_message.h>
39 enum RouterType { StoreForward, WormHole };
69 template <
int DataWidth,
int DestWidthPerHop,
int MaxHops = 1,
70 int PacketIdWidth = 0>
78 packet_id = other.packet_id;
84 packet_id = other.packet_id;
95 data_width = DataWidth,
96 dest_width_per_hop = DestWidthPerHop,
97 dest_width = DestWidthPerHop * MaxHops,
98 packet_id_width = PacketIdWidth,
99 width = data_width + dest_width + packet_id_width,
101 data_end_bit = data_width - 1,
102 dest_start_bit = data_end_bit + 1,
103 dest_end_bit = dest_start_bit + dest_width - 1,
104 packet_id_start_bit = dest_end_bit + 1,
105 packet_id_end_bit = packet_id_start_bit + packet_id_width - 1
108 NVUINTW(data_width) data;
109 NVUINTW(dest_width) dest;
110 NVUINTW(packet_id_width) packet_id;
112 template <
unsigned int Size>
113 void Marshall(Marshaller<Size>& m) {
123 template <
int DataW
idth,
int DestW
idthPerHop,
int MaxHops>
145 data_width = DataWidth,
146 dest_width_per_hop = DestWidthPerHop,
147 dest_width = DestWidthPerHop * MaxHops,
148 width = data_width + dest_width,
150 data_end_bit = data_width - 1,
151 dest_start_bit = data_end_bit + 1,
152 dest_end_bit = dest_start_bit + dest_width - 1,
155 NVUINTW(data_width) data;
156 NVUINTW(dest_width) dest;
158 template <
unsigned int Size>
159 void Marshall(Marshaller<Size>& m) {
170 template <
int DataWidth,
int DestWidthPerHop,
int MaxHops = 1,
171 int PacketIdWidth = 0,
class FlitId =
FlitId2bit,
172 RouterType Rtype = StoreForward>
206 typedef enum { BODY = 0, HEAD = 1, TAIL = 2, SNGL = 3 } Encoding;
208 bool isHeader()
const {
return (data[0] == 1); }
209 bool isBody()
const {
return (data == BODY); }
210 bool isTail()
const {
return (data[1] == 1); }
211 bool isSingle()
const {
return (data == SNGL); }
213 void set(
const Encoding& enc) { data = enc; }
214 void reset() { set(BODY); }
216 bool operator==(
const FlitId2bit& other)
const {
217 return (data == other.data);
224 template <
unsigned int Size>
225 void Marshall(Marshaller<Size>& m) {
230 void set_raw(
const NVUINTC(width) a) { data = a; }
231 NVUINTC(width) get_raw() {
return data; }
237 #ifndef __SYNTHESIS__
282 template <
int DataWidth,
int DestWidthPerHop,
int MaxHops,
int PacketIdWidth,
284 class Flit<DataWidth, DestWidthPerHop, MaxHops, PacketIdWidth, FlitId,
291 Flit& operator=(
const Flit& other) {
294 packet_id = other.packet_id;
295 flit_id = other.flit_id;
302 data_width = DataWidth,
303 dest_width_per_hop = DestWidthPerHop,
304 dest_width = DestWidthPerHop * MaxHops,
305 packet_id_width = PacketIdWidth,
306 flit_id_width = FlitId::width,
307 width = data_width + dest_width + packet_id_width + flit_id_width,
309 data_end_bit = data_width - 1,
310 dest_start_bit = data_end_bit + 1,
311 dest_end_bit = dest_start_bit + dest_width - 1,
312 packet_id_start_bit = dest_end_bit + 1,
313 packet_id_end_bit = packet_id_start_bit + packet_id_width - 1,
314 flit_id_start_bit = packet_id_end_bit + 1,
315 flit_id_end_bit = flit_id_start_bit + flit_id_width - 1
320 NVUINTW(packet_id_width) packet_id;
323 template <
unsigned int Size>
324 void Marshall(Marshaller<Size>& m) {
332 template <
int DataWidth,
int DestWidthPerHop,
int MaxHops,
int PacketIdWidth,
334 void Flit<DataWidth, DestWidthPerHop, MaxHops, PacketIdWidth, FlitId,
335 StoreForward>::reset() {
342 template <
int DataWidth,
int DestWidthPerHop,
int MaxHops,
int PacketIdWidth,
344 Flit<DataWidth, DestWidthPerHop, MaxHops, PacketIdWidth, FlitId,
349 template <
int DataWidth,
int DestWidthPerHop,
int MaxHops,
int PacketIdWidth,
351 Flit<DataWidth, DestWidthPerHop, MaxHops, PacketIdWidth, FlitId,
352 StoreForward>
::Flit(
const Flit<DataWidth, DestWidthPerHop, MaxHops,
353 PacketIdWidth, FlitId,
354 StoreForward>& other) {
357 packet_id = other.packet_id;
358 flit_id = other.flit_id;
368 template <
int DataW
idth,
int PacketIdW
idth,
class FlitId>
375 Flit& operator=(
const Flit& other) {
377 packet_id = other.packet_id;
378 flit_id = other.flit_id;
385 data_width = DataWidth,
386 packet_id_width = PacketIdWidth,
387 flit_id_width = FlitId::width,
388 width = data_width + packet_id_width + flit_id_width,
390 data_end_bit = data_width - 1,
391 packet_id_start_bit = data_end_bit + 1,
392 packet_id_end_bit = packet_id_start_bit + packet_id_width - 1,
393 flit_id_start_bit = packet_id_end_bit + 1,
394 flit_id_end_bit = flit_id_start_bit + flit_id_width - 1
398 NVUINTW(packet_id_width) packet_id;
401 NVUINTW(packet_id_width) get_packet_id()
const {
405 template <
unsigned int Size>
406 void Marshall(Marshaller<Size>& m) {
413 template <
int DataW
idth,
int PacketIdW
idth,
class FlitId>
420 template <
int DataW
idth,
int PacketIdW
idth,
class FlitId>
425 template <
int DataW
idth,
int PacketIdW
idth,
class FlitId>
429 packet_id = other.packet_id;
430 flit_id = other.flit_id;
433 template <
int DataW
idth,
int PacketIdW
idth,
class FlitId>
436 os <<
"<FlitId, PacketID, Data> <" << flit.flit_id <<
"," << flit.packet_id <<
"," << flit.data <<
">";
440 template <
int DataW
idth,
class FlitId>
447 Flit& operator=(
const Flit& other) {
449 flit_id = other.flit_id;
456 data_width = DataWidth,
457 flit_id_width = FlitId::width,
458 width = data_width + flit_id_width,
460 data_end_bit = data_width - 1,
461 flit_id_start_bit = data_end_bit + 1,
462 flit_id_end_bit = flit_id_start_bit + flit_id_width - 1
468 int get_packet_id()
const {
472 template <
unsigned int Size>
473 void Marshall(Marshaller<Size>& m) {
479 template <
int DataW
idth,
class FlitId>
485 template <
int DataW
idth,
class FlitId>
490 template <
int DataW
idth,
class FlitId>
494 flit_id = other.flit_id;
497 template <
int DataW
idth,
class FlitId>
500 os <<
"<FlitId, Data> <" << flit.flit_id <<
"," << flit.data <<
">";
Parameterized implementation of a network packet.
NVUINTW(Wrapped< T >::width) TypeToNVUINT(T in)
Convert Type to NVUINT.