starpu_fxt.c 103 KB

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