parallel_heft.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012 INRIA
  4. * Copyright (C) 2010-2016 Université de Bordeaux
  5. * Copyright (C) 2011 Télécom-SudParis
  6. * Copyright (C) 2016 CNRS
  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. /* Distributed queues using performance modeling to assign tasks */
  20. #include <float.h>
  21. #include <limits.h>
  22. #include <core/workers.h>
  23. #include <core/perfmodel/perfmodel.h>
  24. #include <starpu_parameters.h>
  25. #include <core/detect_combined_workers.h>
  26. #include <core/sched_policy.h>
  27. #ifndef DBL_MIN
  28. #define DBL_MIN __DBL_MIN__
  29. #endif
  30. #ifndef DBL_MAX
  31. #define DBL_MAX __DBL_MAX__
  32. #endif
  33. /* if no priority is set when creating the scheduling context, we use the following ones */
  34. #define DEFAULT_MIN_PRIORITY 0
  35. #define DEFAULT_MAX_PRIORITY 1
  36. //static unsigned ncombinedworkers;
  37. //static enum starpu_perfmodel_archtype applicable_perf_archtypes[STARPU_NARCH_VARIATIONS];
  38. //static unsigned napplicable_perf_archtypes = 0;
  39. /*
  40. * Here are the default values of alpha, beta, gamma
  41. */
  42. #define _STARPU_SCHED_ALPHA_DEFAULT 1.0
  43. #define _STARPU_SCHED_BETA_DEFAULT 1.0
  44. #define _STARPU_SCHED_GAMMA_DEFAULT 1000.0
  45. struct _starpu_pheft_data
  46. {
  47. double alpha;
  48. double beta;
  49. double _gamma;
  50. double idle_power;
  51. /* When we push a task on a combined worker we need all the cpu workers it contains
  52. * to be locked at once */
  53. starpu_pthread_mutex_t global_push_mutex;
  54. };
  55. static double worker_exp_start[STARPU_NMAXWORKERS];
  56. static double worker_exp_end[STARPU_NMAXWORKERS];
  57. static double worker_exp_len[STARPU_NMAXWORKERS];
  58. static int ntasks[STARPU_NMAXWORKERS];
  59. /*!!!!!!! It doesn't work with several contexts because the combined workers are constructed
  60. from the workers available to the program, and not to the context !!!!!!!!!!!!!!!!!!!!!!!
  61. */
  62. static void parallel_heft_pre_exec_hook(struct starpu_task *task)
  63. {
  64. if (!task->cl || task->execute_on_a_specific_worker)
  65. return;
  66. unsigned workerid = starpu_worker_get_id_check();
  67. double model = task->predicted;
  68. double transfer_model = task->predicted_transfer;
  69. if (isnan(model))
  70. model = 0.0;
  71. if (isnan(transfer_model))
  72. transfer_model = 0.0;
  73. starpu_pthread_mutex_t *sched_mutex;
  74. starpu_pthread_cond_t *sched_cond;
  75. starpu_worker_get_sched_condition(workerid, &sched_mutex, &sched_cond);
  76. /* Once we have executed the task, we can update the predicted amount
  77. * of work. */
  78. STARPU_PTHREAD_MUTEX_LOCK_SCHED(sched_mutex);
  79. worker_exp_len[workerid] -= model + transfer_model;
  80. worker_exp_start[workerid] = starpu_timing_now() + model;
  81. worker_exp_end[workerid] = worker_exp_start[workerid] + worker_exp_len[workerid];
  82. ntasks[workerid]--;
  83. STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(sched_mutex);
  84. }
  85. static int push_task_on_best_worker(struct starpu_task *task, int best_workerid, double exp_end_predicted, int prio, unsigned sched_ctx_id)
  86. {
  87. /* make sure someone coule execute that task ! */
  88. STARPU_ASSERT(best_workerid != -1);
  89. struct _starpu_pheft_data *hd = (struct _starpu_pheft_data*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  90. /* Is this a basic worker or a combined worker ? */
  91. unsigned memory_node;
  92. memory_node = starpu_worker_get_memory_node(best_workerid);
  93. if (starpu_get_prefetch_flag())
  94. starpu_prefetch_task_input_on_node(task, memory_node);
  95. int ret = 0;
  96. if (!starpu_worker_is_combined_worker(best_workerid))
  97. {
  98. starpu_pthread_mutex_t *sched_mutex;
  99. starpu_pthread_cond_t *sched_cond;
  100. starpu_worker_get_sched_condition(best_workerid, &sched_mutex, &sched_cond);
  101. STARPU_PTHREAD_MUTEX_LOCK_SCHED(sched_mutex);
  102. task->predicted = exp_end_predicted - worker_exp_end[best_workerid];
  103. /* TODO */
  104. task->predicted_transfer = 0;
  105. worker_exp_len[best_workerid] += task->predicted;
  106. worker_exp_end[best_workerid] = exp_end_predicted;
  107. worker_exp_start[best_workerid] = exp_end_predicted - worker_exp_len[best_workerid];
  108. ntasks[best_workerid]++;
  109. STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(sched_mutex);
  110. /* We don't want it to interlace its task with a combined
  111. * worker's one */
  112. STARPU_PTHREAD_MUTEX_LOCK(&hd->global_push_mutex);
  113. ret = starpu_push_local_task(best_workerid, task, prio);
  114. STARPU_PTHREAD_MUTEX_UNLOCK(&hd->global_push_mutex);
  115. }
  116. else
  117. {
  118. /* This task doesn't belong to an actual worker, it belongs
  119. * to a combined worker and thus the scheduler doesn't care
  120. * of its predicted values which are insignificant */
  121. task->predicted = 0;
  122. task->predicted_transfer = 0;
  123. starpu_parallel_task_barrier_init(task, best_workerid);
  124. int worker_size = 0;
  125. int *combined_workerid;
  126. starpu_combined_worker_get_description(best_workerid, &worker_size, &combined_workerid);
  127. /* All cpu workers must be locked at once */
  128. STARPU_PTHREAD_MUTEX_LOCK(&hd->global_push_mutex);
  129. /* This is a combined worker so we create task aliases */
  130. int i;
  131. for (i = 0; i < worker_size; i++)
  132. {
  133. struct starpu_task *alias = starpu_task_dup(task);
  134. int local_worker = combined_workerid[i];
  135. alias->predicted = exp_end_predicted - worker_exp_end[local_worker];
  136. /* TODO */
  137. alias->predicted_transfer = 0;
  138. alias->destroy = 1;
  139. starpu_pthread_mutex_t *sched_mutex;
  140. starpu_pthread_cond_t *sched_cond;
  141. starpu_worker_get_sched_condition(local_worker, &sched_mutex, &sched_cond);
  142. STARPU_PTHREAD_MUTEX_LOCK_SCHED(sched_mutex);
  143. worker_exp_len[local_worker] += alias->predicted;
  144. worker_exp_end[local_worker] = exp_end_predicted;
  145. worker_exp_start[local_worker] = exp_end_predicted - worker_exp_len[local_worker];
  146. ntasks[local_worker]++;
  147. STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(sched_mutex);
  148. ret |= starpu_push_local_task(local_worker, alias, prio);
  149. }
  150. STARPU_PTHREAD_MUTEX_UNLOCK(&hd->global_push_mutex);
  151. }
  152. return ret;
  153. }
  154. static double compute_expected_end(int workerid, double length)
  155. {
  156. starpu_pthread_mutex_t *sched_mutex;
  157. starpu_pthread_cond_t *sched_cond;
  158. starpu_worker_get_sched_condition(workerid, &sched_mutex, &sched_cond);
  159. if (!starpu_worker_is_combined_worker(workerid))
  160. {
  161. double res;
  162. /* This is a basic worker */
  163. /* Here helgrind would shout that this is unprotected, but we
  164. * are fine with getting outdated values, this is just an
  165. * estimation */
  166. res = worker_exp_start[workerid] + worker_exp_len[workerid] + length;
  167. return res;
  168. }
  169. else
  170. {
  171. /* This is a combined worker, the expected end is the end for the latest worker */
  172. int worker_size;
  173. int *combined_workerid;
  174. starpu_combined_worker_get_description(workerid, &worker_size, &combined_workerid);
  175. double exp_end = DBL_MIN;
  176. /* Here helgrind would shout that this is unprotected, but we
  177. * are fine with getting outdated values, this is just an
  178. * estimation */
  179. int i;
  180. for (i = 0; i < worker_size; i++)
  181. {
  182. double local_exp_start = worker_exp_start[combined_workerid[i]];
  183. double local_exp_len = worker_exp_len[combined_workerid[i]];
  184. double local_exp_end = local_exp_start + local_exp_len + length;
  185. exp_end = STARPU_MAX(exp_end, local_exp_end);
  186. }
  187. return exp_end;
  188. }
  189. }
  190. static double compute_ntasks_end(int workerid, unsigned sched_ctx_id)
  191. {
  192. struct starpu_perfmodel_arch* perf_arch = starpu_worker_get_perf_archtype(workerid, sched_ctx_id);
  193. starpu_pthread_mutex_t *sched_mutex;
  194. starpu_pthread_cond_t *sched_cond;
  195. starpu_worker_get_sched_condition(workerid, &sched_mutex, &sched_cond);
  196. if (!starpu_worker_is_combined_worker(workerid))
  197. {
  198. double res;
  199. /* This is a basic worker */
  200. /* Here helgrind would shout that this is unprotected, but we
  201. * are fine with getting outdated values, this is just an
  202. * estimation */
  203. res = ntasks[workerid] / starpu_worker_get_relative_speedup(perf_arch);
  204. return res;
  205. }
  206. else
  207. {
  208. /* This is a combined worker, the expected end is the end for the latest worker */
  209. int worker_size;
  210. int *combined_workerid;
  211. starpu_combined_worker_get_description(workerid, &worker_size, &combined_workerid);
  212. int ntasks_end=0;
  213. /* Here helgrind would shout that this is unprotected, but we
  214. * are fine with getting outdated values, this is just an
  215. * estimation */
  216. int i;
  217. for (i = 0; i < worker_size; i++)
  218. {
  219. /* XXX: this is actually bogus: not all pushed tasks are necessarily parallel... */
  220. ntasks_end = STARPU_MAX(ntasks_end, (int) ((double) ntasks[combined_workerid[i]] / starpu_worker_get_relative_speedup(perf_arch)));
  221. }
  222. return ntasks_end;
  223. }
  224. }
  225. static int _parallel_heft_push_task(struct starpu_task *task, unsigned prio, unsigned sched_ctx_id)
  226. {
  227. struct _starpu_pheft_data *hd = (struct _starpu_pheft_data*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  228. struct starpu_worker_collection *workers = starpu_sched_ctx_get_worker_collection(sched_ctx_id);
  229. unsigned nworkers_ctx = workers->nworkers;
  230. unsigned worker, worker_ctx = 0;
  231. int best = -1, best_id_ctx = -1;
  232. /* this flag is set if the corresponding worker is selected because
  233. there is no performance prediction available yet */
  234. int forced_best = -1, forced_best_ctx = -1, forced_nimpl = -1;
  235. double local_task_length[nworkers_ctx][STARPU_MAXIMPLEMENTATIONS];
  236. double local_data_penalty[nworkers_ctx][STARPU_MAXIMPLEMENTATIONS];
  237. double local_energy[nworkers_ctx][STARPU_MAXIMPLEMENTATIONS];
  238. double local_exp_end[nworkers_ctx][STARPU_MAXIMPLEMENTATIONS];
  239. double fitness[nworkers_ctx][STARPU_MAXIMPLEMENTATIONS];
  240. double max_exp_end = 0.0;
  241. int skip_worker[nworkers_ctx][STARPU_MAXIMPLEMENTATIONS];
  242. double best_exp_end = DBL_MAX;
  243. //double penality_best = 0.0;
  244. int ntasks_best = -1, ntasks_best_ctx = -1, nimpl_best = -1;
  245. double ntasks_best_end = 0.0;
  246. int calibrating = 0;
  247. /* A priori, we know all estimations */
  248. int unknown = 0;
  249. struct starpu_sched_ctx_iterator it;
  250. memset(skip_worker, 0, nworkers_ctx*STARPU_MAXIMPLEMENTATIONS*sizeof(int));
  251. workers->init_iterator(workers, &it);
  252. while(workers->has_next(workers, &it))
  253. {
  254. worker = workers->get_next(workers, &it);
  255. if(!starpu_worker_is_combined_worker(worker))
  256. {
  257. starpu_pthread_mutex_t *sched_mutex;
  258. starpu_pthread_cond_t *sched_cond;
  259. starpu_worker_get_sched_condition(worker, &sched_mutex, &sched_cond);
  260. /* Sometimes workers didn't take the tasks as early as we expected */
  261. STARPU_PTHREAD_MUTEX_LOCK_SCHED(sched_mutex);
  262. worker_exp_start[worker] = STARPU_MAX(worker_exp_start[worker], starpu_timing_now());
  263. worker_exp_end[worker] = worker_exp_start[worker] + worker_exp_len[worker];
  264. if (worker_exp_end[worker] > max_exp_end)
  265. max_exp_end = worker_exp_end[worker];
  266. STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(sched_mutex);
  267. }
  268. }
  269. unsigned nimpl;
  270. worker_ctx = 0;
  271. while(workers->has_next(workers, &it))
  272. {
  273. worker = workers->get_next(workers, &it);
  274. for (nimpl = 0; nimpl < STARPU_MAXIMPLEMENTATIONS; nimpl++)
  275. {
  276. if (!starpu_combined_worker_can_execute_task(worker, task, nimpl))
  277. {
  278. /* no one on that queue may execute this task */
  279. skip_worker[worker_ctx][nimpl] = 1;
  280. continue;
  281. }
  282. else
  283. {
  284. skip_worker[worker_ctx][nimpl] = 0;
  285. }
  286. struct starpu_perfmodel_arch* perf_arch = starpu_worker_get_perf_archtype(worker, sched_ctx_id);
  287. local_task_length[worker_ctx][nimpl] = starpu_task_expected_length(task, perf_arch,nimpl);
  288. unsigned memory_node = starpu_worker_get_memory_node(worker);
  289. local_data_penalty[worker_ctx][nimpl] = starpu_task_expected_data_transfer_time(memory_node, task);
  290. double ntasks_end = compute_ntasks_end(worker, sched_ctx_id);
  291. if (ntasks_best == -1
  292. || (!calibrating && ntasks_end < ntasks_best_end) /* Not calibrating, take better task */
  293. || (!calibrating && isnan(local_task_length[worker_ctx][nimpl])) /* Not calibrating but this worker is being calibrated */
  294. || (calibrating && isnan(local_task_length[worker_ctx][nimpl]) && ntasks_end < ntasks_best_end) /* Calibrating, compete this worker with other non-calibrated */
  295. )
  296. {
  297. ntasks_best_end = ntasks_end;
  298. ntasks_best = worker;
  299. ntasks_best_ctx = worker_ctx;
  300. nimpl_best = nimpl;
  301. }
  302. if (isnan(local_task_length[worker_ctx][nimpl]))
  303. /* we are calibrating, we want to speed-up calibration time
  304. * so we privilege non-calibrated tasks (but still
  305. * greedily distribute them to avoid dumb schedules) */
  306. calibrating = 1;
  307. if (isnan(local_task_length[worker_ctx][nimpl])
  308. || _STARPU_IS_ZERO(local_task_length[worker_ctx][nimpl]))
  309. /* there is no prediction available for that task
  310. * with that arch yet, so switch to a greedy strategy */
  311. unknown = 1;
  312. if (unknown)
  313. continue;
  314. local_exp_end[worker_ctx][nimpl] = compute_expected_end(worker, local_task_length[worker_ctx][nimpl]);
  315. //fprintf(stderr, "WORKER %d -> length %e end %e\n", worker, local_task_length[worker_ctx][nimpl], local_exp_end[worker][nimpl]);
  316. if (local_exp_end[worker_ctx][nimpl] < best_exp_end)
  317. {
  318. /* a better solution was found */
  319. best_exp_end = local_exp_end[worker_ctx][nimpl];
  320. nimpl_best = nimpl;
  321. }
  322. local_energy[worker_ctx][nimpl] = starpu_task_expected_energy(task, perf_arch,nimpl);
  323. //_STARPU_DEBUG("Scheduler parallel heft: task length (%lf) local energy (%lf) worker (%u) kernel (%u) \n", local_task_length[worker],local_energy[worker],worker,nimpl);
  324. if (isnan(local_energy[worker_ctx][nimpl]))
  325. local_energy[worker_ctx][nimpl] = 0.;
  326. }
  327. worker_ctx++;
  328. }
  329. if (unknown)
  330. {
  331. forced_best = ntasks_best;
  332. forced_best_ctx = ntasks_best_ctx;
  333. forced_nimpl = nimpl_best;
  334. }
  335. double best_fitness = -1;
  336. if (forced_best == -1)
  337. {
  338. worker_ctx = 0;
  339. while(workers->has_next(workers, &it))
  340. {
  341. worker = workers->get_next(workers, &it);
  342. for (nimpl = 0; nimpl < STARPU_MAXIMPLEMENTATIONS; nimpl++)
  343. {
  344. if (skip_worker[worker_ctx][nimpl])
  345. {
  346. /* no one on that queue may execute this task */
  347. continue;
  348. }
  349. fitness[worker_ctx][nimpl] = hd->alpha*(local_exp_end[worker_ctx][nimpl] - best_exp_end)
  350. + hd->beta*(local_data_penalty[worker_ctx][nimpl])
  351. + hd->_gamma*(local_energy[worker_ctx][nimpl]);
  352. if (local_exp_end[worker_ctx][nimpl] > max_exp_end)
  353. /* This placement will make the computation
  354. * longer, take into account the idle
  355. * consumption of other cpus */
  356. fitness[worker_ctx][nimpl] += hd->_gamma * hd->idle_power * (local_exp_end[worker_ctx][nimpl] - max_exp_end) / 1000000.0;
  357. if (best == -1 || fitness[worker_ctx][nimpl] < best_fitness)
  358. {
  359. /* we found a better solution */
  360. best_fitness = fitness[worker_ctx][nimpl];
  361. best = worker;
  362. best_id_ctx = worker_ctx;
  363. nimpl_best = nimpl;
  364. }
  365. // fprintf(stderr, "FITNESS worker %d -> %e local_exp_end %e - local_data_penalty %e\n", worker, fitness[worker][nimpl], local_exp_end[worker][nimpl] - best_exp_end, local_data_penalty[worker][nimpl]);
  366. }
  367. worker_ctx++;
  368. }
  369. }
  370. STARPU_ASSERT(forced_best != -1 || best != -1);
  371. if (forced_best != -1)
  372. {
  373. /* there is no prediction available for that task
  374. * with that arch we want to speed-up calibration time
  375. * so we force this measurement */
  376. best = forced_best;
  377. best_id_ctx = forced_best_ctx;
  378. nimpl_best = forced_nimpl;
  379. //penality_best = 0.0;
  380. best_exp_end = compute_expected_end(best, 0);
  381. }
  382. else
  383. {
  384. //penality_best = local_data_penalty[best_id_ctx][nimpl_best];
  385. best_exp_end = local_exp_end[best_id_ctx][nimpl_best];
  386. }
  387. //_STARPU_DEBUG("Scheduler parallel heft: kernel (%u)\n", nimpl_best);
  388. _starpu_get_job_associated_to_task(task)->nimpl = nimpl_best;
  389. /* we should now have the best worker in variable "best" */
  390. _STARPU_TASK_BREAK_ON(task, sched);
  391. return push_task_on_best_worker(task, best, best_exp_end, prio, sched_ctx_id);
  392. }
  393. static int parallel_heft_push_task(struct starpu_task *task)
  394. {
  395. unsigned sched_ctx_id = task->sched_ctx;
  396. int ret_val = -1;
  397. if (task->priority == STARPU_MAX_PRIO)
  398. {
  399. ret_val = _parallel_heft_push_task(task, 1, sched_ctx_id);
  400. return ret_val;
  401. }
  402. ret_val = _parallel_heft_push_task(task, 0, sched_ctx_id);
  403. return ret_val;
  404. }
  405. static void parallel_heft_add_workers(__attribute__((unused)) unsigned sched_ctx_id, int *workerids, unsigned nworkers)
  406. {
  407. int workerid;
  408. unsigned i;
  409. for (i = 0; i < nworkers; i++)
  410. {
  411. workerid = workerids[i];
  412. struct _starpu_worker *workerarg = _starpu_get_worker_struct(workerid);
  413. /* init these structures only once for each worker */
  414. if(!workerarg->has_prev_init)
  415. {
  416. worker_exp_start[workerid] = starpu_timing_now();
  417. worker_exp_len[workerid] = 0.0;
  418. worker_exp_end[workerid] = worker_exp_start[workerid];
  419. ntasks[workerid] = 0;
  420. workerarg->has_prev_init = 1;
  421. }
  422. }
  423. _starpu_sched_find_worker_combinations(workerids, nworkers);
  424. // start_unclear_part: not very clear where this is used
  425. /* struct _starpu_machine_config *config = (struct _starpu_machine_config *)_starpu_get_machine_config(); */
  426. /* ncombinedworkers = config->topology.ncombinedworkers; */
  427. /* /\* We pre-compute an array of all the perfmodel archs that are applicable *\/ */
  428. /* unsigned total_worker_count = nworkers + ncombinedworkers; */
  429. /* unsigned used_perf_archtypes[STARPU_NARCH_VARIATIONS]; */
  430. /* memset(used_perf_archtypes, 0, sizeof(used_perf_archtypes)); */
  431. /* for (workerid = 0; workerid < total_worker_count; workerid++) */
  432. /* { */
  433. /* enum starpu_perfmodel_archtype perf_archtype = starpu_worker_get_perf_archtype(workerid); */
  434. /* used_perf_archtypes[perf_archtype] = 1; */
  435. /* } */
  436. // end_unclear_part
  437. // napplicable_perf_archtypes = 0;
  438. // int arch;
  439. // for (arch = 0; arch < STARPU_NARCH_VARIATIONS; arch++)
  440. // {
  441. // if (used_perf_archtypes[arch])
  442. // applicable_perf_archtypes[napplicable_perf_archtypes++] = arch;
  443. // }
  444. }
  445. static void initialize_parallel_heft_policy(unsigned sched_ctx_id)
  446. {
  447. struct _starpu_pheft_data *hd = (struct _starpu_pheft_data*)malloc(sizeof(struct _starpu_pheft_data));
  448. if (starpu_sched_ctx_min_priority_is_set(sched_ctx_id) == 0)
  449. starpu_sched_ctx_set_min_priority(sched_ctx_id, DEFAULT_MIN_PRIORITY);
  450. if (starpu_sched_ctx_max_priority_is_set(sched_ctx_id) == 0)
  451. starpu_sched_ctx_set_max_priority(sched_ctx_id, DEFAULT_MAX_PRIORITY);
  452. STARPU_ASSERT_MSG(starpu_sched_ctx_get_min_priority(sched_ctx_id) < starpu_sched_ctx_get_max_priority(sched_ctx_id),
  453. "Priority min %d should be lower than priority max %d\n",
  454. starpu_sched_ctx_get_min_priority(sched_ctx_id), starpu_sched_ctx_get_max_priority(sched_ctx_id));
  455. starpu_sched_ctx_set_policy_data(sched_ctx_id, (void*)hd);
  456. hd->alpha = starpu_get_env_float_default("STARPU_SCHED_ALPHA", _STARPU_SCHED_ALPHA_DEFAULT);
  457. hd->beta = starpu_get_env_float_default("STARPU_SCHED_BETA", _STARPU_SCHED_BETA_DEFAULT);
  458. hd->_gamma = starpu_get_env_float_default("STARPU_SCHED_GAMMA", _STARPU_SCHED_GAMMA_DEFAULT);
  459. hd->idle_power = starpu_get_env_float_default("STARPU_IDLE_POWER", 0.0);
  460. STARPU_PTHREAD_MUTEX_INIT(&hd->global_push_mutex, NULL);
  461. /* Tell helgrind that we are fine with getting outdated values when
  462. * estimating schedules */
  463. STARPU_HG_DISABLE_CHECKING(worker_exp_start);
  464. STARPU_HG_DISABLE_CHECKING(worker_exp_end);
  465. STARPU_HG_DISABLE_CHECKING(worker_exp_len);
  466. STARPU_HG_DISABLE_CHECKING(ntasks);
  467. }
  468. static void parallel_heft_deinit(unsigned sched_ctx_id)
  469. {
  470. struct _starpu_pheft_data *hd = (struct _starpu_pheft_data*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  471. STARPU_PTHREAD_MUTEX_DESTROY(&hd->global_push_mutex);
  472. free(hd);
  473. }
  474. /* TODO: use post_exec_hook to fix the expected start */
  475. struct starpu_sched_policy _starpu_sched_parallel_heft_policy =
  476. {
  477. .init_sched = initialize_parallel_heft_policy,
  478. .deinit_sched = parallel_heft_deinit,
  479. .add_workers = parallel_heft_add_workers,
  480. .remove_workers = NULL,
  481. .push_task = parallel_heft_push_task,
  482. .pop_task = NULL,
  483. .pre_exec_hook = parallel_heft_pre_exec_hook,
  484. .post_exec_hook = NULL,
  485. .pop_every_task = NULL,
  486. .policy_name = "pheft",
  487. .policy_description = "parallel HEFT",
  488. .worker_type = STARPU_WORKER_LIST,
  489. };