cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
triangle_app.cpp
Go to the documentation of this file.
1 
18 // *
19 // * cloudFPGA
20 // * =============================================
21 // * Created: May 2019
22 // * Authors: FAB, WEI, NGL
23 // *
24 // * Description:
25 // * The Role for a Triangle Example application (UDP or TCP)
26 // *
27 
28 #include "triangle_app.hpp"
29 
30 
32  ap_uint<32> *pi_rank,
33  ap_uint<32> *pi_size,
34  stream<NodeId> &sDstNode_sig,
35  ap_uint<32> *po_rx_ports
36  )
37 {
38  //-- DIRECTIVES FOR THIS PROCESS ------------------------------------------
39 #pragma HLS INLINE off
40 //#pragma HLS pipeline II=1 //not necessary
41  //-- STATIC VARIABLES (with RESET) ------------------------------------------
42  static PortFsmType port_fsm = FSM_WRITE_NEW_DATA;
43 #pragma HLS reset variable=port_fsm
44 
45 
46  switch(port_fsm)
47  {
48  default:
49  case FSM_WRITE_NEW_DATA:
50  //Triangle app needs to be reset to process new rank
51  if(!sDstNode_sig.full())
52  {
53  NodeId dst_rank = (*pi_rank + 1) % *pi_size;
54  printf("rank: %d; size: %d; \n", (int) *pi_rank, (int) *pi_size);
55  sDstNode_sig.write(dst_rank);
56  port_fsm = FSM_DONE;
57  }
58  break;
59  case FSM_DONE:
60  *po_rx_ports = 0x1; //currently work only with default ports...
61  break;
62  }
63 }
64 
65 
66 void pEnq(
67  stream<NetworkMetaStream> &siNrc_meta,
68  stream<NetworkWord> &siNrc_data,
69  stream<NetworkMetaStream> &sRxtoTx_Meta,
70  stream<NetworkWord> &sRxpToTxp_Data
71  )
72 {
73  //-- DIRECTIVES FOR THIS PROCESS ------------------------------------------
74 #pragma HLS INLINE off
75 #pragma HLS pipeline II=1
76  //-- STATIC VARIABLES (with RESET) ------------------------------------------
78 #pragma HLS reset variable=enqueueFSM
79  //-- LOCAL VARIABLES ------------------------------------------------------
80  NetworkWord udpWord = NetworkWord();
82 
83  switch(enqueueFSM)
84  {
85  default:
86  case WAIT_FOR_META:
87  if ( !siNrc_meta.empty() && !sRxtoTx_Meta.full() )
88  {
89  meta_tmp = siNrc_meta.read();
90  //meta_tmp.tlast = 1; //just to be sure...
91  sRxtoTx_Meta.write(meta_tmp);
93  }
94  break;
95 
96  case PROCESSING_PACKET:
97  if ( !siNrc_data.empty() && !sRxpToTxp_Data.full() )
98  {
99  udpWord = siNrc_data.read();
100  sRxpToTxp_Data.write(udpWord);
101  if(udpWord.tlast == 1)
102  {
104  }
105  }
106  break;
107  }
108 }
109 
110 
111 void pDeq(
112  stream<NodeId> &sDstNode_sig,
113  stream<NetworkMetaStream> &sRxtoTx_Meta,
114  stream<NetworkWord> &sRxpToTxp_Data,
115  stream<NetworkMetaStream> &soNrc_meta,
116  stream<NetworkWord> &soNrc_data
117  )
118 {
119  //-- DIRECTIVES FOR THIS PROCESS ------------------------------------------
120 #pragma HLS INLINE off
121 #pragma HLS pipeline II=1
122  //-- STATIC VARIABLES (with RESET) ------------------------------------------
124 #pragma HLS reset variable=dequeueFSM
125  //-- STATIC DATAFLOW VARIABLES ------------------------------------------
126  //static NetworkMeta meta_out;
127  static NodeId dst_rank;
128  //-- LOCAL VARIABLES ------------------------------------------------------
129  NetworkWord udpWordTx = NetworkWord();
130 
131  switch(dequeueFSM)
132  {
133  default:
134  case WAIT_FOR_META:
135  if(!sDstNode_sig.empty())
136  {
137  dst_rank = sDstNode_sig.read();
139  //Triangle app needs to be reset to process new rank
140  }
141  break;
142  case WAIT_FOR_STREAM:
143  //-- Forward incoming chunk to SHELL
144  if (
145  !sRxtoTx_Meta.empty()
146  //&& !soNrc_data.full()
147  && !soNrc_meta.full()
148  )
149  {
150  //udpWordTx = sRxpToTxp_Data.read();
151  //soNrc_data.write(udpWordTx);
152 
153  NetworkMeta meta_in = sRxtoTx_Meta.read().tdata;
154  NetworkMeta meta_out = NetworkMeta();
155  //meta_out_stream.tlast = 1;
156  //meta_out_stream.tkeep = 0xFF; //just to be sure!
157 
158  //meta_out.dst_rank = (*pi_rank + 1) % *pi_size;
159  meta_out.dst_rank = dst_rank;
160  //printf("meat_out.dst_rank: %d\n", (int) meta_out_stream.tdata.dst_rank);
161  meta_out.dst_port = DEFAULT_TX_PORT;
162  //meta_out.src_rank = (NodeId) *pi_rank;
163  meta_out.src_rank = NAL_THIS_FPGA_PSEUDO_NID; //will be ignored, it is always this FPGA...
164  meta_out.src_port = DEFAULT_RX_PORT;
165  meta_out.len = meta_in.len;
166 
167  soNrc_meta.write(NetworkMeta(meta_out));
168 
169  //if(udpWordTx.tlast != 1)
170  //{
172  //}
173  //dequeueFSM = WRITE_META;
174  }
175  break;
176  //case WRITE_META:
177  // if(!soNrc_meta.full())
178  // {
179  // soNrc_meta.write(NetworkMeta(meta_out));
180  // dequeueFSM = PROCESSING_PACKET;
181  // }
182  // break;
183 
184  case PROCESSING_PACKET:
185  if( !sRxpToTxp_Data.empty() && !soNrc_data.full())
186  {
187  udpWordTx = sRxpToTxp_Data.read();
188  soNrc_data.write(udpWordTx);
189 
190  if(udpWordTx.tlast == 1)
191  {
193  }
194 
195  }
196  break;
197  }
198 
199 }
200 
201 
202 
203 
212  ap_uint<32> *pi_rank,
213  ap_uint<32> *pi_size,
214  //------------------------------------------------------
215  //-- SHELL / This / UDP/TCP Interfaces
216  //------------------------------------------------------
217  stream<NetworkWord> &siNrc_data,
218  stream<NetworkWord> &soNrc_data,
219  stream<NetworkMetaStream> &siNrc_meta,
220  stream<NetworkMetaStream> &soNrc_meta,
221  ap_uint<32> *po_rx_ports
222  )
223 {
224 
225  //-- DIRECTIVES FOR THE BLOCK ---------------------------------------------
226 #pragma HLS INTERFACE ap_ctrl_none port=return
227 
228 #pragma HLS INTERFACE axis register both port=siNrc_data
229 #pragma HLS INTERFACE axis register both port=soNrc_data
230 
231 #pragma HLS INTERFACE axis register both port=siNrc_meta
232 #pragma HLS INTERFACE axis register both port=soNrc_meta
233 
234 #pragma HLS INTERFACE ap_vld register port=po_rx_ports name=poROL_NRC_Rx_ports
235 #pragma HLS INTERFACE ap_vld register port=pi_rank name=piFMC_ROL_rank
236 #pragma HLS INTERFACE ap_vld register port=pi_size name=piFMC_ROL_size
237 
238 
239  //-- DIRECTIVES FOR THIS PROCESS ------------------------------------------
240 #pragma HLS DATAFLOW
241 
242  //-- STATIC VARIABLES (with RESET) ------------------------------------------
243 
244  //-- STATIC DATAFLOW VARIABLES ------------------------------------------
245  static stream<NetworkWord> sBuffer_Data ("sBuffer_Data");
246  static stream<NetworkMetaStream> sBuffer_Meta ("sBuffer_Meta");
247  static stream<NodeId> sDstNode_sig ("sDstNode_sig");
248 
249 #pragma HLS STREAM variable=sBuffer_Data depth=252
250 #pragma HLS STREAM variable=sBuffer_Meta depth=32
251 #pragma HLS STREAM variable=sDstNode_sig depth=1
252 
253 
254  //-- LOCAL VARIABLES ------------------------------------------------------
255 
256  pPortAndDestionation(pi_rank, pi_size, sDstNode_sig, po_rx_ports);
257 
258  pEnq(siNrc_meta, siNrc_data, sBuffer_Meta, sBuffer_Data);
259 
260  pDeq(sDstNode_sig, sBuffer_Meta, sBuffer_Data, soNrc_meta, soNrc_data);
261 
262 }
263 
#define FSM_WRITE_NEW_DATA
Definition: memtest.hpp:78
#define FSM_DONE
Definition: memtest.hpp:79
#define PacketFsmType
Definition: memtest.hpp:76
#define PortFsmType
Definition: memtest.hpp:80
#define PROCESSING_PACKET
Definition: memtest.hpp:73
#define WAIT_FOR_META
Definition: memtest.hpp:71
#define DEFAULT_RX_PORT
Definition: nal.hpp:139
#define DEFAULT_TX_PORT
Definition: nal.hpp:138
uint8_t enqueueFSM
Definition: uppercase.cpp:54
uint8_t dequeueFSM
Definition: uppercase.cpp:55
ap_uint< 8 > NodeId
Definition: network.hpp:82
#define NAL_THIS_FPGA_PSEUDO_NID
Definition: network.hpp:87
NetworkDataLength len
Definition: network.hpp:99
NodeId dst_rank
Definition: network.hpp:95
NodeId src_rank
Definition: network.hpp:97
NrcPort src_port
Definition: network.hpp:98
NrcPort dst_port
Definition: network.hpp:96
ap_uint< 1 > tlast
Definition: network.hpp:51
void pPortAndDestionation(ap_uint< 32 > *pi_rank, ap_uint< 32 > *pi_size, stream< NodeId > &sDstNode_sig, ap_uint< 32 > *po_rx_ports)
void pDeq(stream< NodeId > &sDstNode_sig, stream< NetworkMetaStream > &sRxtoTx_Meta, stream< NetworkWord > &sRxpToTxp_Data, stream< NetworkMetaStream > &soNrc_meta, stream< NetworkWord > &soNrc_data)
void pEnq(stream< NetworkMetaStream > &siNrc_meta, stream< NetworkWord > &siNrc_data, stream< NetworkMetaStream > &sRxtoTx_Meta, stream< NetworkWord > &sRxpToTxp_Data)
void triangle_app(ap_uint< 32 > *pi_rank, ap_uint< 32 > *pi_size, stream< NetworkWord > &siNrc_data, stream< NetworkWord > &soNrc_data, stream< NetworkMetaStream > &siNrc_meta, stream< NetworkMetaStream > &soNrc_meta, ap_uint< 32 > *po_rx_ports)
Main process of the UDP/TCP Triangle Application. This HLS IP receives a packet and forwards it to th...
#define WAIT_FOR_STREAM