starpu_fxt.c 100 KB

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