starpu_fxt.c 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2013 Université de Bordeaux 1
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #include <starpu.h>
  17. #include <common/config.h>
  18. #include <common/uthash.h>
  19. #ifdef STARPU_HAVE_POTI
  20. #include <poti.h>
  21. #define STARPU_POTI_STR_LEN 200
  22. #endif
  23. #ifdef STARPU_USE_FXT
  24. #include "starpu_fxt.h"
  25. #include <inttypes.h>
  26. #include <starpu_hash.h>
  27. static char *cpus_worker_colors[STARPU_NMAXWORKERS] = {"/greens9/7", "/greens9/6", "/greens9/5", "/greens9/4", "/greens9/9", "/greens9/3", "/greens9/2", "/greens9/1" };
  28. static char *cuda_worker_colors[STARPU_NMAXWORKERS] = {"/ylorrd9/9", "/ylorrd9/6", "/ylorrd9/3", "/ylorrd9/1", "/ylorrd9/8", "/ylorrd9/7", "/ylorrd9/4", "/ylorrd9/2", "/ylorrd9/1"};
  29. static char *opencl_worker_colors[STARPU_NMAXWORKERS] = {"/blues9/9", "/blues9/6", "/blues9/3", "/blues9/1", "/blues9/8", "/blues9/7", "/blues9/4", "/blues9/2", "/blues9/1"};
  30. static char *mic_worker_colors[STARPU_NMAXWORKERS] = {"/reds9/9", "/reds9/6", "/reds9/3", "/reds9/1", "/reds9/8", "/reds9/7", "/reds9/4", "/reds9/2", "/reds9/1"};
  31. static char *scc_worker_colors[STARPU_NMAXWORKERS] = {"/reds9/9", "/reds9/6", "/reds9/3", "/reds9/1", "/reds9/8", "/reds9/7", "/reds9/4", "/reds9/2", "/reds9/1"};
  32. static char *other_worker_colors[STARPU_NMAXWORKERS] = {"/greys9/9", "/greys9/8", "/greys9/7", "/greys9/6"};
  33. static char *worker_colors[STARPU_NMAXWORKERS];
  34. static unsigned opencl_index = 0;
  35. static unsigned cuda_index = 0;
  36. static unsigned cpus_index = 0;
  37. static unsigned mic_index = 0;
  38. static unsigned scc_index = 0;
  39. static unsigned other_index = 0;
  40. static void set_next_other_worker_color(int workerid)
  41. {
  42. worker_colors[workerid] = other_worker_colors[other_index++];
  43. }
  44. static void set_next_cpu_worker_color(int workerid)
  45. {
  46. worker_colors[workerid] = cpus_worker_colors[cpus_index++];
  47. }
  48. static void set_next_cuda_worker_color(int workerid)
  49. {
  50. worker_colors[workerid] = cuda_worker_colors[cuda_index++];
  51. }
  52. static void set_next_opencl_worker_color(int workerid)
  53. {
  54. worker_colors[workerid] = opencl_worker_colors[opencl_index++];
  55. }
  56. static void set_next_mic_worker_color(int workerid)
  57. {
  58. worker_colors[workerid] = mic_worker_colors[mic_index++];
  59. }
  60. static void set_next_scc_worker_color(int workerid)
  61. {
  62. worker_colors[workerid] = scc_worker_colors[scc_index++];
  63. }
  64. static const char *get_worker_color(int workerid)
  65. {
  66. return worker_colors[workerid];
  67. }
  68. static unsigned get_colour_symbol_red(char *name)
  69. {
  70. /* choose some colour ... that's disguting yes */
  71. uint32_t hash_symbol = starpu_hash_crc32c_string(name, 0);
  72. return (unsigned)starpu_hash_crc32c_string("red", hash_symbol) % 1024;
  73. }
  74. static unsigned get_colour_symbol_green(char *name)
  75. {
  76. /* choose some colour ... that's disguting yes */
  77. uint32_t hash_symbol = starpu_hash_crc32c_string(name, 0);
  78. return (unsigned)starpu_hash_crc32c_string("green", hash_symbol) % 1024;
  79. }
  80. static unsigned get_colour_symbol_blue(char *name)
  81. {
  82. /* choose some colour ... that's disguting yes */
  83. uint32_t hash_symbol = starpu_hash_crc32c_string(name, 0);
  84. return (unsigned)starpu_hash_crc32c_string("blue", hash_symbol) % 1024;
  85. }
  86. static double last_codelet_start[STARPU_NMAXWORKERS];
  87. static char last_codelet_symbol[STARPU_NMAXWORKERS][128];
  88. /* If more than a period of time has elapsed, we flush the profiling info,
  89. * otherwise they are accumulated everytime there is a new relevant event. */
  90. #define ACTIVITY_PERIOD 75.0
  91. static double last_activity_flush_timestamp[STARPU_NMAXWORKERS];
  92. static double accumulated_sleep_time[STARPU_NMAXWORKERS];
  93. static double accumulated_exec_time[STARPU_NMAXWORKERS];
  94. LIST_TYPE(_starpu_symbol_name,
  95. char *name;
  96. )
  97. static struct _starpu_symbol_name_list *symbol_list;
  98. LIST_TYPE(_starpu_communication,
  99. unsigned comid;
  100. double comm_start;
  101. double bandwidth;
  102. unsigned src_node;
  103. unsigned dst_node;
  104. )
  105. static struct _starpu_communication_list *communication_list;
  106. /*
  107. * Paje trace file tools
  108. */
  109. static FILE *out_paje_file;
  110. static FILE *distrib_time;
  111. static FILE *activity_file;
  112. /*
  113. * Generic tools
  114. */
  115. static double get_event_time_stamp(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  116. {
  117. return (((double)(ev->time-options->file_offset))/1000000.0);
  118. }
  119. static int nworkers = 0;
  120. struct worker_entry
  121. {
  122. UT_hash_handle hh;
  123. unsigned long tid;
  124. int workerid;
  125. } *worker_ids;
  126. static void register_worker_id(unsigned long tid, int workerid)
  127. {
  128. nworkers++;
  129. struct worker_entry *entry;
  130. HASH_FIND(hh, worker_ids, &tid, sizeof(tid), entry);
  131. STARPU_ASSERT_MSG(workerid < STARPU_NMAXWORKERS, "Too many workers in this trace, please increase the maximum number of CPUs and GPUs to the same value as was used for execution");
  132. /* only register a thread once */
  133. STARPU_ASSERT(entry == NULL);
  134. entry = malloc(sizeof(*entry));
  135. entry->tid = tid;
  136. entry->workerid = workerid;
  137. HASH_ADD(hh, worker_ids, tid, sizeof(tid), entry);
  138. }
  139. static int find_worker_id(unsigned long tid)
  140. {
  141. struct worker_entry *entry;
  142. HASH_FIND(hh, worker_ids, &tid, sizeof(tid), entry);
  143. if (!entry)
  144. return -1;
  145. return entry->workerid;
  146. }
  147. static void update_accumulated_time(int worker, double sleep_time, double exec_time, double current_timestamp, int forceflush)
  148. {
  149. accumulated_sleep_time[worker] += sleep_time;
  150. accumulated_exec_time[worker] += exec_time;
  151. /* If sufficient time has elapsed since the last flush, we have a new
  152. * point in our graph */
  153. double elapsed = current_timestamp - last_activity_flush_timestamp[worker];
  154. if (forceflush || (elapsed > ACTIVITY_PERIOD))
  155. {
  156. if (activity_file)
  157. fprintf(activity_file, "%d\t%.9f\t%.9f\t%.9f\t%.9f\n", worker, current_timestamp, elapsed, accumulated_exec_time[worker], accumulated_sleep_time[worker]);
  158. /* reset the accumulated times */
  159. last_activity_flush_timestamp[worker] = current_timestamp;
  160. accumulated_sleep_time[worker] = 0.0;
  161. accumulated_exec_time[worker] = 0.0;
  162. }
  163. }
  164. /*
  165. * Auxiliary functions for poti handling names
  166. */
  167. #ifdef STARPU_HAVE_POTI
  168. static char *memnode_container_alias(char *output, int len, const char *prefix, long unsigned int memnodeid)
  169. {
  170. snprintf(output, len, "%smn%"PRIu64"", prefix, memnodeid);
  171. return output;
  172. }
  173. static char *memmanager_container_alias(char *output, int len, const char *prefix, long unsigned int memnodeid)
  174. {
  175. snprintf(output, len, "%smm%"PRIu64"", prefix, memnodeid);
  176. return output;
  177. }
  178. static char *thread_container_alias(char *output, int len, const char *prefix, long unsigned int threadid)
  179. {
  180. snprintf(output, len, "%st%"PRIu64"", prefix, threadid);
  181. return output;
  182. }
  183. static char *worker_container_alias(char *output, int len, const char *prefix, long unsigned int workerid)
  184. {
  185. snprintf(output, len, "%sw%"PRIu64"", prefix, workerid);
  186. return output;
  187. }
  188. static char *mpicommthread_container_alias(char *output, int len, const char *prefix)
  189. {
  190. snprintf(output, len, "%smpict", prefix);
  191. return output;
  192. }
  193. static char *program_container_alias(char *output, int len, const char *prefix)
  194. {
  195. snprintf(output, len, "%sp", prefix);
  196. return output;
  197. }
  198. static char *scheduler_container_alias(char *output, int len, const char *prefix)
  199. {
  200. snprintf(output, len, "%ssched", prefix);
  201. return output;
  202. }
  203. #endif
  204. static void memnode_set_state(double time, const char *prefix, unsigned int memnodeid, const char *name)
  205. {
  206. #ifdef STARPU_HAVE_POTI
  207. char container[STARPU_POTI_STR_LEN];
  208. memmanager_container_alias(container, STARPU_POTI_STR_LEN, prefix, memnodeid);
  209. poti_SetState(time, container, "MS", name);
  210. #else
  211. fprintf(out_paje_file, "10 %.9f %smm%u MS %s\n", time, prefix, memnodeid, name);
  212. #endif
  213. }
  214. static void worker_set_state(double time, const char *prefix, long unsigned int workerid, const char *name)
  215. {
  216. #ifdef STARPU_HAVE_POTI
  217. char container[STARPU_POTI_STR_LEN];
  218. thread_container_alias(container, STARPU_POTI_STR_LEN, prefix, workerid);
  219. poti_SetState(time, container, "S", name);
  220. #else
  221. fprintf(out_paje_file, "10 %.9f %st%"PRIu64" S %s\n", time, prefix, workerid, name);
  222. #endif
  223. }
  224. static void mpicommthread_set_state(double time, const char *prefix, const char *name)
  225. {
  226. #ifdef STARPU_HAVE_POTI
  227. char container[STARPU_POTI_STR_LEN];
  228. mpicommthread_container_alias(container, STARPU_POTI_STR_LEN, prefix);
  229. poti_SetState(time, container, "CtS", name);
  230. #else
  231. fprintf(out_paje_file, "10 %.9f %smpict CtS %s\n", time, prefix, name);
  232. #endif
  233. }
  234. /*
  235. * Initialization
  236. */
  237. static void handle_new_mem_node(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  238. {
  239. char *prefix = options->file_prefix;
  240. if (out_paje_file)
  241. {
  242. #ifdef STARPU_HAVE_POTI
  243. char program_container[STARPU_POTI_STR_LEN];
  244. program_container_alias(program_container, STARPU_POTI_STR_LEN, prefix);
  245. char new_memnode_container_alias[STARPU_POTI_STR_LEN], new_memnode_container_name[STARPU_POTI_STR_LEN];
  246. memnode_container_alias (new_memnode_container_alias, STARPU_POTI_STR_LEN, prefix, ev->param[0]);
  247. /* TODO: ramkind */
  248. snprintf(new_memnode_container_name, STARPU_POTI_STR_LEN, "%sMEMNODE%"PRIu64"", prefix, ev->param[0]);
  249. poti_CreateContainer(get_event_time_stamp(ev, options), new_memnode_container_alias, "Mn", program_container, new_memnode_container_name);
  250. memmanager_container_alias (new_memnode_container_alias, STARPU_POTI_STR_LEN, prefix, ev->param[0]);
  251. /* TODO: ramkind */
  252. snprintf(new_memnode_container_name, STARPU_POTI_STR_LEN, "%sMEMMANAGER%"PRIu64"", prefix, ev->param[0]);
  253. poti_CreateContainer(get_event_time_stamp(ev, options), new_memnode_container_alias, "Mm", program_container, new_memnode_container_name);
  254. #else
  255. fprintf(out_paje_file, "7 %.9f %smn%"PRIu64" Mn %sp %sMEMNODE%"PRIu64"\n", get_event_time_stamp(ev, options), prefix, ev->param[0], prefix, options->file_prefix, ev->param[0]);
  256. fprintf(out_paje_file, "7 %.9f %smm%"PRIu64" Mm %sp %sMEMMANAGER%"PRIu64"\n", get_event_time_stamp(ev, options), prefix, ev->param[0], prefix, options->file_prefix, ev->param[0]);
  257. #endif
  258. if (!options->no_bus)
  259. #ifdef STARPU_HAVE_POTI
  260. poti_SetVariable(get_event_time_stamp(ev, options), new_memnode_container_alias, "bw", 0.0);
  261. #else
  262. fprintf(out_paje_file, "13 %.9f %smm%"PRIu64" bw 0.0\n", 0.0f, prefix, ev->param[0]);
  263. #endif
  264. }
  265. }
  266. static void handle_worker_init_start(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  267. {
  268. /*
  269. arg0 : type of worker (cuda, cpu ..)
  270. arg1 : memory node
  271. arg2 : thread id
  272. */
  273. char *prefix = options->file_prefix;
  274. int devid = ev->param[2];
  275. int workerid = ev->param[1];
  276. int nodeid = ev->param[3];
  277. int threadid = ev->param[4];
  278. register_worker_id(threadid, workerid);
  279. char *kindstr = "";
  280. enum starpu_perfmodel_archtype archtype = 0;
  281. switch (ev->param[0])
  282. {
  283. case _STARPU_FUT_APPS_KEY:
  284. set_next_other_worker_color(workerid);
  285. kindstr = "APPS";
  286. break;
  287. case _STARPU_FUT_CPU_KEY:
  288. set_next_cpu_worker_color(workerid);
  289. kindstr = "CPU";
  290. archtype = STARPU_CPU_DEFAULT;
  291. break;
  292. case _STARPU_FUT_CUDA_KEY:
  293. set_next_cuda_worker_color(workerid);
  294. kindstr = "CUDA";
  295. archtype = STARPU_CUDA_DEFAULT + devid;
  296. break;
  297. case _STARPU_FUT_OPENCL_KEY:
  298. set_next_opencl_worker_color(workerid);
  299. kindstr = "OPENCL";
  300. archtype = STARPU_OPENCL_DEFAULT + devid;
  301. break;
  302. case _STARPU_FUT_MIC_KEY:
  303. set_next_mic_worker_color(workerid);
  304. kindstr = "mic";
  305. archtype = STARPU_MIC_DEFAULT + devid;
  306. break;
  307. case _STARPU_FUT_SCC_KEY:
  308. set_next_scc_worker_color(workerid);
  309. kindstr = "scc";
  310. archtype = STARPU_SCC_DEFAULT + devid;
  311. break;
  312. default:
  313. STARPU_ABORT();
  314. }
  315. if (out_paje_file)
  316. {
  317. #ifdef STARPU_HAVE_POTI
  318. char new_thread_container_alias[STARPU_POTI_STR_LEN];
  319. thread_container_alias (new_thread_container_alias, STARPU_POTI_STR_LEN, prefix, threadid);
  320. char new_worker_container_alias[STARPU_POTI_STR_LEN];
  321. worker_container_alias (new_worker_container_alias, STARPU_POTI_STR_LEN, prefix, workerid);
  322. char memnode_container[STARPU_POTI_STR_LEN];
  323. memnode_container_alias(memnode_container, STARPU_POTI_STR_LEN, prefix, nodeid);
  324. char new_thread_container_name[STARPU_POTI_STR_LEN];
  325. snprintf(new_thread_container_name, STARPU_POTI_STR_LEN, "%s%d", prefix, threadid);
  326. char new_worker_container_name[STARPU_POTI_STR_LEN];
  327. snprintf(new_worker_container_name, STARPU_POTI_STR_LEN, "%s%s%d", prefix, kindstr, devid);
  328. poti_CreateContainer(get_event_time_stamp(ev, options), new_thread_container_alias, "T", memnode_container, new_thread_container_name);
  329. poti_CreateContainer(get_event_time_stamp(ev, options), new_worker_container_alias, "W", new_thread_container_alias, new_worker_container_name);
  330. #else
  331. fprintf(out_paje_file, "7 %.9f %st%d T %smn%d %s%d\n",
  332. get_event_time_stamp(ev, options), prefix, threadid, prefix, nodeid, prefix, threadid);
  333. fprintf(out_paje_file, "7 %.9f %sw%d W %st%d %s%s%d\n",
  334. get_event_time_stamp(ev, options), prefix, workerid, prefix, threadid, prefix, kindstr, devid);
  335. #endif
  336. }
  337. /* start initialization */
  338. if (out_paje_file)
  339. worker_set_state(get_event_time_stamp(ev, options), prefix, threadid, "I");
  340. if (activity_file)
  341. fprintf(activity_file, "name\t%d\t%s %d\n", workerid, kindstr, devid);
  342. snprintf(options->worker_names[workerid], 256, "%s %d", kindstr, devid);
  343. options->worker_archtypes[workerid] = archtype;
  344. }
  345. static void handle_worker_init_end(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  346. {
  347. char *prefix = options->file_prefix;
  348. if (out_paje_file)
  349. worker_set_state(get_event_time_stamp(ev, options), prefix, ev->param[0], "B");
  350. /* Initilize the accumulated time counters */
  351. int worker = find_worker_id(ev->param[0]);
  352. last_activity_flush_timestamp[worker] = get_event_time_stamp(ev, options);
  353. accumulated_sleep_time[worker] = 0.0;
  354. accumulated_exec_time[worker] = 0.0;
  355. }
  356. static void handle_worker_deinit_start(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  357. {
  358. char *prefix = options->file_prefix;
  359. if (out_paje_file)
  360. worker_set_state(get_event_time_stamp(ev, options), prefix, ev->param[0], "D");
  361. }
  362. static void handle_worker_deinit_end(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  363. {
  364. char *prefix = options->file_prefix;
  365. if (out_paje_file)
  366. {
  367. #ifdef STARPU_HAVE_POTI
  368. char worker_container[STARPU_POTI_STR_LEN];
  369. thread_container_alias(worker_container, STARPU_POTI_STR_LEN, prefix, ev->param[1]);
  370. poti_DestroyContainer(get_event_time_stamp(ev, options), "T", worker_container);
  371. #else
  372. fprintf(out_paje_file, "8 %.9f %st%"PRIu64" T\n",
  373. get_event_time_stamp(ev, options), prefix, ev->param[1]);
  374. #endif
  375. }
  376. }
  377. #ifdef STARPU_HAVE_POTI
  378. static void create_paje_state_color(char *name, char *type, float red, float green, float blue)
  379. {
  380. char color[STARPU_POTI_STR_LEN];
  381. snprintf(color, STARPU_POTI_STR_LEN, "%f %f %f", red, green, blue);
  382. poti_DefineEntityValue(name, type, name, color);
  383. }
  384. #endif
  385. static void create_paje_state_if_not_found(char *name, struct starpu_fxt_options *options)
  386. {
  387. struct _starpu_symbol_name *itor;
  388. for (itor = _starpu_symbol_name_list_begin(symbol_list);
  389. itor != _starpu_symbol_name_list_end(symbol_list);
  390. itor = _starpu_symbol_name_list_next(itor))
  391. {
  392. if (!strcmp(name, itor->name))
  393. {
  394. /* we found an entry */
  395. return;
  396. }
  397. }
  398. /* it's the first time ... */
  399. struct _starpu_symbol_name *entry = _starpu_symbol_name_new();
  400. entry->name = malloc(strlen(name));
  401. strcpy(entry->name, name);
  402. _starpu_symbol_name_list_push_front(symbol_list, entry);
  403. /* choose some colour ... that's disguting yes */
  404. unsigned hash_symbol_red = get_colour_symbol_red(name);
  405. unsigned hash_symbol_green = get_colour_symbol_green(name);
  406. unsigned hash_symbol_blue = get_colour_symbol_blue(name);
  407. uint32_t hash_sum = hash_symbol_red + hash_symbol_green + hash_symbol_blue;
  408. float red, green, blue;
  409. if (options->per_task_colour)
  410. {
  411. red = (1.0f * hash_symbol_red) / hash_sum;
  412. green = (1.0f * hash_symbol_green) / hash_sum;
  413. blue = (1.0f * hash_symbol_blue) / hash_sum;
  414. }
  415. else
  416. {
  417. /* Use the hardcoded value for execution mode */
  418. red = 0.0f;
  419. green = 0.6f;
  420. blue = 0.4f;
  421. }
  422. /* create the Paje state */
  423. if (out_paje_file)
  424. {
  425. #ifdef STARPU_HAVE_POTI
  426. create_paje_state_color(name, "S", red, green, blue);
  427. create_paje_state_color(name, "Ctx1", 255.0, 255.0, 0.0);
  428. create_paje_state_color(name, "Ctx2", .0, 255.0, 0.0);
  429. create_paje_state_color(name, "Ctx3", 75.0, .0, 130.0);
  430. create_paje_state_color(name, "Ctx4", .0, 245.0, 255.0);
  431. create_paje_state_color(name, "Ctx5", .0, .0, .0);
  432. create_paje_state_color(name, "Ctx6", .0, .0, 128.0);
  433. create_paje_state_color(name, "Ctx7", 105.0, 105.0, 105.0);
  434. create_paje_state_color(name, "Ctx8", 255.0, .0, 255.0);
  435. create_paje_state_color(name, "Ctx9", .0, .0, 1.0);
  436. create_paje_state_color(name, "Ctx10", 154.0, 205.0, 50.0);
  437. #else
  438. fprintf(out_paje_file, "6 %s S %s \"%f %f %f\" \n", name, name, red, green, blue);
  439. fprintf(out_paje_file, "6 %s Ctx1 %s \"255.0 255.0 0.0\" \n", name, name);
  440. fprintf(out_paje_file, "6 %s Ctx2 %s \".0 255.0 .0\" \n", name, name);
  441. fprintf(out_paje_file, "6 %s Ctx3 %s \"75.0 .0 130.0\" \n", name, name);
  442. fprintf(out_paje_file, "6 %s Ctx4 %s \".0 245.0 255.0\" \n", name, name);
  443. fprintf(out_paje_file, "6 %s Ctx5 %s \".0 .0 .0\" \n", name, name);
  444. fprintf(out_paje_file, "6 %s Ctx6 %s \".0 .0 128.0\" \n", name, name);
  445. fprintf(out_paje_file, "6 %s Ctx7 %s \"105.0 105.0 105.0\" \n", name, name);
  446. fprintf(out_paje_file, "6 %s Ctx8 %s \"255.0 .0 255.0\" \n", name, name);
  447. fprintf(out_paje_file, "6 %s Ctx9 %s \".0 .0 1.0\" \n", name, name);
  448. fprintf(out_paje_file, "6 %s Ctx10 %s \"154.0 205.0 50.0\" \n", name, name);
  449. #endif
  450. }
  451. }
  452. static void handle_start_codelet_body(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  453. {
  454. int worker;
  455. worker = find_worker_id(ev->param[2]);
  456. unsigned sched_ctx = ev->param[1];
  457. if (worker < 0) return;
  458. char *prefix = options->file_prefix;
  459. unsigned long has_name = ev->param[3];
  460. char *name = has_name?(char *)&ev->param[4]:"unknown";
  461. snprintf(last_codelet_symbol[worker], sizeof(last_codelet_symbol[worker]), "%s", name);
  462. double start_codelet_time = get_event_time_stamp(ev, options);
  463. last_codelet_start[worker] = start_codelet_time;
  464. create_paje_state_if_not_found(name, options);
  465. if (out_paje_file)
  466. {
  467. worker_set_state(start_codelet_time, prefix, ev->param[2], name);
  468. if (sched_ctx != 0)
  469. {
  470. #ifdef STARPU_HAVE_POTI
  471. char container[STARPU_POTI_STR_LEN];
  472. char ctx[6];
  473. snprintf(ctx, sizeof(ctx), "Ctx%d", sched_ctx);
  474. thread_container_alias(container, STARPU_POTI_STR_LEN, prefix, ev->param[2]);
  475. poti_SetState(start_codelet_time, container, ctx, name);
  476. #else
  477. fprintf(out_paje_file, "10 %.9f %st%"PRIu64" Ctx%d %s\n", start_codelet_time, prefix, ev->param[2], sched_ctx, name);
  478. #endif
  479. }
  480. }
  481. }
  482. static long dumped_codelets_count;
  483. static struct starpu_fxt_codelet_event *dumped_codelets;
  484. static void handle_end_codelet_body(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  485. {
  486. int worker;
  487. worker = find_worker_id(ev->param[4]);
  488. if (worker < 0) return;
  489. char *prefix = options->file_prefix;
  490. double end_codelet_time = get_event_time_stamp(ev, options);
  491. size_t codelet_size = ev->param[1];
  492. uint32_t codelet_hash = ev->param[2];
  493. if (out_paje_file)
  494. worker_set_state(end_codelet_time, prefix, ev->param[4], "B");
  495. double codelet_length = (end_codelet_time - last_codelet_start[worker]);
  496. update_accumulated_time(worker, 0.0, codelet_length, end_codelet_time, 0);
  497. if (distrib_time)
  498. fprintf(distrib_time, "%s\t%s%d\t%ld\t%"PRIx32"\t%.9f\n", last_codelet_symbol[worker],
  499. prefix, worker, codelet_size, codelet_hash, codelet_length);
  500. if (options->dumped_codelets)
  501. {
  502. enum starpu_perfmodel_archtype archtype = ev->param[3];
  503. dumped_codelets_count++;
  504. dumped_codelets = realloc(dumped_codelets, dumped_codelets_count*sizeof(struct starpu_fxt_codelet_event));
  505. snprintf(dumped_codelets[dumped_codelets_count - 1].symbol, 256, "%s", last_codelet_symbol[worker]);
  506. dumped_codelets[dumped_codelets_count - 1].workerid = worker;
  507. dumped_codelets[dumped_codelets_count - 1].archtype = archtype;
  508. dumped_codelets[dumped_codelets_count - 1].size = codelet_size;
  509. dumped_codelets[dumped_codelets_count - 1].hash = codelet_hash;
  510. dumped_codelets[dumped_codelets_count - 1].time = codelet_length;
  511. }
  512. }
  513. static void handle_user_event(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  514. {
  515. int worker;
  516. unsigned long code = ev->param[0];
  517. #ifdef STARPU_HAVE_POTI
  518. char paje_value[STARPU_POTI_STR_LEN], container[STARPU_POTI_STR_LEN];
  519. snprintf(paje_value, STARPU_POTI_STR_LEN, "%lu", code);
  520. #endif
  521. char *prefix = options->file_prefix;
  522. worker = find_worker_id(ev->param[1]);
  523. if (worker < 0)
  524. {
  525. if (out_paje_file)
  526. #ifdef STARPU_HAVE_POTI
  527. program_container_alias (container, STARPU_POTI_STR_LEN, prefix);
  528. #else
  529. fprintf(out_paje_file, "9 %.9f event %sp %lu\n", get_event_time_stamp(ev, options), prefix, code);
  530. #endif
  531. }
  532. else
  533. {
  534. if (out_paje_file)
  535. #ifdef STARPU_HAVE_POTI
  536. thread_container_alias (container, STARPU_POTI_STR_LEN, prefix, ev->param[1]);
  537. #else
  538. fprintf(out_paje_file, "9 %.9f event %st%"PRIu64" %lu\n", get_event_time_stamp(ev, options), prefix, ev->param[1], code);
  539. #endif
  540. }
  541. #ifdef STARPU_HAVE_POTI
  542. if (out_paje_file)
  543. poti_NewEvent(get_event_time_stamp(ev, options), container, "event", paje_value);
  544. #endif
  545. }
  546. static void handle_start_callback(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  547. {
  548. int worker;
  549. worker = find_worker_id(ev->param[1]);
  550. if (worker < 0)
  551. return;
  552. if (out_paje_file)
  553. worker_set_state(get_event_time_stamp(ev, options), options->file_prefix, ev->param[1], "C");
  554. }
  555. static void handle_end_callback(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  556. {
  557. int worker;
  558. worker = find_worker_id(ev->param[1]);
  559. if (worker < 0)
  560. return;
  561. if (out_paje_file)
  562. worker_set_state(get_event_time_stamp(ev, options), options->file_prefix, ev->param[1], "B");
  563. }
  564. static void handle_worker_status(struct fxt_ev_64 *ev, struct starpu_fxt_options *options, const char *newstatus)
  565. {
  566. int worker;
  567. worker = find_worker_id(ev->param[1]);
  568. if (worker < 0)
  569. return;
  570. if (out_paje_file)
  571. worker_set_state(get_event_time_stamp(ev, options), options->file_prefix, ev->param[1], newstatus);
  572. }
  573. static double last_sleep_start[STARPU_NMAXWORKERS];
  574. static void handle_start_sleep(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  575. {
  576. int worker;
  577. worker = find_worker_id(ev->param[0]);
  578. if (worker < 0) return;
  579. double start_sleep_time = get_event_time_stamp(ev, options);
  580. last_sleep_start[worker] = start_sleep_time;
  581. if (out_paje_file)
  582. worker_set_state(get_event_time_stamp(ev, options), options->file_prefix, ev->param[0], "Sl");
  583. }
  584. static void handle_end_sleep(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  585. {
  586. int worker;
  587. worker = find_worker_id(ev->param[0]);
  588. if (worker < 0) return;
  589. double end_sleep_timestamp = get_event_time_stamp(ev, options);
  590. if (out_paje_file)
  591. worker_set_state(end_sleep_timestamp, options->file_prefix, ev->param[0], "B");
  592. double sleep_length = end_sleep_timestamp - last_sleep_start[worker];
  593. update_accumulated_time(worker, sleep_length, 0.0, end_sleep_timestamp, 0);
  594. }
  595. static void handle_data_copy(void)
  596. {
  597. }
  598. static void handle_start_driver_copy(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  599. {
  600. unsigned src = ev->param[0];
  601. unsigned dst = ev->param[1];
  602. unsigned size = ev->param[2];
  603. unsigned comid = ev->param[3];
  604. char *prefix = options->file_prefix;
  605. if (!options->no_bus)
  606. {
  607. if (out_paje_file)
  608. {
  609. double time = get_event_time_stamp(ev, options);
  610. memnode_set_state(time, prefix, dst, "Co");
  611. #ifdef STARPU_HAVE_POTI
  612. char paje_value[STARPU_POTI_STR_LEN], paje_key[STARPU_POTI_STR_LEN], src_memnode_container[STARPU_POTI_STR_LEN];
  613. char program_container[STARPU_POTI_STR_LEN];
  614. snprintf(paje_value, STARPU_POTI_STR_LEN, "%u", size);
  615. snprintf(paje_key, STARPU_POTI_STR_LEN, "com_%u", comid);
  616. program_container_alias(program_container, STARPU_POTI_STR_LEN, prefix);
  617. memmanager_container_alias(src_memnode_container, STARPU_POTI_STR_LEN, prefix, src);
  618. poti_StartLink(time, program_container, "L", src_memnode_container, paje_value, paje_key);
  619. #else
  620. fprintf(out_paje_file, "18 %.9f L %sp %u %smm%u com_%u\n", time, prefix, size, prefix, src, comid);
  621. #endif
  622. }
  623. /* create a structure to store the start of the communication, this will be matched later */
  624. struct _starpu_communication *com = _starpu_communication_new();
  625. com->comid = comid;
  626. com->comm_start = get_event_time_stamp(ev, options);
  627. com->src_node = src;
  628. com->dst_node = dst;
  629. _starpu_communication_list_push_back(communication_list, com);
  630. }
  631. }
  632. static void handle_end_driver_copy(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  633. {
  634. unsigned dst = ev->param[1];
  635. unsigned size = ev->param[2];
  636. unsigned comid = ev->param[3];
  637. char *prefix = options->file_prefix;
  638. if (!options->no_bus)
  639. {
  640. if (out_paje_file)
  641. {
  642. double time = get_event_time_stamp(ev, options);
  643. memnode_set_state(time, prefix, dst, "No");
  644. #ifdef STARPU_HAVE_POTI
  645. char paje_value[STARPU_POTI_STR_LEN], paje_key[STARPU_POTI_STR_LEN];
  646. char dst_memnode_container[STARPU_POTI_STR_LEN], program_container[STARPU_POTI_STR_LEN];
  647. snprintf(paje_value, STARPU_POTI_STR_LEN, "%u", size);
  648. snprintf(paje_key, STARPU_POTI_STR_LEN, "com_%u", comid);
  649. program_container_alias(program_container, STARPU_POTI_STR_LEN, prefix);
  650. memmanager_container_alias(dst_memnode_container, STARPU_POTI_STR_LEN, prefix, dst);
  651. poti_EndLink(time, program_container, "L", dst_memnode_container, paje_value, paje_key);
  652. #else
  653. fprintf(out_paje_file, "19 %.9f L %sp %u %smm%u com_%u\n", time, prefix, size, prefix, dst, comid);
  654. #endif
  655. }
  656. /* look for a data transfer to match */
  657. struct _starpu_communication *itor;
  658. for (itor = _starpu_communication_list_begin(communication_list);
  659. itor != _starpu_communication_list_end(communication_list);
  660. itor = _starpu_communication_list_next(itor))
  661. {
  662. if (itor->comid == comid)
  663. {
  664. double comm_end = get_event_time_stamp(ev, options);
  665. double bandwidth = (double)((0.001*size)/(comm_end - itor->comm_start));
  666. itor->bandwidth = bandwidth;
  667. struct _starpu_communication *com = _starpu_communication_new();
  668. com->comid = comid;
  669. com->comm_start = get_event_time_stamp(ev, options);
  670. com->bandwidth = -bandwidth;
  671. com->src_node = itor->src_node;
  672. com->dst_node = itor->dst_node;
  673. _starpu_communication_list_push_back(communication_list, com);
  674. break;
  675. }
  676. }
  677. }
  678. }
  679. static void handle_start_driver_copy_async(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  680. {
  681. unsigned dst = ev->param[1];
  682. char *prefix = options->file_prefix;
  683. if (!options->no_bus)
  684. if (out_paje_file)
  685. memnode_set_state(get_event_time_stamp(ev, options), prefix, dst, "CoA");
  686. }
  687. static void handle_end_driver_copy_async(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  688. {
  689. unsigned dst = ev->param[1];
  690. char *prefix = options->file_prefix;
  691. if (!options->no_bus)
  692. if (out_paje_file)
  693. memnode_set_state(get_event_time_stamp(ev, options), prefix, dst, "Co");
  694. }
  695. static void handle_memnode_event(struct fxt_ev_64 *ev, struct starpu_fxt_options *options, const char *eventstr)
  696. {
  697. unsigned memnode = ev->param[0];
  698. if (out_paje_file)
  699. memnode_set_state(get_event_time_stamp(ev, options), options->file_prefix, memnode, eventstr);
  700. }
  701. /*
  702. * Number of task submitted to the scheduler
  703. */
  704. static int curq_size = 0;
  705. static void handle_job_push(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  706. {
  707. double current_timestamp = get_event_time_stamp(ev, options);
  708. curq_size++;
  709. if (!options->no_counter && out_paje_file)
  710. {
  711. #ifdef STARPU_HAVE_POTI
  712. char container[STARPU_POTI_STR_LEN];
  713. scheduler_container_alias(container, STARPU_POTI_STR_LEN, options->file_prefix);
  714. poti_SetVariable(current_timestamp, container, "ntask", (double)curq_size);
  715. #else
  716. fprintf(out_paje_file, "13 %.9f %ssched ntask %f\n", current_timestamp, options->file_prefix, (float)curq_size);
  717. #endif
  718. }
  719. if (activity_file)
  720. fprintf(activity_file, "cnt_ready\t%.9f\t%d\n", current_timestamp, curq_size);
  721. }
  722. static void handle_job_pop(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  723. {
  724. double current_timestamp = get_event_time_stamp(ev, options);
  725. curq_size--;
  726. if (!options->no_counter && out_paje_file)
  727. {
  728. #ifdef STARPU_HAVE_POTI
  729. char container[STARPU_POTI_STR_LEN];
  730. scheduler_container_alias(container, STARPU_POTI_STR_LEN, options->file_prefix);
  731. poti_SetVariable(current_timestamp, container, "ntask", (double)curq_size);
  732. #else
  733. fprintf(out_paje_file, "13 %.9f %ssched ntask %f\n", current_timestamp, options->file_prefix, (float)curq_size);
  734. #endif
  735. }
  736. if (activity_file)
  737. fprintf(activity_file, "cnt_ready\t%.9f\t%d\n", current_timestamp, curq_size);
  738. }
  739. static
  740. void handle_update_task_cnt(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  741. {
  742. double current_timestamp = get_event_time_stamp(ev, options);
  743. unsigned long nsubmitted = ev->param[0];
  744. if (activity_file)
  745. fprintf(activity_file, "cnt_submitted\t%.9f\t%lu\n", current_timestamp, nsubmitted);
  746. }
  747. static void handle_codelet_tag(struct fxt_ev_64 *ev)
  748. {
  749. uint64_t tag;
  750. unsigned long job;
  751. tag = ev->param[0];
  752. job = ev->param[1];
  753. _starpu_fxt_dag_add_tag(tag, job);
  754. }
  755. static void handle_codelet_tag_deps(struct fxt_ev_64 *ev)
  756. {
  757. uint64_t child;
  758. uint64_t father;
  759. child = ev->param[0];
  760. father = ev->param[1];
  761. _starpu_fxt_dag_add_tag_deps(child, father);
  762. }
  763. static void handle_task_deps(struct fxt_ev_64 *ev)
  764. {
  765. unsigned long dep_prev = ev->param[0];
  766. unsigned long dep_succ = ev->param[1];
  767. /* There is a dependency between both job id : dep_prev -> dep_succ */
  768. _starpu_fxt_dag_add_task_deps(dep_prev, dep_succ);
  769. }
  770. static void handle_task_done(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  771. {
  772. unsigned long job_id;
  773. job_id = ev->param[0];
  774. unsigned long has_name = ev->param[3];
  775. char *name = has_name?(char *)&ev->param[4]:"unknown";
  776. int worker;
  777. worker = find_worker_id(ev->param[1]);
  778. const char *colour;
  779. char buffer[32];
  780. if (options->per_task_colour)
  781. {
  782. snprintf(buffer, 32, "#%x%x%x",
  783. get_colour_symbol_red(name)/4,
  784. get_colour_symbol_green(name)/4,
  785. get_colour_symbol_blue(name)/4);
  786. colour = &buffer[0];
  787. }
  788. else
  789. {
  790. colour= (worker < 0)?"#aaaaaa":get_worker_color(worker);
  791. }
  792. unsigned exclude_from_dag = ev->param[2];
  793. if (!exclude_from_dag)
  794. _starpu_fxt_dag_set_task_done(job_id, name, colour);
  795. }
  796. static void handle_tag_done(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  797. {
  798. uint64_t tag_id;
  799. tag_id = ev->param[0];
  800. unsigned long has_name = ev->param[2];
  801. char *name = has_name?(char *)&ev->param[3]:"unknown";
  802. int worker;
  803. worker = find_worker_id(ev->param[1]);
  804. const char *colour;
  805. char buffer[32];
  806. if (options->per_task_colour)
  807. {
  808. snprintf(buffer, 32, "%.4f,%.4f,%.4f",
  809. get_colour_symbol_red(name)/1024.0,
  810. get_colour_symbol_green(name)/1024.0,
  811. get_colour_symbol_blue(name)/1024.0);
  812. colour = &buffer[0];
  813. }
  814. else
  815. {
  816. colour= (worker < 0)?"0.0,0.0,0.0":get_worker_color(worker);
  817. }
  818. _starpu_fxt_dag_set_tag_done(tag_id, colour);
  819. }
  820. static void handle_mpi_barrier(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  821. {
  822. int rank = ev->param[0];
  823. STARPU_ASSERT(rank == options->file_rank || options->file_rank == -1);
  824. /* Add an event in the trace */
  825. if (out_paje_file)
  826. {
  827. #ifdef STARPU_HAVE_POTI
  828. char container[STARPU_POTI_STR_LEN], paje_value[STARPU_POTI_STR_LEN];
  829. snprintf(container, STARPU_POTI_STR_LEN, "%sp", options->file_prefix);
  830. snprintf(container, STARPU_POTI_STR_LEN, "%d", rank);
  831. poti_NewEvent(get_event_time_stamp(ev, options), container, "event", paje_value);
  832. #else
  833. fprintf(out_paje_file, "9 %.9f event %sp %d\n", get_event_time_stamp(ev, options), options->file_prefix, rank);
  834. #endif
  835. }
  836. }
  837. static void handle_mpi_start(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  838. {
  839. double date = get_event_time_stamp(ev, options);
  840. char *prefix = options->file_prefix;
  841. if (out_paje_file)
  842. {
  843. #ifdef STARPU_HAVE_POTI
  844. char program_container[STARPU_POTI_STR_LEN];
  845. program_container_alias(program_container, STARPU_POTI_STR_LEN, prefix);
  846. char new_mpicommthread_container_alias[STARPU_POTI_STR_LEN], new_mpicommthread_container_name[STARPU_POTI_STR_LEN];
  847. mpicommthread_container_alias(new_mpicommthread_container_alias, STARPU_POTI_STR_LEN, prefix);
  848. snprintf(new_mpicommthread_container_alias, STARPU_POTI_STR_LEN, "%smpict", prefix);
  849. poti_CreateContainer(date, new_mpicommthread_container_alias, "MPICt", program_container, new_mpicommthread_container_name);
  850. #else
  851. fprintf(out_paje_file, "7 %.9f %smpict MPICt %sp %smpict\n", date, prefix, prefix, prefix);
  852. #endif
  853. mpicommthread_set_state(date, prefix, "Sl");
  854. }
  855. }
  856. static void handle_mpi_stop(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  857. {
  858. double date = get_event_time_stamp(ev, options);
  859. char *prefix = options->file_prefix;
  860. if (out_paje_file)
  861. {
  862. #ifdef STARPU_HAVE_POTI
  863. char mpicommthread_container[STARPU_POTI_STR_LEN];
  864. mpicommthread_container_alias(mpicommthread_container, STARPU_POTI_STR_LEN, prefix);
  865. poti_DestroyContainer(date, "MPICt", mpicommthread_container);
  866. #else
  867. fprintf(out_paje_file, "8 %.9f %smpict MPICt\n",
  868. date, prefix);
  869. #endif
  870. }
  871. }
  872. static void handle_mpi_isend_submit_begin(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  873. {
  874. double date = get_event_time_stamp(ev, options);
  875. if (out_paje_file)
  876. mpicommthread_set_state(date, options->file_prefix, "SdS");
  877. }
  878. static void handle_mpi_isend_submit_end(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  879. {
  880. int dest = ev->param[0];
  881. int mpi_tag = ev->param[1];
  882. size_t size = ev->param[2];
  883. double date = get_event_time_stamp(ev, options);
  884. if (out_paje_file)
  885. mpicommthread_set_state(date, options->file_prefix, "P");
  886. _starpu_fxt_mpi_add_send_transfer(options->file_rank, dest, mpi_tag, size, date);
  887. }
  888. static void handle_mpi_irecv_submit_begin(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  889. {
  890. double date = get_event_time_stamp(ev, options);
  891. if (out_paje_file)
  892. mpicommthread_set_state(date, options->file_prefix, "RvS");
  893. }
  894. static void handle_mpi_irecv_submit_end(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  895. {
  896. double date = get_event_time_stamp(ev, options);
  897. if (out_paje_file)
  898. mpicommthread_set_state(date, options->file_prefix, "P");
  899. }
  900. static void handle_mpi_isend_complete_begin(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  901. {
  902. double date = get_event_time_stamp(ev, options);
  903. if (out_paje_file)
  904. mpicommthread_set_state(date, options->file_prefix, "SdC");
  905. }
  906. static void handle_mpi_isend_complete_end(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  907. {
  908. double date = get_event_time_stamp(ev, options);
  909. if (out_paje_file)
  910. mpicommthread_set_state(date, options->file_prefix, "P");
  911. }
  912. static void handle_mpi_irecv_complete_begin(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  913. {
  914. int src = ev->param[0];
  915. int mpi_tag = ev->param[1];
  916. double date = get_event_time_stamp(ev, options);
  917. if (out_paje_file)
  918. mpicommthread_set_state(date, options->file_prefix, "RvC");
  919. _starpu_fxt_mpi_add_recv_transfer(src, options->file_rank, mpi_tag, date);
  920. }
  921. static void handle_mpi_irecv_complete_end(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  922. {
  923. double date = get_event_time_stamp(ev, options);
  924. if (out_paje_file)
  925. mpicommthread_set_state(date, options->file_prefix, "P");
  926. }
  927. static void handle_mpi_sleep_begin(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  928. {
  929. double date = get_event_time_stamp(ev, options);
  930. if (out_paje_file)
  931. mpicommthread_set_state(date, options->file_prefix, "Sl");
  932. }
  933. static void handle_mpi_sleep_end(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  934. {
  935. double date = get_event_time_stamp(ev, options);
  936. if (out_paje_file)
  937. mpicommthread_set_state(date, options->file_prefix, "P");
  938. }
  939. static void handle_mpi_dtesting_begin(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  940. {
  941. double date = get_event_time_stamp(ev, options);
  942. if (out_paje_file)
  943. mpicommthread_set_state(date, options->file_prefix, "DT");
  944. }
  945. static void handle_mpi_dtesting_end(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  946. {
  947. double date = get_event_time_stamp(ev, options);
  948. if (out_paje_file)
  949. mpicommthread_set_state(date, options->file_prefix, "P");
  950. }
  951. static void handle_mpi_utesting_begin(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  952. {
  953. double date = get_event_time_stamp(ev, options);
  954. if (out_paje_file)
  955. mpicommthread_set_state(date, options->file_prefix, "UT");
  956. }
  957. static void handle_mpi_utesting_end(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  958. {
  959. double date = get_event_time_stamp(ev, options);
  960. if (out_paje_file)
  961. mpicommthread_set_state(date, options->file_prefix, "P");
  962. }
  963. static void handle_mpi_uwait_begin(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  964. {
  965. double date = get_event_time_stamp(ev, options);
  966. if (out_paje_file)
  967. mpicommthread_set_state(date, options->file_prefix, "UW");
  968. }
  969. static void handle_mpi_uwait_end(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  970. {
  971. double date = get_event_time_stamp(ev, options);
  972. if (out_paje_file)
  973. mpicommthread_set_state(date, options->file_prefix, "P");
  974. }
  975. static void handle_set_profiling(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  976. {
  977. int status = ev->param[0];
  978. if (activity_file)
  979. fprintf(activity_file, "set_profiling\t%.9f\t%d\n", get_event_time_stamp(ev, options), status);
  980. }
  981. static void handle_task_wait_for_all(void)
  982. {
  983. _starpu_fxt_dag_add_sync_point();
  984. }
  985. static
  986. void _starpu_fxt_display_bandwidth(struct starpu_fxt_options *options)
  987. {
  988. float current_bandwidth_per_node[STARPU_MAXNODES] = {0.0};
  989. char *prefix = options->file_prefix;
  990. struct _starpu_communication*itor;
  991. for (itor = _starpu_communication_list_begin(communication_list);
  992. itor != _starpu_communication_list_end(communication_list);
  993. itor = _starpu_communication_list_next(itor))
  994. {
  995. current_bandwidth_per_node[itor->src_node] += itor->bandwidth;
  996. if (out_paje_file)
  997. {
  998. #ifdef STARPU_HAVE_POTI
  999. char src_memnode_container[STARPU_POTI_STR_LEN];
  1000. memmanager_container_alias(src_memnode_container, STARPU_POTI_STR_LEN, prefix, itor->src_node);
  1001. poti_SetVariable(itor->comm_start, src_memnode_container, "bw", current_bandwidth_per_node[itor->src_node]);
  1002. #else
  1003. fprintf(out_paje_file, "13 %.9f %smm%u bw %f\n",
  1004. itor->comm_start, prefix, itor->src_node, current_bandwidth_per_node[itor->src_node]);
  1005. #endif
  1006. }
  1007. current_bandwidth_per_node[itor->dst_node] += itor->bandwidth;
  1008. if (out_paje_file)
  1009. {
  1010. #ifdef STARPU_HAVE_POTI
  1011. char dst_memnode_container[STARPU_POTI_STR_LEN];
  1012. memmanager_container_alias(dst_memnode_container, STARPU_POTI_STR_LEN, prefix, itor->dst_node);
  1013. poti_SetVariable(itor->comm_start, dst_memnode_container, "bw", current_bandwidth_per_node[itor->dst_node]);
  1014. #else
  1015. fprintf(out_paje_file, "13 %.9f %smm%u bw %f\n",
  1016. itor->comm_start, prefix, itor->dst_node, current_bandwidth_per_node[itor->dst_node]);
  1017. #endif
  1018. }
  1019. }
  1020. }
  1021. /*
  1022. * Public functions
  1023. */
  1024. static
  1025. void starpu_fxt_parse_new_file(char *filename_in, struct starpu_fxt_options *options)
  1026. {
  1027. /* Open the trace file */
  1028. int fd_in;
  1029. fd_in = open(filename_in, O_RDONLY);
  1030. if (fd_in < 0)
  1031. {
  1032. perror("open failed :");
  1033. exit(-1);
  1034. }
  1035. static fxt_t fut;
  1036. fut = fxt_fdopen(fd_in);
  1037. if (!fut)
  1038. {
  1039. perror("fxt_fdopen :");
  1040. exit(-1);
  1041. }
  1042. fxt_blockev_t block;
  1043. block = fxt_blockev_enter(fut);
  1044. symbol_list = _starpu_symbol_name_list_new();
  1045. communication_list = _starpu_communication_list_new();
  1046. char *prefix = options->file_prefix;
  1047. /* TODO starttime ...*/
  1048. /* create the "program" container */
  1049. if (out_paje_file)
  1050. {
  1051. #ifdef STARPU_HAVE_POTI
  1052. char new_program_container_alias[STARPU_POTI_STR_LEN], new_program_container_name[STARPU_POTI_STR_LEN];
  1053. program_container_alias(new_program_container_alias, STARPU_POTI_STR_LEN, prefix);
  1054. snprintf(new_program_container_name, STARPU_POTI_STR_LEN, "program %s", prefix);
  1055. poti_CreateContainer (0, new_program_container_alias, "P", "MPIroot", new_program_container_name);
  1056. if (!options->no_counter)
  1057. {
  1058. char new_scheduler_container_alias[STARPU_POTI_STR_LEN], new_scheduler_container_name[STARPU_POTI_STR_LEN];
  1059. scheduler_container_alias(new_scheduler_container_alias, STARPU_POTI_STR_LEN, prefix);
  1060. snprintf(new_scheduler_container_name, STARPU_POTI_STR_LEN, "scheduler %s", prefix);
  1061. poti_CreateContainer(0.0, new_scheduler_container_alias, "Sc", new_program_container_alias, new_scheduler_container_name);
  1062. poti_SetVariable(0.0, new_scheduler_container_alias, "ntask", 0.0);
  1063. }
  1064. #else
  1065. fprintf(out_paje_file, "7 0.0 %sp P MPIroot %sprogram \n", prefix, prefix);
  1066. /* create a variable with the number of tasks */
  1067. if (!options->no_counter)
  1068. {
  1069. fprintf(out_paje_file, "7 %.9f %ssched Sc %sp scheduler\n", 0.0, prefix, prefix);
  1070. fprintf(out_paje_file, "13 0.0 %ssched ntask 0.0\n", prefix);
  1071. }
  1072. #endif
  1073. }
  1074. struct fxt_ev_64 ev;
  1075. while(1)
  1076. {
  1077. int ret = fxt_next_ev(block, FXT_EV_TYPE_64, (struct fxt_ev *)&ev);
  1078. if (ret != FXT_EV_OK)
  1079. {
  1080. break;
  1081. }
  1082. switch (ev.code)
  1083. {
  1084. case _STARPU_FUT_WORKER_INIT_START:
  1085. handle_worker_init_start(&ev, options);
  1086. break;
  1087. case _STARPU_FUT_WORKER_INIT_END:
  1088. handle_worker_init_end(&ev, options);
  1089. break;
  1090. case _STARPU_FUT_NEW_MEM_NODE:
  1091. handle_new_mem_node(&ev, options);
  1092. break;
  1093. /* detect when the workers were idling or not */
  1094. case _STARPU_FUT_START_CODELET_BODY:
  1095. handle_start_codelet_body(&ev, options);
  1096. break;
  1097. case _STARPU_FUT_END_CODELET_BODY:
  1098. handle_end_codelet_body(&ev, options);
  1099. break;
  1100. case _STARPU_FUT_START_CALLBACK:
  1101. handle_start_callback(&ev, options);
  1102. break;
  1103. case _STARPU_FUT_END_CALLBACK:
  1104. handle_end_callback(&ev, options);
  1105. break;
  1106. case _STARPU_FUT_UPDATE_TASK_CNT:
  1107. handle_update_task_cnt(&ev, options);
  1108. break;
  1109. /* monitor stack size */
  1110. case _STARPU_FUT_JOB_PUSH:
  1111. handle_job_push(&ev, options);
  1112. break;
  1113. case _STARPU_FUT_JOB_POP:
  1114. handle_job_pop(&ev, options);
  1115. break;
  1116. /* check the memory transfer overhead */
  1117. case _STARPU_FUT_START_FETCH_INPUT:
  1118. handle_worker_status(&ev, options, "Fi");
  1119. break;
  1120. case _STARPU_FUT_START_PUSH_OUTPUT:
  1121. handle_worker_status(&ev, options, "Po");
  1122. break;
  1123. case _STARPU_FUT_START_PROGRESS:
  1124. handle_worker_status(&ev, options, "P");
  1125. break;
  1126. case _STARPU_FUT_END_FETCH_INPUT:
  1127. case _STARPU_FUT_END_PROGRESS:
  1128. case _STARPU_FUT_END_PUSH_OUTPUT:
  1129. handle_worker_status(&ev, options, "B");
  1130. break;
  1131. case _STARPU_FUT_WORKER_SLEEP_START:
  1132. handle_start_sleep(&ev, options);
  1133. break;
  1134. case _STARPU_FUT_WORKER_SLEEP_END:
  1135. handle_end_sleep(&ev, options);
  1136. break;
  1137. case _STARPU_FUT_TAG:
  1138. handle_codelet_tag(&ev);
  1139. break;
  1140. case _STARPU_FUT_TAG_DEPS:
  1141. handle_codelet_tag_deps(&ev);
  1142. break;
  1143. case _STARPU_FUT_TASK_DEPS:
  1144. handle_task_deps(&ev);
  1145. break;
  1146. case _STARPU_FUT_TASK_DONE:
  1147. handle_task_done(&ev, options);
  1148. break;
  1149. case _STARPU_FUT_TAG_DONE:
  1150. handle_tag_done(&ev, options);
  1151. break;
  1152. case _STARPU_FUT_DATA_COPY:
  1153. if (!options->no_bus)
  1154. handle_data_copy();
  1155. break;
  1156. case _STARPU_FUT_START_DRIVER_COPY:
  1157. if (!options->no_bus)
  1158. handle_start_driver_copy(&ev, options);
  1159. break;
  1160. case _STARPU_FUT_END_DRIVER_COPY:
  1161. if (!options->no_bus)
  1162. handle_end_driver_copy(&ev, options);
  1163. break;
  1164. case _STARPU_FUT_START_DRIVER_COPY_ASYNC:
  1165. if (!options->no_bus)
  1166. handle_start_driver_copy_async(&ev, options);
  1167. break;
  1168. case _STARPU_FUT_END_DRIVER_COPY_ASYNC:
  1169. if (!options->no_bus)
  1170. handle_end_driver_copy_async(&ev, options);
  1171. break;
  1172. case _STARPU_FUT_WORK_STEALING:
  1173. /* XXX */
  1174. break;
  1175. case _STARPU_FUT_WORKER_DEINIT_START:
  1176. handle_worker_deinit_start(&ev, options);
  1177. break;
  1178. case _STARPU_FUT_WORKER_DEINIT_END:
  1179. handle_worker_deinit_end(&ev, options);
  1180. break;
  1181. case _STARPU_FUT_START_ALLOC:
  1182. if (!options->no_bus)
  1183. handle_memnode_event(&ev, options, "A");
  1184. break;
  1185. case _STARPU_FUT_START_ALLOC_REUSE:
  1186. if (!options->no_bus)
  1187. handle_memnode_event(&ev, options, "Ar");
  1188. break;
  1189. case _STARPU_FUT_START_MEMRECLAIM:
  1190. handle_memnode_event(&ev, options, "R");
  1191. break;
  1192. case _STARPU_FUT_END_ALLOC:
  1193. case _STARPU_FUT_END_ALLOC_REUSE:
  1194. case _STARPU_FUT_END_MEMRECLAIM:
  1195. if (!options->no_bus)
  1196. handle_memnode_event(&ev, options, "No");
  1197. break;
  1198. case _STARPU_FUT_USER_EVENT:
  1199. handle_user_event(&ev, options);
  1200. break;
  1201. case FUT_MPI_START:
  1202. handle_mpi_start(&ev, options);
  1203. break;
  1204. case FUT_MPI_STOP:
  1205. handle_mpi_stop(&ev, options);
  1206. break;
  1207. case FUT_MPI_BARRIER:
  1208. handle_mpi_barrier(&ev, options);
  1209. break;
  1210. case FUT_MPI_ISEND_SUBMIT_BEGIN:
  1211. handle_mpi_isend_submit_begin(&ev, options);
  1212. break;
  1213. case FUT_MPI_ISEND_SUBMIT_END:
  1214. handle_mpi_isend_submit_end(&ev, options);
  1215. break;
  1216. case FUT_MPI_IRECV_SUBMIT_BEGIN:
  1217. handle_mpi_irecv_submit_begin(&ev, options);
  1218. break;
  1219. case FUT_MPI_IRECV_SUBMIT_END:
  1220. handle_mpi_irecv_submit_end(&ev, options);
  1221. break;
  1222. case FUT_MPI_ISEND_COMPLETE_BEGIN:
  1223. handle_mpi_isend_complete_begin(&ev, options);
  1224. break;
  1225. case FUT_MPI_ISEND_COMPLETE_END:
  1226. handle_mpi_isend_complete_end(&ev, options);
  1227. break;
  1228. case FUT_MPI_IRECV_COMPLETE_BEGIN:
  1229. handle_mpi_irecv_complete_begin(&ev, options);
  1230. break;
  1231. case FUT_MPI_IRECV_COMPLETE_END:
  1232. handle_mpi_irecv_complete_end(&ev, options);
  1233. break;
  1234. case FUT_MPI_SLEEP_BEGIN:
  1235. handle_mpi_sleep_begin(&ev, options);
  1236. break;
  1237. case FUT_MPI_SLEEP_END:
  1238. handle_mpi_sleep_end(&ev, options);
  1239. break;
  1240. case FUT_MPI_DTESTING_BEGIN:
  1241. handle_mpi_dtesting_begin(&ev, options);
  1242. break;
  1243. case FUT_MPI_DTESTING_END:
  1244. handle_mpi_dtesting_end(&ev, options);
  1245. break;
  1246. case FUT_MPI_UTESTING_BEGIN:
  1247. handle_mpi_utesting_begin(&ev, options);
  1248. break;
  1249. case FUT_MPI_UTESTING_END:
  1250. handle_mpi_utesting_end(&ev, options);
  1251. break;
  1252. case FUT_MPI_UWAIT_BEGIN:
  1253. handle_mpi_uwait_begin(&ev, options);
  1254. break;
  1255. case FUT_MPI_UWAIT_END:
  1256. handle_mpi_uwait_end(&ev, options);
  1257. break;
  1258. case _STARPU_FUT_SET_PROFILING:
  1259. handle_set_profiling(&ev, options);
  1260. break;
  1261. case _STARPU_FUT_TASK_WAIT_FOR_ALL:
  1262. handle_task_wait_for_all();
  1263. break;
  1264. default:
  1265. #ifdef STARPU_VERBOSE
  1266. fprintf(stderr, "unknown event.. %x at time %llx WITH OFFSET %llx\n",
  1267. (unsigned)ev.code, (long long unsigned)ev.time, (long long unsigned)(ev.time-options->file_offset));
  1268. #endif
  1269. break;
  1270. }
  1271. }
  1272. /* Close the trace file */
  1273. if (close(fd_in))
  1274. {
  1275. perror("close failed :");
  1276. exit(-1);
  1277. }
  1278. }
  1279. /* Initialize FxT options to default values */
  1280. void starpu_fxt_options_init(struct starpu_fxt_options *options)
  1281. {
  1282. options->per_task_colour = 0;
  1283. options->no_counter = 0;
  1284. options->no_bus = 0;
  1285. options->ninputfiles = 0;
  1286. options->out_paje_path = "paje.trace";
  1287. options->dag_path = "dag.dot";
  1288. options->distrib_time_path = "distrib.data";
  1289. options->dumped_codelets = NULL;
  1290. options->activity_path = "activity.data";
  1291. }
  1292. static
  1293. void starpu_fxt_distrib_file_init(struct starpu_fxt_options *options)
  1294. {
  1295. dumped_codelets_count = 0;
  1296. dumped_codelets = NULL;
  1297. if (options->distrib_time_path)
  1298. {
  1299. distrib_time = fopen(options->distrib_time_path, "w+");
  1300. }
  1301. else
  1302. {
  1303. distrib_time = NULL;
  1304. }
  1305. }
  1306. static
  1307. void starpu_fxt_distrib_file_close(struct starpu_fxt_options *options)
  1308. {
  1309. if (distrib_time)
  1310. fclose(distrib_time);
  1311. if (options->dumped_codelets)
  1312. {
  1313. *options->dumped_codelets = dumped_codelets;
  1314. options->dumped_codelets_count = dumped_codelets_count;
  1315. }
  1316. }
  1317. static
  1318. void starpu_fxt_activity_file_init(struct starpu_fxt_options *options)
  1319. {
  1320. if (options->activity_path)
  1321. activity_file = fopen(options->activity_path, "w+");
  1322. else
  1323. activity_file = NULL;
  1324. }
  1325. static
  1326. void starpu_fxt_activity_file_close(void)
  1327. {
  1328. if (activity_file)
  1329. fclose(activity_file);
  1330. }
  1331. static
  1332. void starpu_fxt_paje_file_init(struct starpu_fxt_options *options)
  1333. {
  1334. /* create a new file */
  1335. if (options->out_paje_path)
  1336. {
  1337. out_paje_file = fopen(options->out_paje_path, "w+");
  1338. if (!out_paje_file)
  1339. {
  1340. fprintf(stderr,"error while opening %s\n", options->out_paje_path);
  1341. perror("fopen");
  1342. exit(1);
  1343. }
  1344. #ifdef STARPU_HAVE_POTI
  1345. poti_init (out_paje_file);
  1346. #endif
  1347. _starpu_fxt_write_paje_header(out_paje_file);
  1348. }
  1349. else
  1350. {
  1351. out_paje_file = NULL;
  1352. }
  1353. }
  1354. static
  1355. void starpu_fxt_paje_file_close(void)
  1356. {
  1357. if (out_paje_file)
  1358. fclose(out_paje_file);
  1359. }
  1360. static uint64_t starpu_fxt_find_start_time(char *filename_in)
  1361. {
  1362. /* Open the trace file */
  1363. int fd_in;
  1364. fd_in = open(filename_in, O_RDONLY);
  1365. if (fd_in < 0)
  1366. {
  1367. perror("open failed :");
  1368. exit(-1);
  1369. }
  1370. static fxt_t fut;
  1371. fut = fxt_fdopen(fd_in);
  1372. if (!fut)
  1373. {
  1374. perror("fxt_fdopen :");
  1375. exit(-1);
  1376. }
  1377. fxt_blockev_t block;
  1378. block = fxt_blockev_enter(fut);
  1379. struct fxt_ev_64 ev;
  1380. int ret = fxt_next_ev(block, FXT_EV_TYPE_64, (struct fxt_ev *)&ev);
  1381. STARPU_ASSERT (ret == FXT_EV_OK);
  1382. /* Close the trace file */
  1383. if (close(fd_in))
  1384. {
  1385. perror("close failed :");
  1386. exit(-1);
  1387. }
  1388. return (ev.time);
  1389. }
  1390. void starpu_fxt_generate_trace(struct starpu_fxt_options *options)
  1391. {
  1392. _starpu_fxt_dag_init(options->dag_path);
  1393. starpu_fxt_distrib_file_init(options);
  1394. starpu_fxt_activity_file_init(options);
  1395. starpu_fxt_paje_file_init(options);
  1396. if (options->ninputfiles == 0)
  1397. {
  1398. return;
  1399. }
  1400. else if (options->ninputfiles == 1)
  1401. {
  1402. /* we usually only have a single trace */
  1403. uint64_t file_start_time = starpu_fxt_find_start_time(options->filenames[0]);
  1404. options->file_prefix = "";
  1405. options->file_offset = file_start_time;
  1406. options->file_rank = -1;
  1407. starpu_fxt_parse_new_file(options->filenames[0], options);
  1408. }
  1409. else
  1410. {
  1411. unsigned inputfile;
  1412. uint64_t offsets[64];
  1413. /*
  1414. * Find the trace offsets:
  1415. * - If there is no sync point
  1416. * psi_k(x) = x - start_k
  1417. * - If there is a sync point sync_k
  1418. * psi_k(x) = x - sync_k + M
  1419. * where M = max { sync_i - start_i | there exists sync_i}
  1420. * More generally:
  1421. * - psi_k(x) = x - offset_k
  1422. */
  1423. int unique_keys[64];
  1424. int rank_k[64];
  1425. uint64_t start_k[64];
  1426. uint64_t sync_k[64];
  1427. unsigned sync_k_exists[64];
  1428. uint64_t M = 0;
  1429. unsigned found_one_sync_point = 0;
  1430. int key = 0;
  1431. unsigned display_mpi = 0;
  1432. /* Compute all start_k */
  1433. for (inputfile = 0; inputfile < options->ninputfiles; inputfile++)
  1434. {
  1435. uint64_t file_start = starpu_fxt_find_start_time(options->filenames[inputfile]);
  1436. start_k[inputfile] = file_start;
  1437. }
  1438. /* Compute all sync_k if they exist */
  1439. for (inputfile = 0; inputfile < options->ninputfiles; inputfile++)
  1440. {
  1441. int ret = _starpu_fxt_mpi_find_sync_point(options->filenames[inputfile],
  1442. &sync_k[inputfile],
  1443. &unique_keys[inputfile],
  1444. &rank_k[inputfile]);
  1445. if (ret == -1)
  1446. {
  1447. /* There was no sync point, we assume there is no offset */
  1448. sync_k_exists[inputfile] = 0;
  1449. }
  1450. else
  1451. {
  1452. if (!found_one_sync_point)
  1453. {
  1454. key = unique_keys[inputfile];
  1455. display_mpi = 1;
  1456. found_one_sync_point = 1;
  1457. }
  1458. else
  1459. {
  1460. if (key != unique_keys[inputfile])
  1461. {
  1462. fprintf(stderr, "Warning: traces are coming from different run so we will not try to display MPI communications.\n");
  1463. display_mpi = 0;
  1464. }
  1465. }
  1466. STARPU_ASSERT(sync_k[inputfile] >= start_k[inputfile]);
  1467. sync_k_exists[inputfile] = 1;
  1468. uint64_t diff = sync_k[inputfile] - start_k[inputfile];
  1469. if (diff > M)
  1470. M = diff;
  1471. }
  1472. }
  1473. /* Compute the offset */
  1474. for (inputfile = 0; inputfile < options->ninputfiles; inputfile++)
  1475. {
  1476. offsets[inputfile] = sync_k_exists[inputfile]?
  1477. (sync_k[inputfile]-M):start_k[inputfile];
  1478. }
  1479. /* generate the Paje trace for the different files */
  1480. for (inputfile = 0; inputfile < options->ninputfiles; inputfile++)
  1481. {
  1482. int filerank = rank_k[inputfile];
  1483. #ifdef STARPU_VERBOSE
  1484. fprintf(stderr, "Handle file %s (rank %d)\n", options->filenames[inputfile], filerank);
  1485. #endif
  1486. char file_prefix[32];
  1487. snprintf(file_prefix, 32, "%d_", filerank);
  1488. options->file_prefix = file_prefix;
  1489. options->file_offset = offsets[inputfile];
  1490. options->file_rank = filerank;
  1491. starpu_fxt_parse_new_file(options->filenames[inputfile], options);
  1492. }
  1493. /* display the MPI transfers if possible */
  1494. if (display_mpi)
  1495. _starpu_fxt_display_mpi_transfers(options, rank_k, out_paje_file);
  1496. }
  1497. _starpu_fxt_display_bandwidth(options);
  1498. /* close the different files */
  1499. starpu_fxt_paje_file_close();
  1500. starpu_fxt_activity_file_close();
  1501. starpu_fxt_distrib_file_close(options);
  1502. _starpu_fxt_dag_terminate();
  1503. options->nworkers = nworkers;
  1504. }
  1505. #endif // STARPU_USE_FXT