cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
MCEuropeanEngine Testbench

This is a subgroup of MCEuropeanEngine accelerated function with only testbench-related functions/classes/. More...

Collaboration diagram for MCEuropeanEngine Testbench:

Files

file  test_mceuropeanengine.cpp
 Testbench for MCEuropeanEngine.
 

Macros

#define THIS_NAME   "TB"
 
#define TRACE_OFF   0x0000
 
#define TRACE_URIF   1 << 1
 
#define TRACE_UAF   1 << 2
 
#define TRACE_MMIO   1 << 3
 
#define TRACE_ALL   0xFFFF
 
#define DEBUG_LEVEL   (TRACE_ALL)
 
#define OK   true
 
#define KO   false
 
#define VALID   true
 
#define UNVALID   false
 
#define DEBUG_TRACE   true
 
#define ENABLED   (ap_uint<1>)1
 
#define DISABLED   (ap_uint<1>)0
 

Functions

stream< UdpWordsSHL_Uaf_Data ("sSHL_Uaf_Data")
 
stream< UdpWordsUAF_Shl_Data ("sUAF_Shl_Data")
 
stream< NetworkMetaStreamsiUdp_meta ("siUdp_meta")
 
stream< NetworkMetaStreamsoUdp_meta ("soUdp_meta")
 
void stepDut ()
 Run a single iteration of the DUT model. More...
 
int main (int argc, char **argv)
 Main testbench of MCEuropeanEngine. More...
 

Variables

ap_uint< 1 > piSHL_This_MmioPostPktEn
 
ap_uint< 1 > piSHL_This_MmioCaptPktEn
 
ap_uint< 32 > s_udp_rx_ports = 0x0
 
ap_uint< 32 > node_rank
 
ap_uint< 32 > cluster_size
 
unsigned int simCnt
 

Detailed Description

This is a subgroup of MCEuropeanEngine accelerated function with only testbench-related functions/classes/.

This is a subgroup of MCEuropeanEngine accelerated function with only testbench-related functions/classes.

Macro Definition Documentation

◆ DEBUG_LEVEL

#define DEBUG_LEVEL   (TRACE_ALL)

Definition at line 48 of file test_mceuropeanengine.cpp.

◆ DEBUG_TRACE

#define DEBUG_TRACE   true

Definition at line 58 of file test_mceuropeanengine.cpp.

◆ DISABLED

#define DISABLED   (ap_uint<1>)0

Definition at line 61 of file test_mceuropeanengine.cpp.

◆ ENABLED

#define ENABLED   (ap_uint<1>)1

Definition at line 60 of file test_mceuropeanengine.cpp.

◆ KO

#define KO   false

Definition at line 55 of file test_mceuropeanengine.cpp.

◆ OK

#define OK   true

Definition at line 54 of file test_mceuropeanengine.cpp.

◆ THIS_NAME

#define THIS_NAME   "TB"

Definition at line 40 of file test_mceuropeanengine.cpp.

◆ TRACE_ALL

#define TRACE_ALL   0xFFFF

Definition at line 46 of file test_mceuropeanengine.cpp.

◆ TRACE_MMIO

#define TRACE_MMIO   1 << 3

Definition at line 45 of file test_mceuropeanengine.cpp.

◆ TRACE_OFF

#define TRACE_OFF   0x0000

Definition at line 42 of file test_mceuropeanengine.cpp.

◆ TRACE_UAF

#define TRACE_UAF   1 << 2

Definition at line 44 of file test_mceuropeanengine.cpp.

◆ TRACE_URIF

#define TRACE_URIF   1 << 1

Definition at line 43 of file test_mceuropeanengine.cpp.

◆ UNVALID

#define UNVALID   false

Definition at line 57 of file test_mceuropeanengine.cpp.

◆ VALID

#define VALID   true

Definition at line 56 of file test_mceuropeanengine.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Main testbench of MCEuropeanEngine.

Returns
0 upon success, nrErr else.

Definition at line 110 of file test_mceuropeanengine.cpp.

110  {
111 
112  //------------------------------------------------------
113  //-- TESTBENCH LOCAL VARIABLES
114  //------------------------------------------------------
115  int nrErr = 0;
116 
117  printf("#####################################################\n");
118  printf("## TESTBENCH STARTS HERE ##\n");
119  printf("#####################################################\n");
120 
121  simCnt = 0;
122  nrErr = 0;
123 
124  if (argc != 2) {
125  printf("Usage : %s <configuration file>. Provided %d\n", argv[0], argc);
126  return -1;
127  }
128 
129  // Ensure that the selection of MTU is a multiple of 8 (Bytes per transaction)
130  assert(PACK_SIZE % 8 == 0);
131 
132  //------------------------------------------------------
133  //-- TESTBENCH LOCAL VARIABLES FOR MCEUROPEANENGINE
134  //------------------------------------------------------
135  varin instruct;
136  const char *fname = argv[1]; //"../../../../etc/mce.conf";
137  if (readFileConfigToStruct(fname, &instruct) != INSIZE) {
138  printf("WARNING: Invalid read size of configration file %s. Will use default...\n", fname);
139  instruct.loop_nm = OUTDEP;
140  instruct.seed = 4332 ; // 441242, 42, 13342;
141  instruct.underlying = 36;
142  instruct.volatility = 0.20;
143  instruct.dividendYield = 0.0;
144  instruct.riskFreeRate = 0.06;
145  instruct.timeLength = 1;
146  instruct.strike = 40;
147  instruct.optionType = 1;
148  instruct.requiredTolerance = 0.02;
149  instruct.requiredSamples = 1; // 262144; // 48128;//0;//1024;//0;
150  instruct.timeSteps = 1;
151  instruct.maxSamples = 1;
152  }
153 
154  if ((instruct.loop_nm == 0) || (instruct.loop_nm > OUTDEP)) {
155  printf("WARNING tb Invalid instruct->loop_nm = %u. Will assign %u\n", (unsigned int)instruct.loop_nm, OUTDEP);
156  instruct.loop_nm = OUTDEP;
157  }
158 
159  // At least MIN_RX_LOOPS for loading data and 2*MIN_TX_LOOPS for processing data and Tx them
160  unsigned int sim_time = MIN_RX_LOOPS + 2*MIN_TX_LOOPS + 10;
161 
162  // input size is known at compile/synthesis time
163  unsigned int tot_trasnfers_in = TOT_TRANSFERS_IN;
164 
165  // output size is not known at compile/synthesis time, since it is related to loop_nm
166  unsigned int outsize = instruct.loop_nm * sizeof(DtUsed);
167  unsigned int tot_trasnfers_out = CEIL(outsize, PACK_SIZE);
168 
169  DtUsed *out = (DtUsed*)malloc(instruct.loop_nm * sizeof(DtUsed));
170  if (!out) {
171  printf("ERROR: Cannot allocate memory for output array. Aborting...\n");
172  return -1;
173  }
174 
175 
176  //------------------------------------------------------
177  //-- STEP-1.1 : CREATE FILE FROM INPUT CONFIGURATION
178  //------------------------------------------------------
179  if (!dumpStructToFile(&instruct, "ifsSHL_Uaf_Data.dat", simCnt)) {
180  nrErr++;
181  }
182 
183  for (unsigned int tb_loop = 0; tb_loop < 1; tb_loop++) {
184  //------------------------------------------------------
185  //-- STEP-2.1 : CREATE TRAFFIC AS INPUT STREAM
186  //------------------------------------------------------
187  if (nrErr == 0) {
188  if (!setInputDataStream(sSHL_Uaf_Data, "sSHL_Uaf_Data", "ifsSHL_Uaf_Data.dat", simCnt)) {
189  printf("### ERROR : Failed to set input data stream \"sSHL_Uaf_Data\". \n");
190  nrErr++;
191  }
192 
193  //there are tot_trasnfers_in streams from the the App to the Role
195  for (unsigned int i = 0; i < tot_trasnfers_in; i++) {
196  siUdp_meta.write(NetworkMetaStream(tmp_meta));
197  }
198  //set correct node_rank and cluster_size
199  node_rank = 1;
200  cluster_size = 2;
201  }
202 
203  //------------------------------------------------------
204  //-- STEP-2.2 : SET THE PASS-THROUGH MODE
205  //------------------------------------------------------
206  //piSHL_This_MmioEchoCtrl.write(ECHO_PATH_THRU);
207  //[TODO] piSHL_This_MmioPostPktEn.write(DISABLED);
208  //[TODO] piSHL_This_MmioCaptPktEn.write(DISABLED);
209 
210  //------------------------------------------------------
211  //-- STEP-3 : MAIN TRAFFIC LOOP
212  //------------------------------------------------------
213  while (!nrErr) {
214 
215  // Keep enough simulation time for sequentially executing the FSMs of the main 3 functions
216  // (Rx-Tx)
217  if (simCnt < sim_time)
218  {
219  stepDut();
220 
221  if(simCnt > 2)
222  {
223  assert(s_udp_rx_ports == 0x1);
224  }
225 
226  //if( !soUdp_meta.empty())
227  //{
228  // NetworkMetaStream tmp_meta = soUdp_meta.read();
229  // printf("NRC received NRCmeta stream from node_rank %d.\n", (int) tmp_meta.tdata.src_rank);
230  //}
231 
232 
233  } else {
234  printf("## End of simulation at cycle=%3d. \n", simCnt);
235  break;
236  }
237 
238  } // End: while()
239 
240  //-------------------------------------------------------
241  //-- STEP-4 : DRAIN AND WRITE OUTPUT FILE STREAMS
242  //-------------------------------------------------------
243  //---- UAF-->SHELL Data ----
244  if (!getOutputDataStream(sUAF_Shl_Data, "sUAF_Shl_Data", "ofsUAF_Shl_Data.dat", simCnt))
245  {
246  nrErr++;
247  }
248  //---- UAF-->SHELL META ----
249  if( !soUdp_meta.empty())
250  {
251  unsigned int i = 0;
252  while( !soUdp_meta.empty())
253  {
254  i++;
255  NetworkMetaStream tmp_meta = soUdp_meta.read();
256  printf("NRC received NRCmeta stream from rank %d to rank %d.\n", (int) tmp_meta.tdata.src_rank, (int) tmp_meta.tdata.dst_rank);
257  assert(tmp_meta.tdata.src_rank == node_rank);
258  //ensure forwarding behavior
259  assert(tmp_meta.tdata.dst_rank == ((tmp_meta.tdata.src_rank + 1) % cluster_size));
260  }
261  //printf("i=%u, tot_trasnfers_in=%u, tot_trasnfers_out=%u\n", i,tot_trasnfers_in, tot_trasnfers_out);
262  assert(i == tot_trasnfers_out);
263  }
264  else {
265  printf("Error No metadata received...\n");
266  nrErr++;
267  }
268 
269  //-------------------------------------------------------
270  //-- STEP-5 : FROM THE OUTPUT FILE CREATE AN ARRAY
271  //-------------------------------------------------------
272 
273  if (!dumpFileToArray("ofsUAF_Shl_Data.dat", out, simCnt)) {
274  printf("### ERROR : Failed to set array from file \"ofsUAF_Shl_Data.dat\". \n");
275  nrErr++;
276  }
277  writeArrayToFile("./hls_out.txt", out);
278  for (unsigned int i = 0; i < instruct.loop_nm; i++) {
279  printf("Option price %u: %f\n", i, out[i]);
280  }
281  //------------------------------------------------------
282  //-- STEP-6 : COMPARE OUTPUT AND GOLDEN FILE STREAMS
283  //------------------------------------------------------
284  int rc1 = system("diff --brief -w -i -y ../../../../test/ofsUAF_Shl_Data.dat \
285  ../../../../test/verify_UAF_Shl_Data.dat");
286  if (rc1)
287  {
288  printf("## Error : File \'ofsUAF_Shl_Data.dat\' does not match \'verify_UAF_Shl_Data.dat\'.\n");
289  } else {
290  printf("Output data in file \'ofsUAF_Shl_Data.dat\' verified.\n");
291  }
292 
293  nrErr += rc1;
294 
295  } // end for tb_loop
296 
297  printf("#####################################################\n");
298  if (nrErr)
299  {
300  printf("## ERROR - TESTBENCH FAILED (RC=%d) !!! ##\n", nrErr);
301  } else {
302  printf("## SUCCESSFULL END OF TESTBENCH (RC=0) ##\n");
303  }
304  printf("#####################################################\n");
305 
306 
307  return(nrErr);
308 }
#define MIN_TX_LOOPS
#define INSIZE
#define MIN_RX_LOOPS
unsigned int simCnt
stream< NetworkMetaStream > siUdp_meta("siUdp_meta")
stream< NetworkMetaStream > soUdp_meta("soUdp_meta")
stream< UdpWord > sUAF_Shl_Data("sUAF_Shl_Data")
void stepDut()
Run a single iteration of the DUT model.
stream< UdpWord > sSHL_Uaf_Data("sSHL_Uaf_Data")
ap_uint< 32 > cluster_size
ap_uint< 32 > s_udp_rx_ports
ap_uint< 32 > node_rank
#define TOT_TRANSFERS_IN
Definition: config.h:68
#define OUTDEP
Definition: config.h:63
#define DtUsed
Definition: config.h:57
#define PACK_SIZE
Definition: config.h:51
#define CEIL(a, b)
Definition: config.h:37
bool setInputDataStream(stream< UdpAppData > &sDataStream, const string dataStreamName, const string inpFileName)
Initialize an input data stream from a file.
Definition: tb_nal.cpp:214
#define DEFAULT_RX_PORT
Definition: nal.hpp:139
bool getOutputDataStream(stream< UdpAppData > &sDataStream, const string dataStreamName, const string outFileName)
Fill an output file with data from an output stream.
Definition: tb_nal.cpp:526
bool dumpFileToArray(const string inpFileName, double *out, int simCnt)
Initialize an input data stream from a file.
Definition: common.cpp:332
bool dumpStructToFile(varin *s, const std::string outFileName, int simCnt)
Fill an output file with data from an output stream.
out
Definition: test.py:12
NetworkMeta tdata
Definition: network.hpp:109
NodeId dst_rank
Definition: network.hpp:95
NodeId src_rank
Definition: network.hpp:97
Definition: config.h:85
double dividendYield
Definition: config.h:90
DtUsedInt seed
Definition: config.h:87
DtUsedInt maxSamples
Definition: config.h:98
double riskFreeRate
Definition: config.h:91
double volatility
Definition: config.h:89
double requiredTolerance
Definition: config.h:95
DtUsedInt loop_nm
Definition: config.h:86
double underlying
Definition: config.h:88
DtUsedInt timeSteps
Definition: config.h:97
double strike
Definition: config.h:93
DtUsedInt requiredSamples
Definition: config.h:96
DtUsedInt optionType
Definition: config.h:94
double timeLength
Definition: config.h:92

◆ siUdp_meta()

stream<NetworkMetaStream> siUdp_meta ( "siUdp_meta"  )
Here is the caller graph for this function:

◆ soUdp_meta()

stream<NetworkMetaStream> soUdp_meta ( "soUdp_meta"  )
Here is the caller graph for this function:

◆ sSHL_Uaf_Data()

stream<UdpWord> sSHL_Uaf_Data ( "sSHL_Uaf_Data"  )
Here is the caller graph for this function:

◆ stepDut()

void stepDut ( )

Run a single iteration of the DUT model.

Returns
Nothing.

Definition at line 93 of file test_mceuropeanengine.cpp.

93  {
99  simCnt++;
100  printf("[%4.4d] STEP DUT \n", simCnt);
101 }
void mceuropeanengine(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 MCEuropeanEngine Application directives.
Here is the call graph for this function:

◆ sUAF_Shl_Data()

stream<UdpWord> sUAF_Shl_Data ( "sUAF_Shl_Data"  )
Here is the caller graph for this function:

Variable Documentation

◆ cluster_size

ap_uint<32> cluster_size

Definition at line 81 of file test_mceuropeanengine.cpp.

◆ node_rank

ap_uint<32> node_rank

Definition at line 80 of file test_mceuropeanengine.cpp.

◆ piSHL_This_MmioCaptPktEn

ap_uint<1> piSHL_This_MmioCaptPktEn

Definition at line 71 of file test_mceuropeanengine.cpp.

◆ piSHL_This_MmioPostPktEn

ap_uint<1> piSHL_This_MmioPostPktEn

Definition at line 70 of file test_mceuropeanengine.cpp.

◆ s_udp_rx_ports

ap_uint<32> s_udp_rx_ports = 0x0

Definition at line 77 of file test_mceuropeanengine.cpp.

◆ simCnt

unsigned int simCnt

Definition at line 86 of file test_mceuropeanengine.cpp.