task.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2019 Inria
  4. * Copyright (C) 2009-2020 Université de Bordeaux
  5. * Copyright (C) 2017 Erwan Leria
  6. * Copyright (C) 2010-2020 CNRS
  7. * Copyright (C) 2013 Thibaut Lambert
  8. * Copyright (C) 2011 Télécom-SudParis
  9. * Copyright (C) 2016 Uppsala University
  10. *
  11. * StarPU is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU Lesser General Public License as published by
  13. * the Free Software Foundation; either version 2.1 of the License, or (at
  14. * your option) any later version.
  15. *
  16. * StarPU is distributed in the hope that it will be useful, but
  17. * WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  19. *
  20. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  21. */
  22. #include <starpu.h>
  23. #include <starpu_profiling.h>
  24. #include <core/workers.h>
  25. #include <core/sched_ctx.h>
  26. #include <core/jobs.h>
  27. #include <core/task.h>
  28. #include <core/task_bundle.h>
  29. #include <core/dependencies/data_concurrency.h>
  30. #include <common/config.h>
  31. #include <common/utils.h>
  32. #include <common/fxt.h>
  33. #include <common/knobs.h>
  34. #include <profiling/profiling.h>
  35. #include <profiling/bound.h>
  36. #include <math.h>
  37. #include <string.h>
  38. #include <core/debug.h>
  39. #include <core/sched_ctx.h>
  40. #include <time.h>
  41. #include <signal.h>
  42. #include <core/simgrid.h>
  43. #ifdef STARPU_HAVE_WINDOWS
  44. #include <windows.h>
  45. #endif
  46. /* global counters */
  47. static int __g_total_submitted;
  48. static int __g_peak_submitted;
  49. static int __g_peak_ready;
  50. /* global counter variables */
  51. int64_t _starpu_task__g_total_submitted__value;
  52. int64_t _starpu_task__g_peak_submitted__value;
  53. int64_t _starpu_task__g_current_submitted__value;
  54. int64_t _starpu_task__g_peak_ready__value;
  55. int64_t _starpu_task__g_current_ready__value;
  56. /* per-worker counters */
  57. static int __w_total_executed;
  58. static int __w_cumul_execution_time;
  59. /* per-codelet counters */
  60. static int __c_total_submitted;
  61. static int __c_peak_submitted;
  62. static int __c_peak_ready;
  63. static int __c_total_executed;
  64. static int __c_cumul_execution_time;
  65. /* - */
  66. /* per-scheduler knobs */
  67. static int __s_max_priority_cap_knob;
  68. static int __s_min_priority_cap_knob;
  69. /* knob variables */
  70. static int __s_max_priority_cap__value;
  71. static int __s_min_priority_cap__value;
  72. static struct starpu_perf_knob_group * __kg_starpu_task__per_scheduler;
  73. /* - */
  74. static void global_sample_updater(struct starpu_perf_counter_sample *sample, void *context)
  75. {
  76. STARPU_ASSERT(context == NULL); /* no context for the global updater */
  77. (void)context;
  78. _starpu_perf_counter_sample_set_int64_value(sample, __g_total_submitted, _starpu_task__g_total_submitted__value);
  79. _starpu_perf_counter_sample_set_int64_value(sample, __g_peak_submitted, _starpu_task__g_peak_submitted__value);
  80. _starpu_perf_counter_sample_set_int64_value(sample, __g_peak_ready, _starpu_task__g_peak_ready__value);
  81. }
  82. static void per_worker_sample_updater(struct starpu_perf_counter_sample *sample, void *context)
  83. {
  84. STARPU_ASSERT(context != NULL);
  85. struct _starpu_worker *worker = context;
  86. _starpu_perf_counter_sample_set_int64_value(sample, __w_total_executed, worker->__w_total_executed__value);
  87. _starpu_perf_counter_sample_set_double_value(sample, __w_cumul_execution_time, worker->__w_cumul_execution_time__value);
  88. }
  89. static void per_codelet_sample_updater(struct starpu_perf_counter_sample *sample, void *context)
  90. {
  91. STARPU_ASSERT(sample->listener != NULL && sample->listener->set != NULL);
  92. struct starpu_perf_counter_set *set = sample->listener->set;
  93. STARPU_ASSERT(set->scope == starpu_perf_counter_scope_per_codelet);
  94. STARPU_ASSERT(context != NULL);
  95. struct starpu_codelet *cl = context;
  96. _starpu_perf_counter_sample_set_int64_value(sample, __c_total_submitted, cl->perf_counter_values->task.total_submitted);
  97. _starpu_perf_counter_sample_set_int64_value(sample, __c_peak_submitted, cl->perf_counter_values->task.peak_submitted);
  98. _starpu_perf_counter_sample_set_int64_value(sample, __c_peak_ready, cl->perf_counter_values->task.peak_ready);
  99. _starpu_perf_counter_sample_set_int64_value(sample, __c_total_executed, cl->perf_counter_values->task.total_executed);
  100. _starpu_perf_counter_sample_set_double_value(sample, __c_cumul_execution_time, cl->perf_counter_values->task.cumul_execution_time);
  101. }
  102. void _starpu__task_c__register_counters(void)
  103. {
  104. {
  105. const enum starpu_perf_counter_scope scope = starpu_perf_counter_scope_global;
  106. __STARPU_PERF_COUNTER_REG("starpu.task", scope, g_total_submitted, int64, "number of tasks submitted globally (since StarPU initialization)");
  107. __STARPU_PERF_COUNTER_REG("starpu.task", scope, g_peak_submitted, int64, "maximum simultaneous number of tasks submitted and not yet ready, globally (since StarPU initialization)");
  108. __STARPU_PERF_COUNTER_REG("starpu.task", scope, g_peak_ready, int64, "maximum simultaneous number of tasks ready and not yet executing, globally (since StarPU initialization)");
  109. _starpu_perf_counter_register_updater(scope, global_sample_updater);
  110. }
  111. {
  112. const enum starpu_perf_counter_scope scope = starpu_perf_counter_scope_per_worker;
  113. __STARPU_PERF_COUNTER_REG("starpu.task", scope, w_total_executed, int64, "number of tasks executed on this worker (since StarPU initialization)");
  114. __STARPU_PERF_COUNTER_REG("starpu.task", scope, w_cumul_execution_time, double, "cumulated execution time of tasks executed on this worker (microseconds, since StarPU initialization)");
  115. _starpu_perf_counter_register_updater(scope, per_worker_sample_updater);
  116. }
  117. {
  118. const enum starpu_perf_counter_scope scope = starpu_perf_counter_scope_per_codelet;
  119. __STARPU_PERF_COUNTER_REG("starpu.task", scope, c_total_submitted, int64, "number of codelet's task instances submitted using this codelet (since enabled)");
  120. __STARPU_PERF_COUNTER_REG("starpu.task", scope, c_peak_submitted, int64, "maximum simultaneous number of codelet's task instances submitted and not yet ready (since enabled)");
  121. __STARPU_PERF_COUNTER_REG("starpu.task", scope, c_peak_ready, int64, "maximum simultaneous number of codelet's task instances ready and not yet executing (since enabled)");
  122. __STARPU_PERF_COUNTER_REG("starpu.task", scope, c_total_executed, int64, "number of codelet's task instances executed using this codelet (since enabled)");
  123. __STARPU_PERF_COUNTER_REG("starpu.task", scope, c_cumul_execution_time, double, "cumulated execution time of codelet's task instances (since enabled)");
  124. _starpu_perf_counter_register_updater(scope, per_codelet_sample_updater);
  125. }
  126. }
  127. /* - */
  128. static void sched_knobs__set(const struct starpu_perf_knob * const knob, void *context, const struct starpu_perf_knob_value * const value)
  129. {
  130. const char * const sched_policy_name = *(const char **)context;
  131. (void) sched_policy_name;
  132. if (knob->id == __s_max_priority_cap_knob)
  133. {
  134. STARPU_ASSERT(value->val_int32_t <= STARPU_MAX_PRIO);
  135. STARPU_ASSERT(value->val_int32_t >= STARPU_MIN_PRIO);
  136. STARPU_ASSERT(value->val_int32_t >= __s_min_priority_cap__value);
  137. __s_max_priority_cap__value = value->val_int32_t;
  138. }
  139. else if (knob->id == __s_min_priority_cap_knob)
  140. {
  141. STARPU_ASSERT(value->val_int32_t <= STARPU_MAX_PRIO);
  142. STARPU_ASSERT(value->val_int32_t >= STARPU_MIN_PRIO);
  143. STARPU_ASSERT(value->val_int32_t <= __s_max_priority_cap__value);
  144. __s_min_priority_cap__value = value->val_int32_t;
  145. }
  146. else
  147. {
  148. STARPU_ASSERT(0);
  149. abort();
  150. }
  151. }
  152. static void sched_knobs__get(const struct starpu_perf_knob * const knob, void *context, struct starpu_perf_knob_value * const value)
  153. {
  154. const char * const sched_policy_name = *(const char **)context;
  155. (void) sched_policy_name;
  156. if (knob->id == __s_max_priority_cap_knob)
  157. {
  158. value->val_int32_t = __s_max_priority_cap__value;
  159. }
  160. else if (knob->id == __s_min_priority_cap_knob)
  161. {
  162. value->val_int32_t = __s_min_priority_cap__value;
  163. }
  164. else
  165. {
  166. STARPU_ASSERT(0);
  167. abort();
  168. }
  169. }
  170. void _starpu__task_c__register_knobs(void)
  171. {
  172. #if 0
  173. {
  174. const enum starpu_perf_knob_scope scope = starpu_perf_knob_scope_global;
  175. __kg_starpu_global = _starpu_perf_knob_group_register(scope, global_knobs__set, global_knobs__get);
  176. }
  177. #endif
  178. #if 0
  179. {
  180. const enum starpu_perf_knob_scope scope = starpu_perf_knob_scope_per_worker;
  181. __kg_starpu_worker__per_worker = _starpu_perf_knob_group_register(scope, worker_knobs__set, worker_knobs__get);
  182. }
  183. #endif
  184. {
  185. const enum starpu_perf_knob_scope scope = starpu_perf_knob_scope_per_scheduler;
  186. __kg_starpu_task__per_scheduler = _starpu_perf_knob_group_register(scope, sched_knobs__set, sched_knobs__get);
  187. /* TODO: priority capping knobs actually work globally for now, the sched policy name is ignored */
  188. __STARPU_PERF_KNOB_REG("starpu.task", __kg_starpu_task__per_scheduler, s_max_priority_cap_knob, int32, "force task priority to this value or below (priority value)");
  189. __s_max_priority_cap__value = STARPU_MAX_PRIO;
  190. __STARPU_PERF_KNOB_REG("starpu.task", __kg_starpu_task__per_scheduler, s_min_priority_cap_knob, int32, "force task priority to this value or above (priority value)");
  191. __s_min_priority_cap__value = STARPU_MIN_PRIO;
  192. }
  193. }
  194. void _starpu__task_c__unregister_knobs(void)
  195. {
  196. _starpu_perf_knob_group_unregister(__kg_starpu_task__per_scheduler);
  197. __kg_starpu_task__per_scheduler = NULL;
  198. }
  199. /* - */
  200. /* XXX this should be reinitialized when StarPU is shutdown (or we should make
  201. * sure that no task remains !) */
  202. /* TODO we could make this hierarchical to avoid contention ? */
  203. //static starpu_pthread_cond_t submitted_cond = STARPU_PTHREAD_COND_INITIALIZER;
  204. /* This key stores the task currently handled by the thread, note that we
  205. * cannot use the worker structure to store that information because it is
  206. * possible that we have a task with a NULL codelet, which means its callback
  207. * could be executed by a user thread as well. */
  208. static starpu_pthread_key_t current_task_key;
  209. static int limit_min_submitted_tasks;
  210. static int limit_max_submitted_tasks;
  211. static int watchdog_crash;
  212. static int watchdog_delay;
  213. /*
  214. * Function to call when watchdog detects that no task has finished for more than STARPU_WATCHDOG_TIMEOUT seconds
  215. */
  216. static void (*watchdog_hook)(void *) = NULL;
  217. static void * watchdog_hook_arg = NULL;
  218. #define _STARPU_TASK_MAGIC 42
  219. /* Called once at starpu_init */
  220. void _starpu_task_init(void)
  221. {
  222. STARPU_PTHREAD_KEY_CREATE(&current_task_key, NULL);
  223. limit_min_submitted_tasks = starpu_get_env_number("STARPU_LIMIT_MIN_SUBMITTED_TASKS");
  224. limit_max_submitted_tasks = starpu_get_env_number("STARPU_LIMIT_MAX_SUBMITTED_TASKS");
  225. watchdog_crash = starpu_get_env_number("STARPU_WATCHDOG_CRASH");
  226. watchdog_delay = starpu_get_env_number_default("STARPU_WATCHDOG_DELAY", 0);
  227. }
  228. void _starpu_task_deinit(void)
  229. {
  230. STARPU_PTHREAD_KEY_DELETE(current_task_key);
  231. }
  232. void starpu_task_init(struct starpu_task *task)
  233. {
  234. /* TODO: memcpy from a template instead? benchmark it */
  235. STARPU_ASSERT(task);
  236. /* As most of the fields must be initialised at NULL, let's put 0
  237. * everywhere */
  238. memset(task, 0, sizeof(struct starpu_task));
  239. task->sequential_consistency = 1;
  240. task->where = -1;
  241. /* Now we can initialise fields which recquire custom value */
  242. /* Note: remember to update STARPU_TASK_INITIALIZER as well */
  243. #if STARPU_DEFAULT_PRIO != 0
  244. task->priority = STARPU_DEFAULT_PRIO;
  245. #endif
  246. task->detach = 1;
  247. #if STARPU_TASK_INVALID != 0
  248. task->status = STARPU_TASK_INVALID;
  249. #endif
  250. task->predicted = NAN;
  251. task->predicted_transfer = NAN;
  252. task->predicted_start = NAN;
  253. task->magic = _STARPU_TASK_MAGIC;
  254. task->sched_ctx = STARPU_NMAX_SCHED_CTXS;
  255. task->flops = 0.0;
  256. }
  257. /* Free all the ressources allocated for a task, without deallocating the task
  258. * structure itself (this is required for statically allocated tasks).
  259. * All values previously set by the user, like codelet and handles, remain
  260. * unchanged */
  261. void starpu_task_clean(struct starpu_task *task)
  262. {
  263. STARPU_ASSERT(task);
  264. task->magic = 0;
  265. /* If a buffer was allocated to store the profiling info, we free it. */
  266. if (task->profiling_info)
  267. {
  268. free(task->profiling_info);
  269. task->profiling_info = NULL;
  270. }
  271. /* If case the task is (still) part of a bundle */
  272. starpu_task_bundle_t bundle = task->bundle;
  273. if (bundle)
  274. starpu_task_bundle_remove(bundle, task);
  275. if (task->dyn_handles)
  276. {
  277. free(task->dyn_handles);
  278. task->dyn_handles = NULL;
  279. free(task->dyn_interfaces);
  280. task->dyn_interfaces = NULL;
  281. }
  282. if (task->dyn_modes)
  283. {
  284. free(task->dyn_modes);
  285. task->dyn_modes = NULL;
  286. }
  287. struct _starpu_job *j = (struct _starpu_job *)task->starpu_private;
  288. if (j)
  289. {
  290. _starpu_job_destroy(j);
  291. task->starpu_private = NULL;
  292. }
  293. }
  294. struct starpu_task * STARPU_ATTRIBUTE_MALLOC starpu_task_create(void)
  295. {
  296. struct starpu_task *task;
  297. _STARPU_MALLOC(task, sizeof(struct starpu_task));
  298. starpu_task_init(task);
  299. /* Dynamically allocated tasks are destroyed by default */
  300. task->destroy = 1;
  301. return task;
  302. }
  303. /* Free the ressource allocated during starpu_task_create. This function can be
  304. * called automatically after the execution of a task by setting the "destroy"
  305. * flag of the starpu_task structure (default behaviour). Calling this function
  306. * on a statically allocated task results in an undefined behaviour. */
  307. void _starpu_task_destroy(struct starpu_task *task)
  308. {
  309. /* If starpu_task_destroy is called in a callback, we just set the destroy
  310. flag. The task will be destroyed after the callback returns */
  311. if (task == starpu_task_get_current()
  312. && _starpu_get_local_worker_status() == STATUS_CALLBACK)
  313. {
  314. task->destroy = 1;
  315. }
  316. else
  317. {
  318. starpu_task_clean(task);
  319. /* TODO handle the case of task with detach = 1 and destroy = 1 */
  320. /* TODO handle the case of non terminated tasks -> assertion failure, it's too dangerous to be doing something like this */
  321. /* Does user want StarPU release cl_arg ? */
  322. if (task->cl_arg_free)
  323. free(task->cl_arg);
  324. /* Does user want StarPU release callback_arg ? */
  325. if (task->callback_arg_free)
  326. free(task->callback_arg);
  327. /* Does user want StarPU release prologue_callback_arg ? */
  328. if (task->prologue_callback_arg_free)
  329. free(task->prologue_callback_arg);
  330. /* Does user want StarPU release prologue_pop_arg ? */
  331. if (task->prologue_callback_pop_arg_free)
  332. free(task->prologue_callback_pop_arg);
  333. free(task);
  334. }
  335. }
  336. void starpu_task_destroy(struct starpu_task *task)
  337. {
  338. STARPU_ASSERT(task);
  339. STARPU_ASSERT_MSG(!task->destroy || !task->detach, "starpu_task_destroy must not be called for task with destroy = 1 and detach = 1");
  340. _starpu_task_destroy(task);
  341. }
  342. int starpu_task_finished(struct starpu_task *task)
  343. {
  344. STARPU_ASSERT(task);
  345. STARPU_ASSERT_MSG(!task->detach, "starpu_task_finished can only be called on tasks with detach = 0");
  346. return _starpu_job_finished(_starpu_get_job_associated_to_task(task));
  347. }
  348. int starpu_task_wait(struct starpu_task *task)
  349. {
  350. _STARPU_LOG_IN();
  351. STARPU_ASSERT(task);
  352. STARPU_ASSERT_MSG(!task->detach, "starpu_task_wait can only be called on tasks with detach = 0");
  353. if (task->detach || task->synchronous)
  354. {
  355. _STARPU_DEBUG("Task is detached or synchronous. Waiting returns immediately\n");
  356. _STARPU_LOG_OUT_TAG("einval");
  357. return -EINVAL;
  358. }
  359. STARPU_ASSERT_MSG(_starpu_worker_may_perform_blocking_calls(), "starpu_task_wait must not be called from a task or callback");
  360. struct _starpu_job *j = _starpu_get_job_associated_to_task(task);
  361. _STARPU_TRACE_TASK_WAIT_START(j);
  362. starpu_do_schedule();
  363. _starpu_wait_job(j);
  364. /* as this is a synchronous task, the liberation of the job
  365. structure was deferred */
  366. if (task->destroy)
  367. _starpu_task_destroy(task);
  368. _starpu_perf_counter_update_global_sample();
  369. _STARPU_TRACE_TASK_WAIT_END();
  370. _STARPU_LOG_OUT();
  371. return 0;
  372. }
  373. int starpu_task_wait_array(struct starpu_task **tasks, unsigned nb_tasks)
  374. {
  375. unsigned i;
  376. for (i = 0; i < nb_tasks; i++)
  377. {
  378. int ret = starpu_task_wait(tasks[i]);
  379. if (ret)
  380. return ret;
  381. }
  382. return 0;
  383. }
  384. #ifdef STARPU_OPENMP
  385. int _starpu_task_test_termination(struct starpu_task *task)
  386. {
  387. STARPU_ASSERT(task);
  388. STARPU_ASSERT_MSG(!task->detach, "starpu_task_wait can only be called on tasks with detach = 0");
  389. if (task->detach || task->synchronous)
  390. {
  391. _STARPU_DEBUG("Task is detached or synchronous\n");
  392. _STARPU_LOG_OUT_TAG("einval");
  393. return -EINVAL;
  394. }
  395. struct _starpu_job *j = (struct _starpu_job *)task->starpu_private;
  396. int ret = _starpu_test_job_termination(j);
  397. if (ret)
  398. {
  399. if (task->destroy)
  400. _starpu_task_destroy(task);
  401. }
  402. return ret;
  403. }
  404. #endif
  405. /* NB in case we have a regenerable task, it is possible that the job was
  406. * already counted. */
  407. int _starpu_submit_job(struct _starpu_job *j, int nodeps)
  408. {
  409. struct starpu_task *task = j->task;
  410. int ret;
  411. #ifdef STARPU_OPENMP
  412. const unsigned continuation = j->continuation;
  413. #else
  414. const unsigned continuation = 0;
  415. #endif
  416. _STARPU_LOG_IN();
  417. /* notify bound computation of a new task */
  418. _starpu_bound_record(j);
  419. _starpu_increment_nsubmitted_tasks_of_sched_ctx(j->task->sched_ctx);
  420. _starpu_sched_task_submit(task);
  421. #ifdef STARPU_USE_SC_HYPERVISOR
  422. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(j->task->sched_ctx);
  423. if(sched_ctx != NULL && j->task->sched_ctx != _starpu_get_initial_sched_ctx()->id && j->task->sched_ctx != STARPU_NMAX_SCHED_CTXS
  424. && sched_ctx->perf_counters != NULL)
  425. {
  426. struct starpu_perfmodel_arch arch;
  427. _STARPU_MALLOC(arch.devices, sizeof(struct starpu_perfmodel_device));
  428. arch.ndevices = 1;
  429. arch.devices[0].type = STARPU_CPU_WORKER;
  430. arch.devices[0].devid = 0;
  431. arch.devices[0].ncores = 1;
  432. _starpu_compute_buffers_footprint(j->task->cl->model, &arch, 0, j);
  433. free(arch.devices);
  434. size_t data_size = 0;
  435. if (j->task->cl)
  436. {
  437. unsigned i, nbuffers = STARPU_TASK_GET_NBUFFERS(j->task);
  438. for(i = 0; i < nbuffers; i++)
  439. {
  440. starpu_data_handle_t handle = STARPU_TASK_GET_HANDLE(task, i);
  441. if (handle != NULL)
  442. data_size += _starpu_data_get_size(handle);
  443. }
  444. }
  445. _STARPU_TRACE_HYPERVISOR_BEGIN();
  446. sched_ctx->perf_counters->notify_submitted_job(j->task, j->footprint, data_size);
  447. _STARPU_TRACE_HYPERVISOR_END();
  448. }
  449. #endif//STARPU_USE_SC_HYPERVISOR
  450. /* We retain handle reference count */
  451. if (task->cl && !continuation)
  452. {
  453. unsigned i;
  454. unsigned nbuffers = STARPU_TASK_GET_NBUFFERS(task);
  455. for (i=0; i<nbuffers; i++)
  456. {
  457. starpu_data_handle_t handle = STARPU_TASK_GET_HANDLE(task, i);
  458. _starpu_spin_lock(&handle->header_lock);
  459. handle->busy_count++;
  460. _starpu_spin_unlock(&handle->header_lock);
  461. }
  462. }
  463. STARPU_PTHREAD_MUTEX_LOCK(&j->sync_mutex);
  464. _starpu_handle_job_submission(j);
  465. #ifdef STARPU_OPENMP
  466. if (continuation)
  467. {
  468. j->discontinuous = 1;
  469. j->continuation = 0;
  470. }
  471. #endif
  472. if (nodeps)
  473. {
  474. ret = _starpu_take_deps_and_schedule(j);
  475. }
  476. else
  477. {
  478. #ifdef STARPU_OPENMP
  479. if (continuation)
  480. {
  481. ret = _starpu_reenforce_task_deps_and_schedule(j);
  482. }
  483. else
  484. #endif
  485. {
  486. ret = _starpu_enforce_deps_and_schedule(j);
  487. }
  488. }
  489. _STARPU_LOG_OUT();
  490. return ret;
  491. }
  492. /* Note: this is racy, so valgrind would complain. But since we'll always put
  493. * the same values, this is not a problem. */
  494. void _starpu_codelet_check_deprecated_fields(struct starpu_codelet *cl)
  495. {
  496. if (!cl)
  497. return;
  498. if (cl->checked)
  499. {
  500. STARPU_RMB();
  501. return;
  502. }
  503. uint32_t where = cl->where;
  504. int is_where_unset = where == 0;
  505. unsigned i, some_impl;
  506. /* Check deprecated and unset fields (where, <device>_func,
  507. * <device>_funcs) */
  508. /* CPU */
  509. if (cl->cpu_func && cl->cpu_func != STARPU_MULTIPLE_CPU_IMPLEMENTATIONS && cl->cpu_funcs[0])
  510. {
  511. _STARPU_DISP("[warning] [struct starpu_codelet] both cpu_func and cpu_funcs are set. Ignoring cpu_func.\n");
  512. cl->cpu_func = STARPU_MULTIPLE_CPU_IMPLEMENTATIONS;
  513. }
  514. if (cl->cpu_func && cl->cpu_func != STARPU_MULTIPLE_CPU_IMPLEMENTATIONS)
  515. {
  516. cl->cpu_funcs[0] = cl->cpu_func;
  517. cl->cpu_func = STARPU_MULTIPLE_CPU_IMPLEMENTATIONS;
  518. }
  519. some_impl = 0;
  520. for (i = 0; i < STARPU_MAXIMPLEMENTATIONS; i++)
  521. if (cl->cpu_funcs[i])
  522. {
  523. some_impl = 1;
  524. break;
  525. }
  526. if (some_impl && cl->cpu_func == 0)
  527. {
  528. cl->cpu_func = STARPU_MULTIPLE_CPU_IMPLEMENTATIONS;
  529. }
  530. if (some_impl && is_where_unset)
  531. {
  532. where |= STARPU_CPU;
  533. }
  534. /* FPGA */
  535. some_impl = 0;
  536. for (i = 0; i < STARPU_MAXIMPLEMENTATIONS; i++)
  537. if (cl->fpga_funcs[i])
  538. {
  539. some_impl = 1;
  540. break;
  541. }
  542. if (some_impl && is_where_unset)
  543. {
  544. where |= STARPU_FPGA;
  545. }
  546. /* CUDA */
  547. if (cl->cuda_func && cl->cuda_func != STARPU_MULTIPLE_CUDA_IMPLEMENTATIONS && cl->cuda_funcs[0])
  548. {
  549. _STARPU_DISP("[warning] [struct starpu_codelet] both cuda_func and cuda_funcs are set. Ignoring cuda_func.\n");
  550. cl->cuda_func = STARPU_MULTIPLE_CUDA_IMPLEMENTATIONS;
  551. }
  552. if (cl->cuda_func && cl->cuda_func != STARPU_MULTIPLE_CUDA_IMPLEMENTATIONS)
  553. {
  554. cl->cuda_funcs[0] = cl->cuda_func;
  555. cl->cuda_func = STARPU_MULTIPLE_CUDA_IMPLEMENTATIONS;
  556. }
  557. some_impl = 0;
  558. for (i = 0; i < STARPU_MAXIMPLEMENTATIONS; i++)
  559. if (cl->cuda_funcs[i])
  560. {
  561. some_impl = 1;
  562. break;
  563. }
  564. if (some_impl && cl->cuda_func == 0)
  565. {
  566. cl->cuda_func = STARPU_MULTIPLE_CUDA_IMPLEMENTATIONS;
  567. }
  568. if (some_impl && is_where_unset)
  569. {
  570. where |= STARPU_CUDA;
  571. }
  572. /* OpenCL */
  573. if (cl->opencl_func && cl->opencl_func != STARPU_MULTIPLE_OPENCL_IMPLEMENTATIONS && cl->opencl_funcs[0])
  574. {
  575. _STARPU_DISP("[warning] [struct starpu_codelet] both opencl_func and opencl_funcs are set. Ignoring opencl_func.\n");
  576. cl->opencl_func = STARPU_MULTIPLE_OPENCL_IMPLEMENTATIONS;
  577. }
  578. if (cl->opencl_func && cl->opencl_func != STARPU_MULTIPLE_OPENCL_IMPLEMENTATIONS)
  579. {
  580. cl->opencl_funcs[0] = cl->opencl_func;
  581. cl->opencl_func = STARPU_MULTIPLE_OPENCL_IMPLEMENTATIONS;
  582. }
  583. some_impl = 0;
  584. for (i = 0; i < STARPU_MAXIMPLEMENTATIONS; i++)
  585. if (cl->opencl_funcs[i])
  586. {
  587. some_impl = 1;
  588. break;
  589. }
  590. if (some_impl && cl->opencl_func == 0)
  591. {
  592. cl->opencl_func = STARPU_MULTIPLE_OPENCL_IMPLEMENTATIONS;
  593. }
  594. if (some_impl && is_where_unset)
  595. {
  596. where |= STARPU_OPENCL;
  597. }
  598. some_impl = 0;
  599. for (i = 0; i < STARPU_MAXIMPLEMENTATIONS; i++)
  600. if (cl->mic_funcs[i])
  601. {
  602. some_impl = 1;
  603. break;
  604. }
  605. if (some_impl && is_where_unset)
  606. {
  607. where |= STARPU_MIC;
  608. }
  609. some_impl = 0;
  610. for (i = 0; i < STARPU_MAXIMPLEMENTATIONS; i++)
  611. if (cl->mpi_ms_funcs[i])
  612. {
  613. some_impl = 1;
  614. break;
  615. }
  616. if (some_impl && is_where_unset)
  617. {
  618. where |= STARPU_MPI_MS;
  619. }
  620. some_impl = 0;
  621. for (i = 0; i < STARPU_MAXIMPLEMENTATIONS; i++)
  622. if (cl->cpu_funcs_name[i])
  623. {
  624. some_impl = 1;
  625. break;
  626. }
  627. if (some_impl && is_where_unset)
  628. {
  629. where |= STARPU_MIC|STARPU_MPI_MS;
  630. }
  631. cl->where = where;
  632. STARPU_WMB();
  633. cl->checked = 1;
  634. }
  635. void _starpu_task_check_deprecated_fields(struct starpu_task *task STARPU_ATTRIBUTE_UNUSED)
  636. {
  637. /* None any more */
  638. }
  639. static int _starpu_task_submit_head(struct starpu_task *task)
  640. {
  641. unsigned is_sync = task->synchronous;
  642. struct _starpu_job *j = _starpu_get_job_associated_to_task(task);
  643. if (task->status == STARPU_TASK_STOPPED || task->status == STARPU_TASK_FINISHED)
  644. task->status = STARPU_TASK_INVALID;
  645. else
  646. STARPU_ASSERT(task->status == STARPU_TASK_INVALID);
  647. if (j->internal)
  648. {
  649. // Internal tasks are submitted to initial context
  650. task->sched_ctx = _starpu_get_initial_sched_ctx()->id;
  651. }
  652. else if (task->sched_ctx == STARPU_NMAX_SCHED_CTXS)
  653. {
  654. // If the task has not specified a context, we set the current context
  655. task->sched_ctx = _starpu_sched_ctx_get_current_context();
  656. }
  657. if (is_sync)
  658. {
  659. /* Perhaps it is not possible to submit a synchronous
  660. * (blocking) task */
  661. STARPU_ASSERT_MSG(_starpu_worker_may_perform_blocking_calls(), "submitting a synchronous task must not be done from a task or a callback");
  662. task->detach = 0;
  663. }
  664. _starpu_task_check_deprecated_fields(task);
  665. _starpu_codelet_check_deprecated_fields(task->cl);
  666. if (task->where== -1 && task->cl)
  667. task->where = task->cl->where;
  668. if (task->cl)
  669. {
  670. unsigned i;
  671. unsigned nbuffers = STARPU_TASK_GET_NBUFFERS(task);
  672. _STARPU_TRACE_UPDATE_TASK_CNT(0);
  673. /* Check buffers */
  674. if (task->dyn_handles == NULL)
  675. STARPU_ASSERT_MSG(STARPU_TASK_GET_NBUFFERS(task) <= STARPU_NMAXBUFS,
  676. "Codelet %p has too many buffers (%d vs max %d). Either use --enable-maxbuffers configure option to increase the max, or use dyn_handles instead of handles.",
  677. task->cl, STARPU_TASK_GET_NBUFFERS(task), STARPU_NMAXBUFS);
  678. if (STARPU_UNLIKELY(task->dyn_handles))
  679. {
  680. _STARPU_MALLOC(task->dyn_interfaces, nbuffers * sizeof(void *));
  681. }
  682. for (i = 0; i < nbuffers; i++)
  683. {
  684. starpu_data_handle_t handle = STARPU_TASK_GET_HANDLE(task, i);
  685. enum starpu_data_access_mode mode = STARPU_TASK_GET_MODE(task, i);
  686. int node = task->cl->specific_nodes ? STARPU_CODELET_GET_NODE(task->cl, i) : -1;
  687. /* Make sure handles are valid */
  688. STARPU_ASSERT_MSG(handle->magic == _STARPU_TASK_MAGIC, "data %p is invalid (was it already unregistered?)", handle);
  689. /* Make sure handles are not partitioned */
  690. STARPU_ASSERT_MSG(handle->nchildren == 0, "only unpartitioned data (or the pieces of a partitioned data) can be used in a task");
  691. /* Make sure the specified node exists */
  692. STARPU_ASSERT_MSG(node == STARPU_SPECIFIC_NODE_LOCAL || node == STARPU_SPECIFIC_NODE_CPU || node == STARPU_SPECIFIC_NODE_SLOW || node == STARPU_SPECIFIC_NODE_LOCAL_OR_CPU || (node >= 0 && node < (int) starpu_memory_nodes_get_count()), "The codelet-specified memory node does not exist");
  693. /* Provide the home interface for now if any,
  694. * for can_execute hooks */
  695. if (handle->home_node != -1)
  696. _STARPU_TASK_SET_INTERFACE(task, starpu_data_get_interface_on_node(handle, handle->home_node), i);
  697. if (!(task->cl->flags & STARPU_CODELET_NOPLANS) &&
  698. ((handle->nplans && !handle->nchildren) || handle->siblings)
  699. && handle->partition_automatic_disabled == 0
  700. )
  701. /* This handle is involved with asynchronous
  702. * partitioning as a parent or a child, make
  703. * sure the right plan is active, submit
  704. * appropiate partitioning / unpartitioning if
  705. * not */
  706. _starpu_data_partition_access_submit(handle, (mode & STARPU_W) != 0);
  707. }
  708. /* Check the type of worker(s) required by the task exist */
  709. if (STARPU_UNLIKELY(!_starpu_worker_exists(task)))
  710. {
  711. _STARPU_LOG_OUT_TAG("ENODEV");
  712. return -ENODEV;
  713. }
  714. /* In case we require that a task should be explicitely
  715. * executed on a specific worker, we make sure that the worker
  716. * is able to execute this task. */
  717. if (STARPU_UNLIKELY(task->execute_on_a_specific_worker && !starpu_combined_worker_can_execute_task(task->workerid, task, 0)))
  718. {
  719. _STARPU_LOG_OUT_TAG("ENODEV");
  720. return -ENODEV;
  721. }
  722. if (task->cl->model)
  723. _starpu_init_and_load_perfmodel(task->cl->model);
  724. if (task->cl->energy_model)
  725. _starpu_init_and_load_perfmodel(task->cl->energy_model);
  726. }
  727. return 0;
  728. }
  729. /* application should submit new tasks to StarPU through this function */
  730. int _starpu_task_submit(struct starpu_task *task, int nodeps)
  731. {
  732. _STARPU_LOG_IN();
  733. STARPU_ASSERT(task);
  734. STARPU_ASSERT_MSG(task->magic == _STARPU_TASK_MAGIC, "Tasks must be created with starpu_task_create, or initialized with starpu_task_init.");
  735. int ret;
  736. {
  737. /* task knobs */
  738. if (task->priority > __s_max_priority_cap__value)
  739. task->priority = __s_max_priority_cap__value;
  740. if (task->priority < __s_min_priority_cap__value)
  741. task->priority = __s_min_priority_cap__value;
  742. }
  743. unsigned is_sync = task->synchronous;
  744. starpu_task_bundle_t bundle = task->bundle;
  745. STARPU_ASSERT_MSG(!(nodeps && bundle), "not supported\n");
  746. /* internally, StarPU manipulates a struct _starpu_job * which is a wrapper around a
  747. * task structure, it is possible that this job structure was already
  748. * allocated. */
  749. struct _starpu_job *j = _starpu_get_job_associated_to_task(task);
  750. const unsigned continuation =
  751. #ifdef STARPU_OPENMP
  752. j->continuation
  753. #else
  754. 0
  755. #endif
  756. ;
  757. if (!_starpu_perf_counter_paused() && !j->internal && !continuation)
  758. {
  759. (void) STARPU_ATOMIC_ADD64(&_starpu_task__g_total_submitted__value, 1);
  760. int64_t value = STARPU_ATOMIC_ADD64(&_starpu_task__g_current_submitted__value, 1);
  761. _starpu_perf_counter_update_max_int64(&_starpu_task__g_peak_submitted__value, value);
  762. _starpu_perf_counter_update_global_sample();
  763. if (task->cl && task->cl->perf_counter_values)
  764. {
  765. struct starpu_perf_counter_sample_cl_values * const pcv = task->cl->perf_counter_values;
  766. (void) STARPU_ATOMIC_ADD64(&pcv->task.total_submitted, 1);
  767. value = STARPU_ATOMIC_ADD64(&pcv->task.current_submitted, 1);
  768. _starpu_perf_counter_update_max_int64(&pcv->task.peak_submitted, value);
  769. _starpu_perf_counter_update_per_codelet_sample(task->cl);
  770. }
  771. }
  772. STARPU_ASSERT_MSG(!(nodeps && continuation), "not supported\n");
  773. if (!j->internal)
  774. {
  775. int nsubmitted_tasks = starpu_task_nsubmitted();
  776. if (limit_max_submitted_tasks >= 0 && limit_max_submitted_tasks < nsubmitted_tasks
  777. && limit_min_submitted_tasks >= 0 && limit_min_submitted_tasks < nsubmitted_tasks)
  778. {
  779. starpu_do_schedule();
  780. _STARPU_TRACE_TASK_THROTTLE_START();
  781. starpu_task_wait_for_n_submitted(limit_min_submitted_tasks);
  782. _STARPU_TRACE_TASK_THROTTLE_END();
  783. }
  784. }
  785. _STARPU_TRACE_TASK_SUBMIT_START();
  786. ret = _starpu_task_submit_head(task);
  787. if (ret)
  788. {
  789. _STARPU_TRACE_TASK_SUBMIT_END();
  790. return ret;
  791. }
  792. if (!continuation)
  793. {
  794. STARPU_ASSERT_MSG(!j->submitted || j->terminated >= 1, "Tasks can not be submitted a second time before being terminated. Please use different task structures, or use the regenerate flag to let the task resubmit itself automatically.");
  795. _STARPU_TRACE_TASK_SUBMIT(j,
  796. _starpu_get_sched_ctx_struct(task->sched_ctx)->iterations[0],
  797. _starpu_get_sched_ctx_struct(task->sched_ctx)->iterations[1]);
  798. }
  799. /* If this is a continuation, we don't modify the implicit data dependencies detected earlier. */
  800. if (task->cl && !continuation)
  801. {
  802. _starpu_job_set_ordered_buffers(j);
  803. if (!nodeps)
  804. _starpu_detect_implicit_data_deps(task);
  805. }
  806. if (STARPU_UNLIKELY(bundle))
  807. {
  808. /* We need to make sure that models for other tasks of the
  809. * bundle are also loaded, so the scheduler can estimate the
  810. * duration of the whole bundle */
  811. STARPU_PTHREAD_MUTEX_LOCK(&bundle->mutex);
  812. struct _starpu_task_bundle_entry *entry;
  813. entry = bundle->list;
  814. while (entry)
  815. {
  816. if (entry->task->cl->model)
  817. _starpu_init_and_load_perfmodel(entry->task->cl->model);
  818. if (entry->task->cl->energy_model)
  819. _starpu_init_and_load_perfmodel(entry->task->cl->energy_model);
  820. entry = entry->next;
  821. }
  822. STARPU_PTHREAD_MUTEX_UNLOCK(&bundle->mutex);
  823. }
  824. /* If profiling is activated, we allocate a structure to store the
  825. * appropriate info. */
  826. struct starpu_profiling_task_info *info;
  827. int profiling = starpu_profiling_status_get();
  828. info = _starpu_allocate_profiling_info_if_needed(task);
  829. task->profiling_info = info;
  830. /* The task is considered as block until we are sure there remains not
  831. * dependency. */
  832. task->status = STARPU_TASK_BLOCKED;
  833. if (STARPU_UNLIKELY(profiling))
  834. _starpu_clock_gettime(&info->submit_time);
  835. ret = _starpu_submit_job(j, nodeps);
  836. #ifdef STARPU_SIMGRID
  837. if (_starpu_simgrid_task_submit_cost())
  838. starpu_sleep(0.000001);
  839. #endif
  840. if (is_sync)
  841. {
  842. _starpu_sched_do_schedule(task->sched_ctx);
  843. _starpu_wait_job(j);
  844. if (task->destroy)
  845. _starpu_task_destroy(task);
  846. }
  847. _STARPU_TRACE_TASK_SUBMIT_END();
  848. _STARPU_LOG_OUT();
  849. return ret;
  850. }
  851. int starpu_task_submit(struct starpu_task *task)
  852. {
  853. return _starpu_task_submit(task, 0);
  854. }
  855. int _starpu_task_submit_internally(struct starpu_task *task)
  856. {
  857. struct _starpu_job *j = _starpu_get_job_associated_to_task(task);
  858. j->internal = 1;
  859. return starpu_task_submit(task);
  860. }
  861. /* application should submit new tasks to StarPU through this function */
  862. int starpu_task_submit_to_ctx(struct starpu_task *task, unsigned sched_ctx_id)
  863. {
  864. task->sched_ctx = sched_ctx_id;
  865. return starpu_task_submit(task);
  866. }
  867. /* The StarPU core can submit tasks directly to the scheduler or a worker,
  868. * skipping dependencies completely (when it knows what it is doing). */
  869. int starpu_task_submit_nodeps(struct starpu_task *task)
  870. {
  871. return _starpu_task_submit(task, 1);
  872. }
  873. /*
  874. * worker->sched_mutex must be locked when calling this function.
  875. */
  876. int _starpu_task_submit_conversion_task(struct starpu_task *task,
  877. unsigned int workerid)
  878. {
  879. int ret;
  880. STARPU_ASSERT(task->cl);
  881. STARPU_ASSERT(task->execute_on_a_specific_worker);
  882. ret = _starpu_task_submit_head(task);
  883. STARPU_ASSERT(ret == 0);
  884. /* We retain handle reference count that would have been acquired by data dependencies. */
  885. unsigned i;
  886. unsigned nbuffers = STARPU_TASK_GET_NBUFFERS(task);
  887. for (i=0; i<nbuffers; i++)
  888. {
  889. starpu_data_handle_t handle = STARPU_TASK_GET_HANDLE(task, i);
  890. _starpu_spin_lock(&handle->header_lock);
  891. handle->busy_count++;
  892. _starpu_spin_unlock(&handle->header_lock);
  893. }
  894. struct _starpu_job *j = _starpu_get_job_associated_to_task(task);
  895. _starpu_increment_nsubmitted_tasks_of_sched_ctx(j->task->sched_ctx);
  896. _starpu_sched_task_submit(task);
  897. STARPU_PTHREAD_MUTEX_LOCK(&j->sync_mutex);
  898. _starpu_handle_job_submission(j);
  899. _starpu_increment_nready_tasks_of_sched_ctx(j->task->sched_ctx, j->task->flops, j->task);
  900. _starpu_job_set_ordered_buffers(j);
  901. STARPU_ASSERT(task->status == STARPU_TASK_INVALID);
  902. task->status = STARPU_TASK_READY;
  903. _starpu_profiling_set_task_push_start_time(task);
  904. unsigned node = starpu_worker_get_memory_node(workerid);
  905. if (starpu_get_prefetch_flag())
  906. starpu_prefetch_task_input_on_node(task, node);
  907. struct _starpu_worker *worker;
  908. worker = _starpu_get_worker_struct(workerid);
  909. starpu_task_list_push_back(&worker->local_tasks, task);
  910. starpu_wake_worker_locked(worker->workerid);
  911. _starpu_profiling_set_task_push_end_time(task);
  912. STARPU_PTHREAD_MUTEX_UNLOCK(&j->sync_mutex);
  913. return 0;
  914. }
  915. void starpu_codelet_init(struct starpu_codelet *cl)
  916. {
  917. memset(cl, 0, sizeof(struct starpu_codelet));
  918. }
  919. #define _STARPU_CODELET_WORKER_NAME_LEN 32
  920. void starpu_codelet_display_stats(struct starpu_codelet *cl)
  921. {
  922. unsigned worker;
  923. unsigned nworkers = starpu_worker_get_count();
  924. if (cl->name)
  925. fprintf(stderr, "Statistics for codelet %s\n", cl->name);
  926. else if (cl->model && cl->model->symbol)
  927. fprintf(stderr, "Statistics for codelet %s\n", cl->model->symbol);
  928. unsigned long total = 0;
  929. for (worker = 0; worker < nworkers; worker++)
  930. total += cl->per_worker_stats[worker];
  931. for (worker = 0; worker < nworkers; worker++)
  932. {
  933. char name[_STARPU_CODELET_WORKER_NAME_LEN];
  934. starpu_worker_get_name(worker, name, _STARPU_CODELET_WORKER_NAME_LEN);
  935. fprintf(stderr, "\t%s -> %lu / %lu (%2.2f %%)\n", name, cl->per_worker_stats[worker], total, (100.0f*cl->per_worker_stats[worker])/total);
  936. }
  937. }
  938. /*
  939. * We wait for all the tasks that have already been submitted. Note that a
  940. * regenerable is not considered finished until it was explicitely set as
  941. * non-regenerale anymore (eg. from a callback).
  942. */
  943. int _starpu_task_wait_for_all_and_return_nb_waited_tasks(void)
  944. {
  945. unsigned nsched_ctxs = _starpu_get_nsched_ctxs();
  946. unsigned sched_ctx_id = nsched_ctxs == 1 ? 0 : starpu_sched_ctx_get_context();
  947. /* if there is no indication about which context to wait,
  948. we wait for all tasks submitted to starpu */
  949. if (sched_ctx_id == STARPU_NMAX_SCHED_CTXS)
  950. {
  951. _STARPU_DEBUG("Waiting for all tasks\n");
  952. STARPU_ASSERT_MSG(_starpu_worker_may_perform_blocking_calls(), "starpu_task_wait_for_all must not be called from a task or callback");
  953. STARPU_AYU_BARRIER();
  954. struct _starpu_machine_config *config = _starpu_get_machine_config();
  955. if(config->topology.nsched_ctxs == 1)
  956. {
  957. _starpu_sched_do_schedule(0);
  958. return _starpu_task_wait_for_all_in_ctx_and_return_nb_waited_tasks(0);
  959. }
  960. else
  961. {
  962. int s;
  963. for(s = 0; s < STARPU_NMAX_SCHED_CTXS; s++)
  964. {
  965. if(config->sched_ctxs[s].do_schedule == 1)
  966. {
  967. _starpu_sched_do_schedule(config->sched_ctxs[s].id);
  968. }
  969. }
  970. for(s = 0; s < STARPU_NMAX_SCHED_CTXS; s++)
  971. {
  972. if(config->sched_ctxs[s].do_schedule == 1)
  973. {
  974. starpu_task_wait_for_all_in_ctx(config->sched_ctxs[s].id);
  975. }
  976. }
  977. return 0;
  978. }
  979. }
  980. else
  981. {
  982. _starpu_sched_do_schedule(sched_ctx_id);
  983. _STARPU_DEBUG("Waiting for tasks submitted to context %u\n", sched_ctx_id);
  984. return _starpu_task_wait_for_all_in_ctx_and_return_nb_waited_tasks(sched_ctx_id);
  985. }
  986. }
  987. int starpu_task_wait_for_all(void)
  988. {
  989. _starpu_task_wait_for_all_and_return_nb_waited_tasks();
  990. if (!_starpu_perf_counter_paused())
  991. _starpu_perf_counter_update_global_sample();
  992. return 0;
  993. }
  994. int _starpu_task_wait_for_all_in_ctx_and_return_nb_waited_tasks(unsigned sched_ctx)
  995. {
  996. _STARPU_TRACE_TASK_WAIT_FOR_ALL_START();
  997. int ret = _starpu_wait_for_all_tasks_of_sched_ctx(sched_ctx);
  998. _STARPU_TRACE_TASK_WAIT_FOR_ALL_END();
  999. /* TODO: improve Temanejo into knowing about contexts ... */
  1000. STARPU_AYU_BARRIER();
  1001. return ret;
  1002. }
  1003. int starpu_task_wait_for_all_in_ctx(unsigned sched_ctx)
  1004. {
  1005. _starpu_task_wait_for_all_in_ctx_and_return_nb_waited_tasks(sched_ctx);
  1006. if (!_starpu_perf_counter_paused())
  1007. _starpu_perf_counter_update_global_sample();
  1008. return 0;
  1009. }
  1010. /*
  1011. * We wait until there's a certain number of the tasks that have already been
  1012. * submitted left. Note that a regenerable is not considered finished until it
  1013. * was explicitely set as non-regenerale anymore (eg. from a callback).
  1014. */
  1015. int starpu_task_wait_for_n_submitted(unsigned n)
  1016. {
  1017. unsigned nsched_ctxs = _starpu_get_nsched_ctxs();
  1018. unsigned sched_ctx_id = nsched_ctxs == 1 ? 0 : starpu_sched_ctx_get_context();
  1019. /* if there is no indication about which context to wait,
  1020. we wait for all tasks submitted to starpu */
  1021. if (sched_ctx_id == STARPU_NMAX_SCHED_CTXS)
  1022. {
  1023. _STARPU_DEBUG("Waiting for all tasks\n");
  1024. STARPU_ASSERT_MSG(_starpu_worker_may_perform_blocking_calls(), "starpu_task_wait_for_n_submitted must not be called from a task or callback");
  1025. struct _starpu_machine_config *config = _starpu_get_machine_config();
  1026. if(config->topology.nsched_ctxs == 1)
  1027. _starpu_wait_for_n_submitted_tasks_of_sched_ctx(0, n);
  1028. else
  1029. {
  1030. int s;
  1031. for(s = 0; s < STARPU_NMAX_SCHED_CTXS; s++)
  1032. {
  1033. if(config->sched_ctxs[s].do_schedule == 1)
  1034. {
  1035. _starpu_wait_for_n_submitted_tasks_of_sched_ctx(config->sched_ctxs[s].id, n);
  1036. }
  1037. }
  1038. }
  1039. }
  1040. else
  1041. {
  1042. _STARPU_DEBUG("Waiting for tasks submitted to context %u\n", sched_ctx_id);
  1043. _starpu_wait_for_n_submitted_tasks_of_sched_ctx(sched_ctx_id, n);
  1044. }
  1045. if (!_starpu_perf_counter_paused())
  1046. _starpu_perf_counter_update_global_sample();
  1047. return 0;
  1048. }
  1049. int starpu_task_wait_for_n_submitted_in_ctx(unsigned sched_ctx, unsigned n)
  1050. {
  1051. _starpu_wait_for_n_submitted_tasks_of_sched_ctx(sched_ctx, n);
  1052. if (!_starpu_perf_counter_paused())
  1053. _starpu_perf_counter_update_global_sample();
  1054. return 0;
  1055. }
  1056. /*
  1057. * We wait until there is no ready task any more (i.e. StarPU will not be able
  1058. * to progress any more).
  1059. */
  1060. int starpu_task_wait_for_no_ready(void)
  1061. {
  1062. STARPU_ASSERT_MSG(_starpu_worker_may_perform_blocking_calls(), "starpu_task_wait_for_no_ready must not be called from a task or callback");
  1063. struct _starpu_machine_config *config = _starpu_get_machine_config();
  1064. if(config->topology.nsched_ctxs == 1)
  1065. {
  1066. _starpu_sched_do_schedule(0);
  1067. _starpu_wait_for_no_ready_of_sched_ctx(0);
  1068. }
  1069. else
  1070. {
  1071. int s;
  1072. for(s = 0; s < STARPU_NMAX_SCHED_CTXS; s++)
  1073. {
  1074. if(config->sched_ctxs[s].do_schedule == 1)
  1075. {
  1076. _starpu_sched_do_schedule(config->sched_ctxs[s].id);
  1077. }
  1078. }
  1079. for(s = 0; s < STARPU_NMAX_SCHED_CTXS; s++)
  1080. {
  1081. if(config->sched_ctxs[s].do_schedule == 1)
  1082. {
  1083. _starpu_wait_for_no_ready_of_sched_ctx(config->sched_ctxs[s].id);
  1084. }
  1085. }
  1086. }
  1087. if (!_starpu_perf_counter_paused())
  1088. _starpu_perf_counter_update_global_sample();
  1089. return 0;
  1090. }
  1091. void starpu_iteration_push(unsigned long iteration)
  1092. {
  1093. struct _starpu_sched_ctx *ctx = _starpu_get_sched_ctx_struct(_starpu_sched_ctx_get_current_context());
  1094. unsigned level = ctx->iteration_level++;
  1095. if (level < sizeof(ctx->iterations)/sizeof(ctx->iterations[0]))
  1096. ctx->iterations[level] = iteration;
  1097. }
  1098. void starpu_iteration_pop(void)
  1099. {
  1100. struct _starpu_sched_ctx *ctx = _starpu_get_sched_ctx_struct(_starpu_sched_ctx_get_current_context());
  1101. STARPU_ASSERT_MSG(ctx->iteration_level > 0, "calls to starpu_iteration_pop must match starpu_iteration_push calls");
  1102. unsigned level = ctx->iteration_level--;
  1103. if (level < sizeof(ctx->iterations)/sizeof(ctx->iterations[0]))
  1104. ctx->iterations[level] = -1;
  1105. }
  1106. void starpu_do_schedule(void)
  1107. {
  1108. struct _starpu_machine_config *config = _starpu_get_machine_config();
  1109. if(config->topology.nsched_ctxs == 1)
  1110. _starpu_sched_do_schedule(0);
  1111. else
  1112. {
  1113. int s;
  1114. for(s = 0; s < STARPU_NMAX_SCHED_CTXS; s++)
  1115. {
  1116. if(config->sched_ctxs[s].do_schedule == 1)
  1117. {
  1118. _starpu_sched_do_schedule(config->sched_ctxs[s].id);
  1119. }
  1120. }
  1121. }
  1122. }
  1123. void
  1124. starpu_drivers_request_termination(void)
  1125. {
  1126. struct _starpu_machine_config *config = _starpu_get_machine_config();
  1127. STARPU_PTHREAD_MUTEX_LOCK(&config->submitted_mutex);
  1128. int nsubmitted = starpu_task_nsubmitted();
  1129. config->submitting = 0;
  1130. if (nsubmitted == 0)
  1131. {
  1132. ANNOTATE_HAPPENS_AFTER(&config->running);
  1133. config->running = 0;
  1134. ANNOTATE_HAPPENS_BEFORE(&config->running);
  1135. STARPU_WMB();
  1136. int s;
  1137. for(s = 0; s < STARPU_NMAX_SCHED_CTXS; s++)
  1138. {
  1139. if(config->sched_ctxs[s].do_schedule == 1)
  1140. {
  1141. _starpu_check_nsubmitted_tasks_of_sched_ctx(config->sched_ctxs[s].id);
  1142. }
  1143. }
  1144. }
  1145. STARPU_PTHREAD_MUTEX_UNLOCK(&config->submitted_mutex);
  1146. }
  1147. int starpu_task_nsubmitted(void)
  1148. {
  1149. int nsubmitted = 0;
  1150. struct _starpu_machine_config *config = _starpu_get_machine_config();
  1151. if(config->topology.nsched_ctxs == 1)
  1152. nsubmitted = _starpu_get_nsubmitted_tasks_of_sched_ctx(0);
  1153. else
  1154. {
  1155. int s;
  1156. for(s = 0; s < STARPU_NMAX_SCHED_CTXS; s++)
  1157. {
  1158. if(config->sched_ctxs[s].do_schedule == 1)
  1159. {
  1160. nsubmitted += _starpu_get_nsubmitted_tasks_of_sched_ctx(config->sched_ctxs[s].id);
  1161. }
  1162. }
  1163. }
  1164. return nsubmitted;
  1165. }
  1166. int starpu_task_nready(void)
  1167. {
  1168. int nready = 0;
  1169. struct _starpu_machine_config *config = _starpu_get_machine_config();
  1170. if(config->topology.nsched_ctxs == 1)
  1171. nready = starpu_sched_ctx_get_nready_tasks(0);
  1172. else
  1173. {
  1174. int s;
  1175. for(s = 0; s < STARPU_NMAX_SCHED_CTXS; s++)
  1176. {
  1177. if(config->sched_ctxs[s].do_schedule == 1)
  1178. {
  1179. nready += starpu_sched_ctx_get_nready_tasks(config->sched_ctxs[s].id);
  1180. }
  1181. }
  1182. }
  1183. return nready;
  1184. }
  1185. /* Return the task currently executed by the worker, or NULL if this is called
  1186. * either from a thread that is not a task or simply because there is no task
  1187. * being executed at the moment. */
  1188. struct starpu_task *starpu_task_get_current(void)
  1189. {
  1190. return (struct starpu_task *) STARPU_PTHREAD_GETSPECIFIC(current_task_key);
  1191. }
  1192. void _starpu_set_current_task(struct starpu_task *task)
  1193. {
  1194. STARPU_PTHREAD_SETSPECIFIC(current_task_key, task);
  1195. }
  1196. int starpu_task_get_current_data_node(unsigned i)
  1197. {
  1198. struct starpu_task *task = starpu_task_get_current();
  1199. if (!task)
  1200. return -1;
  1201. struct _starpu_job *j = _starpu_get_job_associated_to_task(task);
  1202. struct _starpu_data_descr *descrs = _STARPU_JOB_GET_ORDERED_BUFFERS(j);
  1203. unsigned orderedindex = descrs[i].orderedindex;
  1204. return descrs[orderedindex].node;
  1205. }
  1206. #ifdef STARPU_OPENMP
  1207. /* Prepare the fields of the currentl task for accepting a new set of
  1208. * dependencies in anticipation of becoming a continuation.
  1209. *
  1210. * When the task becomes 'continued', it will only be queued again when the new
  1211. * set of dependencies is fulfilled. */
  1212. void _starpu_task_prepare_for_continuation(void)
  1213. {
  1214. _starpu_job_prepare_for_continuation(_starpu_get_job_associated_to_task(starpu_task_get_current()));
  1215. }
  1216. void _starpu_task_prepare_for_continuation_ext(unsigned continuation_resubmit,
  1217. void (*continuation_callback_on_sleep)(void *arg), void *continuation_callback_on_sleep_arg)
  1218. {
  1219. _starpu_job_prepare_for_continuation_ext(_starpu_get_job_associated_to_task(starpu_task_get_current()),
  1220. continuation_resubmit, continuation_callback_on_sleep, continuation_callback_on_sleep_arg);
  1221. }
  1222. void _starpu_task_set_omp_cleanup_callback(struct starpu_task *task, void (*omp_cleanup_callback)(void *arg), void *omp_cleanup_callback_arg)
  1223. {
  1224. _starpu_job_set_omp_cleanup_callback(_starpu_get_job_associated_to_task(task),
  1225. omp_cleanup_callback, omp_cleanup_callback_arg);
  1226. }
  1227. #endif
  1228. /*
  1229. * Returns 0 if tasks does not use any multiformat handle, 1 otherwise.
  1230. */
  1231. int
  1232. _starpu_task_uses_multiformat_handles(struct starpu_task *task)
  1233. {
  1234. unsigned i;
  1235. unsigned nbuffers = STARPU_TASK_GET_NBUFFERS(task);
  1236. for (i = 0; i < nbuffers; i++)
  1237. {
  1238. if (_starpu_data_is_multiformat_handle(STARPU_TASK_GET_HANDLE(task, i)))
  1239. return 1;
  1240. }
  1241. return 0;
  1242. }
  1243. /*
  1244. * Checks whether the given handle needs to be converted in order to be used on
  1245. * the node given as the second argument.
  1246. */
  1247. int
  1248. _starpu_handle_needs_conversion_task(starpu_data_handle_t handle,
  1249. unsigned int node)
  1250. {
  1251. return _starpu_handle_needs_conversion_task_for_arch(handle, starpu_node_get_kind(node));
  1252. }
  1253. int
  1254. _starpu_handle_needs_conversion_task_for_arch(starpu_data_handle_t handle,
  1255. enum starpu_node_kind node_kind)
  1256. {
  1257. /*
  1258. * Here, we assume that CUDA devices and OpenCL devices use the
  1259. * same data structure. A conversion is only needed when moving
  1260. * data from a CPU to a GPU, or the other way around.
  1261. */
  1262. switch (node_kind)
  1263. {
  1264. case STARPU_CPU_RAM:
  1265. switch(starpu_node_get_kind(handle->mf_node))
  1266. {
  1267. case STARPU_CPU_RAM:
  1268. return 0;
  1269. case STARPU_CUDA_RAM: /* Fall through */
  1270. case STARPU_OPENCL_RAM:
  1271. case STARPU_MIC_RAM:
  1272. case STARPU_MPI_MS_RAM:
  1273. return 1;
  1274. default:
  1275. STARPU_ABORT();
  1276. }
  1277. break;
  1278. case STARPU_CUDA_RAM: /* Fall through */
  1279. case STARPU_OPENCL_RAM:
  1280. case STARPU_MIC_RAM:
  1281. case STARPU_MPI_MS_RAM:
  1282. switch(starpu_node_get_kind(handle->mf_node))
  1283. {
  1284. case STARPU_CPU_RAM:
  1285. return 1;
  1286. case STARPU_CUDA_RAM:
  1287. case STARPU_OPENCL_RAM:
  1288. case STARPU_MIC_RAM:
  1289. case STARPU_MPI_MS_RAM:
  1290. return 0;
  1291. default:
  1292. STARPU_ABORT();
  1293. }
  1294. break;
  1295. default:
  1296. STARPU_ABORT();
  1297. }
  1298. /* that instruction should never be reached */
  1299. return -EINVAL;
  1300. }
  1301. void starpu_task_set_implementation(struct starpu_task *task, unsigned impl)
  1302. {
  1303. _starpu_get_job_associated_to_task(task)->nimpl = impl;
  1304. }
  1305. unsigned starpu_task_get_implementation(struct starpu_task *task)
  1306. {
  1307. return _starpu_get_job_associated_to_task(task)->nimpl;
  1308. }
  1309. unsigned long starpu_task_get_job_id(struct starpu_task *task)
  1310. {
  1311. return _starpu_get_job_associated_to_task(task)->job_id;
  1312. }
  1313. static starpu_pthread_t watchdog_thread;
  1314. static int sleep_some(float timeout)
  1315. {
  1316. /* If we do a sleep(timeout), we might have to wait too long at the end of the computation. */
  1317. /* To avoid that, we do several sleep() of 1s (and check after each if starpu is still running) */
  1318. float t;
  1319. for (t = timeout ; t > 1.; t--)
  1320. {
  1321. starpu_sleep(1.);
  1322. if (!_starpu_machine_is_running())
  1323. /* Application finished, don't bother finishing the sleep */
  1324. return 0;
  1325. }
  1326. /* and one final sleep (of less than 1 s) with the rest (if needed) */
  1327. if (t > 0.)
  1328. starpu_sleep(t);
  1329. return 1;
  1330. }
  1331. /* Check from times to times that StarPU does finish some tasks */
  1332. static void *watchdog_func(void *arg)
  1333. {
  1334. char *timeout_env = arg;
  1335. float timeout, delay;
  1336. #ifdef _MSC_VER
  1337. timeout = ((float) _atoi64(timeout_env)) / 1000000;
  1338. #else
  1339. timeout = ((float) atoll(timeout_env)) / 1000000;
  1340. #endif
  1341. delay = ((float) watchdog_delay) / 1000000;
  1342. struct _starpu_machine_config *config = _starpu_get_machine_config();
  1343. starpu_pthread_setname("watchdog");
  1344. if (!sleep_some(delay))
  1345. return NULL;
  1346. STARPU_PTHREAD_MUTEX_LOCK(&config->submitted_mutex);
  1347. while (_starpu_machine_is_running())
  1348. {
  1349. int last_nsubmitted = starpu_task_nsubmitted();
  1350. config->watchdog_ok = 0;
  1351. STARPU_PTHREAD_MUTEX_UNLOCK(&config->submitted_mutex);
  1352. if (!sleep_some(timeout))
  1353. return NULL;
  1354. STARPU_PTHREAD_MUTEX_LOCK(&config->submitted_mutex);
  1355. if (!config->watchdog_ok && last_nsubmitted
  1356. && last_nsubmitted == starpu_task_nsubmitted())
  1357. {
  1358. if (watchdog_hook == NULL)
  1359. _STARPU_MSG("The StarPU watchdog detected that no task finished for %fs (can be configured through STARPU_WATCHDOG_TIMEOUT)\n",
  1360. timeout);
  1361. else
  1362. watchdog_hook(watchdog_hook_arg);
  1363. if (watchdog_crash)
  1364. {
  1365. _STARPU_MSG("Crashing the process\n");
  1366. raise(SIGABRT);
  1367. }
  1368. else if (watchdog_hook == NULL)
  1369. _STARPU_MSG("Set the STARPU_WATCHDOG_CRASH environment variable if you want to abort the process in such a case\n");
  1370. }
  1371. /* Only shout again after another period */
  1372. config->watchdog_ok = 1;
  1373. }
  1374. STARPU_PTHREAD_MUTEX_UNLOCK(&config->submitted_mutex);
  1375. return NULL;
  1376. }
  1377. void starpu_task_watchdog_set_hook(void (*hook)(void *), void *hook_arg)
  1378. {
  1379. watchdog_hook = hook;
  1380. watchdog_hook_arg = hook_arg;
  1381. }
  1382. void _starpu_watchdog_init()
  1383. {
  1384. struct _starpu_machine_config *config = _starpu_get_machine_config();
  1385. char *timeout_env = starpu_getenv("STARPU_WATCHDOG_TIMEOUT");
  1386. STARPU_PTHREAD_MUTEX_INIT(&config->submitted_mutex, NULL);
  1387. if (!timeout_env)
  1388. return;
  1389. STARPU_PTHREAD_CREATE(&watchdog_thread, NULL, watchdog_func, timeout_env);
  1390. }
  1391. void _starpu_watchdog_shutdown(void)
  1392. {
  1393. char *timeout_env = starpu_getenv("STARPU_WATCHDOG_TIMEOUT");
  1394. if (!timeout_env)
  1395. return;
  1396. STARPU_PTHREAD_JOIN(watchdog_thread, NULL);
  1397. }
  1398. static void _starpu_ft_check_support(const struct starpu_task *task)
  1399. {
  1400. unsigned nbuffers = STARPU_TASK_GET_NBUFFERS(task);
  1401. unsigned i;
  1402. for (i = 0; i < nbuffers; i++)
  1403. {
  1404. enum starpu_data_access_mode mode = STARPU_TASK_GET_MODE(task, i);
  1405. STARPU_ASSERT_MSG (mode == STARPU_R || mode == STARPU_W,
  1406. "starpu_task_failed is only supported for tasks with access modes STARPU_R and STARPU_W");
  1407. }
  1408. }
  1409. struct starpu_task *starpu_task_ft_create_retry
  1410. (const struct starpu_task *meta_task, const struct starpu_task *template_task, void (*check_ft)(void *))
  1411. {
  1412. /* Create a new task to actually perform the result */
  1413. struct starpu_task *new_task = starpu_task_create();
  1414. *new_task = *template_task;
  1415. new_task->prologue_callback_func = NULL;
  1416. /* XXX: cl_arg needs to be duplicated */
  1417. STARPU_ASSERT_MSG(!meta_task->cl_arg_free || !meta_task->cl_arg, "not supported yet");
  1418. STARPU_ASSERT_MSG(!meta_task->callback_func, "not supported");
  1419. new_task->callback_func = check_ft;
  1420. new_task->callback_arg = (void*) meta_task;
  1421. new_task->callback_arg_free = 0;
  1422. new_task->prologue_callback_arg_free = 0;
  1423. STARPU_ASSERT_MSG(!new_task->prologue_callback_pop_arg_free, "not supported");
  1424. new_task->use_tag = 0;
  1425. new_task->synchronous = 0;
  1426. new_task->destroy = 1;
  1427. new_task->regenerate = 0;
  1428. new_task->no_submitorder = 1;
  1429. new_task->failed = 0;
  1430. new_task->scheduled = 0;
  1431. new_task->prefetched = 0;
  1432. new_task->status = STARPU_TASK_INVALID;
  1433. new_task->profiling_info = NULL;
  1434. new_task->prev = NULL;
  1435. new_task->next = NULL;
  1436. new_task->starpu_private = NULL;
  1437. new_task->omp_task = NULL;
  1438. return new_task;
  1439. }
  1440. static void _starpu_default_check_ft(void *arg)
  1441. {
  1442. struct starpu_task *meta_task = arg;
  1443. struct starpu_task *current_task = starpu_task_get_current();
  1444. struct starpu_task *new_task;
  1445. int ret;
  1446. if (!current_task->failed)
  1447. {
  1448. starpu_task_ft_success(meta_task);
  1449. return;
  1450. }
  1451. new_task = starpu_task_ft_create_retry
  1452. (meta_task, current_task, _starpu_default_check_ft);
  1453. ret = starpu_task_submit_nodeps(new_task);
  1454. STARPU_ASSERT(!ret);
  1455. }
  1456. void starpu_task_ft_prologue(void *arg)
  1457. {
  1458. struct starpu_task *meta_task = starpu_task_get_current();
  1459. struct starpu_task *new_task;
  1460. void (*check_ft)(void*) = arg;
  1461. int ret;
  1462. if (!check_ft)
  1463. check_ft = _starpu_default_check_ft;
  1464. /* Create a task which will do the actual computation */
  1465. new_task = starpu_task_ft_create_retry
  1466. (meta_task, meta_task, check_ft);
  1467. ret = starpu_task_submit_nodeps(new_task);
  1468. STARPU_ASSERT(!ret);
  1469. /* Make the parent task wait for the result getting correct */
  1470. starpu_task_end_dep_add(meta_task, 1);
  1471. meta_task->where = STARPU_NOWHERE;
  1472. }
  1473. void starpu_task_ft_failed(struct starpu_task *task)
  1474. {
  1475. _starpu_ft_check_support(task);
  1476. task->failed = 1;
  1477. }
  1478. void starpu_task_ft_success(struct starpu_task *meta_task)
  1479. {
  1480. starpu_task_end_dep_release(meta_task);
  1481. }