Jump to content

katang

Members
  • Posts

    108
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

katang's Achievements

Advanced Member

Advanced Member (2/2)

0

Reputation

  1. I am attempting to model a three-state system in SystemC, adapting the biological behavior to gates. (The idea is similar to neuron synapses' biological behavior: I want to use pulses instead of levels.) Say, by default a two-input gate has its both inputs (synapses) and its output (axon) in state Z. If a 'spike' arrives (an event) to one of its inputs, for the duration of the spike, the input is set to 0 or 1 (as received) for a while, then the input changes back to Z. The gate remembers its inputs, and when it receives its second input, it sets its output to the calculated value for a while, then it changes back to Z (and resets input latching). Is this synthesizable? Can its 'real estate' demand be estimated? (How much such a solution increases number of gates in the circuit?) I.e. the level sequence is Z-0/1-Z, instead of 0-1-0.
  2. I need to recompile my app , because I need to use a library that actively uses some features of C++17. However, when I attempt to use it, I receive messages SystemC/2.3.3@minres/stable: Trying with 'minres'... Downloading conanmanifest.txt Downloading conanfile.py SystemC/2.3.3@minres/stable: Downloaded recipe revision 0 ERROR: SystemC/2.3.3@minres/stable: '17' is not a valid 'options.stdcxx' value. Possible values are ['11', '14', '98'] (I would be happy with 14, but that author was not)
  3. I am trying to figure out what module fired. My idea is shown below: the main program runs till the next event, and stops. At that point, I guess, there is no "current_process", so the lines in the comment do not work. Is there something similar for "past_process"? while(sc_pending_activity_at_future_time()) { sc_start( sc_time_to_pending_activity() ); // Run up to the next activity} /* sc_process_handle T = sc_get_current_process_handle(); sc_object* P = T.get_parent_object(); sc_object *Q = sc_get_current_process_b()->get_parent_object();*/ */
  4. Hm. You are voting for quasi-asynchronous operation? I like the idea. Not only because of context switching. I'll learn it. Thank you. So you say, there is no better idea, than to set a flag around notify(), and use that to distinguish the citizens? I think I understand sc_pending_activity_at_future_time() and sc_pending_activity_at_current_time() but, just for my curiosity: how can a clock influence sc_pending_activity()
  5. I want to run my simulation (a clocked design) event-by-event, but do not want to see the clock events. In my design I set a flag upon receiving a clock signal, so in this way I can distinguish the "clock-only" events. However, two more events are also attached to the clock. I have a 15 ns wait in my "design", and I have output such as 14 ns Current Pending Future Pending 14 ns Current Pending Future Pending 14 ns Time Current NOT Pending Future Pending 14050 ps Current Pending Future Pending 14050 ps Current Pending Future Pending 14050 ps Time Current NOT Pending Future Pending As far as I understood, I can see the complete process of clock handling, which is not really interesting for me (at this moment). 1./ Is there any way to reduce the list of pending activities? Or, reject some events? Or, do I use a wrong method? 2./ How the clock influences my test? (I mean: with sc_pending_activity_at_future_time() it runs OK, with sc_pending_activity() it represents an infinite loop.) // while( sc_pending_activity() ) while(sc_pending_activity_at_future_time()) { sc_start( sc_time_to_pending_activity() ); // Run up to the next activity}/* sc_start(10,SC_NS); cerr << '\n' << sc_time_stamp(); if(MySimulator->ClockFlag_Get()) { cerr << " Time"; MySimulator->ClockFlag_Set(false); } if(sc_pending_activity_at_current_time()) cerr << " Current Pending"; else cerr << " Current NOT Pending"; if(sc_pending_activity_at_future_time()) cerr << " Future Pending"; else cerr << " Future NOT Pending"; }
  6. I have a processor-like construction, and the execution time is simulated in the model using wait(time), i.e. I indend to provide the simulated execution time as argument of sc_start(), to imitate step-wise execution. Can I be sure, that in the model, the simulation will stop 'after' executing the simulated instruction; that is, reaching limiting time will terminate execution at the very end of the delta cycle? The other possibility that timeout is only one of the events, and by chance, it can be NOT the last. BTW: as I understood, a second sc_start() will continue simulation "as it was", i.e. it makes no initialisation, uses no maybe forgotten temporary variables, etc. It is correct? BTW2: How can I find out (at the last instruction) that the simulation finished (no more events left in the engine), and no use to issue another sc_start()?
  7. In my main program, I have declared sc_signal<bool, SC_MANY_WRITERS> main_full("full"); later I attempt to bind it as main_fifo1.fifo_full(main_full); but my compiler keeps saying no match for call to ‘(sc_core::sc_signal<bool, (sc_core::sc_writer_policy)1>) (sc_core::sc_signal<bool, (sc_core::sc_writer_policy)1>&)’ My other module declares sc_signal<bool, SC_MANY_WRITERS> fifo_full; With the other policy, I have no problem with binding. What do I wrong?
  8. I want to share some modules; something similar to when HW threads share the same physical core, but they run different SW threads. My idea is that I need vectors of events and data structures. When using static threads, I cannot change simply and safely the thread, and actually, I need to repeat the code for the threads., Even if I use dynamic threads, and can have parameters, the processes must be distinguished and I need several handles. I would need something as when an item on an event vector sends notification, the shared common code receives the index of the item in the vector. Quite similar as the different instantiations of an object share the code, but not their data. Is there any mechanism for what I want to do?
  9. Concerning the waiting: the next_trigger header tells next_trigger() uses all the syntax of wait(), and behaves as if the actual process of "waiting" occurs after the method exits. The next sentence gives a hint, that it "may gain the effect of a wait" but does tell that ! ONLY if I use it in a state machine!. By using a state variable member in the module class, a method may gain the effect of a wait as illustrated in the following example. example code tells // Wait 1 ns similar to Verilog #1 next_trigger(1,SC_NS); Thanks for the explanation. When one skims the example and attempts to understand the new terms, can easily misinterpret the term. Especially if compared to an already known construction. Sorry. Concerning the timing, could you, please, pinpoint the sentence I took from the book you mentioned. "After initialization, simulation processes are run when events occur to which they are sensitive." In my output, it looks like the main() , without dont_initialize(); is just one of the processes executed at zero time, but not part of the initialization. Correct?
  10. I am not sure, but: with the construction SC_THREAD(Thread_node); // PROBLEMATIC LINE dont_initialize(); you say that "I have a thread, that is not sensitive to any event (==cannot be started later), and should not be started at the beginning. Maybe the kernel is not prepared for such a request. Concerning "to instantiate a arbitrary number of processes": you probably have some upper limit on the number of processes, so you can instantiate that maximum number of modules, and than later you limit the actual (active) modules in the simulation to the random value you generate. I hope this helps.
  11. SC started @ 0 s External host thread initial processing Before Event 1 notified from an external host thread ThreadSafeNotify called @ 0 s After Event 1 notified from an external host thread Event 2 notified from an external host thread ThreadSafeNotify called @ 0 s ThreadSafeUpdate called @ 0 s Got event in triggered @ 0 s Got event after next_trigger(10,SC_NS) @ 0 s Got event in triggered again @ 0 s Initializing main() @ 0 s Wait event in main() @ 15 ns SC returned Maybe this issue deserves a separate thread. The output shows, that the time passes only in thread but not method, or only by wait() but not by next_request()? This explains (for me, at least) why main() does not receive an event. The listing tells that next_trigger() advanced the time, but the next line tells it did not. The wait() does. It seems to me that the engine starts before intializing main(). #include <pthread.h> #include <unistd.h> using namespace sc_core; class ThreadSafeEventIf : public sc_interface { virtual void notify(sc_time delay = SC_ZERO_TIME) = 0; virtual const sc_event &default_event(void) const = 0; protected: virtual void update(void) = 0; }; class ThreadSafeEvent : public sc_prim_channel, public ThreadSafeEventIf { public: ThreadSafeEvent(const char *name = ""): event(name) {} void notify(sc_time delay = SC_ZERO_TIME) { this->delay = delay; std::cout << "ThreadSafeNotify called @ "<<sc_time_stamp()<<std::endl; async_request_update(); } const sc_event &default_event(void) const { return event; } protected: virtual void update(void) { event.notify(delay); std::cout << "ThreadSafeUpdate called @ "<<sc_time_stamp()<<std::endl; } sc_event event; sc_time delay; }; SC_MODULE(Foo) { public: SC_CTOR(Foo) { SC_THREAD(main); sensitive << event; SC_METHOD(eventTriggered); sensitive << event; dont_initialize(); std::cout << "SC started @ "<<sc_time_stamp()<<std::endl; } private: void main() { std::cout << "Initializing main() @ "<<sc_time_stamp()<<std::endl; int i=0; while(i++<3) { wait(15,SC_NS); std::cout << "Wait event in main() @ "<<sc_time_stamp()<<std::endl; wait(); std::cout << "Got event in main() @ "<<sc_time_stamp()<<std::endl; } } void eventTriggered() { std::cout << "Got event in triggered @ "<<sc_time_stamp()<<std::endl; next_trigger(10,SC_NS); std::cout << "Got event after next_trigger(10,SC_NS) @ "<<sc_time_stamp()<<std::endl; next_trigger(); std::cout << "Got event in triggered again @ "<<sc_time_stamp()<<std::endl; } public: ThreadSafeEvent event; }; void *externalHostThread(void *arg) { std::cout << "External host thread initial processing" << std::endl; for(int i=0; i<100; i++){ i += 1;} Foo* foo = (Foo*)(arg); std::cout << "Before Event 1 notified from an external host thread" << std::endl; foo->event.notify(); std::cout << "After Event 1 notified from an external host thread" << std::endl; for(int i=0; i<100; i++){ i += 1;} std::cout << "Event 2 notified from an external host thread" << std::endl; foo->event.notify(); } int sc_main(int argc, char *argv[]) { Foo foo("foo"); pthread_t thread; pthread_create(&thread, NULL, externalHostThread, &foo); sc_start(); std::cout << "SC returned" << std::endl; return 0; }
  12. I wonder what is wrong with using usleep(). If I replace it with a dummy cycle, my output is as shown below Interestingly/importantly: 1/ Initializing main() appears where I expected, and correspondingly the event is received also in main(). However, this seems to be a random event; most of the outputs show that main() is intialized only !after! the events serviced, see the 2nd output. 2/ Event2 is sent and received as expected, but 'main()' persist hiding Maybe async_request_update() was not designed to be used right at the beginning of the simulation and something is not initalized? SC started External host thread initial processing Before Event 1 notified from an external host thread ThreadSafeNotify called Initializing main()After Event 1 notified from an external host thread Event 2 notified from an external host thread ThreadSafeNotify called ThreadSafeUpdate called Got event in triggered Got event after next_trigger(10,SC_NS) Got event in triggered again ThreadSafeUpdate called Got event in triggered Got event after next_trigger(10,SC_NS) Got event in triggered again Got event in main() SC returned SC started External host thread initial processing Before Event 1 notified from an external host thread ThreadSafeNotify called After Event 1 notified from an external host thread Event 2 notified from an external host thread ThreadSafeNotify called ThreadSafeUpdate called Got event in triggered Got event after next_trigger(10,SC_NS) Got event in triggered again Initializing main() SC returned
  13. I am getting confused. My output is SC started External host thread started Before Event 1 notified from an external host thread ThreadSafeNotify called After Event 1 notified from an external host thread ThreadSafeUpdate called Got event in triggered Got event after next_trigger Got event in triggered again Initializing main() SC returned I expected 1/ main() is executed before anything starts 2/ also the "After usleep" and "Event 2" messages appear #include <systemc> #include <pthread.h> #include <unistd.h> using namespace sc_core; class ThreadSafeEventIf : public sc_interface { virtual void notify(sc_time delay = SC_ZERO_TIME) = 0; virtual const sc_event &default_event(void) const = 0; protected: virtual void update(void) = 0; }; class ThreadSafeEvent : public sc_prim_channel, public ThreadSafeEventIf { public: ThreadSafeEvent(const char *name = ""): event(name) {} void notify(sc_time delay = SC_ZERO_TIME) { this->delay = delay; std::cout << "ThreadSafeNotify called\n"; async_request_update(); } const sc_event &default_event(void) const { return event; } protected: virtual void update(void) { event.notify(delay); std::cout << "ThreadSafeUpdate called\n"; } sc_event event; sc_time delay; }; SC_MODULE(Foo) { public: SC_CTOR(Foo) { SC_THREAD(main); sensitive << event; SC_METHOD(eventTriggered); sensitive << event; dont_initialize(); std::cout << "SC started\n"; } private: void main() { std::cout << "Initializing main()" << std::endl; int i=0; while(i++<3) { wait(); std::cout << "Got event in main()" << std::endl; } } void eventTriggered() { std::cout << "Got event in triggered" << std::endl; next_trigger(10,SC_NS); std::cout << "Got event after next_trigger" << std::endl; next_trigger(); std::cout << "Got event in triggered again" << std::endl; } public: ThreadSafeEvent event; }; void *externalHostThread(void *arg) { std::cout << "External host thread started" << std::endl; Foo* foo = (Foo*)(arg); std::cout << "Before Event 1 notified from an external host thread" << std::endl; foo->event.notify(); std::cout << "After Event 1 notified from an external host thread" << std::endl; usleep(10 * 1000 * 1000); // Just for the example std::cout << "After usleep from an external host thread" << std::endl; std::cout << "Event 2 notified from an external host thread" << std::endl; foo->event.notify(); } int sc_main(int argc, char *argv[]) { Foo foo("foo"); pthread_t thread; pthread_create(&thread, NULL, externalHostThread, &foo); sc_start(); std::cout << "SC returned" << std::endl; return 0; }
  14. Sorry, I noticed that I did not insert the new source code So, the output again is SC started SC first event notified ThreadSafeNotify called External host thread started Event 1 notified from an external host thread ThreadSafeNotify called ThreadSafeUpdate called Got event in triggered SC returned I am missing 1/ why the "Event2 notified" line is missing (the thread should terminate only after printing it) As the output is prompt, I guess the thread terminates before reaching printing The update() is called after the second notify(); I expected it is called after the third notify() 2/ I expected a "Got event in main()" message, too #include <systemc> #include <pthread.h> #include <unistd.h> using namespace sc_core; class ThreadSafeEventIf : public sc_interface { virtual void notify(sc_time delay = SC_ZERO_TIME) = 0; virtual const sc_event &default_event(void) const = 0; protected: virtual void update(void) = 0; }; class ThreadSafeEvent : public sc_prim_channel, public ThreadSafeEventIf { public: ThreadSafeEvent(const char *name = ""): event(name) {} void notify(sc_time delay = SC_ZERO_TIME) { this->delay = delay; std::cout << "ThreadSafeNotify called\n"; async_request_update(); } const sc_event &default_event(void) const { return event; } protected: virtual void update(void) { event.notify(delay); std::cout << "ThreadSafeUpdate called\n"; } sc_event event; sc_time delay; }; SC_MODULE(Foo) { public: SC_CTOR(Foo) { SC_THREAD(main); sensitive << event; SC_METHOD(eventTriggered); sensitive << event; dont_initialize(); std::cout << "SC started\n"; std::cout << "SC first event notified\n"; event.notify(); } private: void main() { int i=0; while(i++<3) { wait(); std::cout << "Got event in main()" << std::endl; } } void eventTriggered() { std::cout << "Got event in triggered" << std::endl; } public: ThreadSafeEvent event; }; void *externalHostThread(void *arg) { std::cout << "External host thread started" << std::endl; Foo* foo = (Foo*)(arg); std::cout << "Event 1 notified from an external host thread" << std::endl; foo->event.notify(); usleep(1 * 1000 * 1000); // Just for the example std::cout << "Event 2 notified from an external host thread" << std::endl; foo->event.notify(); } int sc_main(int argc, char *argv[]) { Foo foo("foo"); pthread_t thread; pthread_create(&thread, NULL, externalHostThread, &foo); sc_start(); std::cout << "SC returned" << std::endl; return 0; }
  15. It looks like I could not understand some essential points of async_request_update() In the sample program below (if the usleep in externalHostThread is commented out, the output is) SC first event notified ThreadSafeNotify called External host thread started Event 1 notified from an external host thread ThreadSafeNotify called Event 2 notified from an external host thread ThreadSafeNotify called ThreadSafeUpdate called Got event in triggered SC returned if it is uncommented, the output is SC started SC first event notified ThreadSafeNotify called External host thread started Event 1 notified from an external host thread ThreadSafeNotify called ThreadSafeUpdate called Got event in triggered SC returned 1/ That is, I do receive the event in the SC_METHOD, but not in the SC_THREAD 2./ If the delay (imitating some useful processing) is active, the 2nd event is not sent out, the thread returns early. Whay do I wrong?
×
×
  • Create New...