@@ -28,76 +28,52 @@ int main(int argc, char **argv) {
28
28
std::cout << " Usage: " << argv[0 ] << " <XCLBIN Filename>" << std::endl;
29
29
return EXIT_FAILURE;
30
30
}
31
-
32
31
std::string xclbinFilename = argv[1 ];
33
32
34
33
/* FPGATYPE*/ <in_buffer_t , out_buffer_t > fpga (INSTREAMSIZE, OUTSTREAMSIZE, NUM_CU, NUM_THREAD, 100 );
35
34
36
35
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
-
38
36
cl::Program::Binaries bins = xcl::import_binary_file (xclbinFilename); // Load xclbin
39
-
40
37
fpga.initializeOpenCL (devices, bins);
41
38
42
39
fpga.allocateHostMemory (NUM_CHANNEL);
43
40
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;
50
42
std::ifstream fin (" tb_data/tb_input_features.dat" );
51
-
52
43
if (!fin.is_open ()) {
53
44
std::cerr << " Error: Could not open tb_input_features.dat" << std::endl;
54
45
}
55
-
56
- if (!fpr.is_open ()) {
57
- std::cerr << " Error: Could not open tb_output_predictions.dat" << std::endl;
58
- }
59
-
60
46
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 ()) {
64
49
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;
69
53
}
70
54
std::stringstream in (iline);
71
- std::stringstream pred (pline);
72
55
std::string token;
73
56
while (in >> token) {
74
57
in_buffer_t tmp = stof (token);
75
58
inputData.push_back (tmp);
76
59
}
77
- while (pred >> token) {
78
- out_buffer_t tmp = stof (token);
79
- outputPredictions.push_back (tmp);
80
- }
60
+ num_inputs++;
81
61
}
82
- e++;
83
62
}
84
63
85
64
// 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 ));
90
67
91
68
// 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 );
94
71
}
95
72
96
73
std::vector<std::thread> hostAccelerationThreads;
97
74
hostAccelerationThreads.reserve (NUM_THREAD);
98
75
99
76
std::cout << " Beginning FPGA run" << std::endl;
100
-
101
77
auto ts_start = SClock::now ();
102
78
103
79
for (int i = 0 ; i < NUM_THREAD; i++) {
@@ -114,21 +90,18 @@ int main(int argc, char **argv) {
114
90
float throughput = (float (NUM_CU * NUM_THREAD * 100 * BATCHSIZE) /
115
91
float (std::chrono::duration_cast<std::chrono::nanoseconds>(ts_end - ts_start).count ())) *
116
92
1000000000 .;
117
-
118
- std::cout << " Throughput = "
119
- << throughput
120
- <<" predictions/second\n " << std::endl;
93
+ std::cout << " Throughput = " << throughput <<" predictions/second\n " << std::endl;
121
94
122
- std::cout << " Writing hw resaults to file" << std::endl;
95
+ std::cout << " Writing hw results to file" << std::endl;
123
96
std::ofstream resultsFile;
124
97
resultsFile.open (" tb_data/hw_results.dat" , std::ios::trunc);
125
98
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 ;
128
101
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] << " " ;
130
103
}
131
- resultsFile << line .str () << " \n " ;
104
+ resultsFile << oline .str () << " \n " ;
132
105
}
133
106
resultsFile.close ();
134
107
} else {
0 commit comments