starpu_replay.c 20 KB

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