cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
cF Vitis Quantitative Finance
cF » cFp » cFp_Zoo

This is the accelerated functions of Vitis Quantitative Finance sub-library from Vitis Open Source Library. More...

Collaboration diagram for cF Vitis Quantitative Finance:

Modules

 MCEuropeanEngine
 This is the MCEuropeanEngine accelerated function from Vitis Quantitative Finance Open Source Library.
 

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

bool setInputDataStream (stream< UdpWord > &sDataStream, const std::string dataStreamName, const std::string inpFileName, int simCnt)
 Initialize an input data stream from a file. More...
 
bool readDataStream (stream< UdpWord > &sDataStream, UdpWord *udpWord)
 Read data from a stream. More...
 
ap_uint< 64 > pack_ap_uint_64_ (ap_uint< 8 > *buffer)
 Pack an array of 8 x ap_uint<8> into a ap_uint<64> word. More...
 
bool dumpDataToFile (UdpWord *udpWord, std::ofstream &outFileStream)
 Dump a data word to a file. More...
 
bool dumpFileToString (const std::string inpFileName, std::string strOutput, int simCnt)
 Initialize an input data stream from a file. More...
 
bool getOutputDataStream (stream< UdpWord > &sDataStream, const std::string dataStreamName, const std::string outFileName, int simCnt)
 Fill an output file with data from an output stream. More...
 
bool dumpStructToFile (varin *s, const std::string outFileName, int simCnt)
 Fill an output file with data from an output stream. More...
 
bool setInputDataStream (stream< UdpWord > &sDataStream, const string dataStreamName, const string inpFileName, int simCnt)
 Initialize an input data stream from a file. More...
 
void unpack_ap_uint_64_ (ap_uint< 64 > value, ap_uint< 8 > *buffer)
 Unpack an ap_uint<64> word to an array of 8 x ap_uint<8>. More...
 
bool dumpDataToFile (UdpWord *udpWord, ofstream &outFileStream)
 Dump a data word to a file. More...
 
bool getOutputDataStream (stream< UdpWord > &sDataStream, const string dataStreamName, const string outFileName, int simCnt)
 Fill an output file with data from an output stream. More...
 
bool dumpStructToFile (varin *instruct, const string outFileName, int simCnt)
 Fill an output file with data from an image. More...
 
bool dumpFileToArray (const string inpFileName, double *out, int simCnt)
 Initialize an input data stream from a file. More...
 

Detailed Description

This is the accelerated functions of Vitis Quantitative Finance sub-library from Vitis Open Source Library.

Macro Definition Documentation

◆ DEBUG_LEVEL

#define DEBUG_LEVEL   (TRACE_ALL)

Definition at line 54 of file common.hpp.

◆ DEBUG_TRACE

#define DEBUG_TRACE   true

Definition at line 64 of file common.hpp.

◆ DISABLED

#define DISABLED   (ap_uint<1>)0

Definition at line 67 of file common.hpp.

◆ ENABLED

#define ENABLED   (ap_uint<1>)1

Definition at line 66 of file common.hpp.

◆ KO

#define KO   false

Definition at line 61 of file common.hpp.

◆ OK

#define OK   true

Definition at line 60 of file common.hpp.

◆ THIS_NAME

#define THIS_NAME   "TB"

Definition at line 46 of file common.hpp.

◆ TRACE_ALL

#define TRACE_ALL   0xFFFF

Definition at line 52 of file common.hpp.

◆ TRACE_MMIO

#define TRACE_MMIO   1 << 3

Definition at line 51 of file common.hpp.

◆ TRACE_OFF

#define TRACE_OFF   0x0000

Definition at line 48 of file common.hpp.

◆ TRACE_UAF

#define TRACE_UAF   1 << 2

Definition at line 50 of file common.hpp.

◆ TRACE_URIF

#define TRACE_URIF   1 << 1

Definition at line 49 of file common.hpp.

◆ UNVALID

#define UNVALID   false

Definition at line 63 of file common.hpp.

◆ VALID

#define VALID   true

Definition at line 62 of file common.hpp.

Function Documentation

◆ dumpDataToFile() [1/2]

bool dumpDataToFile ( UdpWord udpWord,
ofstream &  outFileStream 
)

Dump a data word to a file.

Parameters
[in]udpWord,apointer to the data word to dump.
[in]outFileStream,theoutput file stream to write to.
Returns
OK if successful, otherwise KO.

Definition at line 150 of file common.cpp.

150  {
151  if (!outFileStream.is_open()) {
152  printf("### ERROR : Output file stream is not open. \n");
153  return(KO);
154  }
155  outFileStream << hex << noshowbase << setfill('0') << setw(16) << udpWord->tdata.to_uint64();
156  outFileStream << " ";
157  outFileStream << hex << noshowbase << setfill('0') << setw(2) << udpWord->tkeep.to_int();
158  outFileStream << " ";
159  outFileStream << setw(1) << udpWord->tlast.to_int() << "\n";
160  return(OK);
161 }
#define OK
Definition: nts_types.hpp:57
#define KO
Definition: nts_types.hpp:58
ap_uint< 64 > tdata
ap_uint< 1 > tlast
ap_uint< 8 > tkeep

◆ dumpDataToFile() [2/2]

bool dumpDataToFile ( UdpWord udpWord,
std::ofstream &  outFileStream 
)

Dump a data word to a file.

Parameters
[in]udpWord,apointer to the data word to dump.
[in]outFileStream,theoutput file stream to write to.
Returns
OK if successful, otherwise KO.

◆ dumpFileToArray()

bool dumpFileToArray ( const string  inpFileName,
double *  out,
int  simCnt 
)

Initialize an input data stream from a file.

Parameters
[in]inpFileNamethe name of the input file to read from.
[out]strOutputthe output string to set.
Returns
OK if successful otherwise KO.

Definition at line 332 of file common.cpp.

332  {
333  string strLine;
334  ifstream inpFileStream;
335  string datFile = "../../../../test/" + inpFileName;
336  UdpWord udpWord;
337  unsigned int i = 0;
338  unsigned int bytes_per_line = 8;
339  ap_uint<8> value[bytes_per_line];
340  intToFloatUnion intToFloat;
341  //-- STEP-1 : OPEN FILE
342  inpFileStream.open(datFile.c_str());
343  if ( !inpFileStream ) {
344  cout << "### ERROR : Could not open the input data file " << datFile << endl;
345  return(KO);
346  }
347 
348  //-- STEP-2 : SET DATA STREAM
349  while (inpFileStream) {
350 
351  if (!inpFileStream.eof()) {
352 
353  getline(inpFileStream, strLine);
354  if (strLine.empty()) continue;
355  sscanf(strLine.c_str(), "%llx %x %d", &udpWord.tdata, &udpWord.tkeep, &udpWord.tlast);
356  //unpack_ap_uint_64_(udpWord.tdata, value);
357 
358  intToFloatUnion intToFloat;
359  intToFloat.i = (DtUsedInt)(udpWord.tdata);
360  assert(i<OUTDEP);
361  out[i++] = intToFloat.f;
362  }
363  }
364 
365  //-- STEP-3: CLOSE FILE
366  inpFileStream.close();
367 
368  return(OK);
369 }
long unsigned int DtUsedInt
Definition: config.h:74
#define OUTDEP
Definition: config.h:63
out
Definition: test.py:12
double f
Definition: config.h:103
DtUsedInt i
Definition: config.h:104

◆ dumpFileToString()

bool dumpFileToString ( const std::string  inpFileName,
std::string  strOutput,
int  simCnt 
)

Initialize an input data stream from a file.

Parameters
[in]inpFileNamethe name of the input file to read from.
[out]strOutputthe output string to set.
Returns
OK if successful otherwise KO.

◆ dumpStructToFile() [1/2]

bool dumpStructToFile ( varin instruct,
const string  outFileName,
int  simCnt 
)

Fill an output file with data from an image.

Parameters
[in]sDataStreamthe input image in xf::cv::Mat format.
[in]outFileNamethe name of the output file to write to.
Returns
OK if successful, otherwise KO.

Definition at line 217 of file common.cpp.

218 {
219  string strLine;
220  ofstream outFileStream;
221  string datFile = "../../../../test/" + outFileName;
222  UdpWord udpWord;
223  bool rc = OK;
224  unsigned int bytes_per_line = 8;
225 
226  //-- STEP-1 : OPEN FILE
227  outFileStream.open(datFile.c_str());
228  if ( !outFileStream ) {
229  cout << "### ERROR : Could not open the output data file " << datFile << endl;
230  return(KO);
231  }
232  ap_uint<8> value[bytes_per_line];
233  unsigned int total_bytes = 0;
234 
235 
236  intToFloatUnion intToFloat;
237 
238  //-- STEP-2 : DUMP STRING DATA TO FILE
239  for (unsigned int i = 0, j = 0; i < INSIZE; i+=sizeof(DtUsed), j++, total_bytes+=bytes_per_line) {
240  switch(j)
241  {
242  case 0:
243  intToFloat.i = instruct->loop_nm;
244  printf("DEBUG instruct->loop_nm = %u\n", (unsigned int)instruct->loop_nm);
245  break;
246  case 1:
247  intToFloat.i = instruct->seed;
248  printf("DEBUG instruct->seed = %u\n", (unsigned int)instruct->seed);
249  break;
250  case 2:
251  intToFloat.f = instruct->underlying;
252  printf("DEBUG instruct->underlying = %f\n", instruct->underlying);
253  break;
254  case 3:
255  intToFloat.f = instruct->volatility;
256  printf("DEBUG instruct->volatility = %f\n", instruct->volatility);
257  break;
258  case 4:
259  intToFloat.f = instruct->dividendYield;
260  printf("DEBUG instruct->dividendYield = %f\n", instruct->dividendYield);
261  break;
262  case 5:
263  intToFloat.f = instruct->riskFreeRate;
264  printf("DEBUG instruct->riskFreeRate = %f\n", instruct->riskFreeRate);
265  break;
266  case 6:
267  intToFloat.f = instruct->timeLength;
268  printf("DEBUG instruct->timeLength = %f\n", instruct->timeLength);
269  break;
270  case 7:
271  intToFloat.f = instruct->strike;
272  printf("DEBUG instruct->strike = %f\n", instruct->strike);
273  break;
274  case 8:
275  intToFloat.i = instruct->optionType;
276  printf("DEBUG instruct->optionType = %u\n", (unsigned int)instruct->optionType);
277  break;
278  case 9:
279  intToFloat.f = instruct->requiredTolerance;
280  printf("DEBUG instruct->requiredTolerance = %f\n", instruct->requiredTolerance);
281  break;
282  case 10:
283  intToFloat.i = instruct->requiredSamples;
284  printf("DEBUG instruct->requiredSamples = %u\n", (unsigned int)instruct->requiredSamples);
285  break;
286  case 11:
287  intToFloat.i = instruct->timeSteps;
288  printf("DEBUG instruct->timeSteps = %u\n", (unsigned int)instruct->timeSteps);
289  break;
290  case 12:
291  intToFloat.i = instruct->maxSamples;
292  printf("DEBUG instruct->maxSamples = %u\n", (unsigned int)instruct->maxSamples);
293  break;
294  default:
295  printf("ERROR: unknown value %u\n", j);
296  rc = KO;
297  break;
298  }
299 
300  udpWord.tdata = (ap_uint<64>)intToFloat.i;
301  udpWord.tkeep = 255;
302  // We are signaling a packet termination either at the end of the image or the end of MTU
303  if ((total_bytes >= (INSIZE - bytes_per_line)) ||
304  ((total_bytes + bytes_per_line) % PACK_SIZE == 0)) {
305  udpWord.tlast = 1;
306  }
307  else {
308  udpWord.tlast = 0;
309  }
310  printf("[%4.4d] IMG TB is dumping string to file [%s] - Data read [%u] = {val=%u, D=0x%16.16llX, K=0x%2.2X, L=%d} \n",
311  simCnt, datFile.c_str(), total_bytes, value,
312  udpWord.tdata.to_long(), udpWord.tkeep.to_int(), udpWord.tlast.to_int());
313  if (!dumpDataToFile(&udpWord, outFileStream)) {
314  rc = KO;
315  break;
316  }
317  }
318  //-- STEP-3: CLOSE FILE
319  outFileStream.close();
320 
321  return(rc);
322 }
int simCnt
Definition: tb_fmc.cpp:113
bool dumpDataToFile(UdpWord *udpWord, ofstream &outFileStream)
Dump a data word to a file.
Definition: common.cpp:153
#define INSIZE
#define DtUsed
Definition: config.h:57
#define PACK_SIZE
Definition: config.h:51
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
Here is the call graph for this function:

◆ dumpStructToFile() [2/2]

bool dumpStructToFile ( varin s,
const std::string  outFileName,
int  simCnt 
)

Fill an output file with data from an output stream.

Parameters
[in]sthe struct with configuration parameters for MCEuropeanEngine.
[in]outFileNamethe name of the output file to write to.
Returns
OK if successful, otherwise KO.

◆ getOutputDataStream() [1/2]

bool getOutputDataStream ( stream< UdpWord > &  sDataStream,
const std::string  dataStreamName,
const std::string  outFileName,
int  simCnt 
)

Fill an output file with data from an output stream.

Parameters
[in]sDataStreamthe output data stream to set.
[in]dataStreamNamethe name of the data stream.
[in]outFileNamethe name of the output file to write to.
Returns
OK if successful, otherwise KO.

◆ getOutputDataStream() [2/2]

bool getOutputDataStream ( stream< UdpWord > &  sDataStream,
const string  dataStreamName,
const string  outFileName,
int  simCnt 
)

Fill an output file with data from an output stream.

Parameters
[in]sDataStream,theoutput data stream to set.
[in]dataStreamName,thename of the data stream.
[in]outFileName,thename of the output file to write to.
Returns
OK if successful, otherwise KO.

Definition at line 173 of file common.cpp.

175 {
176  string strLine;
177  ofstream outFileStream;
178  string datFile = "../../../../test/" + outFileName;
179  UdpWord udpWord;
180  bool rc = OK;
181 
182  //-- STEP-1 : OPEN FILE
183  outFileStream.open(datFile.c_str());
184  if ( !outFileStream ) {
185  cout << "### ERROR : Could not open the output data file " << datFile << endl;
186  return(KO);
187  }
188 
189  //-- STEP-2 : EMPTY STREAM AND DUMP DATA TO FILE
190  while (!sDataStream.empty()) {
191  if (readDataStream(sDataStream, &udpWord) == VALID) {
192  // Print DUT/Data to console
193  printf("[%4.4d] TB is draining output stream [%s] - Data read = {D=0x%16.16llX, K=0x%2.2X, L=%d} \n",
194  simCnt, dataStreamName.c_str(),
195  udpWord.tdata.to_long(), udpWord.tkeep.to_int(), udpWord.tlast.to_int());
196  if (!dumpDataToFile(&udpWord, outFileStream)) {
197  rc = KO;
198  break;
199  }
200  }
201  }
202 
203  //-- STEP-3: CLOSE FILE
204  outFileStream.close();
205 
206  return(rc);
207 }
bool readDataStream(stream< UdpAppData > &sDataStream, UdpAppData *udpWord)
Read data from a stream.
Definition: tb_nal.cpp:395
#define VALID
Definition: tb_nal.cpp:43
Here is the call graph for this function:

◆ pack_ap_uint_64_()

ap_uint<64> pack_ap_uint_64_ ( ap_uint< 8 > *  buffer)

Pack an array of 8 x ap_uint<8> into a ap_uint<64> word.

Parameters
[in]bufferA pointer to an array of 8 x ap_uint<8>
Returns
An ap_uint<64> word.

Definition at line 113 of file common.cpp.

113  {
114 
115  ap_uint<64> value;
116 
117  value = buffer[7];
118  value = (value << 8 ) + buffer[6];
119  value = (value << 8 ) + buffer[5];
120  value = (value << 8 ) + buffer[4];
121  value = (value << 8 ) + buffer[3];
122  value = (value << 8 ) + buffer[2];
123  value = (value << 8 ) + buffer[1];
124  value = (value << 8 ) + buffer[0];
125 
126  return value ;
127 
128 }

◆ readDataStream()

bool readDataStream ( stream< UdpWord > &  sDataStream,
UdpWord udpWord 
)

Read data from a stream.

Parameters
[in]sDataStream,theoutput data stream to read.
[in]dataStreamName,thename of the data stream.
[out]udpWord,apointer to the storage location of the data to read.
Returns
VALID if a data was read, otherwise UNVALID.

Definition at line 100 of file common.cpp.

100  {
101  // Get the DUT/Data results
102  sDataStream.read(*udpWord);
103  return(VALID);
104 }

◆ setInputDataStream() [1/2]

bool setInputDataStream ( stream< UdpWord > &  sDataStream,
const std::string  dataStreamName,
const std::string  inpFileName,
int  simCnt 
)

Initialize an input data stream from a file.

Parameters
[in]sDataStreamthe input data stream to set.
[in]dataStreamNamethe name of the data stream.
[in]inpFileNamethe name of the input file to read from.
Returns
OK if successful otherwise KO.

◆ setInputDataStream() [2/2]

bool setInputDataStream ( stream< UdpWord > &  sDataStream,
const string  dataStreamName,
const string  inpFileName,
int  simCnt 
)

Initialize an input data stream from a file.

Parameters
[in]sDataStreamthe input data stream to set.
[in]dataStreamNamethe name of the data stream.
[in]inpFileNamethe name of the input file to read from.
Returns
OK if successful otherwise KO.

Definition at line 45 of file common.cpp.

46  {
47  string strLine;
48  ifstream inpFileStream;
49  string datFile = "../../../../test/" + inpFileName;
50  UdpWord udpWord;
51 
52  //-- STEP-1 : OPEN FILE
53  inpFileStream.open(datFile.c_str());
54  if ( !inpFileStream ) {
55  cout << "### ERROR : Could not open the input data file " << datFile << endl;
56  return(KO);
57  }
58 
59  //-- STEP-2 : SET DATA STREAM
60  while (inpFileStream) {
61 
62  if (!inpFileStream.eof()) {
63 
64  getline(inpFileStream, strLine);
65  if (strLine.empty()) continue;
66  sscanf(strLine.c_str(), "%llx %x %d", &udpWord.tdata, &udpWord.tkeep, &udpWord.tlast);
67 
68  // Write to sDataStream
69  if (sDataStream.full()) {
70  printf("### ERROR : Stream is full. Cannot write stream with data from file \"%s\".\n", inpFileName.c_str());
71  return(KO);
72  } else {
73  sDataStream.write(udpWord);
74  // Print Data to console
75  printf("[%4.4d] TB is filling input stream [%s] - Data write = {D=0x%16.16llX, K=0x%2.2X, L=%d} \n",
76  simCnt, dataStreamName.c_str(),
77  udpWord.tdata.to_long(), udpWord.tkeep.to_int(), udpWord.tlast.to_int());
78  }
79  }
80  }
81 
82  //-- STEP-3: CLOSE FILE
83  inpFileStream.close();
84 
85  return(OK);
86 }

◆ unpack_ap_uint_64_()

void unpack_ap_uint_64_ ( ap_uint< 64 >  value,
ap_uint< 8 > *  buffer 
)

Unpack an ap_uint<64> word to an array of 8 x ap_uint<8>.

Parameters
[in]bufferA pointer to an ap_uint<64> word
Returns
An ap_uint<64> word.

Definition at line 136 of file common.cpp.

136  {
137 
138  for (unsigned int i=0; i<8; i++) {
139  buffer[i] = (value >> 8*i );
140  }
141 }