starpu_fxt.c 79 KB

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