cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
upper_lower_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 an ASCII case invert application (UDP or TCP)
26 // *
27 
28 #include "upper_lower_app.hpp"
29 
30 
31 uint8_t upper(uint8_t a)
32 {
33 #pragma HLS inline
34  if( (a >= 0x61) && (a <= 0x7a) )
35  {
36  a -= 0x20;
37  }
38  return a;
39 }
40 
41 
42 
43 uint8_t lower(uint8_t a)
44 {
45 #pragma HLS inline
46  if( (a >= 0x41) && (a <= 0x5a) )
47  {
48  a += 0x20;
49  }
50  return a;
51 }
52 
53 uint8_t invert_case(uint8_t a)
54 {
55 #pragma HLS inline
56  uint8_t ret = 0x0;
57  if( (a >= 0x41) && (a <= 0x5a) )
58  {
59  ret = a + 0x20;
60  }
61  else if( (a >= 0x61) && (a <= 0x7a) )
62  {
63  ret = a - 0x20;
64  } else {
65  ret = a;
66  }
67  return ret;
68 }
69 
70 
71 uint64_t invert_word(uint64_t input)
72 {
73 #pragma HLS inline
74  uint64_t output = 0x0;
75  for(uint8_t i = 0; i < 8; i++)
76  {
77 #pragma HLS unroll factor=8
78  output |= ((uint64_t) invert_case((uint8_t) (input >> i*8))) << i*8;
79  }
80  return output;
81 }
82 
83 
85  ap_uint<32> *pi_rank,
86  ap_uint<32> *pi_size,
87  stream<NodeId> &sDstNode_sig,
88  ap_uint<32> *po_rx_ports
89  )
90 {
91  //-- DIRECTIVES FOR THIS PROCESS ------------------------------------------
92 #pragma HLS inline off
93 //#pragma HLS pipeline II=1 //not necessary
94  //-- STATIC VARIABLES (with RESET) ------------------------------------------
95  static PortFsmType port_fsm = FSM_WRITE_NEW_DATA;
96 #pragma HLS reset variable=port_fsm
97 
98 
99  switch(port_fsm)
100  {
101  default:
102  case FSM_WRITE_NEW_DATA:
103  //Triangle app needs to be reset to process new rank
104  if(!sDstNode_sig.full())
105  {
106  NodeId dst_rank = (*pi_rank + 1) % *pi_size;
107  printf("rank: %d; size: %d; \n", (int) *pi_rank, (int) *pi_size);
108  sDstNode_sig.write(dst_rank);
109  port_fsm = FSM_DONE;
110  }
111  break;
112  case FSM_DONE:
113  *po_rx_ports = 0x1; //currently work only with default ports...
114  break;
115  }
116 }
117 
118 
119 void pEnq(
120  stream<NetworkMetaStream> &siNrc_meta,
121  stream<NetworkWord> &siNrc_data,
122  stream<NetworkMetaStream> &sRxtoTx_Meta,
123  stream<NetworkWord> &sRxpToTxp_Data
124  )
125 {
126  //-- DIRECTIVES FOR THIS PROCESS ------------------------------------------
127 #pragma HLS inline off
128 #pragma HLS pipeline II=1
129  //-- STATIC VARIABLES (with RESET) ------------------------------------------
131 #pragma HLS reset variable=enqueueFSM
132  //-- LOCAL VARIABLES ------------------------------------------------------
133  NetworkWord udpWord = NetworkWord();
135  NetworkWord newWord = NetworkWord();
136 
137  switch(enqueueFSM)
138  {
139  default:
140  case WAIT_FOR_META:
141  if ( !siNrc_meta.empty() && !sRxtoTx_Meta.full() )
142  {
143  meta_tmp = siNrc_meta.read();
144  meta_tmp.tlast = 1; //just to be sure...
145  sRxtoTx_Meta.write(meta_tmp);
147  }
148  break;
149 
150  case PROCESSING_PACKET:
151  if ( !siNrc_data.empty() && !sRxpToTxp_Data.full() )
152  {
153  //-- Read incoming data chunk
154  udpWord = siNrc_data.read();
155  newWord = NetworkWord(invert_word(udpWord.tdata), udpWord.tkeep, udpWord.tlast);
156  sRxpToTxp_Data.write(newWord);
157  if(udpWord.tlast == 1)
158  {
160  }
161  }
162  break;
163  }
164 }
165 
166 
167 void pDeq(
168  stream<NodeId> &sDstNode_sig,
169  stream<NetworkMetaStream> &sRxtoTx_Meta,
170  stream<NetworkWord> &sRxpToTxp_Data,
171  stream<NetworkMetaStream> &soNrc_meta,
172  stream<NetworkWord> &soNrc_data
173  )
174 {
175  //-- DIRECTIVES FOR THIS PROCESS ------------------------------------------
176 #pragma HLS inline off
177 #pragma HLS pipeline II=1
178  //-- STATIC VARIABLES (with RESET) ------------------------------------------
180 #pragma HLS reset variable=dequeueFSM
181  //-- STATIC DATAFLOW VARIABLES ------------------------------------------
182  static NetworkMeta meta_out;
183  static NodeId dst_rank;
184  //-- LOCAL VARIABLES ------------------------------------------------------
185  NetworkWord udpWordTx = NetworkWord();
186  //NetworkMeta meta_in = NetworkMeta();
187 
188  switch(dequeueFSM)
189  {
190  default:
191  case WAIT_FOR_META:
192  if(!sDstNode_sig.empty())
193  {
194  dst_rank = sDstNode_sig.read();
196  //Triangle app needs to be reset to process new rank
197  }
198  break;
200  //-- Forward incoming chunk to SHELL
201  if (
202  !sRxtoTx_Meta.empty()
203  //&& !soNrc_data.full()
204  && !soNrc_meta.full()
205  )
206  {
207  //udpWordTx = sRxpToTxp_Data.read();
208  //soNrc_data.write(udpWordTx);
209 
210  NetworkMeta meta_in = sRxtoTx_Meta.read().tdata;
211  meta_out = NetworkMeta();
212  //meta_out_stream.tlast = 1;
213  //meta_out_stream.tkeep = 0xFF; //just to be sure!
214 
215  //meta_out.dst_rank = (*pi_rank + 1) % *pi_size;
216  meta_out.dst_rank = dst_rank;
217  //printf("meat_out.dst_rank: %d\n", (int) meta_out_stream.tdata.dst_rank);
218  meta_out.dst_port = DEFAULT_TX_PORT;
219  //meta_out.src_rank = (NodeId) *pi_rank;
220  meta_out.src_rank = 0; //will be ignored, it is always this FPGA...
221  meta_out.src_port = DEFAULT_RX_PORT;
222  meta_out.len = meta_in.len;
223 
224  soNrc_meta.write(NetworkMeta(meta_out));
225 
226  //if(udpWordTx.tlast != 1)
227  //{
229  //}
230  //dequeueFSM = WRITE_META;
231  }
232  break;
233  //case WRITE_META:
234  // if(!soNrc_meta.full())
235  // {
236  // soNrc_meta.write(NetworkMeta(meta_out));
237  // dequeueFSM = PROCESSING_PACKET;
238  // }
239  // break;
240 
241  case PROCESSING_PACKET:
242  if( !sRxpToTxp_Data.empty() && !soNrc_data.full())
243  {
244  udpWordTx = sRxpToTxp_Data.read();
245  soNrc_data.write(udpWordTx);
246 
247  if(udpWordTx.tlast == 1)
248  {
250  }
251 
252  }
253  break;
254  }
255 
256 }
257 
258 
259 
260 
270  ap_uint<32> *pi_rank,
271  ap_uint<32> *pi_size,
272  //------------------------------------------------------
273  //-- SHELL / This / UDP/TCP Interfaces
274  //------------------------------------------------------
275  stream<NetworkWord> &siNrc_data,
276  stream<NetworkWord> &soNrc_data,
277  stream<NetworkMetaStream> &siNrc_meta,
278  stream<NetworkMetaStream> &soNrc_meta,
279  ap_uint<32> *po_rx_ports
280  )
281 {
282 
283  //-- DIRECTIVES FOR THE BLOCK ---------------------------------------------
284 #pragma HLS INTERFACE ap_ctrl_none port=return
285 
286 #pragma HLS INTERFACE axis register both port=siNrc_data
287 #pragma HLS INTERFACE axis register both port=soNrc_data
288 
289 #pragma HLS INTERFACE axis register both port=siNrc_meta
290 #pragma HLS INTERFACE axis register both port=soNrc_meta
291 
292 #pragma HLS INTERFACE ap_vld register port=po_rx_ports name=poROL_NRC_Rx_ports
293 #pragma HLS INTERFACE ap_vld register port=pi_rank name=piFMC_ROL_rank
294 #pragma HLS INTERFACE ap_vld register port=pi_size name=piFMC_ROL_size
295 
296 
297  //-- DIRECTIVES FOR THIS PROCESS ------------------------------------------
298 #pragma HLS DATAFLOW
299 
300  //-- STATIC VARIABLES (with RESET) ------------------------------------------
301 
302  //-- STATIC DATAFLOW VARIABLES ------------------------------------------
303  static stream<NetworkWord> sRxpToTxp_Data("sRxpToTxP_Data");
304  static stream<NetworkMetaStream> sRxtoTx_Meta("sRxtoTx_Meta");
305  static stream<NodeId> sDstNode_sig("sDstNode_sig");
306 
307 #pragma HLS STREAM variable=sRxpToTxp_Data depth=252
308 #pragma HLS STREAM variable=sRxtoTx_Meta depth=32
309 #pragma HLS STREAM variable=sDstNode_sig depth=1
310 
311 
312  //-- LOCAL VARIABLES ------------------------------------------------------
313 
314  pPortAndDestionation(pi_rank, pi_size, sDstNode_sig, po_rx_ports);
315 
316  pEnq(siNrc_meta, siNrc_data, sRxtoTx_Meta, sRxpToTxp_Data);
317 
318  pDeq(sDstNode_sig, sRxtoTx_Meta, sRxpToTxp_Data, soNrc_meta, soNrc_data);
319 
320 }
321 
#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_STREAM_PAIR
Definition: memtest.hpp:72
#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
string input
Definition: test.py:9
string output
Definition: test.py:10
ap_uint< 8 > NodeId
Definition: network.hpp:82
ap_uint< 1 > tlast
Definition: network.hpp:111
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< 64 > tdata
Definition: network.hpp:49
ap_uint< 8 > tkeep
Definition: network.hpp:50
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)
uint8_t lower(uint8_t a)
uint8_t upper(uint8_t a)
uint64_t invert_word(uint64_t input)
uint8_t invert_case(uint8_t a)
void pDeq(stream< NodeId > &sDstNode_sig, stream< NetworkMetaStream > &sRxtoTx_Meta, stream< NetworkWord > &sRxpToTxp_Data, stream< NetworkMetaStream > &soNrc_meta, stream< NetworkWord > &soNrc_data)
void upper_lower_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, invert the case of A...
void pEnq(stream< NetworkMetaStream > &siNrc_meta, stream< NetworkWord > &siNrc_data, stream< NetworkMetaStream > &sRxtoTx_Meta, stream< NetworkWord > &sRxpToTxp_Data)