Jump to content
ecco

Instantiating N submodules (N is a template parameter)

Recommended Posts

I'll give a brief example of what I intend to to:

 

template <int N>

SC_MODULE(request_scheduler_m) 
{  
   subblock subblock[N];
 
   void proc();
   
   SC_CTOR(request_scheduler_m)     
   {
      unsigned int i;
 
      for (i = 0; i < N; i++)
      {
         round_robin[N]("subblock instance");
      }
(...)
 
Basically, N subblocks must be instantiated inside request_scheduler and N is a template parameter. The compiler is complaining about the code above. Is it possible to do that?

Share this post


Link to post
Share on other sites

The compiler is complaining because you can't supply a constructor argument to an element of an array.

 

Either replace your array of subblocks with an array of pointers to sub-blocks, or, even better, use sc_vector (see 1666-2011).

 

kind regards

Alan

Share this post


Link to post
Share on other sites

Thanks for the answer, using the sc_vector did the trick :)

 

But how can I use vectors when submodules require extra arguments in the constructor? They tried to cover it in 1666-2011, but they wouldn't be able to write a worst explanation even if they would have put a lot of effort on it. Really tough to understand with incomplete examples.

Share this post


Link to post
Share on other sites

I think I can safely say the LRM is not intended to be a tutorial :-)

 

Philipp Hartmann wrote a paper

 

https://complex.offis.de/documents/doc_download/29-scvector-container-and-the-ieee-p1666-2011-systemc-standard

 

and he also wrote the original code.

 

I'm sure Philipp will pop up if you have any further questions,

 

kind regards

Alan

 

P.S. I couldn't get the download link to work - but if you click View, you can then download it from the viewer.

Edited by apfitch

Share this post


Link to post
Share on other sites

Thanks for letting me know, that the download link is somewhat broken.  I tried to fix it and it seems to be working here now.  The link to the details page is https://complex.offis.de/documents/doc_details/29. In this presentation, several examples for "custom creator functions" are given.  Personally, I prefer the variant of using sc_bind in combination with a local member function:

 

// creator function (member function of surrounding block)
subblock*
request_scheduler_m::create_subblock( const char* nm, size_t idx ) {
  // call constructor with other parameters
  subblock* sub_p = new subblock(nm, param_1, param_2);
  return sub_p;
}

// initialize vector with custom creator
subblock_vec.init( N, sc_bind( &request_scheduler_m::create_subblock, this, sc_unnamed::_1, sc_unnamed::_2 ) );

 

Using this variant of a creator, you can easily "store" and/or prepare the values of the module parameters within member variables of the surrounding module.

 

Greetings from Oldenburg,
  Philipp

Edited by Philipp A. Hartmann

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×