starpu_replay.c 20 KB

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