starpu_replay.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2017 Erwan Leria
  4. * Copyright (C) 2017, 2018 CNRS
  5. * Copyright (C) 2016-2018 Université de Bordeaux
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. /*
  19. * This reads a tasks.rec file and replays the recorded task graph.
  20. * Currently, this version is done to run with simgrid.
  21. *
  22. * For further information, contact erwan.leria@inria.fr
  23. */
  24. #include <starpu.h>
  25. #include <unistd.h>
  26. #include <stdio.h>
  27. #include <math.h>
  28. #include <common/uthash.h>
  29. #include <common/utils.h>
  30. #include <starpu_scheduler.h>
  31. #include <common/rbtree.h>
  32. #define REPLAY_NMAX_DEPENDENCIES 8
  33. #define ARRAY_DUP(in, out, n) memcpy(out, in, n * sizeof(*out))
  34. #define ARRAY_INIT(array, n) memset(array, 0, n * sizeof(*array))
  35. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  36. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  37. * Declarations of global variables, structures, pointers, ... *
  38. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  39. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  40. static int static_workerid;
  41. /* TODO: move to core header while moving starpu_replay_sched to core */
  42. extern void schedRecInit(const char * filename);
  43. extern void applySchedRec(struct starpu_task * starpu_task, unsigned long submit_order);
  44. /* Enum for normal and "wontuse" tasks */
  45. enum task_type {NormalTask, WontUseTask};
  46. typedef unsigned long jobid_t;
  47. enum task_type control;
  48. static char *name = NULL;
  49. static char *model = NULL;
  50. static jobid_t jobid;
  51. static jobid_t *dependson;
  52. static long submitorder = -1;
  53. static starpu_tag_t tag;
  54. static int workerid;
  55. static uint32_t footprint;
  56. static double flops;
  57. static double startTime; //start time (The instant when the task starts)
  58. static double endTime; //end time (The instant when the task ends)
  59. static int iteration = -1;
  60. static starpu_data_handle_t handles[STARPU_NMAXBUFS];
  61. static enum starpu_data_access_mode modes[STARPU_NMAXBUFS];
  62. static char normal_reg_signal[STARPU_NMAXBUFS];
  63. /* Use the following arrays when the number of data is greater than STARPU_NMAXBUFS */
  64. starpu_data_handle_t * handles_ptr;
  65. enum starpu_data_access_mode * modes_ptr;
  66. size_t * sizes_set;
  67. static size_t dependson_size;
  68. static size_t ndependson;
  69. static unsigned nb_parameters = 0; /* Number of parameters */
  70. static int alloc_mode; /* If alloc_mode value is 1, then the handles are stored in dyn_handles, else they are in handles */
  71. static int priority = 0;
  72. char * reg_signal = NULL; /* The register signal (0 or 1 coded on 8 bit) is used to know which handle of the task has to be registered in StarPU (in fact to avoid handle twice)*/
  73. static int device;
  74. /* Record all tasks, hashed by jobid. */
  75. static struct task
  76. {
  77. struct starpu_rbtree_node node;
  78. UT_hash_handle hh;
  79. jobid_t jobid;
  80. int iteration;
  81. unsigned long submit_order;
  82. jobid_t *deps;
  83. size_t ndependson;
  84. struct starpu_task task;
  85. enum task_type type;
  86. int reg_signal;
  87. } *tasks;
  88. /* Record handles */
  89. static struct handle
  90. {
  91. UT_hash_handle hh;
  92. starpu_data_handle_t mem_ptr; /* This value should be the registered handle */
  93. starpu_data_handle_t handle; /* The key is the original value of the handle in the file */
  94. } * handles_hash;
  95. /* Record models */
  96. static struct perfmodel
  97. {
  98. UT_hash_handle hh;
  99. struct starpu_perfmodel perfmodel;
  100. char * model_name;
  101. } * model_hash;
  102. /* [SUBMITORDER] The tree of the submit order */
  103. static struct starpu_rbtree tree = STARPU_RBTREE_INITIALIZER;
  104. /* the cmp_fn arg for rb_tree_insert() */
  105. unsigned int diff(struct starpu_rbtree_node * left_elm, struct starpu_rbtree_node * right_elm)
  106. {
  107. return ((struct task *) left_elm)->submit_order - ((struct task *) right_elm)->submit_order;
  108. }
  109. /* Settings for the perfmodel */
  110. struct task_arg
  111. {
  112. uint32_t footprint;
  113. double perf[];
  114. };
  115. uint32_t get_footprint(struct starpu_task * task)
  116. {
  117. return ((struct task_arg*) (task->cl_arg))->footprint;
  118. }
  119. double arch_cost_function(struct starpu_task *task, struct starpu_perfmodel_arch *arch, unsigned nimpl)
  120. {
  121. device = starpu_perfmodel_arch_comb_get(arch->ndevices, arch->devices);
  122. STARPU_ASSERT(device != -1);
  123. /* Then, get the pointer to the value of the expected time */
  124. double * val = (double *) ((struct task_arg *) (task->cl_arg))->perf+device;
  125. if (!(*val == 0 || isnan(*val)))
  126. return *val;
  127. fprintf(stderr, "[starpu] Error, expected_time is 0 or lower (replay.c line : %d)", __LINE__- 6);
  128. return 0.0;
  129. }
  130. /* End of settings */
  131. void dumb_kernel(void) {}
  132. /* [CODELET] Initialization of an unique codelet for all the tasks*/
  133. static int can_execute(unsigned worker_id, struct starpu_task *task, unsigned nimpl)
  134. {
  135. struct starpu_perfmodel_arch * arch = starpu_worker_get_perf_archtype(worker_id, STARPU_NMAX_SCHED_CTXS);
  136. double expected_time = ((struct task_arg *) (task->cl_arg))->perf[starpu_perfmodel_arch_comb_get(arch->ndevices, arch->devices)];
  137. if (!(expected_time == 0 || isnan(expected_time)))
  138. {
  139. return 1;
  140. }
  141. return 0;
  142. }
  143. static struct starpu_perfmodel myperfmodel =
  144. {
  145. .type = STARPU_PER_ARCH,
  146. .arch_cost_function = arch_cost_function,
  147. .footprint = get_footprint,
  148. };
  149. static struct starpu_codelet cl =
  150. {
  151. .cpu_funcs = { (void*) 1 },
  152. .cpu_funcs_name = { "dumb_kernel" },
  153. .cuda_funcs = { (void*) 1 },
  154. .opencl_funcs = { (void*) 1 },
  155. .nbuffers = STARPU_VARIABLE_NBUFFERS,
  156. .can_execute = can_execute,
  157. .model = &myperfmodel,
  158. };
  159. /* * * * * * * * * * * * * *
  160. * * * * * Functions * * * * *
  161. * * * * * * * * * * * * * * */
  162. /* The following function checks if the program has to use static or dynamic arrays*/
  163. static int set_alloc_mode(int total_parameters)
  164. {
  165. return total_parameters <= STARPU_NMAXBUFS;
  166. }
  167. /* According to the allocation mode, modify handles_ptr and modes_ptr in static or dynamic */
  168. static void arrays_managing(int mode)
  169. {
  170. if (mode)
  171. {
  172. handles_ptr = &handles[0];
  173. modes_ptr = &modes[0];
  174. reg_signal = &normal_reg_signal[0];
  175. }
  176. else
  177. {
  178. _STARPU_MALLOC(handles_ptr, sizeof(*handles_ptr) * nb_parameters);
  179. _STARPU_MALLOC(modes_ptr, sizeof(*modes_ptr) * nb_parameters);
  180. _STARPU_CALLOC(reg_signal, nb_parameters, sizeof(char *));
  181. }
  182. }
  183. /* Check if a handle hasn't been registered yet */
  184. static void variable_data_register_check(size_t * array_of_size, int nb_handles)
  185. {
  186. int h;
  187. for (h = 0 ; h < nb_handles ; h++)
  188. {
  189. if(reg_signal[h]) /* Get the register signal, if it's 1 do ... */
  190. {
  191. struct handle * handles_cell;
  192. _STARPU_MALLOC(handles_cell, sizeof(*handles_cell));
  193. STARPU_ASSERT(handles_cell != NULL);
  194. handles_cell->handle = handles_ptr[h]; /* Get the hidden key (initial handle from the file) to store it as a key*/
  195. starpu_variable_data_register(handles_ptr+h, STARPU_MAIN_RAM, (uintptr_t) 1, array_of_size[h]);
  196. handles_cell->mem_ptr = handles_ptr[h]; /* Store the new value of the handle into the hash table */
  197. HASH_ADD(hh, handles_hash, handle, sizeof(handles_ptr[h]), handles_cell);
  198. }
  199. }
  200. }
  201. void reset(void)
  202. {
  203. control = NormalTask;
  204. if (name != NULL)
  205. {
  206. free(name);
  207. name = NULL;
  208. }
  209. if (model != NULL)
  210. {
  211. free(model);
  212. model = NULL;
  213. }
  214. if (sizes_set != NULL)
  215. {
  216. free(sizes_set);
  217. sizes_set = NULL;
  218. }
  219. if (reg_signal != NULL)
  220. {
  221. if (!alloc_mode)
  222. {
  223. free(reg_signal);
  224. reg_signal = NULL;
  225. }
  226. else
  227. {
  228. ARRAY_INIT(reg_signal, nb_parameters);
  229. }
  230. }
  231. jobid = 0;
  232. ndependson = 0;
  233. tag = -1;
  234. workerid = -1;
  235. footprint = 0;
  236. startTime = 0.0;
  237. endTime = 0.0;
  238. if (submitorder != -1)
  239. submitorder = -1;
  240. iteration = -1;
  241. nb_parameters = 0;
  242. alloc_mode = 1;
  243. }
  244. void fix_wontuse_handle(struct task * wontuseTask)
  245. {
  246. if (!wontuseTask->reg_signal)
  247. /* Data was already registered when we created this task, so it's already a handle */
  248. return;
  249. struct handle *handle_tmp;
  250. STARPU_ASSERT(wontuseTask);
  251. /* Data was not registered when we created this task, so this is the application pointer, look it up now */
  252. HASH_FIND(hh, handles_hash, &wontuseTask->task.handles[0], sizeof(wontuseTask->task.handles[0]), handle_tmp);
  253. STARPU_ASSERT(handle_tmp);
  254. wontuseTask->task.handles[0] = handle_tmp->mem_ptr;
  255. }
  256. /* Function that submits all the tasks (used when the program reaches EOF) */
  257. int submit_tasks(void)
  258. {
  259. /* Add dependencies */
  260. const struct starpu_rbtree * tmptree = &tree;
  261. struct starpu_rbtree_node * currentNode = starpu_rbtree_first(tmptree);
  262. unsigned long last_submitorder = 0;
  263. while (currentNode != NULL)
  264. {
  265. struct task * currentTask = (struct task *) currentNode;
  266. if (currentTask->type == NormalTask)
  267. {
  268. STARPU_ASSERT(currentTask->submit_order >= last_submitorder + 1);
  269. while (currentTask->submit_order > last_submitorder + 1)
  270. {
  271. /* Oops, some tasks were not submitted by original application, fake some */
  272. struct starpu_task *task = starpu_task_create();
  273. int ret;
  274. task->cl = NULL;
  275. ret = starpu_task_submit(task);
  276. STARPU_ASSERT(ret == 0);
  277. last_submitorder++;
  278. }
  279. if (currentTask->ndependson > 0)
  280. {
  281. struct starpu_task * taskdeps[currentTask->ndependson];
  282. unsigned i, j = 0;
  283. for (i = 0; i < currentTask->ndependson; i++)
  284. {
  285. struct task * taskdep;
  286. /* Get the ith jobid of deps_jobid */
  287. HASH_FIND(hh, tasks, &currentTask->deps[i], sizeof(jobid), taskdep);
  288. if(taskdep)
  289. {
  290. taskdeps[j] = &taskdep->task;
  291. j ++;
  292. }
  293. }
  294. starpu_task_declare_deps_array(&currentTask->task, j, taskdeps);
  295. }
  296. if (!(currentTask->iteration == -1))
  297. starpu_iteration_push(currentTask->iteration);
  298. applySchedRec(&currentTask->task, currentTask->submit_order);
  299. int ret_val = starpu_task_submit(&currentTask->task);
  300. if (!(currentTask->iteration == -1))
  301. starpu_iteration_pop();
  302. if (ret_val != 0)
  303. {
  304. printf("\nWhile submitting task %lu: return %d\n", currentTask->submit_order, ret_val);
  305. return -1;
  306. }
  307. //printf("submitting task %s (%lu, %llu)\n", currentTask->task.name?currentTask->task.name:"anonymous", currentTask->jobid, (unsigned long long) currentTask->task.tag_id);
  308. printf("\rSubmitting task %lu", currentTask->submit_order);
  309. last_submitorder++;
  310. }
  311. else
  312. {
  313. fix_wontuse_handle(currentTask); /* Add the handle in the wontuse task */
  314. /* FIXME: can not actually work properly since we have
  315. * disabled sequential consistency, so we don't have any
  316. * easy way to make this wait for the last task that
  317. * wrote to the handle. */
  318. starpu_data_wont_use(currentTask->task.handles[0]);
  319. }
  320. currentNode = starpu_rbtree_next(currentNode);
  321. }
  322. printf("\n");
  323. return 1;
  324. }
  325. /* * * * * * * * * * * * * * * */
  326. /* * * * * * MAIN * * * * * * */
  327. /* * * * * * * * * * * * * * */
  328. static void usage(const char *program)
  329. {
  330. fprintf(stderr,"Usage: %s [--static-workerid] tasks.rec [sched.rec]\n", program);
  331. exit(EXIT_FAILURE);
  332. }
  333. int main(int argc, char **argv)
  334. {
  335. starpu_data_set_default_sequential_consistency_flag(0);
  336. FILE *rec;
  337. char *s;
  338. const char *tasks_rec = NULL;
  339. const char *sched_rec = NULL;
  340. unsigned i;
  341. size_t s_allocated = 128;
  342. _STARPU_MALLOC(s, s_allocated);
  343. dependson_size = REPLAY_NMAX_DEPENDENCIES; /* Change the value of REPLAY_NMAX_DEPENCIES to modify the number of dependencies */
  344. _STARPU_MALLOC(dependson, dependson_size * sizeof (* dependson));
  345. alloc_mode = 1;
  346. for (i = 1; i < (unsigned) argc; i++)
  347. {
  348. if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h"))
  349. {
  350. usage(argv[0]);
  351. }
  352. else if (!strcmp(argv[i], "--static-workerid"))
  353. {
  354. static_workerid = 1;
  355. }
  356. else
  357. {
  358. if (!tasks_rec)
  359. tasks_rec = argv[i];
  360. else if (!sched_rec)
  361. sched_rec = argv[i];
  362. else
  363. usage(argv[0]);
  364. }
  365. }
  366. if (!tasks_rec)
  367. usage(argv[0]);
  368. if (sched_rec)
  369. schedRecInit(sched_rec);
  370. rec = fopen(tasks_rec, "r");
  371. if (!rec)
  372. {
  373. fprintf(stderr,"unable to open file %s: %s\n", tasks_rec, strerror(errno));
  374. exit(EXIT_FAILURE);
  375. }
  376. int ret = starpu_init(NULL);
  377. if (ret == -ENODEV) goto enodev;
  378. /* Read line by line, and on empty line submit the task with the accumulated information */
  379. reset();
  380. double start = starpu_timing_now();
  381. while(1)
  382. {
  383. char *ln;
  384. if (!fgets(s, s_allocated, rec))
  385. {
  386. int submitted = submit_tasks();
  387. if (submitted == -1)
  388. {
  389. goto enodev;
  390. }
  391. goto eof;
  392. }
  393. while (!(ln = strchr(s, '\n')))
  394. {
  395. /* fprintf(stderr,"buffer size %d too small, doubling it\n", s_allocated); */
  396. _STARPU_REALLOC(s, s_allocated * 2);
  397. if (!fgets(s + s_allocated-1, s_allocated+1, rec))
  398. {
  399. int submitted = submit_tasks();
  400. if (submitted == -1)
  401. {
  402. goto enodev;
  403. }
  404. goto eof;
  405. }
  406. s_allocated *= 2;
  407. }
  408. if (ln == s)
  409. {
  410. /* Empty line, do task */
  411. struct task * task;
  412. _STARPU_MALLOC(task, sizeof(*task));
  413. starpu_task_init(&task->task);
  414. task->deps = NULL;
  415. if (submitorder != -1)
  416. {
  417. task->submit_order = submitorder;
  418. starpu_rbtree_node_init(&task->node);
  419. starpu_rbtree_insert(&tree, &task->node, diff);
  420. }
  421. task->jobid = jobid;
  422. task->iteration = iteration;
  423. if (name != NULL)
  424. task->task.name = strdup(name);
  425. task->type = control;
  426. if (control == NormalTask)
  427. {
  428. if (workerid >= 0)
  429. {
  430. task->task.priority = priority;
  431. task->task.cl = &cl;
  432. if (static_workerid)
  433. {
  434. task->task.workerid = workerid;
  435. task->task.execute_on_a_specific_worker = 1;
  436. }
  437. if (alloc_mode)
  438. {
  439. /* Duplicating the handles stored (and registered in the current context) into the task */
  440. ARRAY_DUP(modes_ptr, task->task.modes, nb_parameters);
  441. ARRAY_DUP(modes_ptr, task->task.cl->modes, nb_parameters);
  442. variable_data_register_check(sizes_set, nb_parameters);
  443. ARRAY_DUP(handles_ptr, task->task.handles, nb_parameters);
  444. }
  445. else
  446. {
  447. task->task.dyn_modes = modes_ptr;
  448. _STARPU_MALLOC(task->task.cl->dyn_modes, (sizeof(*task->task.cl->dyn_modes) * nb_parameters));
  449. ARRAY_DUP(modes_ptr, task->task.cl->dyn_modes, nb_parameters);
  450. variable_data_register_check(sizes_set, nb_parameters);
  451. task->task.dyn_handles = handles_ptr;
  452. }
  453. task->task.nbuffers = nb_parameters;
  454. struct perfmodel * realmodel;
  455. HASH_FIND_STR(model_hash, model, realmodel);
  456. if (realmodel == NULL)
  457. {
  458. int len = strlen(model);
  459. _STARPU_CALLOC(realmodel, 1, sizeof(struct perfmodel));
  460. _STARPU_MALLOC(realmodel->model_name, sizeof(char) * (len+1));
  461. realmodel->model_name = strcpy(realmodel->model_name, model);
  462. starpu_perfmodel_init(&realmodel->perfmodel);
  463. HASH_ADD_STR(model_hash, model_name, realmodel);
  464. int error = starpu_perfmodel_load_symbol(model, &realmodel->perfmodel);
  465. if (error)
  466. {
  467. fprintf(stderr, "[starpu][Warning] Error loading perfmodel symbol %s\n", model);
  468. exit(EXIT_FAILURE);
  469. }
  470. }
  471. unsigned narch = starpu_perfmodel_get_narch_combs();
  472. struct task_arg *arg;
  473. _STARPU_MALLOC(arg, sizeof(struct task_arg) + sizeof(double) * narch);
  474. arg->footprint = footprint;
  475. double * perfTime = arg->perf;
  476. for (i = 0; i < narch ; i++)
  477. {
  478. struct starpu_perfmodel_arch *arch = starpu_perfmodel_arch_comb_fetch(i);
  479. perfTime[i] = starpu_perfmodel_history_based_expected_perf(&realmodel->perfmodel, arch, footprint);
  480. }
  481. task->task.cl_arg = arg;
  482. task->task.flops = flops;
  483. }
  484. task->task.cl_arg_size = 0;
  485. task->task.tag_id = tag;
  486. task->task.use_tag = 1;
  487. task->ndependson = ndependson;
  488. if (ndependson > 0)
  489. {
  490. _STARPU_MALLOC(task->deps, ndependson * sizeof (* task->deps));
  491. ARRAY_DUP(dependson, task->deps, ndependson);
  492. }
  493. }
  494. else
  495. {
  496. STARPU_ASSERT(nb_parameters == 1);
  497. task->reg_signal = reg_signal[0];
  498. ARRAY_DUP(handles_ptr, task->task.handles, nb_parameters);
  499. }
  500. /* Add this task to task hash */
  501. HASH_ADD(hh, tasks, jobid, sizeof(jobid), task);
  502. reset();
  503. }
  504. /* Record various information */
  505. #define TEST(field) (!strncmp(s, field": ", strlen(field) + 2))
  506. else if(TEST("Control"))
  507. {
  508. char * c = s+9;
  509. if(!strncmp(c, "WontUse", 7))
  510. {
  511. control = WontUseTask;
  512. nb_parameters = 1;
  513. alloc_mode = set_alloc_mode(nb_parameters);
  514. arrays_managing(alloc_mode);
  515. }
  516. else
  517. control = NormalTask;
  518. }
  519. else if (TEST("Name"))
  520. {
  521. *ln = 0;
  522. name = strdup(s+6);
  523. }
  524. else if (TEST("Model"))
  525. {
  526. *ln = 0;
  527. model = strdup(s+7);
  528. }
  529. else if (TEST("JobId"))
  530. jobid = atol(s+7);
  531. else if(TEST("SubmitOrder"))
  532. submitorder = atoi(s+13);
  533. else if (TEST("DependsOn"))
  534. {
  535. char *c = s + 11;
  536. for (ndependson = 0; *c != '\n'; ndependson++)
  537. {
  538. if (ndependson >= dependson_size)
  539. {
  540. dependson_size *= 2;
  541. _STARPU_REALLOC(dependson, dependson_size * sizeof(*dependson));
  542. }
  543. dependson[ndependson] = strtol(c, &c, 10);
  544. }
  545. }
  546. else if (TEST("Tag"))
  547. {
  548. tag = strtol(s+5, NULL, 16);
  549. }
  550. else if (TEST("WorkerId"))
  551. {
  552. workerid = atoi(s+10);
  553. }
  554. else if (TEST("Footprint"))
  555. {
  556. footprint = strtoul(s+11, NULL, 16);
  557. }
  558. else if (TEST("Parameters"))
  559. {
  560. /* Parameters line format is PARAM1_PARAM2_(...)PARAMi_(...)PARAMn */
  561. char * param_str = s + 12;
  562. int count = 0;
  563. for (i = 0 ; param_str[i] != '\n'; i++)
  564. {
  565. if (param_str[i] == '_') /* Checking the number of '_' (underscore), assuming that the file is not corrupted */
  566. {
  567. count++;
  568. }
  569. }
  570. nb_parameters = count + 1; /* There is one underscore per paramater execept for the last one, that's why we have to add +1 (dirty programming) */
  571. /* This part of the algorithm will determine if it needs static or dynamic arrays */
  572. alloc_mode = set_alloc_mode(nb_parameters);
  573. arrays_managing(alloc_mode);
  574. }
  575. else if (TEST("Handles"))
  576. {
  577. char *buffer = s + 9;
  578. const char *delim = " ";
  579. char *token = strtok(buffer, delim);
  580. while (token != NULL)
  581. {
  582. for (i = 0 ; i < nb_parameters ; i++)
  583. {
  584. struct handle *handles_cell; /* A cell of the hash table for the handles */
  585. starpu_data_handle_t handle_value = (starpu_data_handle_t) strtol(token, NULL, 16); /* Get the ith handle on the line (in the file) */
  586. HASH_FIND(hh, handles_hash, &handle_value, sizeof(handle_value), handles_cell); /* Find if the handle_value was already registered as a key in the hash table */
  587. /* If it wasn't, then add it to the hash table */
  588. if (handles_cell == NULL)
  589. {
  590. /* Hide the initial handle from the file into the handles array to find it when necessary */
  591. handles_ptr[i] = handle_value;
  592. reg_signal[i] = 1;
  593. }
  594. else
  595. {
  596. handles_ptr[i] = handles_cell->mem_ptr;
  597. reg_signal[i] = 0;
  598. }
  599. token = strtok(NULL, delim);
  600. }
  601. }
  602. }
  603. else if (TEST("Modes"))
  604. {
  605. char * buffer = s + 7;
  606. int mode_i = 0;
  607. const char * delim = " ";
  608. char * token = strtok(buffer, delim);
  609. while (token != NULL)
  610. {
  611. /* Subject to the names of starpu modes enumerator are not modified */
  612. if (!strncmp(token, "RW", 2))
  613. {
  614. *(modes_ptr+mode_i) = STARPU_RW;
  615. mode_i++;
  616. }
  617. else if (!strncmp(token, "R", 1))
  618. {
  619. *(modes_ptr+mode_i) = STARPU_R;
  620. mode_i++;
  621. }
  622. else if (!strncmp(token, "W", 1))
  623. {
  624. *(modes_ptr+mode_i) = STARPU_W;
  625. mode_i++;
  626. }
  627. /* Other cases produce a warning*/
  628. else
  629. {
  630. fprintf(stderr, "[Warning] A mode is different from R/W (jobid task : %lu)", jobid);
  631. }
  632. token = strtok(NULL, delim);
  633. }
  634. }
  635. else if (TEST("Sizes"))
  636. {
  637. char * buffer = s + 7;
  638. const char * delim = " ";
  639. char * token = strtok(buffer, delim);
  640. int k = 0;
  641. _STARPU_MALLOC(sizes_set, nb_parameters * sizeof(size_t));
  642. while (token != NULL)
  643. {
  644. sizes_set[k] = strtol(token, NULL, 10);
  645. token = strtok(NULL, delim);
  646. k++;
  647. }
  648. }
  649. else if (TEST("StartTime"))
  650. {
  651. startTime = strtod(s+11, NULL);
  652. }
  653. else if (TEST("EndTime"))
  654. {
  655. endTime = strtod(s+9, NULL);
  656. }
  657. else if (TEST("GFlop"))
  658. {
  659. flops = 1000000000 * strtod(s+7, NULL);
  660. }
  661. else if (TEST("Iteration"))
  662. {
  663. iteration = (unsigned) strtol(s+11, NULL, 10);
  664. }
  665. else if (TEST("Priority"))
  666. {
  667. priority = strtol(s + 10, NULL, 10);
  668. }
  669. }
  670. eof:
  671. starpu_task_wait_for_all();
  672. printf("Simulation ended. Elapsed time: %g µs\n", starpu_timing_now() - start);
  673. /* FREE allocated memory */
  674. free(dependson);
  675. free(s);
  676. /* End of FREE */
  677. struct handle * handle,* handletmp;
  678. HASH_ITER(hh, handles_hash, handle, handletmp)
  679. {
  680. starpu_data_unregister(handle->mem_ptr);
  681. HASH_DEL(handles_hash, handle);
  682. free(handle);
  683. }
  684. struct perfmodel * model_s, * modeltmp;
  685. HASH_ITER(hh, model_hash, model_s, modeltmp)
  686. {
  687. starpu_perfmodel_unload_model(&model_s->perfmodel);
  688. HASH_DEL(model_hash, model_s);
  689. free(model_s->model_name);
  690. free(model_s);
  691. }
  692. struct task * task, *tasktmp;
  693. HASH_ITER(hh, tasks, task, tasktmp)
  694. {
  695. free(task->task.cl_arg);
  696. free((char*)task->task.name);
  697. if (task->task.dyn_handles != NULL)
  698. {
  699. free(task->task.dyn_handles);
  700. free(task->task.dyn_modes);
  701. }
  702. HASH_DEL(tasks, task);
  703. starpu_task_clean(&task->task);
  704. free(task->deps);
  705. starpu_rbtree_remove(&tree, &task->node);
  706. free(task);
  707. }
  708. starpu_shutdown();
  709. return 0;
  710. enodev:
  711. return 77;
  712. }