starpu_replay.c 22 KB

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