starpu_fxt.c 118 KB

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