@@ -28,76 +28,52 @@ int main(int argc, char **argv) {
2828 std::cout << " Usage: " << argv[0 ] << " <XCLBIN Filename>" << std::endl;
2929 return EXIT_FAILURE;
3030 }
31-
3231 std::string xclbinFilename = argv[1 ];
3332
3433 /* FPGATYPE*/ <in_buffer_t , out_buffer_t > fpga (INSTREAMSIZE, OUTSTREAMSIZE, NUM_CU, NUM_THREAD, 100 );
3534
3635 std::vector<cl::Device> devices = xcl::get_xil_devices (); // Utility API that finds xilinx platforms and return a list of devices connected to Xilinx platforms
37-
3836 cl::Program::Binaries bins = xcl::import_binary_file (xclbinFilename); // Load xclbin
39-
4037 fpga.initializeOpenCL (devices, bins);
4138
4239 fpga.allocateHostMemory (NUM_CHANNEL);
4340
44- std::cout << " Loading input data from tb_data/tb_input_features.dat"
45- << " and output predictions from tb_data/tb_output_features.dat" << std::endl;
46-
47- std::cout << " Writing output predictions to tb_data/tb_output_predictions.dat" << std::endl;
48-
49- std::ifstream fpr (" tb_data/tb_output_predictions.dat" );
41+ std::cout << " Loading input data from tb_data/tb_input_features.dat" << std::endl;
5042 std::ifstream fin (" tb_data/tb_input_features.dat" );
51-
5243 if (!fin.is_open ()) {
5344 std::cerr << " Error: Could not open tb_input_features.dat" << std::endl;
5445 }
55-
56- if (!fpr.is_open ()) {
57- std::cerr << " Error: Could not open tb_output_predictions.dat" << std::endl;
58- }
59-
6046 std::vector<in_buffer_t > inputData;
61- std::vector<out_buffer_t > outputPredictions;
62- if (fin.is_open () && fpr.is_open ()) {
63- int e = 0 ;
47+ int num_inputs = 0 ;
48+ if (fin.is_open ()) {
6449 std::string iline;
65- std::string pline;
66- while (std::getline (fin, iline) && std::getline (fpr, pline)) {
67- if (e % 10 == 0 ) {
68- std::cout << " Processing input/prediction " << e << std::endl;
50+ while (std::getline (fin, iline)) {
51+ if (num_inputs % 10 == 0 ) {
52+ std::cout << " Processing input " << num_inputs << std::endl;
6953 }
7054 std::stringstream in (iline);
71- std::stringstream pred (pline);
7255 std::string token;
7356 while (in >> token) {
7457 in_buffer_t tmp = stof (token);
7558 inputData.push_back (tmp);
7659 }
77- while (pred >> token) {
78- out_buffer_t tmp = stof (token);
79- outputPredictions.push_back (tmp);
80- }
60+ num_inputs++;
8161 }
82- e++;
8362 }
8463
8564 // Copying in testbench data
86- int n = std::min ((int ) inputData.size (), INSTREAMSIZE * NUM_CU * NUM_THREAD);
87- for (int i = 0 ; i < n; i++) {
88- fpga.source_in [i] = inputData[i];
89- }
65+ int num_samples = std::min (num_inputs, BATCHSIZE * NUM_CU * NUM_THREAD);
66+ memcpy (fpga.source_in .data (), inputData.data (), num_samples * DATA_SIZE_IN * sizeof (in_buffer_t ));
9067
9168 // Padding rest of buffer with arbitrary values
92- for (int i = n ; i < INSTREAMSIZE * NUM_CU * NUM_THREAD; i++) {
93- fpga.source_in [i] = (in_buffer_t )(1234.567 );
69+ for (int i = num_samples * DATA_SIZE_IN ; i < INSTREAMSIZE * NUM_CU * NUM_THREAD; i++) {
70+ fpga.source_in [i] = (in_buffer_t )(2.345678 );
9471 }
9572
9673 std::vector<std::thread> hostAccelerationThreads;
9774 hostAccelerationThreads.reserve (NUM_THREAD);
9875
9976 std::cout << " Beginning FPGA run" << std::endl;
100-
10177 auto ts_start = SClock::now ();
10278
10379 for (int i = 0 ; i < NUM_THREAD; i++) {
@@ -114,21 +90,18 @@ int main(int argc, char **argv) {
11490 float throughput = (float (NUM_CU * NUM_THREAD * 100 * BATCHSIZE) /
11591 float (std::chrono::duration_cast<std::chrono::nanoseconds>(ts_end - ts_start).count ())) *
11692 1000000000 .;
117-
118- std::cout << " Throughput = "
119- << throughput
120- <<" predictions/second\n " << std::endl;
93+ std::cout << " Throughput = " << throughput <<" predictions/second\n " << std::endl;
12194
122- std::cout << " Writing hw resaults to file" << std::endl;
95+ std::cout << " Writing hw results to file" << std::endl;
12396 std::ofstream resultsFile;
12497 resultsFile.open (" tb_data/hw_results.dat" , std::ios::trunc);
12598 if (resultsFile.is_open ()) {
126- for (int i = 0 ; i < NUM_THREAD * NUM_CU * BATCHSIZE ; i++) {
127- std::stringstream line ;
99+ for (int i = 0 ; i < num_samples ; i++) {
100+ std::stringstream oline ;
128101 for (int n = 0 ; n < DATA_SIZE_OUT; n++) {
129- line << (float )fpga.source_hw_results [(i * DATA_SIZE_OUT) + n] << " " ;
102+ oline << (float )fpga.source_hw_results [(i * DATA_SIZE_OUT) + n] << " " ;
130103 }
131- resultsFile << line .str () << " \n " ;
104+ resultsFile << oline .str () << " \n " ;
132105 }
133106 resultsFile.close ();
134107 } else {
0 commit comments