starpu_fxt.c 134 KB

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