Ojos Posted August 10, 2022 Report Share Posted August 10, 2022 I am working in a SystemC module that connects a set of sub-modules stored in a sc_vector< submodule > with sc_vectors of ports and signals. Since the size of the sc_vectors is a parameter (in this case initialized by a constructor parameter), it would be nice to have also a configurable set of processes. They can be static, i.e., configured and registered in the parent module constructor (therefore at elaboration time). I guess that the easiest solution is to put these processes in another sub-module, and just create a sc_vector of the new sub-module. However, I want to avoid the extra overhead of having extra sub-modules, with their port bindings, etc... What would be the best way of doing it? If I use the sc_spawn function, do I need to add the macro SC_INCLUDE_DYNAMIC_PROCESS even if the spawned processes by sc_spawn are not dynamic? Or it is better to use the SC_THREAD/SC_CTHREAD/SC_METHOD macro in a loop with the same class member function as argument in each iteration? Thanks, David. Quote Link to comment Share on other sites More sharing options...
David Black Posted August 10, 2022 Report Share Posted August 10, 2022 To use sc_spawn, yes you need SC_INCLUDE_DYNAMIC_PROCESS. It's a compile-time option to simply allow the code into compilation and has nothing to do with the definition of dynamic vs static in the strictest sense. Also, SC_THREAD/SC_METHOD do not allow for using the same class member more than once if I recall correctly. So you will need to use sc_spawn. Quote Link to comment Share on other sites More sharing options...
Ojos Posted August 12, 2022 Author Report Share Posted August 12, 2022 Thanks David! I have achieved it with sc_spawn. I include a small example just in case it is useful for another user with the same concern. I did also achieved it using SC_METHOD several times with the same member function as argument. It worked in SystemC 2.3.1 with gcc 9.4.0. However, I do not know if this is an intended feature by the standard or just an implementation luck. Besides, you need to access to the current process name to know in which of the concurrent processes you are. With sc_spawn, you can add and id parameter (an int shall be enough) to identify your process. Example (it is my first time writing code in this forum, I hope it looks decent): #include <systemc> #define SC_INCLUDE_DYNAMIC_PROCESSES #include <systemc> // This is to check if the macro must be defined before // the first inclusion of the SystemC library or not. Fortunately, not. #include <string> #include <iostream> using namespace std; template< int N > SC_MODULE(test_spawn_mod) { sc_core::sc_in<bool> clk, rst; sc_core::sc_vector< sc_core::sc_in<bool> > inputs; sc_core::sc_vector< sc_core::sc_out<int> > outputs; void test_method(int addr) { if (inputs[addr]) outputs[addr].write(addr); else outputs[addr].write(0); } void test_multi_method() { cout << "Hi! I am " << sc_core::sc_get_current_process_handle()->name() << endl; } SC_HAS_PROCESS(test_spawn_mod); test_spawn_mod(sc_core::sc_module_name nm): sc_module(nm), inputs("inputs", N), outputs("outputs", N) { for (int i=0; i<N; i++) { SC_METHOD(test_multi_method); sensitive << inputs[i]; sc_core::sc_spawn_options opts; opts.spawn_method(); opts.set_sensitivity(&clk.pos()); sc_core::sc_spawn( sc_bind(&test_spawn_mod<N>::test_method, this, i), ("test_method_"+std::to_string(i)).c_str(), &opts ); } } }; Quote Link to comment Share on other sites More sharing options...
David Black Posted August 12, 2022 Report Share Posted August 12, 2022 I suggest that you invoke your compiler with -DSC_INCLUDE_DYNAMIC_PROCESSES to avoid the issue of making sure all #include's of systemc are preceded by it. You might also consider using https://www.edaplayground.com to put your code when sharing. That way others can examine/execute the code with less effort. It's entirely free and quite popular. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.