cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
memtest_processing.hpp
Go to the documentation of this file.
1 
29 #ifndef _ROLE_MEMTEST_PATTERN_H_
30 #define _ROLE_MEMTEST_PATTERN_H_
31 
32 #include "../include/memtest_library.hpp"
33 #include "../include/memtest_pattern_library.hpp"
34 
35 #define FAULT_INJECTION // macro for fault injection insertion
36 //#define SIMPLER_BANDWIDTH_TEST // macro for usage of the simpler version: BW, FLT CNT, not fault address reporting
37 
38 #define FSM_PROCESSING_WAIT_FOR_META 0
39 #define FSM_PROCESSING_PCKT_PROC 1
40 #define FSM_PROCESSING_STOP 2
41 #define FSM_PROCESSING_START 3
42 #define FSM_PROCESSING_BURST_READING 4
43 #define FSM_PROCESSING_DATAFLOW_WRITE 5
44 #define FSM_PROCESSING_DATAFLOW_READ 6
45 #define FSM_PROCESSING_OUTPUT 7
46 #define FSM_PROCESSING_OUTPUT_2 8
47 #define FSM_PROCESSING_OUTPUT_3 9
48 #define FSM_PROCESSING_OUTPUT_4 10
49 #define FSM_PROCESSING_OUTPUT_5 11
50 #define FSM_PROCESSING_CONTINUOUS_RUN 12
51 #define FSM_PROCESSING_WAIT_FOR_DDR_CONTROLLER_EMPTYNESS 13
52 #define ProcessingFsmType uint8_t
53 
54 
55 
56 #define MEMTEST_ADDRESS_BITWIDTH 40
57 #define MEMTEST_ITERATION_BITWIDTH 16
58 #define MEMTEST_BURST_BITWIDTH 16
59 
60 #define MEMTEST_ADDRESS_HIGH_BIT NETWORK_WORD_BIT_WIDTH-1 // 63
61 #define MEMTEST_ADDRESS_LOW_BIT NETWORK_WORD_BIT_WIDTH-MEMTEST_ADDRESS_BITWIDTH //64-40 = 24
62 
63 #define MEMTEST_ITERATIONS_HIGH_BIT MEMTEST_ADDRESS_LOW_BIT-1 // 23
64 #define MEMTEST_ITERATIONS_LOW_BIT MEMTEST_ITERATIONS_HIGH_BIT+1-MEMTEST_ITERATION_BITWIDTH //
65 
66 #define MEMTEST_BURST_HIGH_BIT MEMTEST_BURST_BITWIDTH-1+MEMTEST_COMMANDS_BITWIDTH// 23
67 #define MEMTEST_BURST_LOW_BIT MEMTEST_BURST_HIGH_BIT+1-MEMTEST_BURST_BITWIDTH // 8
68 
69 const unsigned int top_param_maximum_number_of_beats = 4096;
70 
71 
75 template <const unsigned int maximum_number_of_beats=512>
78  local_mem_addr_t max_address_under_test,
79  ap_uint<64> * writing_cntr,
80  ap_uint<32> * testCounter,
81  unsigned int burst_size)
82 {
83  #pragma HLS INLINE off
84  static hls::stream<ap_uint<64>> sWritePrfCntr_cmd("sWritePrfCntr_cmd");
85  #pragma HLS STREAM variable=sWritePrfCntr_cmd depth=64 dim=1
86  static hls::stream<local_mem_word_t> generatedWriteData("generatedWriteData");
87  #pragma HLS STREAM variable=generatedWriteData depth=64 dim=1
88  #pragma HLS DATAFLOW
89 
90  #ifdef SIMPLER_BANDWIDTH_TEST
91  //Step 1 write data
92  pWriteSimplerTestMemTest<ap_uint<64>>(sWritePrfCntr_cmd, lcl_mem0, max_address_under_test, burst_size);
93  //Step 2 count
94  perfCounterProc2MemCountOnly<ap_uint<64>,ap_uint<64>,64>(sWritePrfCntr_cmd, writing_cntr);
95  #else
96  //Step 1: Generate the data
97  pWRGenerateData2WriteOnStream<4000000>(generatedWriteData,testCounter,max_address_under_test);
98  //Step 2: write
99  pWRStream2WriteMainMemory<ap_uint<64>,4000000,maximum_number_of_beats>(sWritePrfCntr_cmd, generatedWriteData, lcl_mem0, max_address_under_test, burst_size);
100  //Step 2.b: count
101  perfCounterMultipleCounts<ap_uint<64>,ap_uint<64>,64>(sWritePrfCntr_cmd, writing_cntr);
102  #endif
103 }
104 
105 
106 template <const unsigned int maximum_number_of_beats=512>
108  membus_t * lcl_mem1,
109  local_mem_addr_t max_address_under_test,
110  ap_uint<64> * reading_cntr,
111  ap_uint<32> * faulty_addresses_cntr,
112  local_mem_addr_t * first_faulty_address,
113  unsigned int burst_size)
114  {
115  #pragma HLS INLINE off
116 
117  static hls::stream<ap_uint<64>> sReadPrfCntr_cmd("sReadPrfCntr_cmd");
118  #pragma HLS STREAM variable=sReadPrfCntr_cmd depth=maximum_number_of_beats dim=1
119  static hls::stream<local_mem_word_t> generatedReadData("generatedReadData");
120  #pragma HLS STREAM variable=generatedReadData depth=maximum_number_of_beats dim=1
121  static hls::stream<local_mem_word_t> sReadData("sReadData");
122  #pragma HLS STREAM variable=sReadData depth=maximum_number_of_beats dim=1
123  static hls::stream<local_mem_word_t> sGoldData("sGoldData");
124  #pragma HLS STREAM variable=sGoldData depth=maximum_number_of_beats dim=1
125 
126  static hls::stream<ap_uint<64>> sComparisonData("sComparisonData");
127  #pragma HLS STREAM variable=sComparisonData depth=64 dim=1
128  // static hls::stream<local_mem_addr_t> sFaultyAddresses("sFaultyAddresses");
129  // #pragma HLS STREAM variable=sFaultyAddresses depth=64 dim=1
130 
131 #pragma HLS DATAFLOW
132 
133 
134  #ifdef SIMPLER_BANDWIDTH_TEST
135  //Step 1 write data
136  pReadSimplerTestMemTest<ap_uint<64>>(sReadPrfCntr_cmd, lcl_mem1, max_address_under_test, burst_size, faulty_addresses_cntr, first_faulty_address);
137  //Step 2 count
138  perfCounterProc2MemCountOnly<ap_uint<64>,ap_uint<64>,64>(sReadPrfCntr_cmd, reading_cntr);
139  #else
140  //Step 1: Generate the data
143  pRDRead2StreamDataVariableBurstNoMemCpy<ap_uint<64>,4000000,maximum_number_of_beats>( sReadPrfCntr_cmd, generatedReadData, lcl_mem1, max_address_under_test,burst_size);
144  //Step 2: write
145  pRDReadDataStreamAndProduceGold<4000000>(generatedReadData, max_address_under_test, sReadData, sGoldData);
146  //Step 2.b: count
147  perfCounterMultipleCounts<ap_uint<64>,ap_uint<64>,64>(sReadPrfCntr_cmd, reading_cntr);
148  //Step 3: compare
150  pRDCmpStreamsCntWordAligned<4000000,maximum_number_of_beats>(max_address_under_test,sReadData, sGoldData,faulty_addresses_cntr, first_faulty_address);
151  #endif
152 }
153 
154 
155 
178 
190  template<const unsigned int counter_width=64>
192  stream<NetworkWord> &sRxpToProcp_Data,
193  stream<NetworkWord> &sProcpToTxp_Data,
194  stream<NetworkMetaStream> &sRxtoProc_Meta,
195  stream<NetworkMetaStream> &sProctoTx_Meta,
196  bool * start_stop//,
197  #ifdef ENABLE_DDR
198  ,
199  //------------------------------------------------------
200  //-- SHELL / Role / Mem / Mp1 Interface
201  //------------------------------------------------------
204  #endif
205 ){
206  //-- DIRECTIVES FOR THIS PROCESS ------------------------------------------
207 #pragma HLS INLINE off
208  //-- LOCAL VARIABLES ------------------------------------------------------
209  NetworkWord netWord;
210  NetworkWord outNetWord;
211  static NetworkMetaStream outNetMeta = NetworkMetaStream();;
213 
214  static ap_uint<16> max_iterations;
215 
216  static local_mem_addr_t first_faulty_address;
217 
218  static ap_uint<32> faulty_addresses_cntr;
219 
220  static local_mem_addr_t max_address_under_test; // byte addressable;
221  static size_t bytes_sent_for_tx =0;
222 
223 #pragma HLS reset variable=processingFSM
224 #pragma HLS reset variable=outNetMeta
225 #pragma HLS reset variable=max_iterations
226 #pragma HLS reset variable=first_faulty_address
227 #pragma HLS reset variable=faulty_addresses_cntr
228 #pragma HLS reset variable=max_address_under_test
229 #pragma HLS reset variable=processingFSM
230 #pragma HLS reset variable=bytes_sent_for_tx
231 
232  static ap_uint<32> testCounter;
233  static ap_uint<counter_width> reading_cntr = 0;
234  static ap_uint<counter_width> writing_cntr = 0;
235  static unsigned int burst_size=1;
236  static local_mem_addr_t tmp_wordaligned_address = 0;
237  static int emptycntr=0;
238 
239 #pragma HLS reset variable=testCounter
240 #pragma HLS reset variable=tmp_wordaligned_address
241 #pragma HLS reset variable=burst_size
242 
243 
244 //assuming that whnever I send a start I must complete the run and then restart unless a stop
245 // or stopping once done with the run iterations
246  switch(processingFSM)
247  {
249  #if DEBUG_LEVEL == TRACE_ALL
250  printf("DEBUG proc FSM, I am in the WAIT_FOR_META state\n");
251  #endif
252  //resetting once per test suite
253  max_address_under_test = 0;
254  max_iterations=0;
255  bytes_sent_for_tx = 0;
256  burst_size=1;
257  if ( !sRxtoProc_Meta.empty() && !sProctoTx_Meta.full())
258  {
259  outNetMeta = sRxtoProc_Meta.read();
260  sProctoTx_Meta.write(outNetMeta);
262  }
263  break;
264 
266  #if DEBUG_LEVEL == TRACE_ALL
267  printf("DEBUG proc FSM, I am in the PROCESSING_PCKT_PROC state\n");
268  #endif
269 //parse the received data
270  if ( !sRxpToProcp_Data.empty() && !sProcpToTxp_Data.full())
271  {
272  netWord = sRxpToProcp_Data.read();
274  {
275  case TEST_INVLD_CMD:
276  /* FWD an echo of the invalid*/
277  #if DEBUG_LEVEL == TRACE_ALL
278  printf("DEBUG processing the packet with invalid cmd\n");
279  #endif
280  sProcpToTxp_Data.write(netWord);
282  break;
283  case TEST_STOP_CMD:
284  /* call with stop (never started), unset, fwd the stop */
285  #if DEBUG_LEVEL == TRACE_ALL
286  printf("DEBUG processing the packet with stop cmd\n");
287  #endif
288  outNetWord.tdata=TEST_STOP_CMD;
289  outNetWord.tkeep = 0xFF;
290  outNetWord.tlast = 1;
291  sProcpToTxp_Data.write(outNetWord);
293  break;
294  default:
295  /* Execute the test if not invalid or stop*/
296  #if DEBUG_LEVEL == TRACE_ALL
297  printf("DEBUG processing the packet with the address within cmd\n");
298  #endif
299  max_address_under_test = netWord.tdata(MEMTEST_ADDRESS_HIGH_BIT,MEMTEST_ADDRESS_LOW_BIT);
300  max_iterations = netWord.tdata.range(MEMTEST_ITERATIONS_HIGH_BIT,MEMTEST_ITERATIONS_LOW_BIT);
301  #if DEBUG_LEVEL == TRACE_ALL
302  #ifndef __SYNTHESIS__
303  printf("DEBUG processing the packet with the address %s within cmd %s\n", max_address_under_test.to_string().c_str(), max_iterations.to_string().c_str());
304  #endif //__SYNTHESIS__
305  #endif
307  break;
308  }
309  }
310  break;
311 
313  #if DEBUG_LEVEL == TRACE_ALL
314  printf("DEBUG proc FSM, I am in the FSM_PROCESSING_BURST_READING state\n");
315  #endif
316 //parse the received data
317  if ( !sRxpToProcp_Data.empty())
318  {
319  netWord = sRxpToProcp_Data.read();
320  #if DEBUG_LEVEL == TRACE_ALL
321  std::cout << netWord.tdata.to_string() << std::endl;
322  #endif
324  {
325  case TEST_BURSTSIZE_CMD:
326  /* extract the busrt size*/
327  burst_size = netWord.tdata.range(MEMTEST_BURST_HIGH_BIT,MEMTEST_BURST_LOW_BIT);
328 
329  #if DEBUG_LEVEL == TRACE_ALL
330  printf("DEBUG processing the packet with burst cmd, and burst size=%u\n",burst_size);
331  #endif
333  break;
334 
335 
336  default:
337  /*unkown stuff hence using a burst with 1 beat*/
338  #if DEBUG_LEVEL == TRACE_ALL
339  #ifndef __SYNTHESIS__
340  printf("DEBUG processing the packet with smth bad within cmd: %s\n",netWord.tdata.range(MEMTEST_COMMANDS_HIGH_BIT,MEMTEST_COMMANDS_LOW_BIT).to_string().c_str());
341  #endif
342  #endif
343  burst_size=1;
344  sProcpToTxp_Data.write(netWord);
346  break;
347  }
348  }
349  break;
350 
351 //The hw can begin to do something
353  // sOCMDPerfCounter.write(0);//init the counter
354  #if DEBUG_LEVEL == TRACE_ALL
355  printf("DEBUG proc FSM, I am in the START state\n");
356  #endif
357  //setting everything ready to start
358  first_faulty_address = 0;
359  faulty_addresses_cntr = 0;
360  if(max_address_under_test%64==0){
361  tmp_wordaligned_address = max_address_under_test/64;
362  } else {
363  tmp_wordaligned_address = (max_address_under_test/64+1);
364  }
365  #if DEBUG_LEVEL == TRACE_ALL
366  #ifndef __SYNTHESIS__
367  std::cout << " testing the address word aligned" << tmp_wordaligned_address.to_string() << std::endl;
368  #endif
369  #endif
370  reading_cntr = 0;
371  writing_cntr = 0;
372  testCounter = 0;
373  processingFSM = FSM_PROCESSING_DATAFLOW_WRITE;//FSM_PROCESSING_WRITE;
374  break;
375 
376  //run continuously, hence more than once
378  testCounter += 1;
379  reading_cntr = 0;
380  writing_cntr = 0;
381  faulty_addresses_cntr = 0;
382  first_faulty_address = 0;
383 
384  //stopping conditions: either a Stop or the maximum iterations
385  if(*start_stop && testCounter < max_iterations){
386  #if DEBUG_LEVEL == TRACE_ALL
387  #ifndef __SYNTHESIS__
388  printf("DEBUG processing continuous run (still run, iter %s) max iters: %s\n",testCounter.to_string().c_str(),max_iterations.to_string().c_str());
389  #endif //__SYNTHESIS__
390  #endif
391  // check if need another meta to send out!
392  // if already over the MTU size, or with a command (stop case) or with another iteration I need to send out another meta
393  if(bytes_sent_for_tx >= PACK_SIZE){
394  sProctoTx_Meta.write(outNetMeta);
395  #if DEBUG_LEVEL == TRACE_ALL
396  std::cout << "DEBUG: writing an additional meta with bytes sent equal to " << bytes_sent_for_tx << std::endl;
397  #endif
398  bytes_sent_for_tx = 0;
399  }
401 
402  break;
403  }else{
404  #if DEBUG_LEVEL == TRACE_ALL
405  #ifndef __SYNTHESIS__
406  printf("DEBUG processing continuous run (stop the run at iter %s) max iters: %s \n",testCounter.to_string().c_str(),max_iterations.to_string().c_str());
407  #endif //__SYNTHESIS__
408  #endif
409  //signal the end of the packet with the iteration of the tests performed
411  outNetWord.tdata.range(NETWORK_WORD_BIT_WIDTH-1,MEMTEST_COMMANDS_HIGH_BIT+1)=testCounter;
412  outNetWord.tkeep = 0xFF;
413  outNetWord.tlast = 1;
414  sProcpToTxp_Data.write(outNetWord);
416  break;
417  }
418 
424  //Begin to process
426  #if DEBUG_LEVEL == TRACE_ALL
427  printf("DEBUG processing write dataflow\n");
428  #endif
429  pWriteDataflowMemTest<top_param_maximum_number_of_beats>( lcl_mem0,
430  tmp_wordaligned_address , &writing_cntr,&testCounter,burst_size);
432  break;
433 
435  #if DEBUG_LEVEL == TRACE_ALL
436  printf("DEBUG processing the output of a run\n");
437  #endif
438  emptycntr++;
439  if(emptycntr==DDR_LATENCY+1){
441  emptycntr=0;
442  }
443  break;
444 
446 #if DEBUG_LEVEL == TRACE_ALL
447  printf("DEBUG processing read dataflow\n");
448 #endif
449  pReadDataflowMemTest<top_param_maximum_number_of_beats>(lcl_mem1,
450  tmp_wordaligned_address ,&reading_cntr,&faulty_addresses_cntr, &first_faulty_address,burst_size);
452  break;
453 
460  #if DEBUG_LEVEL == TRACE_ALL
461  printf("DEBUG processing the output of a run\n");
462  #endif
463  if(!sProcpToTxp_Data.full()){
464  outNetWord.tdata = max_address_under_test;
465  outNetWord.tkeep = 0xFF;
466  outNetWord.tlast = 0;
467  sProcpToTxp_Data.write(outNetWord);
468  bytes_sent_for_tx += 8;
470  }
471  break;
472 
474  #if DEBUG_LEVEL == TRACE_ALL
475  #ifndef __SYNTHESIS__
476  printf("DEBUG processing the output of a run part 2; faulty address cntr %s\n",faulty_addresses_cntr.to_string().c_str());
477  #endif
478  #endif
479  if(!sProcpToTxp_Data.full()){
480  outNetWord.tdata=faulty_addresses_cntr;
481  outNetWord.tkeep = 0xFF;
482  outNetWord.tlast = 0;
483  sProcpToTxp_Data.write(outNetWord);
484  bytes_sent_for_tx += 8 ;
486  }
487  break;
489  #if DEBUG_LEVEL == TRACE_ALL
490  #ifndef __SYNTHESIS__
491  printf("DEBUG processing the output of a run part 3: first faulty address %s\n",first_faulty_address.to_string().c_str());
492  #endif
493  #endif
494  if(!sProcpToTxp_Data.full()){
495  outNetWord.tdata=first_faulty_address;
496  outNetWord.tkeep = 0xFF;
497  outNetWord.tlast = 0;
498  sProcpToTxp_Data.write(outNetWord);
499  bytes_sent_for_tx += 8;
501  }
502  break;
504  #if DEBUG_LEVEL == TRACE_ALL
505  printf("DEBUG processing the output of a run part 4\n");
506  #endif
507  if(!sProcpToTxp_Data.full()){
508  outNetWord.tdata = writing_cntr;
509  outNetWord.tkeep = 0xFF;
510  outNetWord.tlast = 0;
511  sProcpToTxp_Data.write(outNetWord);
512  bytes_sent_for_tx += 8;
514  }
515  break;
517  #if DEBUG_LEVEL == TRACE_ALL
518  printf("DEBUG processing the output of a run part 4\n");
519  #endif
520  if(!sProcpToTxp_Data.full()){
521  outNetWord.tdata= reading_cntr;
522  outNetWord.tkeep = 0xFF;
523  outNetWord.tlast = 0;
524  sProcpToTxp_Data.write(outNetWord);
525  bytes_sent_for_tx += 8;
527  }
528  break;
529 
530  }
531 };
532 
533 #endif //_ROLE_MEMTEST_PATTERN_H_
#define FSM_PROCESSING_OUTPUT_2
#define FSM_PROCESSING_WAIT_FOR_META
#define MEMTEST_ADDRESS_HIGH_BIT
ap_uint< 40 > local_mem_addr_t
#define ProcessingFsmType
#define FSM_PROCESSING_OUTPUT_3
#define MEMTEST_COMMANDS_HIGH_BIT
Definition: memtest.hpp:67
#define FSM_PROCESSING_WAIT_FOR_DDR_CONTROLLER_EMPTYNESS
#define FSM_PROCESSING_OUTPUT
#define FSM_PROCESSING_CONTINUOUS_RUN
#define DDR_LATENCY
Definition: memtest.hpp:98
#define FSM_PROCESSING_DATAFLOW_WRITE
#define MEMTEST_ITERATIONS_HIGH_BIT
#define ENABLE_DDR
Definition: memtest.hpp:42
void pReadDataflowMemTest(membus_t *lcl_mem1, local_mem_addr_t max_address_under_test, ap_uint< 64 > *reading_cntr, ap_uint< 32 > *faulty_addresses_cntr, local_mem_addr_t *first_faulty_address, unsigned int burst_size)
#define FSM_PROCESSING_OUTPUT_4
membus_512_t membus_t
Definition: memtest.hpp:92
#define MEMTEST_BURST_HIGH_BIT
#define FSM_PROCESSING_START
#define MEMTEST_BURST_LOW_BIT
const unsigned int top_param_maximum_number_of_beats
#define MEMTEST_ADDRESS_LOW_BIT
#define FSM_PROCESSING_DATAFLOW_READ
void pWriteDataflowMemTest(membus_t *lcl_mem0, local_mem_addr_t max_address_under_test, ap_uint< 64 > *writing_cntr, ap_uint< 32 > *testCounter, unsigned int burst_size)
#define FSM_PROCESSING_BURST_READING
#define MEMTEST_ITERATIONS_LOW_BIT
#define FSM_PROCESSING_OUTPUT_5
#define FSM_PROCESSING_PCKT_PROC
#define MEMTEST_COMMANDS_LOW_BIT
Definition: memtest.hpp:68
void pTHISProcessingData(stream< NetworkWord > &sRxpToProcp_Data, stream< NetworkWord > &sProcpToTxp_Data, stream< NetworkMetaStream > &sRxtoProc_Meta, stream< NetworkMetaStream > &sProctoTx_Meta, bool *start_stop)
THIS processing the data once recieved a start command Template function for custom processing.
membus_t lcl_mem0[16384]
membus_t lcl_mem1[16384]
#define PACK_SIZE
Definition: config.h:51
uint8_t processingFSM
Definition: uppercase.cpp:57
@ TEST_ENDOFTESTS_CMD
Definition: memtest.hpp:60
@ TEST_STOP_CMD
Definition: memtest.hpp:61
@ TEST_BURSTSIZE_CMD
Definition: memtest.hpp:59
@ TEST_INVLD_CMD
Definition: memtest.hpp:63
#define NETWORK_WORD_BIT_WIDTH
Definition: network.hpp:46
ap_uint< 64 > tdata
Definition: network.hpp:49
ap_uint< 8 > tkeep
Definition: network.hpp:50
ap_uint< 1 > tlast
Definition: network.hpp:51