starpu_fxt.c 123 KB

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