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 
57 
58 
59 typedef char word_t[8];
60 
61 
72  ap_uint<32> *pi_rank,
73  ap_uint<32> *pi_size,
74  stream<NodeId> &sDstNode_sig,
75  ap_uint<32> *po_rx_ports
76  )
77 {
78  //-- DIRECTIVES FOR THIS PROCESS ------------------------------------------
79 #pragma HLS INLINE
80  //-- STATIC VARIABLES (with RESET) ------------------------------------------
81  static PortFsmType port_fsm = FSM_WRITE_NEW_DATA;
82 #pragma HLS reset variable=port_fsm
83 
84 
85  switch(port_fsm)
86  {
87  default:
88  case FSM_WRITE_NEW_DATA:
89  //Triangle app needs to be reset to process new rank
90  if(!sDstNode_sig.full())
91  {
92  NodeId dst_rank = (*pi_rank + 1) % *pi_size;
93  printf("rank: %d; size: %d; \n", (int) *pi_rank, (int) *pi_size);
94  sDstNode_sig.write(dst_rank);
95  port_fsm = FSM_DONE;
96  }
97  break;
98  case FSM_DONE:
99  *po_rx_ports = 0x1; //currently work only with default ports...
100  break;
101  }
102 
103 }
104 
105 
117 void pRXPath(
118  stream<NetworkWord> &siSHL_This_Data,
119  stream<NetworkMetaStream> &siNrc_meta,
120  stream<NetworkMetaStream> &sRxtoTx_Meta,
121  stream<NetworkWord> &sRxpToTxp_Data,
122  NetworkMetaStream meta_tmp,
123  unsigned int *processed_word_rx,
124  unsigned int *processed_bytes_rx
125  #ifdef ENABLE_DDR
126  ,
127  //------------------------------------------------------
128  //-- SHELL / Role / Mem / Mp1 Interface
129  //------------------------------------------------------
132  #endif
133  )
134 {
135  //-- DIRECTIVES FOR THIS PROCESS ------------------------------------------
136  //#pragma HLS DATAFLOW interval=1
137  #pragma HLS INLINE off
138  //-- LOCAL VARIABLES ------------------------------------------------------
139  NetworkWord netWord;
140  word_t text;
141 
142  switch(enqueueFSM)
143  {
144  case WAIT_FOR_META:
145  printf("DEBUG in pRXPath: enqueueFSM - WAIT_FOR_META, *processed_word_rx=%u, *processed_bytes_rx=%u\n",
146  *processed_word_rx, *processed_bytes_rx);
147  if ( !siNrc_meta.empty() && !sRxtoTx_Meta.full() )
148  {
149  meta_tmp = siNrc_meta.read();
150  meta_tmp.tlast = 1; //just to be sure...
151  sRxtoTx_Meta.write(meta_tmp);
153  }
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  if ( !siSHL_This_Data.empty() && !sRxpToTxp_Data.full() )
160  {
161  //-- Read incoming data chunk
162  netWord = siSHL_This_Data.read();
163 
164 
165  #ifdef ENABLE_DDR
166  membus_t tmp_text;
167  ap_uint<64> tmp_64_bytes;
168  tmp_text.range(63,0) = netWord.tdata;
169  tmp_text.range(511,64) = 0;
170  lcl_mem0[0]=tmp_text;
171  tmp_text=lcl_mem0[0];
172  tmp_64_bytes = tmp_text.range(63,0);
173  memcpy(&text, &tmp_64_bytes, 64/8);
174  //#ifndef __SYNTHESIS__
175  printf("%s\n",text);
176  // #endif
177  #else
178  /* Read in one word_t */
179  memcpy((char*) text, &netWord.tdata, 64/8);
180  #endif
181 
182  /* Convert lower cases to upper cases byte per byte */
183  uppercase_conversion:
184  for (unsigned int i = 0; i < sizeof(text); i++ ) {
185  //#pragma HLS PIPELINE
186  //#pragma HLS UNROLL
187 
188  if (text[i] >= 'a' && text[i] <= 'z')
189  text[i] = text[i] - ('a' - 'A');
190  }
191  memcpy(&netWord.tdata, (char*) text, 64/8);
192 
193  sRxpToTxp_Data.write(netWord);
194  if(netWord.tlast == 1)
195  {
197  }
198  }
199  break;
200  }
201 
202 
203 }
204 
205 
206 
207 
208 
220 void pTXPath(
221  stream<NetworkWord> &soTHIS_Shl_Data,
222  stream<NetworkMetaStream> &soNrc_meta,
223  stream<NetworkWord> &sRxpToTxp_Data,
224  stream<NetworkMetaStream> &sRxtoTx_Meta,
225  stream<NodeId> &sDstNode_sig,
226  unsigned int *processed_word_tx,
227  ap_uint<32> *pi_rank
228  )
229 {
230  //-- DIRECTIVES FOR THIS PROCESS ------------------------------------------
231  //#pragma HLS DATAFLOW interval=1
232  #pragma HLS INLINE
233  //-- LOCAL VARIABLES ------------------------------------------------------
234  NetworkWord netWordTx;
235  NetworkMeta meta_in = NetworkMeta();
236  static NodeId dst_rank;
237 
238  switch(dequeueFSM)
239  {
240  case WAIT_FOR_META:
241  if(!sDstNode_sig.empty())
242  {
243  dst_rank = sDstNode_sig.read();
245  //Triangle app needs to be reset to process new rank
246  }
247  break;
249  printf("DEBUG in pTXPath: dequeueFSM=%d - WAIT_FOR_STREAM_PAIR, *processed_word_tx=%u\n",
250  dequeueFSM, *processed_word_tx);
251  //-- Forward incoming chunk to SHELL
252  *processed_word_tx = 0;
253 
254  /*
255  printf("!sRxpToTxp_Data.empty()=%d\n", !sRxpToTxp_Data.empty());
256  printf("!sRxtoTx_Meta.empty()=%d\n", !sRxtoTx_Meta.empty());
257  printf("!soTHIS_Shl_Data.full()=%d\n", !soTHIS_Shl_Data.full());
258  printf("!soNrc_meta.full()=%d\n", !soNrc_meta.full());
259  */
260 
261  if (( !sRxpToTxp_Data.empty() && !sRxtoTx_Meta.empty()
262  && !soTHIS_Shl_Data.full() && !soNrc_meta.full() ))
263  {
264  netWordTx = sRxpToTxp_Data.read();
265 
266  // in case MTU=8 ensure tlast is set in WAIT_FOR_STREAM_PAIR and don't visit PROCESSING_PACKET
267  if (PACK_SIZE == 8)
268  {
269  netWordTx.tlast = 1;
270  }
271  soTHIS_Shl_Data.write(netWordTx);
272 
273  meta_in = sRxtoTx_Meta.read().tdata;
274  NetworkMetaStream meta_out_stream = NetworkMetaStream();
275  meta_out_stream.tlast = 1;
276  meta_out_stream.tkeep = 0xFF; //just to be sure
277 
278  meta_out_stream.tdata.dst_rank = dst_rank;
279  //meta_out_stream.tdata.dst_port = DEFAULT_TX_PORT;
280  meta_out_stream.tdata.src_rank = (NodeId) *pi_rank;
281  //meta_out_stream.tdata.src_port = DEFAULT_RX_PORT;
282  //printf("rank: %d; size: %d; \n", (int) *pi_rank, (int) *pi_size);
283  //printf("meat_out.dst_rank: %d\n", (int) meta_out_stream.tdata.dst_rank);
284  meta_out_stream.tdata.dst_port = meta_in.src_port;
285  meta_out_stream.tdata.src_port = meta_in.dst_port;
286 
287  //meta_out_stream.tdata.len = meta_in.len;
288  soNrc_meta.write(meta_out_stream);
289 
290  (*processed_word_tx)++;
291 
292  if(netWordTx.tlast != 1)
293  {
295  }
296  }
297  break;
298 
299  case PROCESSING_PACKET:
300  printf("DEBUG in pTXPath: dequeueFSM=%d - PROCESSING_PACKET, *processed_word_tx=%u\n",
301  dequeueFSM, *processed_word_tx);
302  if( !sRxpToTxp_Data.empty() && !soTHIS_Shl_Data.full())
303  {
304  netWordTx = sRxpToTxp_Data.read();
305 
306  // This is a normal termination of the axi stream from vitis functions
307  if(netWordTx.tlast == 1)
308  {
310  }
311 
312  // This is our own termination based on the custom MTU we have set in PACK_SIZE.
313  // TODO: We can map PACK_SIZE to a dynamically assigned value either through MMIO or header
314  // in order to have a functional bitstream for any MTU size
315  (*processed_word_tx)++;
316  if (((*processed_word_tx)*8) % PACK_SIZE == 0)
317  {
318  netWordTx.tlast = 1;
320  }
321 
322  soTHIS_Shl_Data.write(netWordTx);
323  }
324  break;
325  }
326 }
327 
328 
329 
336 
337  ap_uint<32> *pi_rank,
338  ap_uint<32> *pi_size,
339  //------------------------------------------------------
340  //-- SHELL / This / Udp/TCP Interfaces
341  //------------------------------------------------------
342  stream<NetworkWord> &siSHL_This_Data,
343  stream<NetworkWord> &soTHIS_Shl_Data,
344  stream<NetworkMetaStream> &siNrc_meta,
345  stream<NetworkMetaStream> &soNrc_meta,
346  ap_uint<32> *po_rx_ports
347  #ifdef ENABLE_DDR
348  ,
349  //------------------------------------------------------
350  //-- SHELL / Role / Mem / Mp1 Interface
351  //------------------------------------------------------
354  #endif
355  )
356 {
357 
358  //-- DIRECTIVES FOR THE BLOCK ---------------------------------------------
359  //#pragma HLS INTERFACE ap_ctrl_none port=return
360 
361  //#pragma HLS INTERFACE ap_stable port=piSHL_This_MmioEchoCtrl
362 
363 #pragma HLS INTERFACE axis register both port=siSHL_This_Data
364 #pragma HLS INTERFACE axis register both port=soTHIS_Shl_Data
365 
366 #pragma HLS INTERFACE axis register both port=siNrc_meta
367 #pragma HLS INTERFACE axis register both port=soNrc_meta
368 
369 #pragma HLS INTERFACE ap_ovld register port=po_rx_ports name=poROL_NRC_Rx_ports
370 #pragma HLS INTERFACE ap_stable register port=pi_rank name=piFMC_ROL_rank
371 #pragma HLS INTERFACE ap_stable register port=pi_size name=piFMC_ROL_size
372 
373 #ifdef ENABLE_DDR
374 
375 const unsigned int ddr_mem_depth = TOTMEMDW_512;
376 const unsigned int ddr_latency = DDR_LATENCY;
377 const unsigned int num_outstanding_transactions = 256;
378 const unsigned int MAX_BURST_LENGTH_512=64;//Theoretically is 64, 64*512bit = 4096KBytes;
379 
380 // Mapping LCL_MEM0 interface to moMEM_Mp1 channel
381 #pragma HLS INTERFACE m_axi depth=ddr_mem_depth port=lcl_mem0 bundle=moMEM_Mp1\
382  max_read_burst_length=MAX_BURST_LENGTH_512 max_write_burst_length=MAX_BURST_LENGTH_512 offset=direct \
383  num_read_outstanding=num_outstanding_transactions num_write_outstanding=num_outstanding_transactions
384  // latency=ddr_latency
385 
386 // Mapping LCL_MEM1 interface to moMEM_Mp1 channel
387 #pragma HLS INTERFACE m_axi depth=ddr_mem_depth port=lcl_mem1 bundle=moMEM_Mp1 \
388  max_read_burst_length=MAX_BURST_LENGTH_512 max_write_burst_length=MAX_BURST_LENGTH_512 offset=direct \
389  num_read_outstanding=num_outstanding_transactions num_write_outstanding=num_outstanding_transactions
390  //latency=ddr_latency
391 
392 #endif
393 
394  //-- LOCAL VARIABLES ------------------------------------------------------
395  static stream<NetworkWord> sRxpToTxp_Data("sRxpToTxP_Data"); // FIXME: works even with no static
397  static stream<NetworkMetaStream> sRxtoTx_Meta("sRxtoTx_Meta");
398  static unsigned int processed_word_rx;
399  static unsigned int processed_bytes_rx;
400  static unsigned int processed_word_tx;
401  //*po_rx_ports = 0x1; //currently work only with default ports...
402  static stream<NodeId> sDstNode_sig ("sDstNode_sig");
403 
404 
405 
406  //-- DIRECTIVES FOR THIS PROCESS ------------------------------------------
407 #pragma HLS DATAFLOW
408 #pragma HLS reset variable=enqueueFSM
409 #pragma HLS reset variable=dequeueFSM
410 #pragma HLS reset variable=UppercaseFSM
411 #pragma HLS reset variable=processed_word_rx
412 #pragma HLS reset variable=processed_word_tx
413 
414 
415 
416 #ifdef USE_HLSLIB_DATAFLOW
432  // Dataflow functions running in parallel
433  HLSLIB_DATAFLOW_INIT();
434 
435  HLSLIB_DATAFLOW_FUNCTION(pRXPath,
436  siSHL_This_Data,
437  siNrc_meta,
438  sRxtoTx_Meta,
439  meta_tmp,
440  sRxpToTxp_Data,
441  &processed_word_rx,
442  &processed_bytes_rx);
443 
444  HLSLIB_DATAFLOW_FUNCTION(pTXPath,
445  soTHIS_Shl_Data,
446  soNrc_meta,
447  sRxpToTxp_Data,
448  sRxtoTx_Meta,
449  &processed_word_tx,
450  pi_rank,
451  pi_size);
452 
453  HLSLIB_DATAFLOW_FINALIZE();
454 
455 #else // !USE_HLSLIB_DATAFLOW
456 
458  pi_rank,
459  pi_size,
460  sDstNode_sig,
461  po_rx_ports);
462 
463  pRXPath(
464  siSHL_This_Data,
465  siNrc_meta,
466  sRxtoTx_Meta,
467  sRxpToTxp_Data,
468  meta_tmp,
469  &processed_word_rx,
470  &processed_bytes_rx
471  #ifdef ENABLE_DDR
472  ,
473  //------------------------------------------------------
474  //-- SHELL / Role / Mem / Mp1 Interface
475  //------------------------------------------------------
476  lcl_mem0,
477  lcl_mem1
478  #endif
479  );
480 
481  pTXPath(
482  soTHIS_Shl_Data,
483  soNrc_meta,
484  sRxpToTxp_Data,
485  sRxtoTx_Meta,
486  sDstNode_sig,
487  &processed_word_tx,
488  pi_rank);
489 #endif // USE_HLSLIB_DATAFLOW
490 }
491 
492 
#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 DDR_LATENCY
Definition: memtest.hpp:98
#define ENABLE_DDR
Definition: memtest.hpp:42
membus_512_t membus_t
Definition: memtest.hpp:92
#define PROCESSING_PACKET
Definition: memtest.hpp:73
#define WAIT_FOR_STREAM_PAIR
Definition: memtest.hpp:72
#define TOTMEMDW_512
Definition: memtest.hpp:93
#define WAIT_FOR_META
Definition: memtest.hpp:71
membus_t lcl_mem0[16384]
membus_t lcl_mem1[16384]
#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
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
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
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