int sc_main(int argc, char* argv[]) { mesh dut("dut", 4, 5); for (size_t j=0; j<dut.cols; ++j ) for (size_t i=0; i<dut.rows; ++i ) cout << dut.nodes[i][j].name() << " - " << dut.nodes[i][j].kind() << endl; cout << "Program completed" << endl; return 0; }
int sc_main(int, char *argv[]) { sc_clock clock("clock"); DUT dut("dut"); sc_rvd<sc_uint<8> > dut_to_tb; sc_rvd<sc_uint<8> > tb_to_dut; sc_signal<bool> reset; TB_DUT tb("tb"); sc_trace_file *tf; dut.m_clk(clock); dut.m_reset(reset); dut.m_input(tb_to_dut); dut.m_output(dut_to_tb); tb.m_clk(clock); tb.m_reset(reset); tb.m_from_dut(dut_to_tb); tb.m_to_dut(tb_to_dut); tf = sc_create_vcd_trace_file("../results/wave"); sc_trace(tf, clock, "clk"); sc_trace(tf, dut_to_tb.m_data, "data_d"); sc_trace(tf, dut_to_tb.m_ready, "ready_d"); sc_trace(tf, dut_to_tb.m_valid, "valid_d"); sc_trace(tf, tb_to_dut.m_data, "data_t"); sc_trace(tf, tb_to_dut.m_ready, "ready_t"); sc_trace(tf, tb_to_dut.m_valid, "valid_t"); std::cout << "producer dut consumer" << endl; reset = false; sc_start(1, SC_NS); reset = true; sc_start(); std::cout << "program completed" << endl; return 0; }
int sc_main (int argc, char *argv[]) { cout << "SYSTEMC_VERSION="<<dec<<SYSTEMC_VERSION<<endl; cout << "Compiled with pointer size "<<((sizeof(char*)==8) ? "-m64":"-m32")<<endl; // Timescale #if (SYSTEMC_VERSION>=20070314) sc_set_time_resolution(100.0, SC_FS); #elif (SYSTEMC_VERSION>20011000) sc_set_time_resolution(100.0, SC_FS); sc_set_default_time_unit(1.0, SC_NS); sc_report::make_warnings_errors(true); #else sc_time dut(1.0, sc_ns); sc_set_default_time_unit(dut); #endif // SYSTEMC_VERSION #ifndef NC_SYSTEMC // Simulation logfile sp_log_file splog; splog.open ("sim.log"); splog.redirect_cout(); #endif // Pins #if SYSTEMC_VERSION >= 20060505 sc_clock clk("clk",5,SC_NS); // We want a non-integer half period to prove VCD works #else sc_clock clk("clk",5); #endif // SYSTEMC_VERSION ExBench* bench; SP_CELL (bench,ExBench); SP_PIN (bench,clk,clk); bench->configure(); // Verify the #sp include worked #ifndef NC_SYSTEMC # if SYSTEMC_VERSION < 20060505 sc_initialize(); # endif #endif // Example enumeration usage MyENumClass enval = MyENumClass::ONE; cout << "Assigned to enumeration = "<<enval<<endl; // Prints "ONE" cout << "Iterating an enumeration ="; for (MyENumSimple::iterator it=MyENumSimple::begin(); it!=MyENumSimple::end(); ++it) { cout << " " << (*it).ascii(); } cout << endl; #ifndef NC_SYSTEMC // SystemC traces are flawed, you can't even trace ports sc_trace_file *tf = sc_create_vcd_trace_file("sim_sc" ); sc_trace(tf, clk, "clk"); #if SYSTEMC_VERSION >= 20070314 tf->set_time_unit(1, SC_NS); #endif // SystemPerl traces SpTraceFile* stp = new SpTraceFile; bench->trace(stp,999); stp->open("sim_sp.vcd"); // Alternative SystemPerl traces, allowing rollover // After running, concat the two files to make the vcd file. SpTraceFile* stp2 = new SpTraceFile; stp2->rolloverMB(1); // Rollover logfiles when size > 1MB bench->trace(stp2,999); stp2->open("sim_sp2.vcd"); #endif // NC_SYSTEMC cout << "Starting\n"; #if SYSTEMC_VERSION >= 20060505 sc_start(); #else sc_start(-1); #endif // SYSTEMC_VERSION cout << "Done\n"; #ifndef NC_SYSTEMC sc_close_vcd_trace_file(tf); SpTraceVcd::flush_all(); #endif // NC_SYSTEMC // Coverage mkdir("logs", 0777); SpCoverage::write(); // Writes logs/coverage.pl return (0); }
//------------------------------------------------------------------------ // Digitrec testbench //------------------------------------------------------------------------ int main() { // Output file that saves the test bench results std::ofstream outfile; outfile.open("out.dat"); // Read input file for the testing set std::string line; std::ifstream myfile ("data/testing_set.dat"); // HLS streams for communicating with the cordic block hls::stream<bit32_t> digitrec_in; hls::stream<bit32_t> digitrec_out; // Number of test instances const int N = 180; // Arrays to store test data and expected results digit inputs[N]; int expecteds[N]; // Timer Timer timer("digitrec FPGA"); int nbytes; int error = 0; int num_test_insts = 0; bit32_t interpreted_digit; if ( myfile.is_open() ) { //-------------------------------------------------------------------- // Read data from the input file into two arrays //-------------------------------------------------------------------- for (int i = 0; i < N; ++i) { assert( std::getline( myfile, line) ); // Read handwritten digit input std::string hex_digit = line.substr(2, line.find(",")-2); digit input_digit = hexstring_to_int64 (hex_digit); // Read expected digit int input_value = strtoul(line.substr(line.find(",") + 1, line.length()).c_str(), NULL, 10); // Store the digits into arrays inputs[i] = input_digit; expecteds[i] = input_value; } timer.start(); //-------------------------------------------------------------------- // Send data digitrec //-------------------------------------------------------------------- for (int i = 0; i < N; ++i ) { // Read input from array and split into two 32-bit words bit32_t input_lo = inputs[i].range(31,0); bit32_t input_hi = inputs[i].range(48,32); // Write words to the device digitrec_in.write( input_lo ); digitrec_in.write( input_hi ); } //-------------------------------------------------------------------- // Execute the digitrec sim and receive data //-------------------------------------------------------------------- for (int i = 0; i < N; ++i ) { // Call design under test (DUT) dut( digitrec_in, digitrec_out ); // Read result bit32_t interpreted_digit = digitrec_out.read(); num_test_insts++; // Check for any difference between k-NN interpreted digit vs. expected digit if ( interpreted_digit != expecteds[i] ) { error++; } } timer.stop(); // Report overall error out of all testing instances std::cout << "Number of test instances = " << num_test_insts << std::endl; std::cout << "Overall Error Rate = " << std::setprecision(3) << ( (double)error / num_test_insts ) * 100 << "%" << std::endl; outfile << "Number of test instances = " << num_test_insts << std::endl; outfile << "Overall Error Rate = " << std::setprecision(3) << ( (double) error / num_test_insts ) * 100 << "%" << std::endl; // Close input file for the testing set myfile.close(); } else std::cout << "Unable to open file for the testing set!" << std::endl; // Close output file outfile.close(); return 0; }
//-------------------------------------- // main function of TB //-------------------------------------- int main(int argc, char** argv) { // sin output double ans = 0; // cos output // sin & cos calculated by math.h double m_an = 0.0; // Error terms double err_ratio; double accum_err; // arrays to store the output double array[NUM_DEGREE]; // HLS streams for communicating with the cordic block //hls::stream<bit32_t> cordic_in; hls::stream<bit32_t> cordic_out; //------------------------------------------------------------ // Send data to CORDIC sim //------------------------------------------------------------ for (int i = 1; i < NUM_DEGREE; i++) { bit32_t input = i; // Send both words to the HLS module // cordic_in.write( input ); //cordic_in.write( input+1 ); } //------------------------------------------------------------ // Execute CORDIC sim and store results //------------------------------------------------------------ for (int i = 1; i < NUM_DEGREE; i++) { // Run the HLS function dut( cordic_out ); // Read the two 32-bit cosine output words, low word first bit32_t output; output = cordic_out.read(); // Store to array array[i] = output; } //------------------------------------------------------------ // Check results //------------------------------------------------------------ for (int i = 1; i < NUM_DEGREE; ++i) { // Load the stored result ans = array[i]; m_an = i; // Calculate normalized error err_ratio = ( abs_double( (double)ans - m_an) / (m_an) ) * 100.0; // Accumulate error ratios accum_err += err_ratio * err_ratio; std::cout << "ans = "<< ans <<" m_an = "<<m_an<<"\n"; } //------------------------------------------------------------ // Write out root mean squared error (RMSE) of error ratios //------------------------------------------------------------ // Print to screen std::cout << "#------------------------------------------------\n" << "Overall_Error_Test = " << RMSE(accum_err) << "\n" << "#------------------------------------------------\n"; return 0; }