cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
uppercase.cpp
Go to the documentation of this file.
1 
17 
38 #include "../include/uppercase.hpp"
39 #include "../../../../../HOST/custom/uppercase/languages/cplusplus/include/config.h"
40 
41 #ifdef USE_HLSLIB_DATAFLOW
42 #include "../../../../../hlslib/include/hlslib/xilinx/Stream.h"
43 #include "../../../../../hlslib/include/hlslib/xilinx/Simulation.h"
44 #endif
45 
46 #ifdef USE_HLSLIB_STREAM
47 using hlslib::Stream;
48 #endif
49 using hls::stream;
50 
51 #define Data_t_in ap_axiu<INPUT_PTR_WIDTH, 0, 0, 0>
52 #define Data_t_out ap_axiu<OUTPUT_PTR_WIDTH, 0, 0, 0>
53 
58 
59 
60 typedef char word_t[8];
61 
62 
73  ap_uint<32> *pi_rank,
74  ap_uint<32> *pi_size,
75  stream<NodeId> &sDstNode_sig,
76  ap_uint<32> *po_rx_ports
77  )
78 {
79  //-- DIRECTIVES FOR THIS PROCESS ------------------------------------------
80 #pragma HLS INLINE off
81  //-- STATIC VARIABLES (with RESET) ------------------------------------------
82  static PortFsmType port_fsm = FSM_WRITE_NEW_DATA;
83 #pragma HLS reset variable=port_fsm
84 
85 
86  switch(port_fsm)
87  {
88  default:
89  case FSM_WRITE_NEW_DATA:
90  //Triangle app needs to be reset to process new rank
91  if(!sDstNode_sig.full())
92  {
93  NodeId dst_rank = (*pi_rank + 1) % *pi_size;
94  printf("rank: %d; size: %d; \n", (int) *pi_rank, (int) *pi_size);
95  sDstNode_sig.write(dst_rank);
96  port_fsm = FSM_DONE;
97  }
98  break;
99  case FSM_DONE:
100  *po_rx_ports = 0x1; //currently work only with default ports...
101  break;
102  }
103 
104 }
105 
106 
119 void pRXPath(
120  stream<NetworkWord> &siSHL_This_Data,
121  stream<NetworkMetaStream> &siNrc_meta,
122  stream<NetworkMetaStream> &sRxtoTx_Meta,
123  stream<NetworkWord> &sRxpToProcp_Data,
124  NetworkMetaStream meta_tmp,
125  bool * start_stop,
126  unsigned int *processed_word_rx,
127  unsigned int *processed_bytes_rx
128  )
129 {
130  //-- DIRECTIVES FOR THIS PROCESS ------------------------------------------
131  //#pragma HLS DATAFLOW interval=1
132  #pragma HLS INLINE
133  //-- LOCAL VARIABLES ------------------------------------------------------
134  NetworkWord netWord;
135  // word_t text;
136  //UppercaseCmd fsmCmd;
137  static bool start_stop_local = false;
138 #pragma HLS reset variable=start_stop_local
139 
140  *start_stop = start_stop_local;
141  switch(enqueueFSM)
142  {
143  case WAIT_FOR_META:
144  printf("DEBUG in pRXPath: enqueueFSM - WAIT_FOR_META, *processed_word_rx=%u, *processed_bytes_rx=%u\n",
145  *processed_word_rx, *processed_bytes_rx);
146  if ( !siNrc_meta.empty() && !sRxtoTx_Meta.full() )
147  {
148  meta_tmp = siNrc_meta.read();
149  meta_tmp.tlast = 1; //just to be sure...
150  sRxtoTx_Meta.write(meta_tmp);
152  }
153  // *start_stop = start_stop_local;
154  break;
155 
156  case PROCESSING_PACKET:
157  printf("DEBUG in pRXPath: enqueueFSM - PROCESSING_PACKET, *processed_word_rx=%u, *processed_bytes_rx=%u\n",
158  *processed_word_rx, *processed_bytes_rx);
159  //*start_stop = start_stop_local;
160 
161  if ( !siSHL_This_Data.empty() && !sRxpToProcp_Data.full() )
162  {
163  //-- Read incoming data chunk
164  netWord = siSHL_This_Data.read();
165 
166  switch(netWord.tdata)
167  {
168  case(START_CMD):
169  start_stop_local=true;
170  *start_stop=true;
171  netWord.tdata=1;//28506595412;//"B_ACK";
172  break;
173  case(STOP_CMD):
174  start_stop_local=false;
175  *start_stop=false;
176  netWord.tdata=0;//358080398155;//"S_ACK" string
177  netWord.tlast = 1;
178  break;
179  default:
180  if (start_stop_local)
181  {
182  //some data manipulation here
183  }
184  break;
185 
186  }
187  sRxpToProcp_Data.write(netWord);
188  if(netWord.tlast == 1)
189  {
191  }
192  }
193  break;
194  }
195 
196 
197 }
198 
199 
200 
210  stream<NetworkWord> &sRxpToProcp_Data,
211  stream<NetworkWord> &sProcpToTxp_Data,
212  bool * start_stop
213  ){
214 
215  //-- DIRECTIVES FOR THIS PROCESS ------------------------------------------
216 #pragma HLS INLINE off
217  //-- LOCAL VARIABLES ------------------------------------------------------
218  NetworkWord netWord;
219  word_t text;
220 
221  switch(processingFSM)
222  {
223  case FSM_PROCESSING_STOP:
224  printf("DEBUG proc FSM, I am in the stop state\n");
225  if ( !sRxpToProcp_Data.empty() && !sProcpToTxp_Data.full() )
226  {
227  //-- Read incoming data chunk
228  netWord = sRxpToProcp_Data.read();
229  sProcpToTxp_Data.write(netWord);
230  }
231  if ( *start_stop )
232  {
234  }
235  break;
236 
238  if ( !sRxpToProcp_Data.empty() && !sProcpToTxp_Data.full() )
239  {
240  //-- Read incoming data chunk
241  if ( *start_stop ) {
242  netWord = sRxpToProcp_Data.read();
243  /* Read in one word_t */
244  memcpy((char*) text, &netWord.tdata, 64/8);
245 
246  /* Convert lower cases to upper cases byte per byte */
247  uppercase_conversion:
248  for (unsigned int i = 0; i < sizeof(text); i++ ) {
249 
250  if (text[i] >= 'a' && text[i] <= 'z')
251  text[i] = text[i] - ('a' - 'A');
252  }
253  memcpy(&netWord.tdata, (char*) text, 64/8);
254 
255  sProcpToTxp_Data.write(netWord);
256  if(netWord.tlast == 1)
257  {
259  }
260  } else {
262  }
263 
264  }
265  break;
266  }
267  };
268 
269 
270 
271 
283 void pTXPath(
284  stream<NetworkWord> &soTHIS_Shl_Data,
285  stream<NetworkMetaStream> &soNrc_meta,
286  stream<NetworkWord> &sProcpToTxp_Data,
287  stream<NetworkMetaStream> &sRxtoTx_Meta,
288  stream<NodeId> &sDstNode_sig,
289  unsigned int *processed_word_tx,
290  ap_uint<32> *pi_rank
291  )
292 {
293  //-- DIRECTIVES FOR THIS PROCESS ------------------------------------------
294  //#pragma HLS DATAFLOW interval=1
295  #pragma HLS INLINE
296  //-- LOCAL VARIABLES ------------------------------------------------------
297  NetworkWord netWordTx;
298  NetworkMeta meta_in = NetworkMeta();
299  static NodeId dst_rank;
300 
301  switch(dequeueFSM)
302  {
303  case WAIT_FOR_META:
304  if(!sDstNode_sig.empty())
305  {
306  dst_rank = sDstNode_sig.read();
308  //Triangle app needs to be reset to process new rank
309  }
310  break;
312  printf("DEBUG in pTXPath: dequeueFSM=%d - WAIT_FOR_STREAM_PAIR, *processed_word_tx=%u\n",
313  dequeueFSM, *processed_word_tx);
314  //-- Forward incoming chunk to SHELL
315  *processed_word_tx = 0;
316 
317  /*
318  printf("!sRxpToProcp_Data.empty()=%d\n", !sRxpToProcp_Data.empty());
319  printf("!sRxtoTx_Meta.empty()=%d\n", !sRxtoTx_Meta.empty());
320  printf("!soTHIS_Shl_Data.full()=%d\n", !soTHIS_Shl_Data.full());
321  printf("!soNrc_meta.full()=%d\n", !soNrc_meta.full());
322  */
323 
324  if (( !sProcpToTxp_Data.empty() && !sRxtoTx_Meta.empty()
325  && !soTHIS_Shl_Data.full() && !soNrc_meta.full() ))
326  {
327  netWordTx = sProcpToTxp_Data.read();
328 
329  // in case MTU=8 ensure tlast is set in WAIT_FOR_STREAM_PAIR and don't visit PROCESSING_PACKET
330  if (PACK_SIZE == 8)
331  {
332  netWordTx.tlast = 1;
333  }
334  soTHIS_Shl_Data.write(netWordTx);
335 
336  meta_in = sRxtoTx_Meta.read().tdata;
337  NetworkMetaStream meta_out_stream = NetworkMetaStream();
338  meta_out_stream.tlast = 1;
339  meta_out_stream.tkeep = 0xFF; //just to be sure
340 
341  meta_out_stream.tdata.dst_rank = dst_rank;
342  //meta_out_stream.tdata.dst_port = DEFAULT_TX_PORT;
343  meta_out_stream.tdata.src_rank = (NodeId) *pi_rank;
344  //meta_out_stream.tdata.src_port = DEFAULT_RX_PORT;
345  //printf("rank: %d; size: %d; \n", (int) *pi_rank, (int) *pi_size);
346  //printf("meat_out.dst_rank: %d\n", (int) meta_out_stream.tdata.dst_rank);
347  meta_out_stream.tdata.dst_port = meta_in.src_port;
348  meta_out_stream.tdata.src_port = meta_in.dst_port;
349 
350  //meta_out_stream.tdata.len = meta_in.len;
351  soNrc_meta.write(meta_out_stream);
352 
353  (*processed_word_tx)++;
354 
355  if(netWordTx.tlast != 1)
356  {
358  }
359  }
360  break;
361 
362  case PROCESSING_PACKET:
363  printf("DEBUG in pTXPath: dequeueFSM=%d - PROCESSING_PACKET, *processed_word_tx=%u\n",
364  dequeueFSM, *processed_word_tx);
365  if( !sProcpToTxp_Data.empty() && !soTHIS_Shl_Data.full())
366  {
367  netWordTx = sProcpToTxp_Data.read();
368 
369  // This is a normal termination of the axi stream from vitis functions
370  if(netWordTx.tlast == 1)
371  {
373  }
374 
375  // This is our own termination based on the custom MTU we have set in PACK_SIZE.
376  // TODO: We can map PACK_SIZE to a dynamically assigned value either through MMIO or header
377  // in order to have a functional bitstream for any MTU size
378  (*processed_word_tx)++;
379  if (((*processed_word_tx)*8) % PACK_SIZE == 0)
380  {
381  netWordTx.tlast = 1;
383  }
384 
385  soTHIS_Shl_Data.write(netWordTx);
386  }
387  break;
388  }
389 }
390 
391 
392 
398 void uppercase(
399 
400  ap_uint<32> *pi_rank,
401  ap_uint<32> *pi_size,
402  //------------------------------------------------------
403  //-- SHELL / This / Udp/TCP Interfaces
404  //------------------------------------------------------
405  stream<NetworkWord> &siSHL_This_Data,
406  stream<NetworkWord> &soTHIS_Shl_Data,
407  stream<NetworkMetaStream> &siNrc_meta,
408  stream<NetworkMetaStream> &soNrc_meta,
409  ap_uint<32> *po_rx_ports
410  )
411 {
412 
413  //-- DIRECTIVES FOR THE BLOCK ---------------------------------------------
414  //#pragma HLS INTERFACE ap_ctrl_none port=return
415 
416  //#pragma HLS INTERFACE ap_stable port=piSHL_This_MmioEchoCtrl
417 
418 #pragma HLS INTERFACE axis register both port=siSHL_This_Data
419 #pragma HLS INTERFACE axis register both port=soTHIS_Shl_Data
420 
421 #pragma HLS INTERFACE axis register both port=siNrc_meta
422 #pragma HLS INTERFACE axis register both port=soNrc_meta
423 
424 #pragma HLS INTERFACE ap_ovld register port=po_rx_ports name=poROL_NRC_Rx_ports
425 #pragma HLS INTERFACE ap_stable register port=pi_rank name=piFMC_ROL_rank
426 #pragma HLS INTERFACE ap_stable register port=pi_size name=piFMC_ROL_size
427 
428 
429  //-- LOCAL VARIABLES ------------------------------------------------------
430  // static stream<NetworkWord> sRxpToProcp_Data("sRxpToProcp_Data"); // FIXME: works even with no static
432  static stream<NetworkMetaStream> sRxtoTx_Meta("sRxtoTx_Meta");
433  static stream<NetworkWord> sProcpToTxp_Data("sProcpToTxp_Data"); // FIXME: works even with no static
434  static stream<NetworkWord> sRxpToProcp_Data("sRxpToProcp_Data"); // FIXME: works even with no static
435 
436 
437 
438  static unsigned int processed_word_rx;
439  static unsigned int processed_bytes_rx;
440  static unsigned int processed_word_tx;
441  //*po_rx_ports = 0x1; //currently work only with default ports...
442  static stream<NodeId> sDstNode_sig ("sDstNode_sig");
443  bool start_stop;
444 
445 
446 
447 
448 
449  //-- DIRECTIVES FOR THIS PROCESS ------------------------------------------
450 #pragma HLS DATAFLOW
451 #pragma HLS reset variable=enqueueFSM
452 #pragma HLS reset variable=dequeueFSM
453 #pragma HLS reset variable=UppercaseFSM
454 #pragma HLS reset variable=processingFSM
455 #pragma HLS reset variable=processed_word_rx
456 #pragma HLS reset variable=processed_word_tx
457 
458 
459 
460 #ifdef USE_HLSLIB_DATAFLOW
476  // Dataflow functions running in parallel
477  HLSLIB_DATAFLOW_INIT();
478 
479  HLSLIB_DATAFLOW_FUNCTION(pRXPath,
480  siSHL_This_Data,
481  siNrc_meta,
482  sRxtoTx_Meta,
483  meta_tmp,
484  sRxpToProcp_Data,
485  &processed_word_rx,
486  &processed_bytes_rx);
487 
488  HLSLIB_DATAFLOW_FUNCTION(pTXPath,
489  soTHIS_Shl_Data,
490  soNrc_meta,
491  sRxpToProcp_Data,
492  sRxtoTx_Meta,
493  &processed_word_tx,
494  pi_rank,
495  pi_size);
496 
497  HLSLIB_DATAFLOW_FINALIZE();
498 
499 #else // !USE_HLSLIB_DATAFLOW
500 
502  pi_rank,
503  pi_size,
504  sDstNode_sig,
505  po_rx_ports);
506 
507  pRXPath(
508  siSHL_This_Data,
509  siNrc_meta,
510  sRxtoTx_Meta,
511  sRxpToProcp_Data,
512  meta_tmp,
513  &start_stop,
514  &processed_word_rx,
515  &processed_bytes_rx);
516 
518  sRxpToProcp_Data,
519  sProcpToTxp_Data,
520  &start_stop);
521 
522 
523  pTXPath(
524  soTHIS_Shl_Data,
525  soNrc_meta,
526  sProcpToTxp_Data,
527  sRxtoTx_Meta,
528  sDstNode_sig,
529  &processed_word_tx,
530  pi_rank);
531 #endif // USE_HLSLIB_DATAFLOW
532 }
533 
534 
#define ProcessingFsmType
#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 FSM_PROCESSING_STOP
#define FSM_PROCESSING_START
#define WAIT_FOR_META
Definition: memtest.hpp:71
#define PACK_SIZE
Definition: config.h:51
void pPortAndDestionation(ap_uint< 32 > *pi_rank, ap_uint< 32 > *pi_size, stream< NodeId > &sDstNode_sig, ap_uint< 32 > *po_rx_ports)
pPortAndDestionation - Setup the port and the destination rank.
Definition: uppercase.cpp:71
uint8_t enqueueFSM
Definition: uppercase.cpp:54
uint8_t processingFSM
Definition: uppercase.cpp:57
void pRXPath(stream< NetworkWord > &siSHL_This_Data, stream< NetworkMetaStream > &siNrc_meta, stream< NetworkMetaStream > &sRxtoTx_Meta, stream< NetworkWord > &sRxpToTxp_Data, NetworkMetaStream meta_tmp, unsigned int *processed_word_rx, unsigned int *processed_bytes_rx)
Receive Path - From SHELL to THIS.
Definition: uppercase.cpp:117
void pTXPath(stream< NetworkWord > &soTHIS_Shl_Data, stream< NetworkMetaStream > &soNrc_meta, stream< NetworkWord > &sRxpToTxp_Data, stream< NetworkMetaStream > &sRxtoTx_Meta, stream< NodeId > &sDstNode_sig, unsigned int *processed_word_tx, ap_uint< 32 > *pi_rank)
Transmit Path - From THIS to SHELL.
Definition: uppercase.cpp:220
void pTHISProcessingData(stream< NetworkWord > &sRxpToProcp_Data, stream< NetworkWord > &sProcpToTxp_Data, bool *start_stop)
THIS processing the data once recieved a start command.
Definition: uppercase.cpp:209
uint8_t UppercaseFSM
Definition: uppercase.cpp:56
uint8_t dequeueFSM
Definition: uppercase.cpp:55
void uppercase(ap_uint< 32 > *pi_rank, ap_uint< 32 > *pi_size, stream< NetworkWord > &siSHL_This_Data, stream< NetworkWord > &soTHIS_Shl_Data, stream< NetworkMetaStream > &siNrc_meta, stream< NetworkMetaStream > &soNrc_meta, ap_uint< 32 > *po_rx_ports)
Main process of the Uppercase Application directives.
Definition: uppercase.cpp:335
char word_t[8]
Definition: uppercase.cpp:59
@ STOP_CMD
Definition: uppercase.hpp:69
@ START_CMD
Definition: uppercase.hpp:70
ap_uint< 8 > NodeId
Definition: network.hpp:82
ap_uint< 1 > tlast
Definition: network.hpp:111
ap_uint< 8 > tkeep
Definition: network.hpp:110
NetworkMeta tdata
Definition: network.hpp:109
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< 1 > tlast
Definition: network.hpp:51