Jump to content

2d array bind issue (sc_vector<sc_vector<sc_in<int>>>)


Devil

Recommended Posts

her is my `group_dot.h`,
V is 9 and G is 8 defined in `parameters.h`

#pragma once
#include <systemc.h>
#include "parameters.h"
#include <iostream>

SC_MODULE (GroupDot) {
    sc_vector<sc_in<int>> x;
    sc_vector<sc_in<int>> b;
    sc_out<int> out;

    SC_CTOR (GroupDot): x("x", V), b("b", V){
        SC_METHOD(mac);
        for(int i=0; i < V; i++){
            sensitive << x[i] << b[i];
        }
    }

    void mac(){
        int temp = 0;
        // out = 0;
        for(int i=0; i<V; i++){
            temp = temp + x[i] * b[i];
            // out = out + x[i] * b[i];
        }
        out = temp;
    }
};
 
And her is `compute_unit.h`
 
#pragma once
#include <systemc>
#include "group_dot.h"
#include "parameters.h"
#include <vector>
#include <string>
#include <iostream>

SC_MODULE (ComputeUnit) {
    sc_vector<sc_vector<sc_in<int>>> x;
    sc_vector<sc_vector<sc_in<int>>> b;
    sc_vector<sc_out<int>> out;
    sc_vector<GroupDot> groups;

    SC_CTOR (ComputeUnit)
        : groups("group", G), x("x", G), b("b", G), out("out", G){
        for(int g=0;g<G;g++){
            x[g].init(V);
            b[g].init(V);
            groups[g].x(x[g]);
            groups[g].b(b[g]);
            groups[g].out(out[g]);
        }
    }


};

 

 
When running, I got this "Error: (E109) complete binding failed: port not bound: port 'compute_1.b_7_8' (sc_in)"
Link to comment
Share on other sites

4 hours ago, Eyck said:

You do not show where you bind the input ports x and b to signals. You problem is not with the hierarchical binding from ComputeUnit::b to GroupDot::b

Here's my "main.cc" file which binds signals to ports

 

#include <systemc>
#include "compute_unit.h"
#include <iostream>


int sc_main(int argc, char* argv[])
{
    ComputeUnit compute_1("compute_1");
    sc_vector<sc_vector<sc_signal<int>>> x("x", G);
    sc_vector<sc_vector<sc_signal<int>>> b("b", G);
    sc_vector<sc_signal<int>> out("out", G);
    for (int i; i < G; i++){
        x[i].init(V);
        b[i].init(V);
        
    }
    compute_1.x(x);
    compute_1.b(b);
    compute_1.out(out);

    sc_start(3, SC_SEC);

    return (0);
}

 

Link to comment
Share on other sites

I tried reproducing the error with the shared code and initially I could not. I see 'G x V' (8x9) ports bound correctly when compiling with g++ and my own installation of the SystemC 2.3.3 library.

However, I then tried using a commercial simulator and do get the port binding error at runtime! After a trivial change to the code gave different results again, the non-deterministic behavior pointed to an uninitialized variable.

The loop in your sc_main has not initialized the loop index 'g', so it is undefined whether that loop body will be entered to call init().

Compiling with clang++ -Wall will warn about this uninitialized loop index variable:

  experiment.cpp:131:17: warning: variable 'g' is uninitialized when used here [-Wuninitialized]
      for (int g; g<G; g++) {
                  ^
  experiment.cpp:131:15: note: initialize the variable 'g' to silence this warning
      for (int g; g<G; g++) {
                ^
                 = 0

Compiling with g++ -Wall will warn as well, but only if optimizations are enabled (-O1 or higher):

  experiment.cpp:131:14: warning: ‘g’ may be used uninitialized in this function [-Wmaybe-uninitialized]
    131 |     for (int g; g<G; g++) {
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...