starpu_replay.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835
  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)
  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)
  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. STARPU_ASSERT(wontuseTask);
  245. HASH_FIND(hh, handles_hash, &wontuseTask->task.handles[0], sizeof(wontuseTask->task.handles[0]), handle_tmp);
  246. STARPU_ASSERT(handle_tmp);
  247. wontuseTask->task.handles[0] = handle_tmp->mem_ptr;
  248. }
  249. /* Function that submits all the tasks (used when the program reaches EOF) */
  250. int submit_tasks(void)
  251. {
  252. /* Add dependencies */
  253. const struct starpu_rbtree * tmptree = &tree;
  254. struct starpu_rbtree_node * currentNode = starpu_rbtree_first(tmptree);
  255. unsigned long last_submitorder = 0;
  256. while (currentNode != NULL)
  257. {
  258. struct task * currentTask = (struct task *) currentNode;
  259. if (currentTask->type == NormalTask)
  260. {
  261. STARPU_ASSERT(currentTask->submit_order >= last_submitorder + 1);
  262. while (currentTask->submit_order > last_submitorder + 1)
  263. {
  264. /* Oops, some tasks were not submitted by original application, fake some */
  265. struct starpu_task *task = starpu_task_create();
  266. int ret;
  267. task->cl = NULL;
  268. ret = starpu_task_submit(task);
  269. STARPU_ASSERT(ret == 0);
  270. last_submitorder++;
  271. }
  272. if (currentTask->ndependson > 0)
  273. {
  274. struct starpu_task * taskdeps[currentTask->ndependson];
  275. unsigned i;
  276. for (i = 0; i < currentTask->ndependson; i++)
  277. {
  278. struct task * taskdep;
  279. /* Get the ith jobid of deps_jobid */
  280. HASH_FIND(hh, tasks, &currentTask->deps[i], sizeof(jobid), taskdep);
  281. STARPU_ASSERT(taskdep);
  282. taskdeps[i] = &taskdep->task;
  283. }
  284. starpu_task_declare_deps_array(&currentTask->task, currentTask->ndependson, taskdeps);
  285. }
  286. if (!(currentTask->iteration == -1))
  287. starpu_iteration_push(currentTask->iteration);
  288. applySchedRec(&currentTask->task, currentTask->submit_order);
  289. int ret_val = starpu_task_submit(&currentTask->task);
  290. if (!(currentTask->iteration == -1))
  291. starpu_iteration_pop();
  292. if (ret_val != 0)
  293. return -1;
  294. //printf("submitting task %s (%lu, %llu)\n", currentTask->task.name?currentTask->task.name:"anonymous", currentTask->jobid, (unsigned long long) currentTask->task.tag_id);
  295. printf("\rsubmitting task %lu", currentTask->submit_order);
  296. last_submitorder++;
  297. }
  298. else
  299. {
  300. fix_wontuse_handle(currentTask); /* Add the handle in the wontuse task */
  301. /* FIXME: can not actually work properly since we have
  302. * disabled sequential consistency, so we don't have any
  303. * easy way to make this wait for the last task that
  304. * wrote to the handle. */
  305. starpu_data_wont_use(currentTask->task.handles[0]);
  306. }
  307. currentNode = starpu_rbtree_next(currentNode);
  308. }
  309. printf("\n");
  310. return 1;
  311. }
  312. /* * * * * * * * * * * * * * * */
  313. /* * * * * * MAIN * * * * * * */
  314. /* * * * * * * * * * * * * * */
  315. int main(int argc, char **argv)
  316. {
  317. starpu_data_set_default_sequential_consistency_flag(0);
  318. FILE *rec;
  319. char *s;
  320. size_t s_allocated = 128;
  321. _STARPU_MALLOC(s, s_allocated);
  322. dependson_size = REPLAY_NMAX_DEPENDENCIES; /* Change the value of REPLAY_NMAX_DEPENCIES to modify the number of dependencies */
  323. _STARPU_MALLOC(dependson, dependson_size * sizeof (* dependson));
  324. alloc_mode = 1;
  325. if (argc <= 1)
  326. {
  327. fprintf(stderr,"Usage: %s tasks.rec [sched.rec]\n", argv[0]);
  328. exit(EXIT_FAILURE);
  329. }
  330. if (argc >= 3)
  331. schedRecInit(argv[2]);
  332. rec = fopen(argv[1], "r");
  333. if (!rec)
  334. {
  335. fprintf(stderr,"unable to open file %s: %s\n", argv[1], strerror(errno));
  336. exit(EXIT_FAILURE);
  337. }
  338. int ret = starpu_init(NULL);
  339. if (ret == -ENODEV) goto enodev;
  340. /* Read line by line, and on empty line submit the task with the accumulated information */
  341. reset();
  342. while(1)
  343. {
  344. char *ln;
  345. if (!fgets(s, s_allocated, rec))
  346. {
  347. int submitted = submit_tasks();
  348. if (submitted == -1)
  349. {
  350. goto enodev;
  351. }
  352. goto eof;
  353. }
  354. while (!(ln = strchr(s, '\n')))
  355. {
  356. /* fprintf(stderr,"buffer size %d too small, doubling it\n", s_allocated); */
  357. _STARPU_REALLOC(s, s_allocated * 2);
  358. if (!fgets(s + s_allocated-1, s_allocated+1, rec))
  359. {
  360. int submitted = submit_tasks();
  361. if (submitted == -1)
  362. {
  363. goto enodev;
  364. }
  365. goto eof;
  366. }
  367. s_allocated *= 2;
  368. }
  369. if (ln == s)
  370. {
  371. /* Empty line, do task */
  372. struct task * task;
  373. _STARPU_MALLOC(task, sizeof(*task));
  374. starpu_task_init(&task->task);
  375. task->deps = NULL;
  376. if (submitorder != -1)
  377. {
  378. task->submit_order = submitorder;
  379. starpu_rbtree_node_init(&task->node);
  380. starpu_rbtree_insert(&tree, &task->node, diff);
  381. }
  382. task->jobid = jobid;
  383. task->iteration = iteration;
  384. if (name != NULL)
  385. task->task.name = strdup(name);
  386. task->type = control;
  387. if (control == NormalTask)
  388. {
  389. if (workerid >= 0)
  390. {
  391. task->task.priority = priority;
  392. task->task.cl = &cl;
  393. task->task.workerid = workerid;
  394. if (alloc_mode)
  395. {
  396. /* Duplicating the handles stored (and registered in the current context) into the task */
  397. ARRAY_DUP(modes_ptr, task->task.modes, nb_parameters);
  398. ARRAY_DUP(modes_ptr, task->task.cl->modes, nb_parameters);
  399. variable_data_register_check(sizes_set, nb_parameters);
  400. ARRAY_DUP(handles_ptr, task->task.handles, nb_parameters);
  401. }
  402. else
  403. {
  404. task->task.dyn_modes = modes_ptr;
  405. _STARPU_MALLOC(task->task.cl->dyn_modes, (sizeof(*task->task.cl->dyn_modes) * nb_parameters));
  406. ARRAY_DUP(modes_ptr, task->task.cl->dyn_modes, nb_parameters);
  407. variable_data_register_check(sizes_set, nb_parameters);
  408. task->task.dyn_handles = handles_ptr;
  409. }
  410. task->task.nbuffers = nb_parameters;
  411. struct perfmodel * realmodel;
  412. HASH_FIND_STR(model_hash, model, realmodel);
  413. if (realmodel == NULL)
  414. {
  415. int len = strlen(model);
  416. _STARPU_CALLOC(realmodel, 1, sizeof(struct perfmodel));
  417. _STARPU_MALLOC(realmodel->model_name, sizeof(char) * (len+1));
  418. realmodel->model_name = strcpy(realmodel->model_name, model);
  419. starpu_perfmodel_init(&realmodel->perfmodel);
  420. HASH_ADD_STR(model_hash, model_name, realmodel);
  421. int error = starpu_perfmodel_load_symbol(model, &realmodel->perfmodel);
  422. if (error)
  423. {
  424. fprintf(stderr, "[starpu][Warning] Error loading perfmodel symbol %s\n", model);
  425. exit(EXIT_FAILURE);
  426. }
  427. }
  428. int narch = starpu_perfmodel_get_narch_combs();
  429. struct task_arg *arg;
  430. _STARPU_MALLOC(arg, sizeof(struct task_arg) + sizeof(double) * narch);
  431. arg->footprint = footprint;
  432. double * perfTime = arg->perf;
  433. int i;
  434. for (i = 0; i < narch ; i++)
  435. {
  436. struct starpu_perfmodel_arch *arch = starpu_perfmodel_arch_comb_fetch(i);
  437. perfTime[i] = starpu_perfmodel_history_based_expected_perf(&realmodel->perfmodel, arch, footprint);
  438. }
  439. task->task.cl_arg = arg;
  440. task->task.flops = flops;
  441. }
  442. task->task.cl_arg_size = 0;
  443. task->task.tag_id = tag;
  444. task->task.use_tag = 1;
  445. task->ndependson = ndependson;
  446. if (ndependson > 0)
  447. {
  448. _STARPU_MALLOC(task->deps, ndependson * sizeof (* task->deps));
  449. ARRAY_DUP(dependson, task->deps, ndependson);
  450. }
  451. }
  452. else
  453. {
  454. ARRAY_DUP(handles_ptr, task->task.handles, nb_parameters);
  455. }
  456. /* Add this task to task hash */
  457. HASH_ADD(hh, tasks, jobid, sizeof(jobid), task);
  458. reset();
  459. }
  460. /* Record various information */
  461. #define TEST(field) (!strncmp(s, field": ", strlen(field) + 2))
  462. else if(TEST("Control"))
  463. {
  464. char * c = s+9;
  465. if(!strncmp(c, "WontUse", 7))
  466. {
  467. control = WontUseTask;
  468. nb_parameters = 1;
  469. alloc_mode = set_alloc_mode(nb_parameters);
  470. arrays_managing(alloc_mode);
  471. }
  472. else
  473. control = NormalTask;
  474. }
  475. else if (TEST("Name"))
  476. {
  477. *ln = 0;
  478. name = strdup(s+6);
  479. }
  480. else if (TEST("Model"))
  481. {
  482. *ln = 0;
  483. model = strdup(s+7);
  484. }
  485. else if (TEST("JobId"))
  486. jobid = atol(s+7);
  487. else if(TEST("SubmitOrder"))
  488. submitorder = atoi(s+13);
  489. else if (TEST("DependsOn"))
  490. {
  491. char *c = s + 11;
  492. for (ndependson = 0; *c != '\n'; ndependson++)
  493. {
  494. if (ndependson >= dependson_size)
  495. {
  496. dependson_size *= 2;
  497. _STARPU_REALLOC(dependson, dependson_size * sizeof(*dependson));
  498. }
  499. dependson[ndependson] = strtol(c, &c, 10);
  500. }
  501. }
  502. else if (TEST("Tag"))
  503. tag = strtol(s+5, NULL, 16);
  504. else if (TEST("WorkerId"))
  505. workerid = atoi(s+10);
  506. else if (TEST("Footprint"))
  507. {
  508. footprint = strtoul(s+11, NULL, 16);
  509. }
  510. else if (TEST("Parameters"))
  511. {
  512. /* Parameters line format is PARAM1_PARAM2_(...)PARAMi_(...)PARAMn */
  513. char * param_str = s + 12;
  514. unsigned i;
  515. int count = 0;
  516. for (i = 0 ; param_str[i] != '\n'; i++)
  517. {
  518. if (param_str[i] == '_') /* Checking the number of '_' (underscore), assuming that the file is not corrupted */
  519. {
  520. count++;
  521. }
  522. }
  523. 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) */
  524. /* This part of the algorithm will determine if it needs static or dynamic arrays */
  525. alloc_mode = set_alloc_mode(nb_parameters);
  526. arrays_managing(alloc_mode);
  527. }
  528. else if (TEST("Handles"))
  529. {
  530. char *buffer = s + 9;
  531. const char *delim = " ";
  532. char *token = strtok(buffer, delim);
  533. while (token != NULL)
  534. {
  535. int i;
  536. for (i = 0 ; i < nb_parameters ; i++)
  537. {
  538. struct handle *handles_cell; /* A cell of the hash table for the handles */
  539. starpu_data_handle_t handle_value = (starpu_data_handle_t) strtol(token, NULL, 16); /* Get the ith handle on the line (in the file) */
  540. 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 */
  541. /* If it wasn't, then add it to the hash table */
  542. if (handles_cell == NULL)
  543. {
  544. /* Hide the initial handle from the file into the handles array to find it when necessary */
  545. handles_ptr[i] = handle_value;
  546. reg_signal[i] = 1;
  547. }
  548. else
  549. {
  550. handles_ptr[i] = handles_cell->mem_ptr;
  551. }
  552. token = strtok(NULL, delim);
  553. }
  554. }
  555. }
  556. else if (TEST("Modes"))
  557. {
  558. char * buffer = s + 7;
  559. int mode_i = 0;
  560. int i = 0;
  561. const char * delim = " ";
  562. char * token = strtok(buffer, delim);
  563. while (token != NULL)
  564. {
  565. /* Subject to the names of starpu modes enumerator are not modified */
  566. if (!strncmp(token, "RW", 2))
  567. {
  568. *(modes_ptr+mode_i) = STARPU_RW;
  569. mode_i++;
  570. i++;
  571. }
  572. else if (!strncmp(token, "R", 1))
  573. {
  574. *(modes_ptr+mode_i) = STARPU_R;
  575. mode_i++;
  576. }
  577. else if (!strncmp(token, "W", 1))
  578. {
  579. *(modes_ptr+mode_i) = STARPU_W;
  580. mode_i++;
  581. }
  582. /* Other cases produce a warning*/
  583. else
  584. {
  585. fprintf(stderr, "[Warning] A mode is different from R/W (jobid task : %lu)", jobid);
  586. }
  587. token = strtok(NULL, delim);
  588. }
  589. }
  590. else if (TEST("Sizes"))
  591. {
  592. char * buffer = s + 7;
  593. const char * delim = " ";
  594. char * token = strtok(buffer, delim);
  595. int k = 0;
  596. _STARPU_MALLOC(sizes_set, nb_parameters * sizeof(size_t));
  597. while (token != NULL)
  598. {
  599. sizes_set[k] = strtol(token, NULL, 10);
  600. token = strtok(NULL, delim);
  601. k++;
  602. }
  603. }
  604. else if (TEST("StartTime"))
  605. {
  606. startTime = strtod(s+11, NULL);
  607. }
  608. else if (TEST("EndTime"))
  609. {
  610. endTime = strtod(s+9, NULL);
  611. }
  612. else if (TEST("GFlop"))
  613. {
  614. flops = 1000000000 * strtod(s+7, NULL);
  615. }
  616. else if (TEST("Iteration"))
  617. {
  618. iteration = (unsigned) strtol(s+11, NULL, 10);
  619. }
  620. else if (TEST("Priority"))
  621. {
  622. priority = strtol(s + 10, NULL, 10);
  623. }
  624. }
  625. eof:
  626. starpu_task_wait_for_all();
  627. /* FREE allocated memory */
  628. free(dependson);
  629. free(s);
  630. /* End of FREE */
  631. struct handle * handle,* handletmp;
  632. HASH_ITER(hh, handles_hash, handle, handletmp)
  633. {
  634. starpu_data_unregister(handle->mem_ptr);
  635. HASH_DEL(handles_hash, handle);
  636. free(handle);
  637. }
  638. struct perfmodel * model_s, * modeltmp;
  639. HASH_ITER(hh, model_hash, model_s, modeltmp)
  640. {
  641. starpu_perfmodel_unload_model(&model_s->perfmodel);
  642. HASH_DEL(model_hash, model_s);
  643. free(model_s->model_name);
  644. free(model_s);
  645. }
  646. struct task * task, *tasktmp;
  647. HASH_ITER(hh, tasks, task, tasktmp)
  648. {
  649. free(task->task.cl_arg);
  650. free((char*)task->task.name);
  651. if (task->task.dyn_handles != NULL)
  652. {
  653. free(task->task.dyn_handles);
  654. free(task->task.dyn_modes);
  655. }
  656. HASH_DEL(tasks, task);
  657. starpu_task_clean(&task->task);
  658. free(task->deps);
  659. starpu_rbtree_remove(&tree, &task->node);
  660. free(task);
  661. }
  662. starpu_shutdown();
  663. return 0;
  664. enodev:
  665. return 77;
  666. }