starpu_fxt.c 117 KB

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