starpu_fxt.c 85 KB

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