16 #ifndef MATCH_MODULE_H
17 #define MATCH_MODULE_H
35 #if defined(ENABLE_SYNC_RESET)
36 #define NVHLS_NEG_RESET_SIGNAL_IS(port) reset_signal_is(port,false)
37 #define NVHLS_POS_RESET_SIGNAL_IS(port) reset_signal_is(port,true)
39 #define NVHLS_NEG_RESET_SIGNAL_IS(port) async_reset_signal_is(port,false)
40 #define NVHLS_POS_RESET_SIGNAL_IS(port) async_reset_signal_is(port,true)
43 #include <nvhls_trace.h>
44 #include <nvhls_marshaller.h>
45 #include <nvhls_message.h>
56 #if defined(__SYNTHESIS__) && defined(HLS_CATAPULT) && __cplusplus >= 201103L
57 #define nvhls_concat(s1,s2) (std::string(s2)).c_str()
59 #define nvhls_concat(s1,s2) (std::string(s1) + "_" + std::string(s2)).c_str()
112 #ifndef __SYNTHESIS__
113 sc_attr_base* module_indicator;
116 Module() : sc_module(sc_gen_unique_name(
"module")), clk(
"clk"), rst(
"rst") {
117 #ifndef __SYNTHESIS__
118 module_indicator =
new sc_attr_base(
"match_module");
119 this->add_attribute(*module_indicator);
122 Module(sc_module_name nm) : sc_module(nm), clk(
"clk"), rst(
"rst") {
123 #ifndef __SYNTHESIS__
124 module_indicator =
new sc_attr_base(
"match_module");
125 this->add_attribute(*module_indicator);
130 #ifndef __SYNTHESIS__
131 delete module_indicator;
137 #ifndef __SYNTHESIS__
139 std::map<std::string, uint64> stats_;
144 #ifndef __SYNTHESIS__
147 bool IsModule(sc_object* obj) {
151 if(!obj->kind() || !obj->name())
154 #ifndef __SYNTHESIS__
155 return (obj->get_attribute(
"match_module") != 0);
157 std::string objName = obj->name();
158 return ((strncmp(obj->kind(),
"sc_module", 9) == 0) &&
159 (objName.find(
"dummyPortManager") == std::string::npos ) &&
160 (objName.find(
"rocket") == std::string::npos ) &&
161 (objName.find(
"router") == std::string::npos )
168 std::vector<Module*> GetChildren() {
169 std::vector<sc_object*> children = get_child_objects();
170 std::vector<Module*> result;
172 if(children.size() != 0) {
173 for (
unsigned i = 0; i < children.size(); i++) {
174 if (IsModule(children[i])) {
175 result.push_back((
Module*)(children[i]));
185 void IncrStat(
const std::string& name,
unsigned int num = 1) {
186 #ifndef __SYNTHESIS__
187 stats_[name] = stats_[name] + num;
191 void IncrStatIndexed(
const std::string& name,
unsigned int idx,
192 unsigned int num = 1) {
193 #ifndef __SYNTHESIS__
194 std::stringstream final_name;
195 final_name << name <<
"_" << idx;
196 stats_[final_name.str()] = stats_[final_name.str()] + num;
204 #ifndef __SYNTHESIS__
205 tracer_.SetCurrentLevel(l);
206 tracer_ << sc_time_stamp() <<
": ";
207 if (get_parent() != NULL) {
208 if (get_parent()->get_parent() != NULL) {
209 if (get_parent()->get_parent()->get_parent() != NULL) {
210 if (get_parent()->get_parent()->get_parent()->get_parent() != NULL) {
211 if (get_parent()->get_parent()->get_parent()->get_parent()->get_parent() != NULL) {
212 if (strncmp(get_parent()->get_parent()->get_parent()->get_parent()->get_parent()->basename(),
"", 1)) {
213 tracer_ << get_parent()->get_parent()->get_parent()->get_parent()->get_parent()->basename() <<
".";
217 if (strncmp(get_parent()->get_parent()->get_parent()->get_parent()->basename(),
"", 1)) {
218 tracer_ << get_parent()->get_parent()->get_parent()->get_parent()->basename() <<
".";
222 if (strncmp(get_parent()->get_parent()->get_parent()->basename(),
"", 1)) {
223 tracer_ << get_parent()->get_parent()->get_parent()->basename() <<
".";
227 if (strncmp(get_parent()->get_parent()->basename(),
"", 1)) {
228 tracer_ << get_parent()->get_parent()->basename() <<
".";
232 if (strncmp(get_parent()->basename(),
"", 1)) {
233 tracer_ << get_parent()->basename() <<
".";
236 if (strncmp(basename(),
"", 1)) {
237 tracer_ << basename() <<
": ";
243 Tracer& ASSERT(
bool cond) {
244 #ifndef __SYNTHESIS__
247 tracer_.SetCurrentLevel(tracer_.GetTraceLevel());
251 tracer_.SetCurrentLevel(tracer_.GetTraceLevel() + 1);
253 tracer_ <<
"ASSERTION FAILURE: ";
254 tracer_ << sc_time_stamp() <<
": ";
255 if (strncmp(name(),
"", 1)) {
256 tracer_ << name() <<
": ";
263 void SetTraceLevel(
int l) {
264 #ifndef __SYNTHESIS__
265 tracer_.SetTraceLevel(l);
266 std::vector<Module*> children = GetChildren();
267 for (
unsigned int i = 0; i < children.size(); i++) {
268 children[i]->SetTraceLevel(l);
274 void RecordEvent(
const std::string& name, uint64 param = 0) {
276 #ifndef __SYNTHESIS__
281 void PrintStats(std::ostream& ofile,
unsigned int lvl,
Module* aggregator) {
282 #ifndef __SYNTHESIS__
283 for (std::map<std::string, uint64>::iterator it = stats_.begin();
284 it != stats_.end(); it++) {
286 ofile << it->first <<
": " << it->second << std::endl;
289 aggregator->IncrStat(it->first, it->second);
293 void Indent(std::ostream& ofile,
unsigned int lvl) {
294 #ifndef __SYNTHESIS__
295 for (
unsigned int x = 0; x < 2 * lvl; x++) {
303 #ifndef __SYNTHESIS__
304 return (stats_.size() != 0);
309 bool ChildrenHaveStats() {
310 bool has_stats =
false;
311 #ifndef __SYNTHESIS__
312 std::vector<Module*> children = GetChildren();
313 if(children.size() != 0) {
314 for (
unsigned int x = 0; x < children.size(); x++) {
315 has_stats |= children[x]->HasStats();
317 has_stats |= children[x]->ChildrenHaveStats();
324 void DumpStats(std::ostream& ofile,
unsigned int lvl,
Module* aggregator) {
325 #ifndef __SYNTHESIS__
326 if (!HasStats() && !ChildrenHaveStats()) {
331 ofile << name() <<
":" << std::endl;
332 Module* final_aggregator = ChildrenHaveStats() ? NULL : aggregator;
334 PrintStats(ofile, lvl + 1, final_aggregator);
336 std::vector<Module*> children = GetChildren();
338 if (ChildrenHaveStats()) {
340 for (
unsigned int x = 0; x < children.size(); x++) {
341 children[x]->DumpStats(ofile, lvl + 1,
this);
346 ofile <<
"Totals:" << std::endl;
347 PrintStats(ofile, 1, aggregator);
349 Indent(ofile, lvl + 1);
350 ofile <<
"Sub-totals (" << name() <<
"):" << std::endl;
351 PrintStats(ofile, lvl + 2, aggregator);
356 static const unsigned int width = 0;
357 template <
unsigned int Size>
358 void Marshall(Marshaller<Size>& m) {
Matchlib Module class: a wrapper of sc_module with tracing and stats support.
Tracer class to dump simulation stats to an output stream (stdout by default).