39 #include "PracticalSockets.h"
40 #include "../include/config.h"
45 void delay(
unsigned int mseconds)
47 clock_t goal = mseconds +
clock();
48 while (goal >
clock());
56 cout <<
"...build with: " << endl;
57 cout <<
" ██████╗███████╗██████╗ ███████╗ ██████╗ ██████╗ " << endl;
58 cout <<
"██╔════╝██╔════╝██╔══██╗ ╚══███╔╝██╔═══██╗██╔═══██╗ " << endl;
59 cout <<
"██║ █████╗ ██████╔╝ ███╔╝ ██║ ██║██║ ██║ " << endl;
60 cout <<
"██║ ██╔══╝ ██╔═══╝ ███╔╝ ██║ ██║██║ ██║ " << endl;
61 cout <<
"╚██████╗██║ ██║███████╗███████╗╚██████╔╝╚██████╔╝ " << endl;
62 cout <<
" ╚═════╝╚═╝ ╚═╝╚══════╝╚══════╝ ╚═════╝ ╚═════╝ " << endl;
63 cout <<
"A cloudFPGA project from IBM ZRL v1.0 " << endl;
64 cout <<
"Quantitative Finance Monte-Carlo European Pricing Engine " << endl;
70 int uppercase(
char *s_servAddress,
char *s_servPort,
char *input_str,
char *output_str,
bool net_type)
77 int main(
int argc,
char *argv[])
79 if ((argc < 3) || (argc > 4)) {
80 cerr <<
"Usage: " << argv[0] <<
" <Server> <Server Port> <input string> <optional output string>\n";
92 string s_servAddress = argv[1];
93 char *s_servPort = argv[2];
97 string servAddress = s_servAddress;
98 unsigned short servPort;
99 if (net_type ==
udp) {
100 servPort = Socket::resolveService(s_servPort,
"udp");
102 else if (net_type ==
tcp) {
103 servPort = atoi(s_servPort);
106 cout <<
"ERROR: Invalid type of socket type provided: " << net_type <<
" Choosed one of (tcp=0 or udp=1)" << endl;
110 unsigned int recvMsgSize;
112 std::string input_string;
124 #ifndef TB_SIM_CFP_VITIS
125 UDPSocket udpsock(servPort);
132 TCPSocket tcpsock(servAddress, servPort);
140 input_string.assign(input_str);
142 input_string.assign(argv[3]);
144 if (input_string.length() == 0) {
145 cerr <<
"Empty string provided. Aborting...\n\n" << endl;
149 clock_t start_cycle_main =
clock();
150 cout <<
" ___________________________________________________________________ " << endl;
151 cout <<
"/ \\" << endl;
152 cout <<
"INFO: Batch # " << ++
num_frame << endl;
157 unsigned int total_pack = 1 + (input_string.length() - 1) /
PACK_SIZE;
158 unsigned int total_bytes = total_pack *
PACK_SIZE;
159 unsigned int bytes_in_last_pack = input_string.length() - (total_pack - 1) *
PACK_SIZE;
161 cout <<
"INFO: Network socket : " << ((net_type ==
tcp) ?
"TCP" :
"UDP") << endl;
162 cout <<
"INFO: Total packets to send/receive = " << total_pack << endl;
163 cout <<
"INFO: Total bytes to send/receive = " << input_string.length() << endl;
164 cout <<
"INFO: Total bytes in " << total_pack <<
" packets = " << total_bytes << endl;
165 cout <<
"INFO: Bytes in last packet = " << bytes_in_last_pack << endl;
166 cout <<
"INFO: Packet size (custom MTU) = " <<
PACK_SIZE << endl;
171 clock_t start_cycle_uppercase_hw =
clock();
176 clock_t last_cycle_tx =
clock();
178 for (
unsigned int i = 0; i < total_pack; i++) {
179 if ( i == total_pack - 1 ) {
180 sending_now = bytes_in_last_pack;
183 udpsock.sendTo( & input_string[i *
PACK_SIZE], sending_now, servAddress, servPort);
185 tcpsock.send( & input_string[i *
PACK_SIZE], sending_now);
189 clock_t next_cycle_tx =
clock();
190 double duration_tx = (next_cycle_tx - last_cycle_tx) / (
double) CLOCKS_PER_SEC;
191 cout <<
"INFO: Effective SPS TX:" << (1 / duration_tx) <<
" \tkbps:" << (
PACK_SIZE *
192 total_pack / duration_tx / 1024 * 8) << endl;
193 last_cycle_tx = next_cycle_tx;
199 clock_t last_cycle_rx =
clock();
201 cout <<
"INFO: Expecting length of packs:" << total_pack << endl;
202 char * longbuf =
new char[
PACK_SIZE * total_pack];
203 for (
unsigned int i = 0; i < input_string.length(); ) {
205 if ( i == total_pack - 1 ) {
206 receiving_now = bytes_in_last_pack;
209 recvMsgSize = udpsock.recvFrom(buffer,
BUF_LEN, servAddress, servPort);
211 recvMsgSize = tcpsock.recv(buffer,
BUF_LEN);
213 if (recvMsgSize != receiving_now) {
214 cerr <<
"WARNING: Received unexpected size pack:" << recvMsgSize <<
". Expected: " <<
215 receiving_now << endl;
217 memcpy( & longbuf[i], buffer, recvMsgSize);
222 cout <<
"INFO: Received packet from " << servAddress <<
":" << servPort << endl;
225 char *output_string = output_str;
227 char *output_string = (
char*)malloc((input_string.length()+1)*
sizeof(char));
229 output_string = strncpy(output_string, longbuf, input_string.length());
230 output_string[input_string.length()]=
'\0';
231 cout <<
"INFO: Received string : " << output_string << endl;
232 clock_t next_cycle_rx =
clock();
233 double duration_rx = (next_cycle_rx - last_cycle_rx) / (
double) CLOCKS_PER_SEC;
234 cout <<
"INFO: Effective SPS RX:" << (1 / duration_rx) <<
" \tkbps:" << (
PACK_SIZE *
235 total_pack / duration_rx / 1024 * 8) << endl;
236 last_cycle_rx = next_cycle_rx;
238 clock_t end_cycle_uppercase_hw = next_cycle_rx;
240 double duration_uppercase_hw = (end_cycle_uppercase_hw - start_cycle_uppercase_hw) /
241 (
double) CLOCKS_PER_SEC;
242 cout <<
"INFO: HW exec. time:" << duration_uppercase_hw <<
" seconds" << endl;
243 cout <<
"INFO: Effective SPS HW:" << (1 / duration_uppercase_hw) <<
" \tkbps:" <<
244 (
PACK_SIZE * total_pack / duration_uppercase_hw / 1024 * 8) << endl;
246 double duration_main = (
clock() - start_cycle_main) / (
double) CLOCKS_PER_SEC;
247 cout <<
"INFO: Effective SPS E2E:" << (1 / duration_main) << endl;
248 cout <<
"\\___________________________________________________________________/" << endl
252 }
catch (SocketException & e) {
253 cerr << e.what() << endl;
cat GET request dos socat stdio tcp
void uppercase(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 Uppercase Application directives.
int main(int argc, char *argv[])
void delay(unsigned int mseconds)