text: //
  //    rfnoc-hls-neuralnet: Vivado HLS code for neural-net building blocks
  //
  //    Copyright (C) 2017 EJ Kreinar
  //
  //    This program is free software: you can redistribute it and/or modify
  //    it under the terms of the GNU General Public License as published by
  //    the Free Software Foundation, either version 3 of the License, or
  //    (at your option) any later version.
  //
  //    This program is distributed in the hope that it will be useful,
  //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  //    GNU General Public License for more details.
  //
  //    You should have received a copy of the GNU General Public License
  //    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  //
  #include <fstream>
  #include <iostream>
  #include <algorithm>
  #include <vector>
  #include <map>
  #include <stdio.h>
  #include <stdlib.h>
  #include <math.h>
  
  #include "firmware/myproject.h"
  #define CL_HPP_CL_1_2_DEFAULT_BUILD
  #define CL_HPP_TARGET_OPENCL_VERSION 120
  #define CL_HPP_MINIMUM_OPENCL_VERSION 120
  #define CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY 1
  
  #include <CL/cl2.hpp>
  #define CHECKPOINT 5000
  
  namespace nnet {
      bool trace_enabled = true;
      std::map<std::string, void *> *trace_outputs = NULL;
      size_t trace_type_size = sizeof(double);
  }
  
  int main(int argc, char **argv)
  {
    char *xclbinFilename = "myproject.xclbin";
    std::vector<cl::Device> devices;
    cl::Device device;
    std::vector<cl::Platform> platforms;
    bool found_device = false;
    cl_int err;
    //traversing all Platforms To find Xilinx Platform and targeted
    //Device in Xilinx Platform
    cl::Platform::get(&platforms);
    for (size_t i = 0; (i < platforms.size()) & (found_device == false); i++)
    {
      cl::Platform platform = platforms[i];
      std::string platformName = platform.getInfo<CL_PLATFORM_NAME>();
      if (platformName == "Xilinx")
      {
        devices.clear();
        platform.getDevices(CL_DEVICE_TYPE_ACCELERATOR, &devices);
        if (devices.size())
        {
          device = devices[0];
          found_device = true;
          break;
        }
      }
    }
    if (found_device == false)
    {
      std::cout << "Error: Unable to find Target Device "
                << device.getInfo<CL_DEVICE_NAME>() << std::endl;
      return EXIT_FAILURE;
    }
    // Creating Context and Command Queue for selected device
    cl::Context context(device);
    cl::CommandQueue q(context, device, CL_QUEUE_PROFILING_ENABLE);
    std::ifstream bin_file(xclbinFilename, std::ifstream::binary);
    bin_file.seekg(0, bin_file.end);
    unsigned nb = bin_file.tellg();
    if(nb <1 )
      std::cout << "read xclbin file:"<< xclbinFilename <<" error! and len is " << nb << std::endl;
    bin_file.seekg(0, bin_file.beg);
    char *buf = new char[nb];
    bin_file.read(buf, nb);
    cl::Program::Binaries bins;
    bins.push_back({buf, nb});
    devices.resize(1);
    std::cout << "Loading: '" << xclbinFilename << "   device:" << devices[0].getInfo<CL_DEVICE_NAME>() << std::endl;
    cl::Program program(context, devices, bins, NULL, &err);
    if (err != CL_SUCCESS)
    {
      std::cout << "Failed to program device with xclbin file!\n";
    }
    else
    {
      std::cout << "Device program successful!\n";
    }
    //load top-level-function from xclbin file
  
    //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");
  
  #ifdef RTL_SIM
    std::string RESULTS_LOG = "tb_data/rtl_cosim_results.log";
  #else
    std::string RESULTS_LOG = "tb_data/csim_results.log";
  #endif
    std::ofstream fout(RESULTS_LOG);
  
    std::string iline;
    std::string pline;
    int e = 0;
    int narg = 0;
    // hls-fpga-machine-learning insert parameters declaration and then set arg 
  
    if (fin.is_open() && fpr.is_open()) {
      while ( std::getline(fin,iline) && std::getline (fpr,pline) ) {
        if (e % CHECKPOINT == 0) std::cout << "Processing input " << e << std::endl;
        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 top-level-function
  
        //hls-fpga-machine-learning insert tb-output
  
        if (e % CHECKPOINT == 0) {
          std::cout << "Predictions" << std::endl;
          //hls-fpga-machine-learning insert predictions
          std::cout << "Quantized predictions" << std::endl;
          //hls-fpga-machine-learning insert quantized
        }
        e++;
      }
      fin.close();
      fpr.close();
    } else {
      std::cout << "INFO: Unable to open input/predictions file, using default input." << std::endl;
  
      //hls-fpga-machine-learning insert zero
  
      //hls-fpga-machine-learning insert top-level-function
  
      //hls-fpga-machine-learning insert output
  
      //hls-fpga-machine-learning insert tb-output
    }
  
    fout.close();
    std::cout << "INFO: Saved inference results to file: " << RESULTS_LOG << std::endl;
  
    return 0;
  }
  