cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
test_mceuropeanengine.cpp
Go to the documentation of this file.
1 
17 
32 #include "../../common/src/common.cpp"
33 
34 using namespace std;
35 
36 //---------------------------------------------------------
37 // HELPERS FOR THE DEBUGGING TRACES
38 // .e.g: DEBUG_LEVEL = (MDL_TRACE | IPS_TRACE)
39 //---------------------------------------------------------
40 #define THIS_NAME "TB"
41 
42 #define TRACE_OFF 0x0000
43 #define TRACE_URIF 1 << 1
44 #define TRACE_UAF 1 << 2
45 #define TRACE_MMIO 1 << 3
46 #define TRACE_ALL 0xFFFF
47 
48 #define DEBUG_LEVEL (TRACE_ALL)
49 
50 
51 //------------------------------------------------------
52 //-- TESTBENCH DEFINES
53 //------------------------------------------------------
54 #define OK true
55 #define KO false
56 #define VALID true
57 #define UNVALID false
58 #define DEBUG_TRACE true
59 
60 #define ENABLED (ap_uint<1>)1
61 #define DISABLED (ap_uint<1>)0
62 
63 
64 //------------------------------------------------------
65 //-- DUT INTERFACES AS GLOBAL VARIABLES
66 //------------------------------------------------------
67 
68 //-- SHELL / Uaf / Mmio / Config Interfaces
69 //ap_uint<2> piSHL_This_MmioEchoCtrl;
72 
73 //-- SHELL / Uaf / Udp Interfaces
74 stream<UdpWord> sSHL_Uaf_Data ("sSHL_Uaf_Data");
75 stream<UdpWord> sUAF_Shl_Data ("sUAF_Shl_Data");
76 
77 ap_uint<32> s_udp_rx_ports = 0x0;
78 stream<NetworkMetaStream> siUdp_meta ("siUdp_meta");
79 stream<NetworkMetaStream> soUdp_meta ("soUdp_meta");
80 ap_uint<32> node_rank;
81 ap_uint<32> cluster_size;
82 
83 //------------------------------------------------------
84 //-- TESTBENCH GLOBAL VARIABLES
85 //------------------------------------------------------
86 unsigned int simCnt;
87 
88 
89 
93 void stepDut() {
99  simCnt++;
100  printf("[%4.4d] STEP DUT \n", simCnt);
101 }
102 
103 
104 
105 
110 int main(int argc, char** argv) {
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 }
309 
310 
311 
312 
#define MIN_TX_LOOPS
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.
#define INSIZE
#define MIN_RX_LOOPS
unsigned int simCnt
stream< NetworkMetaStream > siUdp_meta("siUdp_meta")
int main(int argc, char **argv)
Main testbench of MCEuropeanEngine.
stream< NetworkMetaStream > soUdp_meta("soUdp_meta")
ap_uint< 1 > piSHL_This_MmioCaptPktEn
ap_uint< 1 > piSHL_This_MmioPostPktEn
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