parallel_heft.c 20 KB

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