starpu_fxt.c 85 KB

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