错误:(E109)完成绑定失败:端口未绑定:端口'chol.port_16'(sc_out)

时间:2017-04-04 07:36:03

标签: c++ systemc

I am new to systemc and I get the port binding error. Could someone help me resolve this error. Below are the files written

Define.h

#ifndef DEFINE_CHOL_H
#define DEFINE_CHOL_H

#include "systemc.h"

#include <iostream>
#include "stdio.h"



#define INFILENAME         "cholesky.txt"   // input data


#define OUTFILENAME_GOLDEN       "cholesky_output_golden.txt"
#define OUTFILENAME              "cholesky_output.txt"
#define DIFFFILENAME             "cholesky_diff.txt"

//#define WAVE_DUMP          // set do dump waveform or set as compile option -DWAVE_DUMP

#endif




    chol.h

#ifndef CHOL
#define CHOL
#define SC_INCLUDE_FX
#include "define.h"

SC_MODULE (chol) {


public:

   // Inputs
   sc_in_clk clk;
   sc_in<bool> rst;
   sc_in<sc_fixed<16,10, SC_TRN, SC_WRAP> > chol_in_data[3][3] ;


   // Output
   sc_out<sc_fixed<16,10, SC_TRN, SC_WRAP> > chol_out_data[3][3] ;


   /* F */
 void chol_main ( void );
   //sc_fixed<32,16, SC_TRN, SC_WRAP> cholesky(sc_fixed<32,16, SC_TRN, SC_WRAP> *);


   // Constructor
 SC_CTOR (chol) {

       SC_CTHREAD (chol_main, clk.pos() );
       reset_signal_is(rst, false) ;
       sensitive << clk.pos();

   }

   // Destructor
   ~chol() {}


};

#endif



cholesky.cpp


#include "chol.h"
#include <math.h>

//Main Thread
    void chol::chol_main () {
// Variable declaration

    sc_fixed<16,10, SC_TRN, SC_WRAP> chol_output[3][3];
    sc_fixed<16,10, SC_TRN, SC_WRAP> chol_in[3][3];
    sc_fixed<16,10, SC_TRN, SC_WRAP> chol_out1[3][3];
    int n=3;

// Reset cycle//
        //chol_output.write(0);
        //wait();


//Main Thread

            while (true) {


                for (int i=0; i<n; i++)
                {
                for(int j=0; j<=i; j++)
                {
                    chol_in[i][j] = chol_in_data[i][j].read();
                }
                }
                }

            for (int i=0; i<n; i++)
            {
            for (int j=0; j<=i; j++)
            {
            sc_fixed<16,10, SC_TRN, SC_WRAP> sum = 0;
            for (int k=0; k<j; k++)
            {
                sum += chol_output[i][k] * chol_output[j][k];
            }
            if (i==j)
            {
                chol_output[i][i] = sqrt(chol_in[i][i] - sum) ;
            }
            else
            {
                chol_output[i][j] = 1.0 / chol_output[j][j] * (chol_in[i][j] - sum);
            }
            }
            }
// Cholesky Function
        //chol_output = cholesky (chol_in);
        for (int i=0; i<n; i++)
            {
            for (int j=0; j<=i; j++)
            {
                chol_out_data[i][j].write (chol_output[i][j]);  
            }
            }                                                                                                                       
    }



tb_chol.h

#ifndef TEST_CHOL
#define TEST_CHOL
#define SC_INCLUDE_FX

#include "define.h"

//#include "sc_module.h"


SC_MODULE(test_CHOL){

//In
    sc_in_clk          clk;
    sc_in<bool>          rst;

    sc_out<sc_fixed<16,10, SC_TRN, SC_WRAP> > chol_in_data[3][3];        
    sc_in<sc_fixed<16,10, SC_TRN, SC_WRAP> > chol_out_data[3][3] ; 


  // File Pointers

    FILE *out_chol_golden_file, *in_chol_file, *out_chol_file, *diff_chol;

  // Compare Results
  void compare_results();

  // Send Thread
  void recv();

  // Receive Thread
  void send();

 // Constructor   
   SC_CTOR ( test_CHOL ) {

    SC_CTHREAD(send,clk.pos());
    reset_signal_is(rst,false);

    SC_CTHREAD(recv,clk.pos());
    reset_signal_is(rst,false);
  };

  ~test_CHOL(){};


};

#endif



tb_chol.cpp



#include "tb_chol.h"
#include <math.h>

// send thread 

void test_CHOL::send() {
 // Variable declaration

    sc_fixed<16,10, SC_TRN, SC_WRAP> chol_in;
    int n=3;

    //reset routine

    //chol_in_data.write(0);
    //rst.write(1);
    //wait();
    //rst.write(0);
    //wait();

    in_chol_file = fopen(INFILENAME, "rt");


  if(!in_chol_file){
    cout << "Could not open " << INFILENAME << "\n";
    sc_stop();
    exit(-1);
  }

  wait();

  while(true) {
   for(int i=0;i<n;i++)
  {
  for (int j=0;j<=i;j++)
  {
  while(fscanf(in_chol_file,"%u",&chol_in)!=EOF){
  chol_in_data[i][j].write(chol_in);
   wait();
  }
  }
  }
  fclose(in_chol_file);

  cout << endl << "Start Comparing Results" << endl;
  compare_results();
  sc_stop();

  wait();
  }
}



// Receive Data Thread

void test_CHOL::recv() {

    // Variable Declaration

    sc_fixed<16,10, SC_TRN, SC_WRAP> chol_out_write=0;
    int n=3;

    out_chol_file = fopen (OUTFILENAME, "wt");


     if(!out_chol_file){
    cout << "Could not open " << OUTFILENAME << "\n";
    sc_stop();
    exit(-1);
    }

  wait();

  while (true) {
  for(int i=0;i<n;i++)
  {
  for (int j=0;j<=i;j++)
  {

  chol_out_write = chol_out_data[i][j].read();
  fprintf(out_chol_file,"%f \n",chol_out_write);

  wait();
}
}
  }


}

// compare results function

void test_CHOL::compare_results(){

sc_fixed<16,10, SC_TRN, SC_WRAP> outchol, outchol_golden;
int line=1;

// close the file where the outputs are stored
 fclose(out_chol_file);

 out_chol_file = fopen (OUTFILENAME, "rt");


     if(!out_chol_file){
    cout << "Could not open " << OUTFILENAME << endl;
    sc_stop();
    exit(-1);
    }

 // Load the Golden Output from file 

 out_chol_golden_file = fopen (OUTFILENAME_GOLDEN,"rt");


  if(!out_chol_golden_file){
    cout << "Could not open " << OUTFILENAME_GOLDEN << endl;
    sc_stop();
    exit(-1);
    }

// Comparing the results with golden output 

 diff_chol = fopen (DIFFFILENAME,"w");

 if(!diff_chol){
    cout << "Could not open " << DIFFFILENAME << "\n";
    sc_stop();
    exit(-1);
    }

 while(fscanf(out_chol_golden_file, "%f", &outchol_golden)!= EOF) {
   fscanf(out_chol_file, "%f", &outchol);

   if (outchol != outchol_golden ) {

   cout <<"Golden" << outchol_golden <<" -- output " << outchol << "\n The variation in [line:" << line << "] is " << outchol_golden - outchol;
   fprintf(diff_chol,"\nOutput variation Golden : %f -- Output: %f",outchol_golden,  outchol ,"Difference is :", outchol_golden - outchol );
   }
 }


}




main.cpp


#include "chol.h"
#include "tb_chol.h"
#define SC_INCLUDE_FX

int sc_main(int argc, char** argv)
{

  //sc_in_clk          clk;
  sc_clock                clk("clk", 25, SC_NS, 0.5, 12.5, SC_NS, true);
  sc_signal<bool>         rst;

  sc_signal<sc_fixed<16,10, SC_TRN, SC_WRAP> > chol_in_data[3][3];   
  sc_signal<sc_fixed<16,10, SC_TRN, SC_WRAP> > chol_out_data[3][3];

chol  *chol0;
test_CHOL *test_CHOL0;

// Connect to test bench
int n = 3;

test_CHOL0 = new test_CHOL("test_CHOL0");
test_CHOL0->clk(clk);
test_CHOL0->rst(rst);
  for(int i=0;i<n;i++)
  {
  for (int j=0;j<=i;j++)
  {
test_CHOL0->chol_in_data[i][j](chol_in_data[i][j]);
test_CHOL0->chol_out_data[i][j](chol_out_data[i][j]);
 }
 }



// Connect to CHOL

chol0 = new chol ("chol");
chol0->clk(clk);
chol0->rst(rst);
 for(int i=0;i<n;i++)
  {
  for (int j=0;j<=i;j++)
  {
chol0->chol_in_data[i][j](chol_in_data[i][j]);
chol0->chol_out_data[i][j](chol_out_data[i][j]);
 }
 }



  sc_start( 25, SC_NS );
  rst.write(0);

  sc_start( 25, SC_NS );
  rst.write(1);

  sc_start();

  return 0;

 };

以上代码执行cholesky Factorization。我执行矩阵分解,我正在将cholesky模块的2d数组的输出写入连接到cholesky testbench模块的信号端口。

我从chol实例收到一些端口连接错误,但我无法弄清楚要纠正什么。

提前致谢

0 个答案:

没有答案