starpu_fxt.c 117 KB

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