starpu_fxt.c 118 KB

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