36 #include "../../../../../HOST/quantitative_finance/mceuropeanengine/languages/cplusplus/include/config.h"
37 #include "../include/mceuropeanengine.hpp"
39 #if defined USE_HLSLIB_DATAFLOW || defined USE_HLSLIB_STREAM
40 #include "../../../../../hlslib/include/hlslib/xilinx/Stream.h"
41 #include "../../../../../hlslib/include/hlslib/xilinx/Simulation.h"
44 #ifdef USE_HLSLIB_STREAM
61 unsigned int *processed_word_rx,
62 unsigned int *struct_loaded)
66 for (
unsigned int i=0; i<loop_cnt; i++) {
67 printf(
"DEBUG: Checking: word.tkeep=%u >> %u = %u\n", word.
tkeep.to_int(), i, (word.
tkeep.to_int() >> i));
68 if ((word.
tkeep >> i) == 0) {
69 printf(
"WARNING: value with tkeep=0 at i=%u\n", i);
74 switch((*processed_word_rx)++)
77 if ((intToFloat.
i == 0) || (intToFloat.
i >
OUTDEP)) {
78 printf(
"WARNING Invalid instruct->loop_nm = %u. Will assign %u\n", (
unsigned int)intToFloat.
i,
OUTDEP);
84 printf(
"DEBUG instruct->loop_nm = %u\n", (
unsigned int)instruct->
loop_nm);
87 instruct->
seed = intToFloat.
i;
88 printf(
"DEBUG instruct->seed = %u\n", (
unsigned int)instruct->
seed);
92 printf(
"DEBUG instruct->underlying = %f\n", instruct->
underlying);
96 printf(
"DEBUG instruct->volatility = %f\n", instruct->
volatility);
100 printf(
"DEBUG instruct->dividendYield = %f\n", instruct->
dividendYield);
104 printf(
"DEBUG instruct->riskFreeRate = %f\n", instruct->
riskFreeRate);
108 printf(
"DEBUG instruct->timeLength = %f\n", instruct->
timeLength);
111 instruct->
strike = intToFloat.
f;
112 printf(
"DEBUG instruct->strike = %f\n", instruct->
strike);
116 printf(
"DEBUG instruct->optionType = %u\n", (
unsigned int)instruct->
optionType);
124 printf(
"DEBUG instruct->requiredSamples = %u\n", (
unsigned int)instruct->
requiredSamples);
128 printf(
"DEBUG instruct->timeSteps = %u\n", (
unsigned int)instruct->
timeSteps);
132 printf(
"DEBUG instruct->maxSamples = %u\n", (
unsigned int)instruct->
maxSamples);
134 printf(
"DEBUG in storeWordToStruct: WARNING - you've loaded the struct. Will put *struct_loaded = 1.\n");
159 stream<NetworkWord> &siSHL_This_Data,
160 stream<NetworkMetaStream> &siNrc_meta,
163 unsigned int *processed_word_rx,
164 unsigned int *struct_loaded
176 printf(
"DEBUG in pRXPath: enqueueFSM - WAIT_FOR_META, *processed_word_rx=%u\n",
178 if ( !siNrc_meta.empty())
180 meta_tmp = siNrc_meta.read();
187 printf(
"DEBUG in pRXPath: enqueueFSM - PROCESSING_PACKET, *processed_word_rx=%u\n",
189 if ( !siSHL_This_Data.empty() )
192 netWord = siSHL_This_Data.read();
194 if(netWord.
tlast == 1)
218 stream<NetworkWord> &sRxpToTxp_Data,
219 stream<NetworkMetaStream> &sRxtoTx_Meta,
223 unsigned int *processed_word_rx,
224 unsigned int *processed_word_proc,
225 unsigned int *struct_loaded
234 static bool finished =
false;
235 #pragma HLS reset variable=finished
240 printf(
"DEBUG in pProcPath: WAIT_FOR_META\n");
241 *processed_word_proc = 0;
243 if ( (*struct_loaded) == 1 )
246 *processed_word_rx = 0;
252 printf(
"DEBUG in pProcPath: PROCESSING_PACKET\n");
274 printf(
"DEBUG in pProcPath: PROCESSING_WAIT\n");
284 printf(
"DEBUG in pProcPath: MCEUROPEANENGINE_RETURN_RESULTS, *processed_word_proc=%u\n", *processed_word_proc);
285 if ( !sRxpToTxp_Data.full() && !sRxtoTx_Meta.full()) {
287 printf(
"DEBUG in pProcPath: New packet will be needed. Writting to sRxtoTx_Meta.\n");
288 sRxtoTx_Meta.write(meta_tmp);
291 if ( (*processed_word_proc) == instruct->
loop_nm-1 ) {
299 unsigned int keep = 255;
300 intToFloat.
f =
out[(*processed_word_proc)++];
301 newWord =
NetworkWord((ap_uint<64>)intToFloat.
i, keep, last);
302 sRxpToTxp_Data.write(newWord);
323 stream<NetworkWord> &soTHIS_Shl_Data,
324 stream<NetworkMetaStream> &soNrc_meta,
325 stream<NetworkWord> &sRxpToTxp_Data,
326 stream<NetworkMetaStream> &sRxtoTx_Meta,
327 unsigned int *processed_word_tx,
328 ap_uint<32> *pi_rank,
343 printf(
"DEBUG in pTXPath: dequeueFSM=%d - WAIT_FOR_STREAM_PAIR, *processed_word_tx=%u\n",
346 *processed_word_tx = 0;
355 if (( !sRxpToTxp_Data.empty() && !sRxtoTx_Meta.empty()
356 && !soTHIS_Shl_Data.full() && !soNrc_meta.full() ))
358 netWordTx = sRxpToTxp_Data.read();
365 soTHIS_Shl_Data.write(netWordTx);
367 meta_in = sRxtoTx_Meta.read().tdata;
369 meta_out_stream.
tlast = 1;
370 meta_out_stream.
tkeep = 0xFF;
381 soNrc_meta.write(meta_out_stream);
383 (*processed_word_tx)++;
385 if(netWordTx.
tlast != 1)
393 printf(
"DEBUG in pTXPath: dequeueFSM=%d - PROCESSING_PACKET, *processed_word_tx=%u\n",
395 if( !sRxpToTxp_Data.empty() && !soTHIS_Shl_Data.full())
397 netWordTx = sRxpToTxp_Data.read();
398 (*processed_word_tx)++;
401 if(netWordTx.
tlast == 1)
413 soTHIS_Shl_Data.write(netWordTx);
428 ap_uint<32> *pi_rank,
429 ap_uint<32> *pi_size,
433 stream<NetworkWord> &siSHL_This_Data,
434 stream<NetworkWord> &soTHIS_Shl_Data,
435 stream<NetworkMetaStream> &siNrc_meta,
436 stream<NetworkMetaStream> &soNrc_meta,
437 ap_uint<32> *po_rx_ports
446 #pragma HLS INTERFACE axis register both port=siSHL_This_Data
447 #pragma HLS INTERFACE axis register both port=soTHIS_Shl_Data
449 #pragma HLS INTERFACE axis register both port=siNrc_meta
450 #pragma HLS INTERFACE axis register both port=soNrc_meta
452 #pragma HLS INTERFACE ap_ovld register port=po_rx_ports name=poROL_NRC_Rx_ports
453 #pragma HLS INTERFACE ap_stable register port=pi_rank name=piFMC_ROL_rank
454 #pragma HLS INTERFACE ap_stable register port=pi_size name=piFMC_ROL_size
459 static stream<NetworkWord> sRxpToTxp_Data(
"sRxpToTxP_Data");
460 static stream<NetworkMetaStream> sRxtoTx_Meta(
"sRxtoTx_Meta");
461 static unsigned int processed_word_rx = 0;
462 static unsigned int processed_word_tx = 0;
463 static unsigned int processed_word_proc = 0;
464 static unsigned int struct_loaded = 0;
465 static varin instruct;
473 #pragma HLS stream variable=sRxtoTx_Meta depth=tot_transfers
475 #pragma HLS reset variable=enqueueFSM
476 #pragma HLS reset variable=dequeueFSM
477 #pragma HLS reset variable=MCEuropeanEngineFSM
478 #pragma HLS reset variable=processed_word_rx
479 #pragma HLS reset variable=processed_word_tx
480 #pragma HLS reset variable=processed_word_proc
481 #pragma HLS reset variable=struct_loaded
484 #ifdef USE_HLSLIB_DATAFLOW
501 HLSLIB_DATAFLOW_INIT();
503 HLSLIB_DATAFLOW_FUNCTION(
pRXPath,
518 &processed_word_proc,
521 HLSLIB_DATAFLOW_FUNCTION(
pTXPath,
530 HLSLIB_DATAFLOW_FINALIZE();
548 &processed_word_proc,
void pProcPath(stream< NetworkWord > &sRxpToTxp_Data, stream< NetworkMetaStream > &sRxtoTx_Meta, NetworkMetaStream meta_tmp, varin *instruct, double *out, unsigned int *processed_word_rx, unsigned int *processed_word_proc, unsigned int *struct_loaded)
Processing Path - Main processing FSM for Vitis kernels.
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.
void pTXPath(stream< NetworkWord > &soTHIS_Shl_Data, stream< NetworkMetaStream > &soNrc_meta, stream< NetworkWord > &sRxpToTxp_Data, stream< NetworkMetaStream > &sRxtoTx_Meta, unsigned int *processed_word_tx, ap_uint< 32 > *pi_rank, ap_uint< 32 > *pi_size)
Transmit Path - From THIS to SHELL.
#define MCEUROPEANENGINE_RETURN_RESULTS
void storeWordToStruct(NetworkWord word, varin *instruct, unsigned int *processed_word_rx, unsigned int *struct_loaded)
Store a word from ethernet to a local AXI stream.
#define BITS_PER_10GBITETHRNET_AXI_PACKET
void pRXPath(stream< NetworkWord > &siSHL_This_Data, stream< NetworkMetaStream > &siNrc_meta, varin *instruct, NetworkMetaStream meta_tmp, unsigned int *processed_word_rx, unsigned int *struct_loaded)
Receive Path - From SHELL to THIS.
uint8_t MCEuropeanEngineFSM
long unsigned int DtUsedInt
#define PROCESSING_PACKET
#define WAIT_FOR_STREAM_PAIR
void kernel_mc(DtUsedInt loop_nm, DtUsedInt seed, DtUsed underlying, DtUsed volatility, DtUsed dividendYield, DtUsed riskFreeRate, DtUsed timeLength, DtUsed strike, DtUsedInt optionType, DtUsed out[OUTDEP], DtUsed requiredTolerance, DtUsedInt requiredSamples, DtUsedInt timeSteps, DtUsedInt maxSamples, bool *finished)
DtUsedInt requiredSamples