starpu_fxt.c 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2015 Université de Bordeaux
  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. #include <string.h>
  20. #ifdef STARPU_HAVE_POTI
  21. #include <poti.h>
  22. #define STARPU_POTI_STR_LEN 200
  23. #endif
  24. #ifdef STARPU_USE_FXT
  25. #include "starpu_fxt.h"
  26. #include <inttypes.h>
  27. #include <starpu_hash.h>
  28. #define CPUS_WORKER_COLORS_NB 8
  29. #define CUDA_WORKER_COLORS_NB 9
  30. #define OPENCL_WORKER_COLORS_NB 9
  31. #define MIC_WORKER_COLORS_NB 9
  32. #define SCC_WORKER_COLORS_NB 9
  33. #define OTHER_WORKER_COLORS_NB 4
  34. static char *cpus_worker_colors[CPUS_WORKER_COLORS_NB] = {"/greens9/7", "/greens9/6", "/greens9/5", "/greens9/4", "/greens9/9", "/greens9/3", "/greens9/2", "/greens9/1" };
  35. static char *cuda_worker_colors[CUDA_WORKER_COLORS_NB] = {"/ylorrd9/9", "/ylorrd9/6", "/ylorrd9/3", "/ylorrd9/1", "/ylorrd9/8", "/ylorrd9/7", "/ylorrd9/4", "/ylorrd9/2", "/ylorrd9/1"};
  36. static char *opencl_worker_colors[OPENCL_WORKER_COLORS_NB] = {"/blues9/9", "/blues9/6", "/blues9/3", "/blues9/1", "/blues9/8", "/blues9/7", "/blues9/4", "/blues9/2", "/blues9/1"};
  37. static char *mic_worker_colors[MIC_WORKER_COLORS_NB] = {"/reds9/9", "/reds9/6", "/reds9/3", "/reds9/1", "/reds9/8", "/reds9/7", "/reds9/4", "/reds9/2", "/reds9/1"};
  38. static char *scc_worker_colors[SCC_WORKER_COLORS_NB] = {"/reds9/9", "/reds9/6", "/reds9/3", "/reds9/1", "/reds9/8", "/reds9/7", "/reds9/4", "/reds9/2", "/reds9/1"};
  39. static char *other_worker_colors[OTHER_WORKER_COLORS_NB] = {"/greys9/9", "/greys9/8", "/greys9/7", "/greys9/6"};
  40. static char *worker_colors[STARPU_NMAXWORKERS];
  41. static unsigned opencl_index = 0;
  42. static unsigned cuda_index = 0;
  43. static unsigned cpus_index = 0;
  44. static unsigned mic_index = 0;
  45. static unsigned scc_index = 0;
  46. static unsigned other_index = 0;
  47. static void set_next_other_worker_color(int workerid)
  48. {
  49. if (workerid >= STARPU_NMAXWORKERS)
  50. return;
  51. worker_colors[workerid] = other_worker_colors[other_index++];
  52. if (other_index == OTHER_WORKER_COLORS_NB) other_index = 0;
  53. }
  54. static void set_next_cpu_worker_color(int workerid)
  55. {
  56. if (workerid >= STARPU_NMAXWORKERS)
  57. return;
  58. worker_colors[workerid] = cpus_worker_colors[cpus_index++];
  59. if (cpus_index == CPUS_WORKER_COLORS_NB) cpus_index = 0;
  60. }
  61. static void set_next_cuda_worker_color(int workerid)
  62. {
  63. if (workerid >= STARPU_NMAXWORKERS)
  64. return;
  65. worker_colors[workerid] = cuda_worker_colors[cuda_index++];
  66. if (cuda_index == CUDA_WORKER_COLORS_NB) cuda_index = 0;
  67. }
  68. static void set_next_opencl_worker_color(int workerid)
  69. {
  70. if (workerid >= STARPU_NMAXWORKERS)
  71. return;
  72. worker_colors[workerid] = opencl_worker_colors[opencl_index++];
  73. if (opencl_index == OPENCL_WORKER_COLORS_NB) opencl_index = 0;
  74. }
  75. static void set_next_mic_worker_color(int workerid)
  76. {
  77. if (workerid >= STARPU_NMAXWORKERS)
  78. return;
  79. worker_colors[workerid] = mic_worker_colors[mic_index++];
  80. if (mic_index == MIC_WORKER_COLORS_NB) mic_index = 0;
  81. }
  82. static void set_next_scc_worker_color(int workerid)
  83. {
  84. if (workerid >= STARPU_NMAXWORKERS)
  85. return;
  86. worker_colors[workerid] = scc_worker_colors[scc_index++];
  87. if (scc_index == SCC_WORKER_COLORS_NB) scc_index = 0;
  88. }
  89. static const char *get_worker_color(int workerid)
  90. {
  91. if (workerid >= STARPU_NMAXWORKERS)
  92. workerid = STARPU_NMAXWORKERS - 1;
  93. return worker_colors[workerid];
  94. }
  95. static unsigned get_colour_symbol_red(char *name)
  96. {
  97. /* choose some colour ... that's disguting yes */
  98. uint32_t hash_symbol = starpu_hash_crc32c_string(name, 0);
  99. return (unsigned)starpu_hash_crc32c_string("red", hash_symbol) % 1024;
  100. }
  101. static unsigned get_colour_symbol_green(char *name)
  102. {
  103. /* choose some colour ... that's disguting yes */
  104. uint32_t hash_symbol = starpu_hash_crc32c_string(name, 0);
  105. return (unsigned)starpu_hash_crc32c_string("green", hash_symbol) % 1024;
  106. }
  107. static unsigned get_colour_symbol_blue(char *name)
  108. {
  109. /* choose some colour ... that's disguting yes */
  110. uint32_t hash_symbol = starpu_hash_crc32c_string(name, 0);
  111. return (unsigned)starpu_hash_crc32c_string("blue", hash_symbol) % 1024;
  112. }
  113. static double last_codelet_start[STARPU_NMAXWORKERS];
  114. /* _STARPU_FUT_DO_PROBE4STR records only 4 longs */
  115. static char last_codelet_symbol[STARPU_NMAXWORKERS][4*sizeof(unsigned long)];
  116. static int last_codelet_parameter[STARPU_NMAXWORKERS];
  117. #define MAX_PARAMETERS 8
  118. #ifdef STARPU_ENABLE_PAJE_CODELET_DETAILS
  119. static char last_codelet_parameter_description[STARPU_NMAXWORKERS][MAX_PARAMETERS][FXT_MAX_PARAMS*sizeof(unsigned long)];
  120. #endif
  121. /* If more than a period of time has elapsed, we flush the profiling info,
  122. * otherwise they are accumulated everytime there is a new relevant event. */
  123. #define ACTIVITY_PERIOD 75.0
  124. static double last_activity_flush_timestamp[STARPU_NMAXWORKERS];
  125. static double accumulated_sleep_time[STARPU_NMAXWORKERS];
  126. static double accumulated_exec_time[STARPU_NMAXWORKERS];
  127. static double reclaiming[STARPU_MAXNODES];
  128. LIST_TYPE(_starpu_symbol_name,
  129. char *name;
  130. )
  131. static struct _starpu_symbol_name_list *symbol_list;
  132. LIST_TYPE(_starpu_communication,
  133. unsigned comid;
  134. double comm_start;
  135. double bandwidth;
  136. unsigned src_node;
  137. unsigned dst_node;
  138. )
  139. static struct _starpu_communication_list *communication_list;
  140. /*
  141. * Paje trace file tools
  142. */
  143. static FILE *out_paje_file;
  144. static FILE *distrib_time;
  145. static FILE *activity_file;
  146. /*
  147. * Generic tools
  148. */
  149. static double get_event_time_stamp(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  150. {
  151. return (((double)(ev->time-options->file_offset))/1000000.0);
  152. }
  153. static int nworkers = 0;
  154. struct worker_entry
  155. {
  156. UT_hash_handle hh;
  157. unsigned long tid;
  158. int workerid;
  159. int sync;
  160. } *worker_ids;
  161. static int register_worker_id(unsigned long tid, int workerid, int sync)
  162. {
  163. nworkers++;
  164. struct worker_entry *entry;
  165. HASH_FIND(hh, worker_ids, &tid, sizeof(tid), entry);
  166. STARPU_ASSERT_MSG(workerid < STARPU_NMAXWORKERS, "Too many workers in this trace, please increase in ./configure invocation the maximum number of CPUs and GPUs to the same value as was used for execution");
  167. /* only register a thread once */
  168. if (entry)
  169. return 0;
  170. entry = malloc(sizeof(*entry));
  171. entry->tid = tid;
  172. entry->workerid = workerid;
  173. entry->sync = sync;
  174. HASH_ADD(hh, worker_ids, tid, sizeof(tid), entry);
  175. return 1;
  176. }
  177. static int find_worker_id(unsigned long tid)
  178. {
  179. struct worker_entry *entry;
  180. HASH_FIND(hh, worker_ids, &tid, sizeof(tid), entry);
  181. if (!entry)
  182. return -1;
  183. return entry->workerid;
  184. }
  185. static int find_sync(unsigned long tid)
  186. {
  187. struct worker_entry *entry;
  188. HASH_FIND(hh, worker_ids, &tid, sizeof(tid), entry);
  189. if (!entry)
  190. return 0;
  191. return entry->sync;
  192. }
  193. static void update_accumulated_time(int worker, double sleep_time, double exec_time, double current_timestamp, int forceflush)
  194. {
  195. accumulated_sleep_time[worker] += sleep_time;
  196. accumulated_exec_time[worker] += exec_time;
  197. /* If sufficient time has elapsed since the last flush, we have a new
  198. * point in our graph */
  199. double elapsed = current_timestamp - last_activity_flush_timestamp[worker];
  200. if (forceflush || (elapsed > ACTIVITY_PERIOD))
  201. {
  202. if (activity_file)
  203. 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]);
  204. /* reset the accumulated times */
  205. last_activity_flush_timestamp[worker] = current_timestamp;
  206. accumulated_sleep_time[worker] = 0.0;
  207. accumulated_exec_time[worker] = 0.0;
  208. }
  209. }
  210. /*
  211. * Auxiliary functions for poti handling names
  212. */
  213. #ifdef STARPU_HAVE_POTI
  214. static char *memnode_container_alias(char *output, int len, const char *prefix, long unsigned int memnodeid)
  215. {
  216. snprintf(output, len, "%smn%lu", prefix, memnodeid);
  217. return output;
  218. }
  219. static char *memmanager_container_alias(char *output, int len, const char *prefix, long unsigned int memnodeid)
  220. {
  221. snprintf(output, len, "%smm%lu", prefix, memnodeid);
  222. return output;
  223. }
  224. static char *thread_container_alias(char *output, int len, const char *prefix, long unsigned int threadid)
  225. {
  226. snprintf(output, len, "%st%lu", prefix, threadid);
  227. return output;
  228. }
  229. static char *worker_container_alias(char *output, int len, const char *prefix, long unsigned int workerid)
  230. {
  231. snprintf(output, len, "%sw%lu", prefix, workerid);
  232. return output;
  233. }
  234. static char *mpicommthread_container_alias(char *output, int len, const char *prefix)
  235. {
  236. snprintf(output, len, "%smpict", prefix);
  237. return output;
  238. }
  239. static char *program_container_alias(char *output, int len, const char *prefix)
  240. {
  241. snprintf(output, len, "%sp", prefix);
  242. return output;
  243. }
  244. static char *scheduler_container_alias(char *output, int len, const char *prefix)
  245. {
  246. snprintf(output, len, "%ssched", prefix);
  247. return output;
  248. }
  249. #endif
  250. static void memnode_set_state(double time, const char *prefix, unsigned int memnodeid, const char *name)
  251. {
  252. #ifdef STARPU_HAVE_POTI
  253. char container[STARPU_POTI_STR_LEN];
  254. memmanager_container_alias(container, STARPU_POTI_STR_LEN, prefix, memnodeid);
  255. poti_SetState(time, container, "MS", name);
  256. #else
  257. fprintf(out_paje_file, "10 %.9f %smm%u MS %s\n", time, prefix, memnodeid, name);
  258. #endif
  259. }
  260. static void worker_set_state(double time, const char *prefix, long unsigned int workerid, const char *name)
  261. {
  262. #ifdef STARPU_HAVE_POTI
  263. char container[STARPU_POTI_STR_LEN];
  264. worker_container_alias(container, STARPU_POTI_STR_LEN, prefix, workerid);
  265. poti_SetState(time, container, "WS", name);
  266. #else
  267. fprintf(out_paje_file, "10 %.9f %sw%lu WS %s\n", time, prefix, workerid, name);
  268. #endif
  269. }
  270. static void worker_push_state(double time, const char *prefix, long unsigned int workerid, const char *name)
  271. {
  272. #ifdef STARPU_HAVE_POTI
  273. char container[STARPU_POTI_STR_LEN];
  274. worker_container_alias(container, STARPU_POTI_STR_LEN, prefix, workerid);
  275. poti_PushState(time, container, "WS", name);
  276. #else
  277. fprintf(out_paje_file, "11 %.9f %sw%lu WS %s\n", time, prefix, workerid, name);
  278. #endif
  279. }
  280. static void worker_pop_state(double time, const char *prefix, long unsigned int workerid)
  281. {
  282. #ifdef STARPU_HAVE_POTI
  283. char container[STARPU_POTI_STR_LEN];
  284. worker_container_alias(container, STARPU_POTI_STR_LEN, prefix, workerid);
  285. poti_PopState(time, container, "WS");
  286. #else
  287. fprintf(out_paje_file, "12 %.9f %sw%lu WS\n", time, prefix, workerid);
  288. #endif
  289. }
  290. static void thread_set_state(double time, const char *prefix, long unsigned int threadid, const char *name)
  291. {
  292. if (!find_sync(threadid))
  293. /* Unless using worker sets, collapse thread and worker */
  294. return worker_set_state(time, prefix, find_worker_id(threadid), name);
  295. #ifdef STARPU_HAVE_POTI
  296. char container[STARPU_POTI_STR_LEN];
  297. thread_container_alias(container, STARPU_POTI_STR_LEN, prefix, threadid);
  298. poti_SetState(time, container, "S", name);
  299. #else
  300. fprintf(out_paje_file, "10 %.9f %st%lu S %s\n", time, prefix, threadid, name);
  301. #endif
  302. }
  303. static void thread_push_state(double time, const char *prefix, long unsigned int threadid, const char *name)
  304. {
  305. if (!find_sync(threadid))
  306. /* Unless using worker sets, collapse thread and worker */
  307. return worker_push_state(time, prefix, find_worker_id(threadid), name);
  308. #ifdef STARPU_HAVE_POTI
  309. char container[STARPU_POTI_STR_LEN];
  310. thread_container_alias(container, STARPU_POTI_STR_LEN, prefix, threadid);
  311. poti_PushState(time, container, "S", name);
  312. #else
  313. fprintf(out_paje_file, "11 %.9f %st%lu S %s\n", time, prefix, threadid, name);
  314. #endif
  315. }
  316. static void thread_pop_state(double time, const char *prefix, long unsigned int threadid)
  317. {
  318. if (!find_sync(threadid))
  319. /* Unless using worker sets, collapse thread and worker */
  320. return worker_pop_state(time, prefix, find_worker_id(threadid));
  321. #ifdef STARPU_HAVE_POTI
  322. char container[STARPU_POTI_STR_LEN];
  323. thread_container_alias(container, STARPU_POTI_STR_LEN, prefix, threadid);
  324. poti_PopState(time, container, "S");
  325. #else
  326. fprintf(out_paje_file, "12 %.9f %st%lu S\n", time, prefix, threadid);
  327. #endif
  328. }
  329. #ifdef STARPU_ENABLE_PAJE_CODELET_DETAILS
  330. static void worker_set_detailed_state(double time, const char *prefix, long unsigned int workerid, const char *name, unsigned long size, const char *parameters, unsigned long footprint, unsigned long long tag, unsigned long job_id)
  331. {
  332. #ifdef STARPU_HAVE_POTI
  333. char container[STARPU_POTI_STR_LEN];
  334. worker_container_alias(container, STARPU_POTI_STR_LEN, prefix, workerid);
  335. /* TODO: set detailed state */
  336. poti_SetState(time, container, "WS", name);
  337. #else
  338. fprintf(out_paje_file, "20 %.9f %sw%lu WS %s %lu %s %08lx %016llx %lu\n", time, prefix, workerid, name, size, parameters, footprint, tag, job_id);
  339. #endif
  340. }
  341. #endif
  342. static void mpicommthread_set_state(double time, const char *prefix, const char *name)
  343. {
  344. #ifdef STARPU_HAVE_POTI
  345. char container[STARPU_POTI_STR_LEN];
  346. mpicommthread_container_alias(container, STARPU_POTI_STR_LEN, prefix);
  347. poti_SetState(time, container, "CtS", name);
  348. #else
  349. fprintf(out_paje_file, "10 %.9f %smpict CtS %s\n", time, prefix, name);
  350. #endif
  351. }
  352. /*
  353. * Initialization
  354. */
  355. static void handle_new_mem_node(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  356. {
  357. char *prefix = options->file_prefix;
  358. if (out_paje_file)
  359. {
  360. #ifdef STARPU_HAVE_POTI
  361. char program_container[STARPU_POTI_STR_LEN];
  362. program_container_alias(program_container, STARPU_POTI_STR_LEN, prefix);
  363. char new_memnode_container_alias[STARPU_POTI_STR_LEN], new_memnode_container_name[STARPU_POTI_STR_LEN];
  364. char new_memmanager_container_alias[STARPU_POTI_STR_LEN], new_memmanager_container_name[STARPU_POTI_STR_LEN];
  365. memnode_container_alias (new_memnode_container_alias, STARPU_POTI_STR_LEN, prefix, ev->param[0]);
  366. /* TODO: ramkind */
  367. snprintf(new_memnode_container_name, STARPU_POTI_STR_LEN, "%sMEMNODE%"PRIu64"", prefix, ev->param[0]);
  368. poti_CreateContainer(get_event_time_stamp(ev, options), new_memnode_container_alias, "Mn", program_container, new_memnode_container_name);
  369. memmanager_container_alias (new_memmanager_container_alias, STARPU_POTI_STR_LEN, prefix, ev->param[0]);
  370. /* TODO: ramkind */
  371. snprintf(new_memmanager_container_name, STARPU_POTI_STR_LEN, "%sMEMMANAGER%"PRIu64"", prefix, ev->param[0]);
  372. poti_CreateContainer(get_event_time_stamp(ev, options), new_memmanager_container_alias, "Mm", new_memnode_container_alias, new_memmanager_container_name);
  373. #else
  374. 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]);
  375. fprintf(out_paje_file, "7 %.9f %smm%"PRIu64" Mm %smn%"PRIu64" %sMEMMANAGER%"PRIu64"\n", get_event_time_stamp(ev, options), prefix, ev->param[0], prefix, ev->param[0], options->file_prefix, ev->param[0]);
  376. #endif
  377. if (!options->no_bus)
  378. #ifdef STARPU_HAVE_POTI
  379. poti_SetVariable(get_event_time_stamp(ev, options), new_memnode_container_alias, "bw", get_event_time_stamp(ev, options));
  380. #else
  381. fprintf(out_paje_file, "13 %.9f %smm%"PRIu64" bw 0.0\n", get_event_time_stamp(ev, options), prefix, ev->param[0]);
  382. #endif
  383. }
  384. }
  385. static void handle_worker_init_start(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  386. {
  387. /*
  388. arg0 : type of worker (cuda, cpu ..)
  389. arg1 : memory node
  390. arg2 : thread id
  391. */
  392. char *prefix = options->file_prefix;
  393. int devid = ev->param[2];
  394. int workerid = ev->param[1];
  395. int nodeid = ev->param[3];
  396. int set = ev->param[4];
  397. int threadid = ev->param[5];
  398. int new_thread;
  399. new_thread = register_worker_id(threadid, workerid, set);
  400. char *kindstr = "";
  401. struct starpu_perfmodel_arch arch;
  402. arch.ndevices = 1;
  403. arch.devices = (struct starpu_perfmodel_device *)malloc(sizeof(struct starpu_perfmodel_device));
  404. switch (ev->param[0])
  405. {
  406. case _STARPU_FUT_APPS_KEY:
  407. set_next_other_worker_color(workerid);
  408. kindstr = "APPS";
  409. break;
  410. case _STARPU_FUT_CPU_KEY:
  411. set_next_cpu_worker_color(workerid);
  412. kindstr = "CPU";
  413. arch.devices[0].type = STARPU_CPU_WORKER;
  414. arch.devices[0].devid = 0;
  415. arch.devices[0].ncores = 1;
  416. break;
  417. case _STARPU_FUT_CUDA_KEY:
  418. set_next_cuda_worker_color(workerid);
  419. kindstr = "CUDA";
  420. arch.devices[0].type = STARPU_CUDA_WORKER;
  421. arch.devices[0].devid = devid;
  422. arch.devices[0].ncores = 1;
  423. break;
  424. case _STARPU_FUT_OPENCL_KEY:
  425. set_next_opencl_worker_color(workerid);
  426. kindstr = "OPENCL";
  427. arch.devices[0].type = STARPU_OPENCL_WORKER;
  428. arch.devices[0].devid = devid;
  429. arch.devices[0].ncores = 1;
  430. break;
  431. case _STARPU_FUT_MIC_KEY:
  432. set_next_mic_worker_color(workerid);
  433. kindstr = "mic";
  434. arch.devices[0].type = STARPU_MIC_WORKER;
  435. arch.devices[0].devid = devid;
  436. arch.devices[0].ncores = 1;
  437. break;
  438. case _STARPU_FUT_SCC_KEY:
  439. set_next_scc_worker_color(workerid);
  440. kindstr = "scc";
  441. arch.devices[0].type = STARPU_SCC_WORKER;
  442. arch.devices[0].devid = devid;
  443. arch.devices[0].ncores = 1;
  444. break;
  445. default:
  446. STARPU_ABORT();
  447. }
  448. if (out_paje_file)
  449. {
  450. #ifdef STARPU_HAVE_POTI
  451. char new_thread_container_alias[STARPU_POTI_STR_LEN];
  452. thread_container_alias (new_thread_container_alias, STARPU_POTI_STR_LEN, prefix, threadid);
  453. char new_worker_container_alias[STARPU_POTI_STR_LEN];
  454. worker_container_alias (new_worker_container_alias, STARPU_POTI_STR_LEN, prefix, workerid);
  455. char memnode_container[STARPU_POTI_STR_LEN];
  456. memnode_container_alias(memnode_container, STARPU_POTI_STR_LEN, prefix, nodeid);
  457. char new_thread_container_name[STARPU_POTI_STR_LEN];
  458. snprintf(new_thread_container_name, STARPU_POTI_STR_LEN, "%s%d", prefix, threadid);
  459. char new_worker_container_name[STARPU_POTI_STR_LEN];
  460. snprintf(new_worker_container_name, STARPU_POTI_STR_LEN, "%s%s%d", prefix, kindstr, devid);
  461. if (new_thread)
  462. poti_CreateContainer(get_event_time_stamp(ev, options), new_thread_container_alias, "T", memnode_container, new_thread_container_name);
  463. poti_CreateContainer(get_event_time_stamp(ev, options), new_worker_container_alias, "W", new_thread_container_alias, new_worker_container_name);
  464. #else
  465. if (new_thread)
  466. fprintf(out_paje_file, "7 %.9f %st%d T %smn%d %s%d\n",
  467. get_event_time_stamp(ev, options), prefix, threadid, prefix, nodeid, prefix, threadid);
  468. fprintf(out_paje_file, "7 %.9f %sw%d W %st%d %s%s%d\n",
  469. get_event_time_stamp(ev, options), prefix, workerid, prefix, threadid, prefix, kindstr, devid);
  470. #endif
  471. }
  472. /* start initialization */
  473. if (out_paje_file)
  474. thread_set_state(get_event_time_stamp(ev, options), prefix, threadid, "I");
  475. if (activity_file)
  476. fprintf(activity_file, "name\t%d\t%s %d\n", workerid, kindstr, devid);
  477. snprintf(options->worker_names[workerid], 256, "%s %d", kindstr, devid);
  478. options->worker_archtypes[workerid] = arch;
  479. }
  480. static void handle_worker_init_end(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  481. {
  482. char *prefix = options->file_prefix;
  483. int worker;
  484. if (out_paje_file)
  485. thread_set_state(get_event_time_stamp(ev, options), prefix, ev->param[0], "B");
  486. if (ev->nb_params < 2)
  487. worker = find_worker_id(ev->param[0]);
  488. else
  489. worker = ev->param[1];
  490. if (out_paje_file)
  491. worker_set_state(get_event_time_stamp(ev, options), prefix, worker, "I");
  492. /* Initilize the accumulated time counters */
  493. last_activity_flush_timestamp[worker] = get_event_time_stamp(ev, options);
  494. accumulated_sleep_time[worker] = 0.0;
  495. accumulated_exec_time[worker] = 0.0;
  496. }
  497. static void handle_worker_deinit_start(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  498. {
  499. char *prefix = options->file_prefix;
  500. if (out_paje_file)
  501. thread_set_state(get_event_time_stamp(ev, options), prefix, ev->param[0], "D");
  502. }
  503. static void handle_worker_deinit_end(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  504. {
  505. char *prefix = options->file_prefix;
  506. if (out_paje_file)
  507. {
  508. #ifdef STARPU_HAVE_POTI
  509. char worker_container[STARPU_POTI_STR_LEN];
  510. thread_container_alias(worker_container, STARPU_POTI_STR_LEN, prefix, ev->param[1]);
  511. poti_DestroyContainer(get_event_time_stamp(ev, options), "T", worker_container);
  512. #else
  513. fprintf(out_paje_file, "8 %.9f %st%"PRIu64" T\n",
  514. get_event_time_stamp(ev, options), prefix, ev->param[1]);
  515. #endif
  516. }
  517. }
  518. #ifdef STARPU_HAVE_POTI
  519. static void create_paje_state_color(char *name, char *type, float red, float green, float blue)
  520. {
  521. char color[STARPU_POTI_STR_LEN];
  522. snprintf(color, STARPU_POTI_STR_LEN, "%f %f %f", red, green, blue);
  523. poti_DefineEntityValue(name, type, name, color);
  524. }
  525. #endif
  526. static void create_paje_state_if_not_found(char *name, struct starpu_fxt_options *options)
  527. {
  528. struct _starpu_symbol_name *itor;
  529. for (itor = _starpu_symbol_name_list_begin(symbol_list);
  530. itor != _starpu_symbol_name_list_end(symbol_list);
  531. itor = _starpu_symbol_name_list_next(itor))
  532. {
  533. if (!strcmp(name, itor->name))
  534. {
  535. /* we found an entry */
  536. return;
  537. }
  538. }
  539. /* it's the first time ... */
  540. struct _starpu_symbol_name *entry = _starpu_symbol_name_new();
  541. entry->name = malloc(strlen(name) + 1);
  542. strcpy(entry->name, name);
  543. _starpu_symbol_name_list_push_front(symbol_list, entry);
  544. /* choose some colour ... that's disguting yes */
  545. unsigned hash_symbol_red = get_colour_symbol_red(name);
  546. unsigned hash_symbol_green = get_colour_symbol_green(name);
  547. unsigned hash_symbol_blue = get_colour_symbol_blue(name);
  548. uint32_t hash_sum = hash_symbol_red + hash_symbol_green + hash_symbol_blue;
  549. float red, green, blue;
  550. if (options->per_task_colour)
  551. {
  552. red = (1.0f * hash_symbol_red) / hash_sum;
  553. green = (1.0f * hash_symbol_green) / hash_sum;
  554. blue = (1.0f * hash_symbol_blue) / hash_sum;
  555. }
  556. else
  557. {
  558. /* Use the hardcoded value for execution mode */
  559. red = 0.0f;
  560. green = 0.6f;
  561. blue = 0.4f;
  562. }
  563. /* create the Paje state */
  564. if (out_paje_file)
  565. {
  566. #ifdef STARPU_HAVE_POTI
  567. create_paje_state_color(name, "WS", red, green, blue);
  568. int i;
  569. for(i = 1; i < STARPU_NMAX_SCHED_CTXS; i++)
  570. {
  571. char ctx[10];
  572. snprintf(ctx, sizeof(ctx), "Ctx%d", i);
  573. if(i%10 == 1)
  574. create_paje_state_color(name, ctx, 255.0, 102.0, 255.0);
  575. if(i%10 == 2)
  576. create_paje_state_color(name, ctx, .0, 255.0, 0.0);
  577. if(i%10 == 3)
  578. create_paje_state_color(name, ctx, 255.0, 255.0, .0);
  579. if(i%10 == 4)
  580. create_paje_state_color(name, ctx, .0, 245.0, 255.0);
  581. if(i%10 == 5)
  582. create_paje_state_color(name, ctx, .0, .0, .0);
  583. if(i%10 == 6)
  584. create_paje_state_color(name, ctx, .0, .0, 128.0);
  585. if(i%10 == 7)
  586. create_paje_state_color(name, ctx, 105.0, 105.0, 105.0);
  587. if(i%10 == 8)
  588. create_paje_state_color(name, ctx, 255.0, .0, 255.0);
  589. if(i%10 == 9)
  590. create_paje_state_color(name, ctx, .0, .0, 1.0);
  591. if(i%10 == 0)
  592. create_paje_state_color(name, ctx, 154.0, 205.0, 50.0);
  593. }
  594. /* create_paje_state_color(name, "Ctx1", 255.0, 102.0, 255.0); */
  595. /* create_paje_state_color(name, "Ctx2", .0, 255.0, 0.0); */
  596. /* create_paje_state_color(name, "Ctx3", 255.0, 255.0, .0); */
  597. /* create_paje_state_color(name, "Ctx4", .0, 245.0, 255.0); */
  598. /* create_paje_state_color(name, "Ctx5", .0, .0, .0); */
  599. /* create_paje_state_color(name, "Ctx6", .0, .0, 128.0); */
  600. /* create_paje_state_color(name, "Ctx7", 105.0, 105.0, 105.0); */
  601. /* create_paje_state_color(name, "Ctx8", 255.0, .0, 255.0); */
  602. /* create_paje_state_color(name, "Ctx9", .0, .0, 1.0); */
  603. /* create_paje_state_color(name, "Ctx10", 154.0, 205.0, 50.0); */
  604. #else
  605. fprintf(out_paje_file, "6 %s WS %s \"%f %f %f\" \n", name, name, red, green, blue);
  606. int i;
  607. for(i = 1; i < STARPU_NMAX_SCHED_CTXS; i++)
  608. {
  609. if(i%10 == 1)
  610. fprintf(out_paje_file, "6 %s Ctx%d %s \"255.0 102.0 255.0\" \n", name, i, name);
  611. if(i%10 == 2)
  612. fprintf(out_paje_file, "6 %s Ctx%d %s \".0 255.0 .0\" \n", name, i, name);
  613. if(i%10 == 3)
  614. fprintf(out_paje_file, "6 %s Ctx%d %s \"225.0 225.0 .0\" \n", name, i, name);
  615. if(i%10 == 4)
  616. fprintf(out_paje_file, "6 %s Ctx%d %s \".0 245.0 255.0\" \n", name, i, name);
  617. if(i%10 == 5)
  618. fprintf(out_paje_file, "6 %s Ctx%d %s \".0 .0 .0\" \n", name, i, name);
  619. if(i%10 == 6)
  620. fprintf(out_paje_file, "6 %s Ctx%d %s \".0 .0 128.0\" \n", name, i, name);
  621. if(i%10 == 7)
  622. fprintf(out_paje_file, "6 %s Ctx%d %s \"105.0 105.0 105.0\" \n", name, i, name);
  623. if(i%10 == 8)
  624. fprintf(out_paje_file, "6 %s Ctx%d %s \"255.0 .0 255.0\" \n", name, i, name);
  625. if(i%10 == 9)
  626. fprintf(out_paje_file, "6 %s Ctx%d %s \".0 .0 1.0\" \n", name, i, name);
  627. if(i%10 == 0)
  628. fprintf(out_paje_file, "6 %s Ctx%d %s \"154.0 205.0 50.0\" \n", name, i, name);
  629. }
  630. /* fprintf(out_paje_file, "6 %s Ctx1 %s \"255.0 102.0 255.0\" \n", name, name); */
  631. /* fprintf(out_paje_file, "6 %s Ctx2 %s \".0 255.0 .0\" \n", name, name); */
  632. /* fprintf(out_paje_file, "6 %s Ctx3 %s \"225.0 225.0 .0\" \n", name, name); */
  633. /* fprintf(out_paje_file, "6 %s Ctx4 %s \".0 245.0 255.0\" \n", name, name); */
  634. /* fprintf(out_paje_file, "6 %s Ctx5 %s \".0 .0 .0\" \n", name, name); */
  635. /* fprintf(out_paje_file, "6 %s Ctx6 %s \".0 .0 128.0\" \n", name, name); */
  636. /* fprintf(out_paje_file, "6 %s Ctx7 %s \"105.0 105.0 105.0\" \n", name, name); */
  637. /* fprintf(out_paje_file, "6 %s Ctx8 %s \"255.0 .0 255.0\" \n", name, name); */
  638. /* fprintf(out_paje_file, "6 %s Ctx9 %s \".0 .0 1.0\" \n", name, name); */
  639. /* fprintf(out_paje_file, "6 %s Ctx10 %s \"154.0 205.0 50.0\" \n", name, name); */
  640. #endif
  641. }
  642. }
  643. static void handle_start_codelet_body(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  644. {
  645. int worker = ev->param[2];
  646. if (worker < 0) return;
  647. unsigned long has_name = ev->param[3];
  648. char *name = has_name?(char *)&ev->param[4]:"unknown";
  649. snprintf(last_codelet_symbol[worker], sizeof(last_codelet_symbol[worker]), "%s", name);
  650. last_codelet_parameter[worker] = 0;
  651. double start_codelet_time = get_event_time_stamp(ev, options);
  652. last_codelet_start[worker] = start_codelet_time;
  653. create_paje_state_if_not_found(name, options);
  654. #ifndef STARPU_ENABLE_PAJE_CODELET_DETAILS
  655. if (out_paje_file)
  656. {
  657. char *prefix = options->file_prefix;
  658. unsigned sched_ctx = ev->param[1];
  659. worker_set_state(start_codelet_time, prefix, ev->param[2], name);
  660. if (sched_ctx != 0)
  661. {
  662. #ifdef STARPU_HAVE_POTI
  663. char container[STARPU_POTI_STR_LEN];
  664. char ctx[6];
  665. snprintf(ctx, sizeof(ctx), "Ctx%d", sched_ctx);
  666. worker_container_alias(container, STARPU_POTI_STR_LEN, prefix, ev->param[2]);
  667. poti_SetState(start_codelet_time, container, ctx, name);
  668. #else
  669. fprintf(out_paje_file, "10 %.9f %sw%"PRIu64" Ctx%d %s\n", start_codelet_time, prefix, ev->param[2], sched_ctx, name);
  670. #endif
  671. }
  672. }
  673. #endif /* STARPU_ENABLE_PAJE_CODELET_DETAILS */
  674. }
  675. static void handle_codelet_data(struct fxt_ev_64 *ev STARPU_ATTRIBUTE_UNUSED, struct starpu_fxt_options *options STARPU_ATTRIBUTE_UNUSED)
  676. {
  677. #ifdef STARPU_ENABLE_PAJE_CODELET_DETAILS
  678. int worker = ev->param[0];
  679. if (worker < 0) return;
  680. if (out_paje_file)
  681. {
  682. int num = last_codelet_parameter[worker]++;
  683. if (num >= MAX_PARAMETERS)
  684. return;
  685. snprintf(last_codelet_parameter_description[worker][num], sizeof(last_codelet_parameter_description[worker][num]), "%s", (char*) &ev->param[1]);
  686. }
  687. #endif /* STARPU_ENABLE_PAJE_CODELET_DETAILS */
  688. }
  689. static void handle_codelet_details(struct fxt_ev_64 *ev STARPU_ATTRIBUTE_UNUSED, struct starpu_fxt_options *options STARPU_ATTRIBUTE_UNUSED)
  690. {
  691. #ifdef STARPU_ENABLE_PAJE_CODELET_DETAILS
  692. int worker = ev->param[5];
  693. unsigned long job_id = ev->param[6];
  694. unsigned sched_ctx = ev->param[1];
  695. if (worker < 0) return;
  696. char *prefix = options->file_prefix;
  697. if (out_paje_file)
  698. {
  699. int i;
  700. char parameters[256];
  701. size_t eaten = 0;
  702. if (!last_codelet_parameter[worker])
  703. eaten += snprintf(parameters + eaten, sizeof(parameters) - eaten, "nodata");
  704. else
  705. for (i = 0; i < last_codelet_parameter[worker] && i < MAX_PARAMETERS; i++)
  706. {
  707. eaten += snprintf(parameters + eaten, sizeof(parameters) - eaten, "%s%s", i?"_":"", last_codelet_parameter_description[worker][i]);
  708. }
  709. worker_set_detailed_state(last_codelet_start[worker], prefix, worker, last_codelet_symbol[worker], ev->param[2], parameters, ev->param[3], ev->param[4], job_id);
  710. if (sched_ctx != 0)
  711. {
  712. #ifdef STARPU_HAVE_POTI
  713. char container[STARPU_POTI_STR_LEN];
  714. char ctx[6];
  715. snprintf(ctx, sizeof(ctx), "Ctx%d", sched_ctx);
  716. worker_container_alias(container, STARPU_POTI_STR_LEN, prefix, ev->param[5]);
  717. poti_SetState(last_codelet_start[worker], container, ctx, last_codelet_symbol[worker]);
  718. #else
  719. fprintf(out_paje_file, "20 %.9f %sw%"PRIu64" Ctx%d %s %lu %s %08lx %016llx %lu\n", last_codelet_start[worker], prefix, ev->param[2], sched_ctx, last_codelet_symbol[worker], (unsigned long) ev->param[2], parameters, (unsigned long) ev->param[3], (unsigned long long) ev->param[4], job_id);
  720. #endif
  721. }
  722. }
  723. #endif /* STARPU_ENABLE_PAJE_CODELET_DETAILS */
  724. }
  725. static long dumped_codelets_count;
  726. static struct starpu_fxt_codelet_event *dumped_codelets;
  727. static void handle_end_codelet_body(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  728. {
  729. int worker = ev->param[3];
  730. if (worker < 0) return;
  731. char *prefix = options->file_prefix;
  732. double end_codelet_time = get_event_time_stamp(ev, options);
  733. size_t codelet_size = ev->param[1];
  734. uint32_t codelet_hash = ev->param[2];
  735. if (out_paje_file)
  736. worker_set_state(end_codelet_time, prefix, worker, "I");
  737. double codelet_length = (end_codelet_time - last_codelet_start[worker]);
  738. update_accumulated_time(worker, 0.0, codelet_length, end_codelet_time, 0);
  739. if (distrib_time)
  740. fprintf(distrib_time, "%s\t%s%d\t%ld\t%"PRIx32"\t%.9f\n", last_codelet_symbol[worker],
  741. prefix, worker, (unsigned long) codelet_size, codelet_hash, codelet_length);
  742. if (options->dumped_codelets)
  743. {
  744. dumped_codelets_count++;
  745. dumped_codelets = realloc(dumped_codelets, dumped_codelets_count*sizeof(struct starpu_fxt_codelet_event));
  746. snprintf(dumped_codelets[dumped_codelets_count - 1].symbol, 256, "%s", last_codelet_symbol[worker]);
  747. dumped_codelets[dumped_codelets_count - 1].workerid = worker;
  748. snprintf(dumped_codelets[dumped_codelets_count - 1].perfmodel_archname, 256, "%s", (char *)&ev->param[4]);
  749. dumped_codelets[dumped_codelets_count - 1].size = codelet_size;
  750. dumped_codelets[dumped_codelets_count - 1].hash = codelet_hash;
  751. dumped_codelets[dumped_codelets_count - 1].time = codelet_length;
  752. }
  753. }
  754. static void handle_start_executing(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  755. {
  756. char *prefix = options->file_prefix;
  757. if (out_paje_file)
  758. thread_set_state(get_event_time_stamp(ev, options), prefix, ev->param[0], "E");
  759. }
  760. static void handle_end_executing(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  761. {
  762. char *prefix = options->file_prefix;
  763. if (out_paje_file)
  764. thread_set_state(get_event_time_stamp(ev, options), prefix, ev->param[0], "B");
  765. }
  766. static void handle_user_event(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  767. {
  768. int worker;
  769. unsigned long code = ev->param[0];
  770. #ifdef STARPU_HAVE_POTI
  771. char paje_value[STARPU_POTI_STR_LEN], container[STARPU_POTI_STR_LEN];
  772. snprintf(paje_value, STARPU_POTI_STR_LEN, "%lu", code);
  773. #endif
  774. char *prefix = options->file_prefix;
  775. worker = find_worker_id(ev->param[1]);
  776. if (worker < 0)
  777. {
  778. if (out_paje_file)
  779. #ifdef STARPU_HAVE_POTI
  780. program_container_alias (container, STARPU_POTI_STR_LEN, prefix);
  781. #else
  782. fprintf(out_paje_file, "9 %.9f user_event %sp %lu\n", get_event_time_stamp(ev, options), prefix, code);
  783. #endif
  784. }
  785. else
  786. {
  787. if (out_paje_file)
  788. #ifdef STARPU_HAVE_POTI
  789. thread_container_alias (container, STARPU_POTI_STR_LEN, prefix, ev->param[1]);
  790. #else
  791. fprintf(out_paje_file, "9 %.9f user_event %st%"PRIu64" %lu\n", get_event_time_stamp(ev, options), prefix, ev->param[1], code);
  792. #endif
  793. }
  794. #ifdef STARPU_HAVE_POTI
  795. if (out_paje_file)
  796. poti_NewEvent(get_event_time_stamp(ev, options), container, "user_event", paje_value);
  797. #endif
  798. }
  799. static void handle_start_callback(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  800. {
  801. int worker;
  802. worker = find_worker_id(ev->param[1]);
  803. if (worker < 0)
  804. return;
  805. if (out_paje_file)
  806. thread_set_state(get_event_time_stamp(ev, options), options->file_prefix, ev->param[1], "C");
  807. }
  808. static void handle_end_callback(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  809. {
  810. int worker;
  811. worker = find_worker_id(ev->param[1]);
  812. if (worker < 0)
  813. return;
  814. if (out_paje_file)
  815. thread_set_state(get_event_time_stamp(ev, options), options->file_prefix, ev->param[1], "B");
  816. }
  817. static void handle_hypervisor_begin(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  818. {
  819. int worker;
  820. worker = find_worker_id(ev->param[0]);
  821. if (worker < 0)
  822. return;
  823. if (out_paje_file)
  824. thread_set_state(get_event_time_stamp(ev, options), options->file_prefix, ev->param[0], "H");
  825. }
  826. static void handle_hypervisor_end(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  827. {
  828. int worker;
  829. worker = find_worker_id(ev->param[0]);
  830. if (worker < 0)
  831. return;
  832. if (out_paje_file)
  833. thread_set_state(get_event_time_stamp(ev, options), options->file_prefix, ev->param[0], "B");
  834. }
  835. static void handle_worker_status(struct fxt_ev_64 *ev, struct starpu_fxt_options *options, const char *newstatus)
  836. {
  837. int worker;
  838. worker = find_worker_id(ev->param[1]);
  839. if (worker < 0)
  840. return;
  841. if (out_paje_file)
  842. thread_set_state(get_event_time_stamp(ev, options), options->file_prefix, ev->param[1], newstatus);
  843. }
  844. static double last_sleep_start[STARPU_NMAXWORKERS];
  845. static void handle_worker_scheduling_start(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  846. {
  847. int worker;
  848. worker = find_worker_id(ev->param[0]);
  849. if (worker < 0) return;
  850. if (out_paje_file)
  851. thread_set_state(get_event_time_stamp(ev, options), options->file_prefix, ev->param[0], "Sc");
  852. }
  853. static void handle_worker_scheduling_end(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  854. {
  855. int worker;
  856. worker = find_worker_id(ev->param[0]);
  857. if (worker < 0) return;
  858. if (out_paje_file)
  859. thread_set_state(get_event_time_stamp(ev, options), options->file_prefix, ev->param[0], "B");
  860. }
  861. static void handle_worker_scheduling_push(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  862. {
  863. int worker;
  864. worker = find_worker_id(ev->param[0]);
  865. if (worker < 0) return;
  866. if (out_paje_file)
  867. thread_push_state(get_event_time_stamp(ev, options), options->file_prefix, ev->param[0], "Sc");
  868. }
  869. static void handle_worker_scheduling_pop(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  870. {
  871. int worker;
  872. worker = find_worker_id(ev->param[0]);
  873. if (worker < 0) return;
  874. if (out_paje_file)
  875. thread_pop_state(get_event_time_stamp(ev, options), options->file_prefix, ev->param[0]);
  876. }
  877. static void handle_worker_sleep_start(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  878. {
  879. int worker;
  880. worker = find_worker_id(ev->param[0]);
  881. if (worker < 0) return;
  882. double start_sleep_time = get_event_time_stamp(ev, options);
  883. last_sleep_start[worker] = start_sleep_time;
  884. if (out_paje_file)
  885. thread_set_state(get_event_time_stamp(ev, options), options->file_prefix, ev->param[0], "Sl");
  886. }
  887. static void handle_worker_sleep_end(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  888. {
  889. int worker;
  890. worker = find_worker_id(ev->param[0]);
  891. if (worker < 0) return;
  892. double end_sleep_timestamp = get_event_time_stamp(ev, options);
  893. if (out_paje_file)
  894. thread_set_state(end_sleep_timestamp, options->file_prefix, ev->param[0], "B");
  895. double sleep_length = end_sleep_timestamp - last_sleep_start[worker];
  896. update_accumulated_time(worker, sleep_length, 0.0, end_sleep_timestamp, 0);
  897. }
  898. static void handle_data_copy(void)
  899. {
  900. }
  901. static void handle_start_driver_copy(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  902. {
  903. unsigned src = ev->param[0];
  904. unsigned dst = ev->param[1];
  905. unsigned size = ev->param[2];
  906. unsigned comid = ev->param[3];
  907. char *prefix = options->file_prefix;
  908. if (!options->no_bus)
  909. {
  910. if (out_paje_file)
  911. {
  912. double time = get_event_time_stamp(ev, options);
  913. memnode_set_state(time, prefix, dst, "Co");
  914. #ifdef STARPU_HAVE_POTI
  915. char paje_value[STARPU_POTI_STR_LEN], paje_key[STARPU_POTI_STR_LEN], src_memnode_container[STARPU_POTI_STR_LEN];
  916. char program_container[STARPU_POTI_STR_LEN];
  917. snprintf(paje_value, STARPU_POTI_STR_LEN, "%u", size);
  918. snprintf(paje_key, STARPU_POTI_STR_LEN, "com_%u", comid);
  919. program_container_alias(program_container, STARPU_POTI_STR_LEN, prefix);
  920. memmanager_container_alias(src_memnode_container, STARPU_POTI_STR_LEN, prefix, src);
  921. poti_StartLink(time, program_container, "L", src_memnode_container, paje_value, paje_key);
  922. #else
  923. fprintf(out_paje_file, "18 %.9f L %sp %u %smm%u com_%u\n", time, prefix, size, prefix, src, comid);
  924. #endif
  925. }
  926. /* create a structure to store the start of the communication, this will be matched later */
  927. struct _starpu_communication *com = _starpu_communication_new();
  928. com->comid = comid;
  929. com->comm_start = get_event_time_stamp(ev, options);
  930. com->src_node = src;
  931. com->dst_node = dst;
  932. _starpu_communication_list_push_back(communication_list, com);
  933. }
  934. }
  935. static void handle_work_stealing(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  936. {
  937. unsigned dst = ev->param[0];
  938. unsigned src = ev->param[1];
  939. unsigned size = 0;
  940. unsigned comid = 0;
  941. char *prefix = options->file_prefix;
  942. if (out_paje_file)
  943. {
  944. double time = get_event_time_stamp(ev, options);
  945. #ifdef STARPU_HAVE_POTI
  946. char paje_value[STARPU_POTI_STR_LEN], paje_key[STARPU_POTI_STR_LEN], src_worker_container[STARPU_POTI_STR_LEN], dst_worker_container[STARPU_POTI_STR_LEN];
  947. char program_container[STARPU_POTI_STR_LEN];
  948. snprintf(paje_value, STARPU_POTI_STR_LEN, "%u", size);
  949. snprintf(paje_key, STARPU_POTI_STR_LEN, "steal_%u", comid);
  950. program_container_alias(program_container, STARPU_POTI_STR_LEN, prefix);
  951. worker_container_alias(src_worker_container, STARPU_POTI_STR_LEN, prefix, src);
  952. worker_container_alias(dst_worker_container, STARPU_POTI_STR_LEN, prefix, dst);
  953. poti_StartLink(time, program_container, "L", src_worker_container, paje_value, paje_key);
  954. poti_EndLink(time+0.000000001, program_container, "L", dst_worker_container, paje_value, paje_key);
  955. #else
  956. fprintf(out_paje_file, "18 %.9f L %sp %u %sw%d steal_%u\n", time, prefix, size, prefix, src, comid);
  957. fprintf(out_paje_file, "19 %.9f L %sp %u %sw%d steal_%u\n", time+0.000000001, prefix, size, prefix, dst, comid);
  958. #endif
  959. }
  960. }
  961. static void handle_end_driver_copy(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  962. {
  963. unsigned dst = ev->param[1];
  964. unsigned size = ev->param[2];
  965. unsigned comid = ev->param[3];
  966. char *prefix = options->file_prefix;
  967. if (!options->no_bus)
  968. {
  969. if (out_paje_file)
  970. {
  971. double time = get_event_time_stamp(ev, options);
  972. memnode_set_state(time, prefix, dst, "No");
  973. #ifdef STARPU_HAVE_POTI
  974. char paje_value[STARPU_POTI_STR_LEN], paje_key[STARPU_POTI_STR_LEN];
  975. char dst_memnode_container[STARPU_POTI_STR_LEN], program_container[STARPU_POTI_STR_LEN];
  976. snprintf(paje_value, STARPU_POTI_STR_LEN, "%u", size);
  977. snprintf(paje_key, STARPU_POTI_STR_LEN, "com_%u", comid);
  978. program_container_alias(program_container, STARPU_POTI_STR_LEN, prefix);
  979. memmanager_container_alias(dst_memnode_container, STARPU_POTI_STR_LEN, prefix, dst);
  980. poti_EndLink(time, program_container, "L", dst_memnode_container, paje_value, paje_key);
  981. #else
  982. fprintf(out_paje_file, "19 %.9f L %sp %u %smm%u com_%u\n", time, prefix, size, prefix, dst, comid);
  983. #endif
  984. }
  985. /* look for a data transfer to match */
  986. struct _starpu_communication *itor;
  987. for (itor = _starpu_communication_list_begin(communication_list);
  988. itor != _starpu_communication_list_end(communication_list);
  989. itor = _starpu_communication_list_next(itor))
  990. {
  991. if (itor->comid == comid)
  992. {
  993. double comm_end = get_event_time_stamp(ev, options);
  994. double bandwidth = (double)((0.001*size)/(comm_end - itor->comm_start));
  995. itor->bandwidth = bandwidth;
  996. struct _starpu_communication *com = _starpu_communication_new();
  997. com->comid = comid;
  998. com->comm_start = get_event_time_stamp(ev, options);
  999. com->bandwidth = -bandwidth;
  1000. com->src_node = itor->src_node;
  1001. com->dst_node = itor->dst_node;
  1002. _starpu_communication_list_push_back(communication_list, com);
  1003. break;
  1004. }
  1005. }
  1006. }
  1007. }
  1008. static void handle_start_driver_copy_async(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  1009. {
  1010. unsigned dst = ev->param[1];
  1011. char *prefix = options->file_prefix;
  1012. if (!options->no_bus)
  1013. if (out_paje_file)
  1014. memnode_set_state(get_event_time_stamp(ev, options), prefix, dst, "CoA");
  1015. }
  1016. static void handle_end_driver_copy_async(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  1017. {
  1018. unsigned dst = ev->param[1];
  1019. char *prefix = options->file_prefix;
  1020. if (!options->no_bus)
  1021. if (out_paje_file)
  1022. memnode_set_state(get_event_time_stamp(ev, options), prefix, dst, "Co");
  1023. }
  1024. static void handle_memnode_event(struct fxt_ev_64 *ev, struct starpu_fxt_options *options, const char *eventstr)
  1025. {
  1026. unsigned memnode = ev->param[0];
  1027. if (out_paje_file)
  1028. memnode_set_state(get_event_time_stamp(ev, options), options->file_prefix, memnode, eventstr);
  1029. }
  1030. /*
  1031. * Number of task submitted to the scheduler
  1032. */
  1033. static int curq_size = 0;
  1034. static int nsubmitted = 0;
  1035. static void handle_job_push(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  1036. {
  1037. double current_timestamp = get_event_time_stamp(ev, options);
  1038. curq_size++;
  1039. if (!options->no_counter && out_paje_file)
  1040. {
  1041. #ifdef STARPU_HAVE_POTI
  1042. char container[STARPU_POTI_STR_LEN];
  1043. scheduler_container_alias(container, STARPU_POTI_STR_LEN, options->file_prefix);
  1044. poti_SetVariable(current_timestamp, container, "nready", (double)curq_size);
  1045. #else
  1046. fprintf(out_paje_file, "13 %.9f %ssched nready %f\n", current_timestamp, options->file_prefix, (float)curq_size);
  1047. #endif
  1048. }
  1049. if (activity_file)
  1050. fprintf(activity_file, "cnt_ready\t%.9f\t%d\n", current_timestamp, curq_size);
  1051. }
  1052. static void handle_job_pop(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  1053. {
  1054. double current_timestamp = get_event_time_stamp(ev, options);
  1055. curq_size--;
  1056. nsubmitted--;
  1057. if (!options->no_counter && out_paje_file)
  1058. {
  1059. #ifdef STARPU_HAVE_POTI
  1060. char container[STARPU_POTI_STR_LEN];
  1061. scheduler_container_alias(container, STARPU_POTI_STR_LEN, options->file_prefix);
  1062. poti_SetVariable(current_timestamp, container, "nready", (double)curq_size);
  1063. poti_SetVariable(current_timestamp, container, "nsubmitted", (double)nsubmitted);
  1064. #else
  1065. fprintf(out_paje_file, "13 %.9f %ssched nready %f\n", current_timestamp, options->file_prefix, (float)curq_size);
  1066. fprintf(out_paje_file, "13 %.9f %ssched nsubmitted %f\n", current_timestamp, options->file_prefix, (float)nsubmitted);
  1067. #endif
  1068. }
  1069. if (activity_file)
  1070. {
  1071. fprintf(activity_file, "cnt_ready\t%.9f\t%d\n", current_timestamp, curq_size);
  1072. fprintf(activity_file, "cnt_submitted\t%.9f\t%d\n", current_timestamp, nsubmitted);
  1073. }
  1074. }
  1075. static
  1076. void handle_update_task_cnt(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  1077. {
  1078. double current_timestamp = get_event_time_stamp(ev, options);
  1079. nsubmitted++;
  1080. if (!options->no_counter && out_paje_file)
  1081. {
  1082. #ifdef STARPU_HAVE_POTI
  1083. char container[STARPU_POTI_STR_LEN];
  1084. scheduler_container_alias(container, STARPU_POTI_STR_LEN, options->file_prefix);
  1085. poti_SetVariable(current_timestamp, container, "nsubmitted", (double)nsubmitted);
  1086. #else
  1087. fprintf(out_paje_file, "13 %.9f %ssched nsubmitted %f\n", current_timestamp, options->file_prefix, (float)nsubmitted);
  1088. #endif
  1089. }
  1090. if (activity_file)
  1091. fprintf(activity_file, "cnt_submitted\t%.9f\t%d\n", current_timestamp, nsubmitted);
  1092. }
  1093. static void handle_tag(struct fxt_ev_64 *ev)
  1094. {
  1095. uint64_t tag;
  1096. unsigned long job;
  1097. tag = ev->param[0];
  1098. job = ev->param[1];
  1099. _starpu_fxt_dag_add_tag(tag, job);
  1100. }
  1101. static void handle_tag_deps(struct fxt_ev_64 *ev)
  1102. {
  1103. uint64_t child;
  1104. uint64_t father;
  1105. child = ev->param[0];
  1106. father = ev->param[1];
  1107. _starpu_fxt_dag_add_tag_deps(child, father);
  1108. }
  1109. static void handle_task_deps(struct fxt_ev_64 *ev)
  1110. {
  1111. unsigned long dep_prev = ev->param[0];
  1112. unsigned long dep_succ = ev->param[1];
  1113. /* There is a dependency between both job id : dep_prev -> dep_succ */
  1114. _starpu_fxt_dag_add_task_deps(dep_prev, dep_succ);
  1115. }
  1116. static void handle_task_done(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  1117. {
  1118. unsigned long job_id;
  1119. job_id = ev->param[0];
  1120. unsigned long has_name = ev->param[3];
  1121. char *name = has_name?(char *)&ev->param[4]:"unknown";
  1122. int worker;
  1123. worker = find_worker_id(ev->param[1]);
  1124. const char *colour;
  1125. char buffer[32];
  1126. if (options->per_task_colour)
  1127. {
  1128. snprintf(buffer, 32, "#%x%x%x",
  1129. get_colour_symbol_red(name)/4,
  1130. get_colour_symbol_green(name)/4,
  1131. get_colour_symbol_blue(name)/4);
  1132. colour = &buffer[0];
  1133. }
  1134. else
  1135. {
  1136. colour= (worker < 0)?"#aaaaaa":get_worker_color(worker);
  1137. }
  1138. unsigned exclude_from_dag = ev->param[2];
  1139. if (!exclude_from_dag)
  1140. _starpu_fxt_dag_set_task_done(job_id, name, colour);
  1141. }
  1142. static void handle_tag_done(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  1143. {
  1144. uint64_t tag_id;
  1145. tag_id = ev->param[0];
  1146. unsigned long has_name = ev->param[2];
  1147. char *name = has_name?(char *)&ev->param[3]:"unknown";
  1148. int worker;
  1149. worker = find_worker_id(ev->param[1]);
  1150. const char *colour;
  1151. char buffer[32];
  1152. if (options->per_task_colour)
  1153. {
  1154. snprintf(buffer, 32, "%.4f,%.4f,%.4f",
  1155. get_colour_symbol_red(name)/1024.0,
  1156. get_colour_symbol_green(name)/1024.0,
  1157. get_colour_symbol_blue(name)/1024.0);
  1158. colour = &buffer[0];
  1159. }
  1160. else
  1161. {
  1162. colour= (worker < 0)?"0.0,0.0,0.0":get_worker_color(worker);
  1163. }
  1164. _starpu_fxt_dag_set_tag_done(tag_id, colour);
  1165. }
  1166. static void handle_mpi_barrier(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  1167. {
  1168. int rank = ev->param[0];
  1169. STARPU_ASSERT(rank == options->file_rank || options->file_rank == -1);
  1170. /* Add an event in the trace */
  1171. if (out_paje_file)
  1172. {
  1173. #ifdef STARPU_HAVE_POTI
  1174. char container[STARPU_POTI_STR_LEN], paje_value[STARPU_POTI_STR_LEN];
  1175. snprintf(container, STARPU_POTI_STR_LEN, "%sp", options->file_prefix);
  1176. snprintf(paje_value, STARPU_POTI_STR_LEN, "%d", rank);
  1177. poti_NewEvent(get_event_time_stamp(ev, options), container, "prog_event", paje_value);
  1178. #else
  1179. fprintf(out_paje_file, "9 %.9f prog_event %sp %d\n", get_event_time_stamp(ev, options), options->file_prefix, rank);
  1180. #endif
  1181. }
  1182. }
  1183. static void handle_mpi_start(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  1184. {
  1185. double date = get_event_time_stamp(ev, options);
  1186. char *prefix = options->file_prefix;
  1187. if (out_paje_file)
  1188. {
  1189. #ifdef STARPU_HAVE_POTI
  1190. char program_container[STARPU_POTI_STR_LEN];
  1191. program_container_alias(program_container, STARPU_POTI_STR_LEN, prefix);
  1192. char new_mpicommthread_container_alias[STARPU_POTI_STR_LEN], new_mpicommthread_container_name[STARPU_POTI_STR_LEN];
  1193. mpicommthread_container_alias(new_mpicommthread_container_alias, STARPU_POTI_STR_LEN, prefix);
  1194. snprintf(new_mpicommthread_container_alias, STARPU_POTI_STR_LEN, "%smpict", prefix);
  1195. poti_CreateContainer(date, new_mpicommthread_container_alias, "MPICt", program_container, new_mpicommthread_container_name);
  1196. #else
  1197. fprintf(out_paje_file, "7 %.9f %smpict MPICt %sp %smpict\n", date, prefix, prefix, prefix);
  1198. #endif
  1199. mpicommthread_set_state(date, prefix, "Sl");
  1200. }
  1201. }
  1202. static void handle_mpi_stop(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  1203. {
  1204. double date = get_event_time_stamp(ev, options);
  1205. char *prefix = options->file_prefix;
  1206. if (out_paje_file)
  1207. {
  1208. #ifdef STARPU_HAVE_POTI
  1209. char mpicommthread_container[STARPU_POTI_STR_LEN];
  1210. mpicommthread_container_alias(mpicommthread_container, STARPU_POTI_STR_LEN, prefix);
  1211. poti_DestroyContainer(date, "MPICt", mpicommthread_container);
  1212. #else
  1213. fprintf(out_paje_file, "8 %.9f %smpict MPICt\n",
  1214. date, prefix);
  1215. #endif
  1216. }
  1217. }
  1218. static void handle_mpi_isend_submit_begin(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  1219. {
  1220. double date = get_event_time_stamp(ev, options);
  1221. if (out_paje_file)
  1222. mpicommthread_set_state(date, options->file_prefix, "SdS");
  1223. }
  1224. static void handle_mpi_isend_submit_end(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  1225. {
  1226. int dest = ev->param[0];
  1227. int mpi_tag = ev->param[1];
  1228. size_t size = ev->param[2];
  1229. double date = get_event_time_stamp(ev, options);
  1230. if (out_paje_file)
  1231. mpicommthread_set_state(date, options->file_prefix, "P");
  1232. _starpu_fxt_mpi_add_send_transfer(options->file_rank, dest, mpi_tag, size, date);
  1233. }
  1234. static void handle_mpi_irecv_submit_begin(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  1235. {
  1236. double date = get_event_time_stamp(ev, options);
  1237. if (out_paje_file)
  1238. mpicommthread_set_state(date, options->file_prefix, "RvS");
  1239. }
  1240. static void handle_mpi_irecv_submit_end(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  1241. {
  1242. double date = get_event_time_stamp(ev, options);
  1243. if (out_paje_file)
  1244. mpicommthread_set_state(date, options->file_prefix, "P");
  1245. }
  1246. static void handle_mpi_isend_complete_begin(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  1247. {
  1248. double date = get_event_time_stamp(ev, options);
  1249. if (out_paje_file)
  1250. mpicommthread_set_state(date, options->file_prefix, "SdC");
  1251. }
  1252. static void handle_mpi_isend_complete_end(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  1253. {
  1254. double date = get_event_time_stamp(ev, options);
  1255. if (out_paje_file)
  1256. mpicommthread_set_state(date, options->file_prefix, "P");
  1257. }
  1258. static void handle_mpi_irecv_complete_begin(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  1259. {
  1260. int src = ev->param[0];
  1261. int mpi_tag = ev->param[1];
  1262. double date = get_event_time_stamp(ev, options);
  1263. if (out_paje_file)
  1264. mpicommthread_set_state(date, options->file_prefix, "RvC");
  1265. _starpu_fxt_mpi_add_recv_transfer(src, options->file_rank, mpi_tag, date);
  1266. }
  1267. static void handle_mpi_irecv_complete_end(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  1268. {
  1269. double date = get_event_time_stamp(ev, options);
  1270. if (out_paje_file)
  1271. mpicommthread_set_state(date, options->file_prefix, "P");
  1272. }
  1273. static void handle_mpi_sleep_begin(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  1274. {
  1275. double date = get_event_time_stamp(ev, options);
  1276. if (out_paje_file)
  1277. mpicommthread_set_state(date, options->file_prefix, "Sl");
  1278. }
  1279. static void handle_mpi_sleep_end(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  1280. {
  1281. double date = get_event_time_stamp(ev, options);
  1282. if (out_paje_file)
  1283. mpicommthread_set_state(date, options->file_prefix, "P");
  1284. }
  1285. static void handle_mpi_dtesting_begin(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  1286. {
  1287. double date = get_event_time_stamp(ev, options);
  1288. if (out_paje_file)
  1289. mpicommthread_set_state(date, options->file_prefix, "DT");
  1290. }
  1291. static void handle_mpi_dtesting_end(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  1292. {
  1293. double date = get_event_time_stamp(ev, options);
  1294. if (out_paje_file)
  1295. mpicommthread_set_state(date, options->file_prefix, "P");
  1296. }
  1297. static void handle_mpi_utesting_begin(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  1298. {
  1299. double date = get_event_time_stamp(ev, options);
  1300. if (out_paje_file)
  1301. mpicommthread_set_state(date, options->file_prefix, "UT");
  1302. }
  1303. static void handle_mpi_utesting_end(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  1304. {
  1305. double date = get_event_time_stamp(ev, options);
  1306. if (out_paje_file)
  1307. mpicommthread_set_state(date, options->file_prefix, "P");
  1308. }
  1309. static void handle_mpi_uwait_begin(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  1310. {
  1311. double date = get_event_time_stamp(ev, options);
  1312. if (out_paje_file)
  1313. mpicommthread_set_state(date, options->file_prefix, "UW");
  1314. }
  1315. static void handle_mpi_uwait_end(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  1316. {
  1317. double date = get_event_time_stamp(ev, options);
  1318. if (out_paje_file)
  1319. mpicommthread_set_state(date, options->file_prefix, "P");
  1320. }
  1321. static void handle_set_profiling(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  1322. {
  1323. int status = ev->param[0];
  1324. if (activity_file)
  1325. fprintf(activity_file, "set_profiling\t%.9f\t%d\n", get_event_time_stamp(ev, options), status);
  1326. }
  1327. static void handle_task_wait_for_all(void)
  1328. {
  1329. _starpu_fxt_dag_add_sync_point();
  1330. }
  1331. static void handle_event(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  1332. {
  1333. char *event = (char*)&ev->param[0];
  1334. /* Add an event in the trace */
  1335. if (out_paje_file)
  1336. {
  1337. #ifdef STARPU_HAVE_POTI
  1338. char container[STARPU_POTI_STR_LEN];
  1339. snprintf(container, STARPU_POTI_STR_LEN, "%sp", options->file_prefix);
  1340. poti_NewEvent(get_event_time_stamp(ev, options), container, "prog_event", event);
  1341. #else
  1342. fprintf(out_paje_file, "9 %.9f prog_event %sp %s\n", get_event_time_stamp(ev, options), options->file_prefix, event);
  1343. #endif
  1344. }
  1345. }
  1346. static void handle_thread_event(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
  1347. {
  1348. /* Add an event in the trace */
  1349. if (out_paje_file)
  1350. {
  1351. char *event = (char*)&ev->param[1];
  1352. #ifdef STARPU_HAVE_POTI
  1353. char container[STARPU_POTI_STR_LEN];
  1354. thread_container_alias(container, STARPU_POTI_STR_LEN, options->file_prefix, ev->param[0]);
  1355. poti_NewEvent(get_event_time_stamp(ev, options), container, "thread_event", event);
  1356. #else
  1357. fprintf(out_paje_file, "9 %.9f thread_event %st%"PRIu64" %s\n", get_event_time_stamp(ev, options), options->file_prefix, ev->param[0], event);
  1358. #endif
  1359. }
  1360. }
  1361. static
  1362. void _starpu_fxt_display_bandwidth(struct starpu_fxt_options *options)
  1363. {
  1364. float current_bandwidth_per_node[STARPU_MAXNODES] = {0.0};
  1365. char *prefix = options->file_prefix;
  1366. struct _starpu_communication*itor;
  1367. for (itor = _starpu_communication_list_begin(communication_list);
  1368. itor != _starpu_communication_list_end(communication_list);
  1369. itor = _starpu_communication_list_next(itor))
  1370. {
  1371. current_bandwidth_per_node[itor->src_node] += itor->bandwidth;
  1372. if (out_paje_file)
  1373. {
  1374. #ifdef STARPU_HAVE_POTI
  1375. char src_memnode_container[STARPU_POTI_STR_LEN];
  1376. memmanager_container_alias(src_memnode_container, STARPU_POTI_STR_LEN, prefix, itor->src_node);
  1377. poti_SetVariable(itor->comm_start, src_memnode_container, "bw", current_bandwidth_per_node[itor->src_node]);
  1378. #else
  1379. fprintf(out_paje_file, "13 %.9f %smm%u bw %f\n",
  1380. itor->comm_start, prefix, itor->src_node, current_bandwidth_per_node[itor->src_node]);
  1381. #endif
  1382. }
  1383. current_bandwidth_per_node[itor->dst_node] += itor->bandwidth;
  1384. if (out_paje_file)
  1385. {
  1386. #ifdef STARPU_HAVE_POTI
  1387. char dst_memnode_container[STARPU_POTI_STR_LEN];
  1388. memmanager_container_alias(dst_memnode_container, STARPU_POTI_STR_LEN, prefix, itor->dst_node);
  1389. poti_SetVariable(itor->comm_start, dst_memnode_container, "bw", current_bandwidth_per_node[itor->dst_node]);
  1390. #else
  1391. fprintf(out_paje_file, "13 %.9f %smm%u bw %f\n",
  1392. itor->comm_start, prefix, itor->dst_node, current_bandwidth_per_node[itor->dst_node]);
  1393. #endif
  1394. }
  1395. }
  1396. }
  1397. static
  1398. void _starpu_fxt_parse_new_file(char *filename_in, struct starpu_fxt_options *options)
  1399. {
  1400. /* Open the trace file */
  1401. int fd_in;
  1402. fd_in = open(filename_in, O_RDONLY);
  1403. if (fd_in < 0)
  1404. {
  1405. perror("open failed :");
  1406. exit(-1);
  1407. }
  1408. static fxt_t fut;
  1409. fut = fxt_fdopen(fd_in);
  1410. if (!fut)
  1411. {
  1412. perror("fxt_fdopen :");
  1413. exit(-1);
  1414. }
  1415. fxt_blockev_t block;
  1416. block = fxt_blockev_enter(fut);
  1417. symbol_list = _starpu_symbol_name_list_new();
  1418. communication_list = _starpu_communication_list_new();
  1419. char *prefix = options->file_prefix;
  1420. /* TODO starttime ...*/
  1421. /* create the "program" container */
  1422. if (out_paje_file)
  1423. {
  1424. #ifdef STARPU_HAVE_POTI
  1425. char new_program_container_alias[STARPU_POTI_STR_LEN], new_program_container_name[STARPU_POTI_STR_LEN];
  1426. program_container_alias(new_program_container_alias, STARPU_POTI_STR_LEN, prefix);
  1427. snprintf(new_program_container_name, STARPU_POTI_STR_LEN, "program %s", prefix);
  1428. poti_CreateContainer (0, new_program_container_alias, "P", "MPIroot", new_program_container_name);
  1429. if (!options->no_counter)
  1430. {
  1431. char new_scheduler_container_alias[STARPU_POTI_STR_LEN], new_scheduler_container_name[STARPU_POTI_STR_LEN];
  1432. scheduler_container_alias(new_scheduler_container_alias, STARPU_POTI_STR_LEN, prefix);
  1433. snprintf(new_scheduler_container_name, STARPU_POTI_STR_LEN, "scheduler %s", prefix);
  1434. poti_CreateContainer(0.0, new_scheduler_container_alias, "Sc", new_program_container_alias, new_scheduler_container_name);
  1435. poti_SetVariable(0.0, new_scheduler_container_alias, "nsubmitted", 0.0);
  1436. poti_SetVariable(0.0, new_scheduler_container_alias, "nready", 0.0);
  1437. }
  1438. #else
  1439. fprintf(out_paje_file, "7 0.0 %sp P MPIroot %sprogram \n", prefix, prefix);
  1440. /* create a variable with the number of tasks */
  1441. if (!options->no_counter)
  1442. {
  1443. fprintf(out_paje_file, "7 %.9f %ssched Sc %sp scheduler\n", 0.0, prefix, prefix);
  1444. fprintf(out_paje_file, "13 0.0 %ssched nsubmitted 0.0\n", prefix);
  1445. fprintf(out_paje_file, "13 0.0 %ssched nready 0.0\n", prefix);
  1446. }
  1447. #endif
  1448. }
  1449. struct fxt_ev_64 ev;
  1450. while(1)
  1451. {
  1452. int ret = fxt_next_ev(block, FXT_EV_TYPE_64, (struct fxt_ev *)&ev);
  1453. if (ret != FXT_EV_OK)
  1454. {
  1455. break;
  1456. }
  1457. switch (ev.code)
  1458. {
  1459. case _STARPU_FUT_WORKER_INIT_START:
  1460. handle_worker_init_start(&ev, options);
  1461. break;
  1462. case _STARPU_FUT_WORKER_INIT_END:
  1463. handle_worker_init_end(&ev, options);
  1464. break;
  1465. case _STARPU_FUT_NEW_MEM_NODE:
  1466. handle_new_mem_node(&ev, options);
  1467. break;
  1468. /* detect when the workers were idling or not */
  1469. case _STARPU_FUT_START_CODELET_BODY:
  1470. handle_start_codelet_body(&ev, options);
  1471. break;
  1472. case _STARPU_FUT_CODELET_DATA:
  1473. handle_codelet_data(&ev, options);
  1474. break;
  1475. case _STARPU_FUT_CODELET_DETAILS:
  1476. handle_codelet_details(&ev, options);
  1477. break;
  1478. case _STARPU_FUT_END_CODELET_BODY:
  1479. handle_end_codelet_body(&ev, options);
  1480. break;
  1481. case _STARPU_FUT_START_EXECUTING:
  1482. handle_start_executing(&ev, options);
  1483. break;
  1484. case _STARPU_FUT_END_EXECUTING:
  1485. handle_end_executing(&ev, options);
  1486. break;
  1487. case _STARPU_FUT_START_CALLBACK:
  1488. handle_start_callback(&ev, options);
  1489. break;
  1490. case _STARPU_FUT_END_CALLBACK:
  1491. handle_end_callback(&ev, options);
  1492. break;
  1493. case _STARPU_FUT_UPDATE_TASK_CNT:
  1494. handle_update_task_cnt(&ev, options);
  1495. break;
  1496. /* monitor stack size */
  1497. case _STARPU_FUT_JOB_PUSH:
  1498. handle_job_push(&ev, options);
  1499. break;
  1500. case _STARPU_FUT_JOB_POP:
  1501. handle_job_pop(&ev, options);
  1502. break;
  1503. /* check the memory transfer overhead */
  1504. case _STARPU_FUT_START_FETCH_INPUT:
  1505. handle_worker_status(&ev, options, "Fi");
  1506. break;
  1507. case _STARPU_FUT_START_PUSH_OUTPUT:
  1508. handle_worker_status(&ev, options, "Po");
  1509. break;
  1510. case _STARPU_FUT_START_PROGRESS:
  1511. handle_worker_status(&ev, options, "P");
  1512. break;
  1513. case _STARPU_FUT_START_UNPARTITION:
  1514. handle_worker_status(&ev, options, "U");
  1515. break;
  1516. case _STARPU_FUT_END_FETCH_INPUT:
  1517. case _STARPU_FUT_END_PROGRESS:
  1518. case _STARPU_FUT_END_PUSH_OUTPUT:
  1519. case _STARPU_FUT_END_UNPARTITION:
  1520. handle_worker_status(&ev, options, "B");
  1521. break;
  1522. case _STARPU_FUT_WORKER_SCHEDULING_START:
  1523. handle_worker_scheduling_start(&ev, options);
  1524. break;
  1525. case _STARPU_FUT_WORKER_SCHEDULING_END:
  1526. handle_worker_scheduling_end(&ev, options);
  1527. break;
  1528. case _STARPU_FUT_WORKER_SCHEDULING_PUSH:
  1529. handle_worker_scheduling_push(&ev, options);
  1530. break;
  1531. case _STARPU_FUT_WORKER_SCHEDULING_POP:
  1532. handle_worker_scheduling_pop(&ev, options);
  1533. break;
  1534. case _STARPU_FUT_WORKER_SLEEP_START:
  1535. handle_worker_sleep_start(&ev, options);
  1536. break;
  1537. case _STARPU_FUT_WORKER_SLEEP_END:
  1538. handle_worker_sleep_end(&ev, options);
  1539. break;
  1540. case _STARPU_FUT_TAG:
  1541. handle_tag(&ev);
  1542. break;
  1543. case _STARPU_FUT_TAG_DEPS:
  1544. handle_tag_deps(&ev);
  1545. break;
  1546. case _STARPU_FUT_TASK_DEPS:
  1547. handle_task_deps(&ev);
  1548. break;
  1549. case _STARPU_FUT_TASK_DONE:
  1550. handle_task_done(&ev, options);
  1551. break;
  1552. case _STARPU_FUT_TAG_DONE:
  1553. handle_tag_done(&ev, options);
  1554. break;
  1555. case _STARPU_FUT_DATA_COPY:
  1556. if (!options->no_bus)
  1557. handle_data_copy();
  1558. break;
  1559. case _STARPU_FUT_DATA_LOAD:
  1560. break;
  1561. case _STARPU_FUT_START_DRIVER_COPY:
  1562. if (!options->no_bus)
  1563. handle_start_driver_copy(&ev, options);
  1564. break;
  1565. case _STARPU_FUT_END_DRIVER_COPY:
  1566. if (!options->no_bus)
  1567. handle_end_driver_copy(&ev, options);
  1568. break;
  1569. case _STARPU_FUT_START_DRIVER_COPY_ASYNC:
  1570. if (!options->no_bus)
  1571. handle_start_driver_copy_async(&ev, options);
  1572. break;
  1573. case _STARPU_FUT_END_DRIVER_COPY_ASYNC:
  1574. if (!options->no_bus)
  1575. handle_end_driver_copy_async(&ev, options);
  1576. break;
  1577. case _STARPU_FUT_WORK_STEALING:
  1578. handle_work_stealing(&ev, options);
  1579. break;
  1580. case _STARPU_FUT_WORKER_DEINIT_START:
  1581. handle_worker_deinit_start(&ev, options);
  1582. break;
  1583. case _STARPU_FUT_WORKER_DEINIT_END:
  1584. handle_worker_deinit_end(&ev, options);
  1585. break;
  1586. case _STARPU_FUT_START_ALLOC:
  1587. if (!options->no_bus)
  1588. handle_memnode_event(&ev, options, "A");
  1589. break;
  1590. case _STARPU_FUT_START_ALLOC_REUSE:
  1591. if (!options->no_bus)
  1592. handle_memnode_event(&ev, options, "Ar");
  1593. break;
  1594. case _STARPU_FUT_END_ALLOC:
  1595. case _STARPU_FUT_END_ALLOC_REUSE:
  1596. if (!options->no_bus)
  1597. handle_memnode_event(&ev, options, "No");
  1598. break;
  1599. case _STARPU_FUT_START_FREE:
  1600. if (!options->no_bus)
  1601. {
  1602. handle_memnode_event(&ev, options, "F");
  1603. }
  1604. break;
  1605. case _STARPU_FUT_END_FREE:
  1606. if (!options->no_bus)
  1607. {
  1608. unsigned memnode = ev.param[0];
  1609. if (reclaiming[memnode])
  1610. handle_memnode_event(&ev, options, "R");
  1611. else
  1612. handle_memnode_event(&ev, options, "No");
  1613. }
  1614. break;
  1615. case _STARPU_FUT_START_WRITEBACK:
  1616. if (!options->no_bus)
  1617. {
  1618. handle_memnode_event(&ev, options, "W");
  1619. }
  1620. break;
  1621. case _STARPU_FUT_END_WRITEBACK:
  1622. if (!options->no_bus)
  1623. {
  1624. unsigned memnode = ev.param[0];
  1625. if (reclaiming[memnode])
  1626. handle_memnode_event(&ev, options, "R");
  1627. else
  1628. handle_memnode_event(&ev, options, "No");
  1629. }
  1630. break;
  1631. case _STARPU_FUT_START_MEMRECLAIM:
  1632. if (!options->no_bus)
  1633. {
  1634. unsigned memnode = ev.param[0];
  1635. reclaiming[memnode] = 1;
  1636. handle_memnode_event(&ev, options, "R");
  1637. }
  1638. break;
  1639. case _STARPU_FUT_END_MEMRECLAIM:
  1640. if (!options->no_bus)
  1641. {
  1642. unsigned memnode = ev.param[0];
  1643. reclaiming[memnode] = 0;
  1644. handle_memnode_event(&ev, options, "No");
  1645. }
  1646. break;
  1647. case _STARPU_FUT_USER_EVENT:
  1648. handle_user_event(&ev, options);
  1649. break;
  1650. case _STARPU_MPI_FUT_START:
  1651. handle_mpi_start(&ev, options);
  1652. break;
  1653. case _STARPU_MPI_FUT_STOP:
  1654. handle_mpi_stop(&ev, options);
  1655. break;
  1656. case _STARPU_MPI_FUT_BARRIER:
  1657. handle_mpi_barrier(&ev, options);
  1658. break;
  1659. case _STARPU_MPI_FUT_ISEND_SUBMIT_BEGIN:
  1660. handle_mpi_isend_submit_begin(&ev, options);
  1661. break;
  1662. case _STARPU_MPI_FUT_ISEND_SUBMIT_END:
  1663. handle_mpi_isend_submit_end(&ev, options);
  1664. break;
  1665. case _STARPU_MPI_FUT_IRECV_SUBMIT_BEGIN:
  1666. handle_mpi_irecv_submit_begin(&ev, options);
  1667. break;
  1668. case _STARPU_MPI_FUT_IRECV_SUBMIT_END:
  1669. handle_mpi_irecv_submit_end(&ev, options);
  1670. break;
  1671. case _STARPU_MPI_FUT_ISEND_COMPLETE_BEGIN:
  1672. handle_mpi_isend_complete_begin(&ev, options);
  1673. break;
  1674. case _STARPU_MPI_FUT_ISEND_COMPLETE_END:
  1675. handle_mpi_isend_complete_end(&ev, options);
  1676. break;
  1677. case _STARPU_MPI_FUT_IRECV_COMPLETE_BEGIN:
  1678. handle_mpi_irecv_complete_begin(&ev, options);
  1679. break;
  1680. case _STARPU_MPI_FUT_IRECV_COMPLETE_END:
  1681. handle_mpi_irecv_complete_end(&ev, options);
  1682. break;
  1683. case _STARPU_MPI_FUT_SLEEP_BEGIN:
  1684. handle_mpi_sleep_begin(&ev, options);
  1685. break;
  1686. case _STARPU_MPI_FUT_SLEEP_END:
  1687. handle_mpi_sleep_end(&ev, options);
  1688. break;
  1689. case _STARPU_MPI_FUT_DTESTING_BEGIN:
  1690. handle_mpi_dtesting_begin(&ev, options);
  1691. break;
  1692. case _STARPU_MPI_FUT_DTESTING_END:
  1693. handle_mpi_dtesting_end(&ev, options);
  1694. break;
  1695. case _STARPU_MPI_FUT_UTESTING_BEGIN:
  1696. handle_mpi_utesting_begin(&ev, options);
  1697. break;
  1698. case _STARPU_MPI_FUT_UTESTING_END:
  1699. handle_mpi_utesting_end(&ev, options);
  1700. break;
  1701. case _STARPU_MPI_FUT_UWAIT_BEGIN:
  1702. handle_mpi_uwait_begin(&ev, options);
  1703. break;
  1704. case _STARPU_MPI_FUT_UWAIT_END:
  1705. handle_mpi_uwait_end(&ev, options);
  1706. break;
  1707. case _STARPU_FUT_SET_PROFILING:
  1708. handle_set_profiling(&ev, options);
  1709. break;
  1710. case _STARPU_FUT_TASK_WAIT_FOR_ALL:
  1711. handle_task_wait_for_all();
  1712. break;
  1713. case _STARPU_FUT_EVENT:
  1714. handle_event(&ev, options);
  1715. break;
  1716. case _STARPU_FUT_THREAD_EVENT:
  1717. handle_thread_event(&ev, options);
  1718. break;
  1719. case _STARPU_FUT_LOCKING_MUTEX:
  1720. break;
  1721. case _STARPU_FUT_MUTEX_LOCKED:
  1722. break;
  1723. case _STARPU_FUT_UNLOCKING_MUTEX:
  1724. break;
  1725. case _STARPU_FUT_MUTEX_UNLOCKED:
  1726. break;
  1727. case _STARPU_FUT_TRYLOCK_MUTEX:
  1728. break;
  1729. case _STARPU_FUT_RDLOCKING_RWLOCK:
  1730. break;
  1731. case _STARPU_FUT_RWLOCK_RDLOCKED:
  1732. break;
  1733. case _STARPU_FUT_WRLOCKING_RWLOCK:
  1734. break;
  1735. case _STARPU_FUT_RWLOCK_WRLOCKED:
  1736. break;
  1737. case _STARPU_FUT_UNLOCKING_RWLOCK:
  1738. break;
  1739. case _STARPU_FUT_RWLOCK_UNLOCKED:
  1740. break;
  1741. case _STARPU_FUT_LOCKING_SPINLOCK:
  1742. break;
  1743. case _STARPU_FUT_SPINLOCK_LOCKED:
  1744. break;
  1745. case _STARPU_FUT_UNLOCKING_SPINLOCK:
  1746. break;
  1747. case _STARPU_FUT_SPINLOCK_UNLOCKED:
  1748. break;
  1749. case _STARPU_FUT_TRYLOCK_SPINLOCK:
  1750. break;
  1751. case _STARPU_FUT_COND_WAIT_BEGIN:
  1752. break;
  1753. case _STARPU_FUT_COND_WAIT_END:
  1754. break;
  1755. case _STARPU_FUT_BARRIER_WAIT_BEGIN:
  1756. break;
  1757. case _STARPU_FUT_BARRIER_WAIT_END:
  1758. break;
  1759. case _STARPU_FUT_MEMORY_FULL:
  1760. break;
  1761. case _STARPU_FUT_SCHED_COMPONENT_POP_PRIO:
  1762. break;
  1763. case _STARPU_FUT_SCHED_COMPONENT_PUSH_PRIO:
  1764. break;
  1765. case _STARPU_FUT_HYPERVISOR_BEGIN:
  1766. handle_hypervisor_begin(&ev, options);
  1767. break;
  1768. case _STARPU_FUT_HYPERVISOR_END:
  1769. handle_hypervisor_end(&ev, options);
  1770. break;
  1771. /* We can safely ignore FUT internal events */
  1772. case FUT_SETUP_CODE:
  1773. case FUT_CALIBRATE0_CODE:
  1774. case FUT_CALIBRATE1_CODE:
  1775. case FUT_CALIBRATE2_CODE:
  1776. case FUT_KEYCHANGE_CODE:
  1777. case FUT_NEW_LWP_CODE:
  1778. case FUT_GCC_INSTRUMENT_ENTRY_CODE:
  1779. break;
  1780. default:
  1781. #ifdef STARPU_VERBOSE
  1782. fprintf(stderr, "unknown event.. %x at time %llx WITH OFFSET %llx\n",
  1783. (unsigned)ev.code, (long long unsigned)ev.time, (long long unsigned)(ev.time-options->file_offset));
  1784. #endif
  1785. break;
  1786. }
  1787. }
  1788. /* Close the trace file */
  1789. if (close(fd_in))
  1790. {
  1791. perror("close failed :");
  1792. exit(-1);
  1793. }
  1794. }
  1795. /* Initialize FxT options to default values */
  1796. void starpu_fxt_options_init(struct starpu_fxt_options *options)
  1797. {
  1798. options->per_task_colour = 0;
  1799. options->no_counter = 0;
  1800. options->no_bus = 0;
  1801. options->ninputfiles = 0;
  1802. options->out_paje_path = "paje.trace";
  1803. options->dag_path = "dag.dot";
  1804. options->distrib_time_path = "distrib.data";
  1805. options->dumped_codelets = NULL;
  1806. options->activity_path = "activity.data";
  1807. }
  1808. static
  1809. void _starpu_fxt_distrib_file_init(struct starpu_fxt_options *options)
  1810. {
  1811. dumped_codelets_count = 0;
  1812. dumped_codelets = NULL;
  1813. if (options->distrib_time_path)
  1814. {
  1815. distrib_time = fopen(options->distrib_time_path, "w+");
  1816. }
  1817. else
  1818. {
  1819. distrib_time = NULL;
  1820. }
  1821. }
  1822. static
  1823. void _starpu_fxt_distrib_file_close(struct starpu_fxt_options *options)
  1824. {
  1825. if (distrib_time)
  1826. fclose(distrib_time);
  1827. if (options->dumped_codelets)
  1828. {
  1829. *options->dumped_codelets = dumped_codelets;
  1830. options->dumped_codelets_count = dumped_codelets_count;
  1831. }
  1832. }
  1833. static
  1834. void _starpu_fxt_activity_file_init(struct starpu_fxt_options *options)
  1835. {
  1836. if (options->activity_path)
  1837. activity_file = fopen(options->activity_path, "w+");
  1838. else
  1839. activity_file = NULL;
  1840. }
  1841. static
  1842. void _starpu_fxt_activity_file_close(void)
  1843. {
  1844. if (activity_file)
  1845. fclose(activity_file);
  1846. }
  1847. static
  1848. void _starpu_fxt_paje_file_init(struct starpu_fxt_options *options)
  1849. {
  1850. /* create a new file */
  1851. if (options->out_paje_path)
  1852. {
  1853. out_paje_file = fopen(options->out_paje_path, "w+");
  1854. if (!out_paje_file)
  1855. {
  1856. fprintf(stderr,"error while opening %s\n", options->out_paje_path);
  1857. perror("fopen");
  1858. exit(1);
  1859. }
  1860. #ifdef STARPU_HAVE_POTI
  1861. poti_init (out_paje_file);
  1862. #endif
  1863. _starpu_fxt_write_paje_header(out_paje_file);
  1864. }
  1865. else
  1866. {
  1867. out_paje_file = NULL;
  1868. }
  1869. }
  1870. static
  1871. void _starpu_fxt_paje_file_close(void)
  1872. {
  1873. if (out_paje_file)
  1874. fclose(out_paje_file);
  1875. }
  1876. static
  1877. uint64_t _starpu_fxt_find_start_time(char *filename_in)
  1878. {
  1879. /* Open the trace file */
  1880. int fd_in;
  1881. fd_in = open(filename_in, O_RDONLY);
  1882. if (fd_in < 0)
  1883. {
  1884. perror("open failed :");
  1885. exit(-1);
  1886. }
  1887. static fxt_t fut;
  1888. fut = fxt_fdopen(fd_in);
  1889. if (!fut)
  1890. {
  1891. perror("fxt_fdopen :");
  1892. exit(-1);
  1893. }
  1894. fxt_blockev_t block;
  1895. block = fxt_blockev_enter(fut);
  1896. struct fxt_ev_64 ev;
  1897. int ret = fxt_next_ev(block, FXT_EV_TYPE_64, (struct fxt_ev *)&ev);
  1898. STARPU_ASSERT (ret == FXT_EV_OK);
  1899. /* Close the trace file */
  1900. if (close(fd_in))
  1901. {
  1902. perror("close failed :");
  1903. exit(-1);
  1904. }
  1905. return (ev.time);
  1906. }
  1907. void starpu_fxt_generate_trace(struct starpu_fxt_options *options)
  1908. {
  1909. _starpu_fxt_dag_init(options->dag_path);
  1910. _starpu_fxt_distrib_file_init(options);
  1911. _starpu_fxt_activity_file_init(options);
  1912. _starpu_fxt_paje_file_init(options);
  1913. if (options->ninputfiles == 0)
  1914. {
  1915. return;
  1916. }
  1917. else if (options->ninputfiles == 1)
  1918. {
  1919. /* we usually only have a single trace */
  1920. uint64_t file_start_time = _starpu_fxt_find_start_time(options->filenames[0]);
  1921. options->file_prefix = "";
  1922. options->file_offset = file_start_time;
  1923. options->file_rank = -1;
  1924. _starpu_fxt_parse_new_file(options->filenames[0], options);
  1925. }
  1926. else
  1927. {
  1928. unsigned inputfile;
  1929. uint64_t offsets[options->ninputfiles];
  1930. /*
  1931. * Find the trace offsets:
  1932. * - If there is no sync point
  1933. * psi_k(x) = x - start_k
  1934. * - If there is a sync point sync_k
  1935. * psi_k(x) = x - sync_k + M
  1936. * where M = max { sync_i - start_i | there exists sync_i}
  1937. * More generally:
  1938. * - psi_k(x) = x - offset_k
  1939. */
  1940. int unique_keys[options->ninputfiles];
  1941. int rank_k[options->ninputfiles];
  1942. uint64_t start_k[options->ninputfiles];
  1943. uint64_t sync_k[options->ninputfiles];
  1944. unsigned sync_k_exists[options->ninputfiles];
  1945. uint64_t M = 0;
  1946. unsigned found_one_sync_point = 0;
  1947. int key = 0;
  1948. unsigned display_mpi = 0;
  1949. /* Compute all start_k */
  1950. for (inputfile = 0; inputfile < options->ninputfiles; inputfile++)
  1951. {
  1952. uint64_t file_start = _starpu_fxt_find_start_time(options->filenames[inputfile]);
  1953. start_k[inputfile] = file_start;
  1954. }
  1955. /* Compute all sync_k if they exist */
  1956. for (inputfile = 0; inputfile < options->ninputfiles; inputfile++)
  1957. {
  1958. int ret = _starpu_fxt_mpi_find_sync_point(options->filenames[inputfile],
  1959. &sync_k[inputfile],
  1960. &unique_keys[inputfile],
  1961. &rank_k[inputfile]);
  1962. if (ret == -1)
  1963. {
  1964. /* There was no sync point, we assume there is no offset */
  1965. sync_k_exists[inputfile] = 0;
  1966. }
  1967. else
  1968. {
  1969. if (!found_one_sync_point)
  1970. {
  1971. key = unique_keys[inputfile];
  1972. display_mpi = 1;
  1973. found_one_sync_point = 1;
  1974. }
  1975. else
  1976. {
  1977. if (key != unique_keys[inputfile])
  1978. {
  1979. fprintf(stderr, "Warning: traces are coming from different run so we will not try to display MPI communications.\n");
  1980. display_mpi = 0;
  1981. }
  1982. }
  1983. STARPU_ASSERT(sync_k[inputfile] >= start_k[inputfile]);
  1984. sync_k_exists[inputfile] = 1;
  1985. uint64_t diff = sync_k[inputfile] - start_k[inputfile];
  1986. if (diff > M)
  1987. M = diff;
  1988. }
  1989. }
  1990. /* Compute the offset */
  1991. for (inputfile = 0; inputfile < options->ninputfiles; inputfile++)
  1992. {
  1993. offsets[inputfile] = sync_k_exists[inputfile]?
  1994. (sync_k[inputfile]-M):start_k[inputfile];
  1995. }
  1996. /* generate the Paje trace for the different files */
  1997. for (inputfile = 0; inputfile < options->ninputfiles; inputfile++)
  1998. {
  1999. int filerank = rank_k[inputfile];
  2000. _STARPU_DISP("Parsing file %s (rank %d)\n", options->filenames[inputfile], filerank);
  2001. char file_prefix[32];
  2002. snprintf(file_prefix, sizeof(file_prefix), "%d_", filerank);
  2003. options->file_prefix = file_prefix;
  2004. options->file_offset = offsets[inputfile];
  2005. options->file_rank = filerank;
  2006. _starpu_fxt_parse_new_file(options->filenames[inputfile], options);
  2007. }
  2008. /* display the MPI transfers if possible */
  2009. if (display_mpi)
  2010. _starpu_fxt_display_mpi_transfers(options, rank_k, out_paje_file);
  2011. }
  2012. _starpu_fxt_display_bandwidth(options);
  2013. /* close the different files */
  2014. _starpu_fxt_paje_file_close();
  2015. _starpu_fxt_activity_file_close();
  2016. _starpu_fxt_distrib_file_close(options);
  2017. _starpu_fxt_dag_terminate();
  2018. options->nworkers = nworkers;
  2019. }
  2020. #define DATA_STR_MAX_SIZE 15
  2021. struct parse_task
  2022. {
  2023. unsigned exec_time;
  2024. unsigned data_total;
  2025. char *codelet_name;
  2026. };
  2027. static struct parse_task tasks[STARPU_NMAXWORKERS];
  2028. struct starpu_data_trace_kernel
  2029. {
  2030. UT_hash_handle hh;
  2031. char *name;
  2032. FILE *file;
  2033. } *kernels;
  2034. #define NANO_SEC_TO_MILI_SEC 0.000001
  2035. static FILE *codelet_list;
  2036. static void write_task(struct parse_task pt)
  2037. {
  2038. struct starpu_data_trace_kernel *kernel;
  2039. char *codelet_name = pt.codelet_name;
  2040. HASH_FIND_STR(kernels, codelet_name, kernel);
  2041. //fprintf(stderr, "%p %p %s\n", kernel, kernels, codelet_name);
  2042. if(kernel == NULL)
  2043. {
  2044. kernel = malloc(sizeof(*kernel));
  2045. kernel->name = strdup(codelet_name);
  2046. //fprintf(stderr, "%s\n", kernel->name);
  2047. kernel->file = fopen(codelet_name, "w+");
  2048. if(!kernel->file)
  2049. {
  2050. perror("open failed :");
  2051. exit(-1);
  2052. }
  2053. HASH_ADD_STR(kernels, name, kernel);
  2054. fprintf(codelet_list, "%s\n", codelet_name);
  2055. }
  2056. double time = pt.exec_time * NANO_SEC_TO_MILI_SEC;
  2057. fprintf(kernel->file, "%lf %d\n", time, pt.data_total);
  2058. }
  2059. void starpu_fxt_write_data_trace(char *filename_in)
  2060. {
  2061. int fd_in;
  2062. fd_in = open(filename_in, O_RDONLY);
  2063. if (fd_in < 0)
  2064. {
  2065. perror("open failed :");
  2066. exit(-1);
  2067. }
  2068. static fxt_t fut;
  2069. fut = fxt_fdopen(fd_in);
  2070. if (!fut)
  2071. {
  2072. perror("fxt_fdopen :");
  2073. exit(-1);
  2074. }
  2075. codelet_list = fopen("codelet_list", "w+");
  2076. if(!codelet_list)
  2077. {
  2078. perror("open failed :");
  2079. exit(-1);
  2080. }
  2081. fxt_blockev_t block;
  2082. block = fxt_blockev_enter(fut);
  2083. struct fxt_ev_64 ev;
  2084. int workerid=-1;
  2085. unsigned long has_name = 0;
  2086. while(1)
  2087. {
  2088. int ret = fxt_next_ev(block, FXT_EV_TYPE_64, (struct fxt_ev *)&ev);
  2089. if (ret != FXT_EV_OK)
  2090. {
  2091. break;
  2092. }
  2093. switch (ev.code)
  2094. {
  2095. case _STARPU_FUT_WORKER_INIT_START:
  2096. register_worker_id(ev.param[5], ev.param[1], ev.param[4]);
  2097. break;
  2098. case _STARPU_FUT_START_CODELET_BODY:
  2099. workerid = ev.param[2];
  2100. tasks[workerid].exec_time = ev.time;
  2101. has_name = ev.param[3];
  2102. tasks[workerid].codelet_name = strdup(has_name ? (char *) &ev.param[4] : "unknown");
  2103. //fprintf(stderr, "start codelet :[%d][%s]\n", workerid, tasks[workerid].codelet_name);
  2104. break;
  2105. case _STARPU_FUT_END_CODELET_BODY:
  2106. workerid = ev.param[6];
  2107. assert(workerid != -1);
  2108. tasks[workerid].exec_time = ev.time - tasks[workerid].exec_time;
  2109. write_task(tasks[workerid]);
  2110. break;
  2111. case _STARPU_FUT_DATA_LOAD:
  2112. workerid = ev.param[0];
  2113. tasks[workerid].data_total = ev.param[1];
  2114. break;
  2115. default:
  2116. #ifdef STARPU_VERBOSE
  2117. fprintf(stderr, "unknown event.. %x at time %llx WITH OFFSET %llx\n",
  2118. (unsigned)ev.code, (long long unsigned)ev.time, (long long unsigned)(ev.time));
  2119. #endif
  2120. break;
  2121. }
  2122. }
  2123. if (close(fd_in))
  2124. {
  2125. perror("close failed :");
  2126. exit(-1);
  2127. }
  2128. if(fclose(codelet_list))
  2129. {
  2130. perror("close failed :");
  2131. exit(-1);
  2132. }
  2133. struct starpu_data_trace_kernel *kernel, *tmp;
  2134. HASH_ITER(hh, kernels, kernel, tmp)
  2135. {
  2136. if(fclose(kernel->file))
  2137. {
  2138. perror("close failed :");
  2139. exit(-1);
  2140. }
  2141. HASH_DEL(kernels, kernel);
  2142. free(kernel->name);
  2143. free(kernel);
  2144. }
  2145. }
  2146. #endif // STARPU_USE_FXT