Jump to content

Dynamic instantiation of templated modules


bitfield

Recommended Posts

Hello,

I am trying to figure out a design for a  systolic array. For that I will need to instantiate shift registers with different delays for each row. E.g. the first row
has no delay, the second one is delayed by one cycle, the third by two cycles etc. I have tried to do the following

template<int WIDTH, int HEIGT>
class SystolicArray : sc_module{
  sc_module shift_registers[HEIGHT];

  SC_CTOR(SystolicArray){
    for(int h = 1; h < HEIGHT; h++){   
      shift_registers[h-1] = new ShiftRegister<h>
      //Connect stuff
    }
  }

This fails with an error: # Error: systolic_array.h(61): error: the value of ‘h’ is not usable in a constant expression.
My question then is: How would I go about designing this? Because all the information is available at compile time through the templates of SystolicArray I just can't figure out how
to do this. Also, I want to stick to the synthesizable subset of SystemC. Thank you!

Link to comment
Share on other sites

If you are using Modern C++ (C++14 or C++17 would be best), then you could accomplish this with constexpr functions. You should also consider using sc_vector. Vanilla C/C++ arrays are simply evil anyhow. For non-SystemC components (i.e., modules, ports, channels) use std::vector<T> or std::array<T>). Also, you would save some code space if you used simple constructor arguments for your ShiftRegister and implement with std::vector.

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...