starpu_fxt.c 140 KB

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