Skip to content

Commit

Permalink
Expand test bench
Browse files Browse the repository at this point in the history
  • Loading branch information
vloncar committed Jan 22, 2019
1 parent cafdb9e commit 547425b
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 89 deletions.
2 changes: 1 addition & 1 deletion hls-template/build_prj.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ set_top myproject
add_files firmware/myproject.cpp -cflags "-I[file normalize nnet_utils] -std=c++0x"
add_files -tb myproject_test.cpp -cflags "-I[file normalize nnet_utils] -std=c++0x"
add_files -tb firmware/weights
#add_files -tb tb_data
add_files -tb tb_data
open_solution -reset "solution1"
catch {config_array_partition -maximum_size 4096}
set_part {xc7vx690tffg1927-2}
Expand Down
66 changes: 55 additions & 11 deletions hls-template/myproject_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,65 @@
#include "firmware/myproject.h"
#include "nnet_helpers.h"

int main(int argc, char **argv) {
//load input data from text file
std::ifstream fin("tb_data/tb_input_features.dat");
//load predictions from text file
std::ifstream fpr("tb_data/tb_output_predictions.dat");

int main(int argc, char **argv)
{
std::string iline;
std::string pline;
int e = 0;
if (fin.is_open() && fpr.is_open()) {
std::ofstream fout;
fout.open("tb_output_data.dat");
while ( std::getline(fin,iline) && std::getline (fpr,pline) ) {
if (e%5000==0) std::cout << "Processing event " << e << std::endl;
e++;
char* cstr=const_cast<char*>(iline.c_str());
char* current;
std::vector<float> in;
current=strtok(cstr," ");
while(current!=NULL){
in.push_back(atof(current));
current=strtok(NULL," ");
}
cstr=const_cast<char*>(pline.c_str());
std::vector<float> pr;
current=strtok(cstr," ");
while(current!=NULL){
pr.push_back(atof(current));
current=strtok(NULL," ");
}

//hls-fpga-machine-learning insert data
//hls-fpga-machine-learning insert data
result_t res_str[N_OUTPUTS] = {0};
unsigned short size_in, size_out;
myproject(data_str, res_str, size_in, size_out);


result_t res_str[N_OUTPUTS] = {0};
unsigned short size_in, size_out;
myproject(data_str, res_str, size_in, size_out);

for(int i=0; i<N_OUTPUTS; i++){
std::cout << res_str[i] << " ";
for(int i=0; i<N_OUTPUTS; i++) {
fout << res_str[i] << " ";
}
fout << "\n";
if (e%5000==0) {
std::cout << "Predictions" << std::endl;
for(int i=0; i<N_OUTPUTS; i++) {
std::cout << pr[i] << " ";
}
std::cout << std::endl;
std::cout << "Quantized predictions" << std::endl;
for(int i=0; i<N_OUTPUTS; i++) {
std::cout << res_str[i] << " ";
}
std::cout << std::endl;
}
}
fin.close();
fpr.close();
fout.close();
} else {
std::cout << "Unable to open input/predictions file" << std::endl;
}
std::cout << std::endl;

return 0;
}
Loading

0 comments on commit 547425b

Please sign in to comment.