From aeec70ea74d0a4e239d0db7da4819bc77f1cdad0 Mon Sep 17 00:00:00 2001
From: Thierry <thierry.gautier@inrialpes.fr>
Date: Thu, 18 Jan 2018 17:18:59 +0100
Subject: [PATCH] =?UTF-8?q?[fix]=C2=A0generated=20loops.csv=20that=20conta?=
 =?UTF-8?q?ins=20evt=20for=20loops=20scheduling.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 runtime/src/katracereader.cpp | 72 +++++++++++++++++++++++------------
 1 file changed, 47 insertions(+), 25 deletions(-)

diff --git a/runtime/src/katracereader.cpp b/runtime/src/katracereader.cpp
index a89416b..1f6695f 100644
--- a/runtime/src/katracereader.cpp
+++ b/runtime/src/katracereader.cpp
@@ -392,12 +392,20 @@ static void callback_print_event(
                 << ", schedtype: " << KAAPI_EVENT_DATA(event,1,u)
                 << ", count: " << KAAPI_EVENT_DATA(event,2,u);
     break;
+    case KAAPI_EVT_LOOP_MDATA:
+      std::cout << " loopid: " << KAAPI_EVENT_DATA(event,0,u)
+                << ", ub: " << KAAPI_EVENT_DATA(event,1,u)
+                << ", lb: " << KAAPI_EVENT_DATA(event,2,u)
+                << ", stride: " << KAAPI_EVENT_DATA(event,3,u);
+    break;
     case KAAPI_EVT_LOOP_END  :
       std::cout << " loopid: " << KAAPI_EVENT_DATA(event,0,u);
     break;
     case KAAPI_EVT_LOOP_NEXT :
       std::cout << " loopid: " << KAAPI_EVENT_DATA(event,0,u)
-                << ", count: " << KAAPI_EVENT_DATA(event,1,u);
+                << ", ub: " << KAAPI_EVENT_DATA(event,1,u)
+                << ", lb: " << KAAPI_EVENT_DATA(event,2,u)
+                << ", stride: " << KAAPI_EVENT_DATA(event,3,u);
     break;
 
     default:
@@ -1330,22 +1338,25 @@ struct kproc_t : public state_t {
 struct loopinfo_t : public event_t {
   enum { BEGIN, END, DISPATCH };
   loopinfo_t(int k)
-   : event_t(), type(k), wid(0)
+   : event_t(), type(k), wid(0), count(0), ub(0), lb(0), stride(0)
   {}
   int kid;
   int type;
   uint64_t wid;
   uint64_t count;
+  int64_t ub;
+  int64_t lb;
+  int64_t stride;
 };
 
 /* Loop state per thread */
 struct loopstate_t : public state_t {
   loopstate_t()
-   : state_t(), kid(0), wid(0), type(0), count(0)
+   : state_t(), kid(0), wid(0), schedtype(0), count(0)
   {}
   int kid;
   uint64_t wid;
-  uint64_t type;
+  uint64_t schedtype;
   uint64_t count;
 };
 
@@ -1401,6 +1412,7 @@ struct parallel_region_t : public state_t {
   std::vector<threadstate_t> threadstates;
   std::vector<state_t>       barrierstates;
   std::vector<loopstate_t>   loopstates;
+  std::vector<loopinfo_t>    loopevts;
   std::vector<ident_t>       last_perthread; /* per kproc id entry that
                   keep the top stack threadstates of the last THREAD_STATE/BEG or 0 */
 
@@ -1934,32 +1946,40 @@ printf("pred[id:%i/%p] = {id:%i}/%p\n", succ->id, (void*)succ->addr, task->id, (
     case KAAPI_EVT_BARRIER_END:
     break;
 
-    case KAAPI_EVT_LOOP_BEGIN:
+    case KAAPI_EVT_LOOP_BEGIN: /* both: a state creation and an event */
     {
-      loopinfo_t li(loopinfo_t::BEGIN);
-      li.start = event->date;
-      li.kid   = kid;
-      li.wid   = KAAPI_EVENT_DATA(event,0,u);
-      li.count = KAAPI_EVENT_DATA(event,2,u);
       loopstate_t ls;
       ls.start = event->date;
-      ls.kid   = kid;
       ls.wid   = KAAPI_EVENT_DATA(event,0,u);
-      ls.type  = KAAPI_EVENT_DATA(event,1,u);
-      ls.count = 0;
+      ls.kid   = kid;
+      ls.schedtype = KAAPI_EVENT_DATA(event,1,u);
+      ls.count = KAAPI_EVENT_DATA(event,2,u);
       if (rpr->loopstack.size() <= kid)
         rpr->loopstack.resize(kid+1);
       rpr->loopstack[kid].push_back( ls );
     } break;
+    case KAAPI_EVT_LOOP_MDATA:
+    {
+      loopinfo_t li(loopinfo_t::BEGIN);
+      li.start = event->date;
+      li.kid   = kid;
+      li.wid   = KAAPI_EVENT_DATA(event,0,u);
+      li.ub    = KAAPI_EVENT_DATA(event,1,u);
+      li.lb    = KAAPI_EVENT_DATA(event,2,u);
+      li.stride= KAAPI_EVENT_DATA(event,3,u);
+      rpr->loopevts.push_back( li );
+    } break;
     case KAAPI_EVT_LOOP_END  :
     {
       loopinfo_t li(loopinfo_t::END);
       li.start = event->date;
       li.kid   = kid;
       li.wid   = KAAPI_EVENT_DATA(event,0,u);
-      li.count = 0;
+      rpr->loopevts.push_back( li );
       loopstate_t& ls = rpr->loopstack[kid].back();
       ls.stop  = event->date;
+      ls.kid   = kid;
+      ls.wid   = li.wid;
       rpr->loopstates.push_back( ls );
       rpr->loopstack[kid].pop_back();
     } break;
@@ -1969,10 +1989,11 @@ printf("pred[id:%i/%p] = {id:%i}/%p\n", succ->id, (void*)succ->addr, task->id, (
       li.start = event->date;
       li.kid   = kid;
       li.wid   = KAAPI_EVENT_DATA(event,0,u);
-      li.count = KAAPI_EVENT_DATA(event,1,u);
+      li.ub    = KAAPI_EVENT_DATA(event,1,u);
+      li.lb    = KAAPI_EVENT_DATA(event,2,u);
+      li.stride= KAAPI_EVENT_DATA(event,3,u);
+      rpr->loopevts.push_back( li );
 
-      loopstate_t& ls = rpr->loopstack[kid].back();
-      ls.count += KAAPI_EVENT_DATA(event,1,u);
     } break;
 
     default:
@@ -2559,14 +2580,17 @@ int csv_parallel_region_t::closefile(int cpucount)
       exit(-1);
     }
   }
-
-  for (size_t i=0; i<loopstates.size(); ++i)
+  /* header */
+  fprintf(csv_parallel_region_t::fout_loops,
+    "Resource, Stamp, Wid, EvtType, UB, LB, Stride"
+  );
+  for (size_t i=0; i<loopevts.size(); ++i)
   {
-    loopstate_t& ls = loopstates[i];
+    loopinfo_t& li = loopevts[i];
     fprintf(csv_parallel_region_t::fout_loops,
-      "%i, %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 "\n",
-      ls.kid, ls.start, ls.stop, ls.delay(),
-      ls.wid, ls.count
+      "%i, %" PRIu64 ", %" PRIu64 ", %i, %" PRIi64 ", %" PRIi64 ", %" PRIi64 "\n",
+      li.kid, li.start, li.wid, li.type,
+      li.ub, li.lb, li.stride
     );
   }
   fflush(csv_parallel_region_t::fout_loops);
@@ -2812,13 +2836,11 @@ static kaapi_fnc_event parse_option( const int argc, const char** argv, int* cou
     else if (strcmp(argv[i], "--gpu-transfer") ==0)
       katracereader_options.gputransfer = 1;
 #endif
-#if 0
     else if (strcmp(argv[i], "--stat") ==0)
     {
       option = 's';
       katracereader_options.simulator = 1;
     }
-#endif
 #if 0
     else if (strcmp(argv[i], "--timestep") ==0)
     {
-- 
GitLab