starpu_fxt.c 122 KB

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