starpu_fxt.c 140 KB

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