workers.c 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2016 Université de Bordeaux
  4. * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 CNRS
  5. * Copyright (C) 2010, 2011 INRIA
  6. * Copyright (C) 2011 Télécom-SudParis
  7. * Copyright (C) 2011-2012, 2016 INRIA
  8. *
  9. * StarPU is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU Lesser General Public License as published by
  11. * the Free Software Foundation; either version 2.1 of the License, or (at
  12. * your option) any later version.
  13. *
  14. * StarPU is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  17. *
  18. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  19. */
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22. #include <common/config.h>
  23. #include <common/utils.h>
  24. #include <common/graph.h>
  25. #include <core/progress_hook.h>
  26. #include <core/workers.h>
  27. #include <core/debug.h>
  28. #include <core/disk.h>
  29. #include <core/task.h>
  30. #include <datawizard/malloc.h>
  31. #include <profiling/profiling.h>
  32. #include <starpu_task_list.h>
  33. #include <sched_policies/sched_component.h>
  34. #include <datawizard/memory_nodes.h>
  35. #include <top/starpu_top_core.h>
  36. #include <drivers/mp_common/sink_common.h>
  37. #include <drivers/scc/driver_scc_common.h>
  38. #include <drivers/mpi/driver_mpi_common.h>
  39. #include <drivers/cpu/driver_cpu.h>
  40. #include <drivers/cuda/driver_cuda.h>
  41. #include <drivers/opencl/driver_opencl.h>
  42. #ifdef STARPU_SIMGRID
  43. #include <core/simgrid.h>
  44. #endif
  45. #if defined(_WIN32) && !defined(__CYGWIN__)
  46. #include <windows.h>
  47. #endif
  48. /* acquire/release semantic for concurrent initialization/de-initialization */
  49. static starpu_pthread_mutex_t init_mutex = STARPU_PTHREAD_MUTEX_INITIALIZER;
  50. static starpu_pthread_cond_t init_cond = STARPU_PTHREAD_COND_INITIALIZER;
  51. static int init_count = 0;
  52. static enum { UNINITIALIZED, CHANGING, INITIALIZED } initialized = UNINITIALIZED;
  53. int _starpu_keys_initialized STARPU_ATTRIBUTE_INTERNAL;
  54. starpu_pthread_key_t _starpu_worker_key STARPU_ATTRIBUTE_INTERNAL;
  55. starpu_pthread_key_t _starpu_worker_set_key STARPU_ATTRIBUTE_INTERNAL;
  56. struct _starpu_machine_config _starpu_config STARPU_ATTRIBUTE_INTERNAL;
  57. static int check_entire_platform;
  58. /* Pointers to argc and argv
  59. */
  60. static int *my_argc = 0;
  61. static char ***my_argv = NULL;
  62. /* Initialize value of static argc and argv, called when the process begins
  63. */
  64. void _starpu_set_argc_argv(int *argc_param, char ***argv_param)
  65. {
  66. my_argc = argc_param;
  67. my_argv = argv_param;
  68. }
  69. int *_starpu_get_argc()
  70. {
  71. return my_argc;
  72. }
  73. char ***_starpu_get_argv()
  74. {
  75. return my_argv;
  76. }
  77. int _starpu_is_initialized(void)
  78. {
  79. return initialized == INITIALIZED;
  80. }
  81. /* Makes sure that at least one of the workers of type <arch> can execute
  82. * <task>, for at least one of its implementations. */
  83. static uint32_t _starpu_worker_exists_and_can_execute(struct starpu_task *task,
  84. enum starpu_worker_archtype arch)
  85. {
  86. int i;
  87. _starpu_codelet_check_deprecated_fields(task->cl);
  88. /* make sure there is a worker on the machine able to execute the
  89. task, independent of the sched_ctx, this latter may receive latter on
  90. the necessary worker - the user or the hypervisor should take care this happens */
  91. struct _starpu_sched_ctx *sched_ctx = check_entire_platform == 1 ? _starpu_get_initial_sched_ctx() : _starpu_get_sched_ctx_struct(task->sched_ctx);
  92. struct starpu_worker_collection *workers = sched_ctx->workers;
  93. struct starpu_sched_ctx_iterator it;
  94. workers->init_iterator(workers, &it);
  95. while(workers->has_next(workers, &it))
  96. {
  97. i = workers->get_next(workers, &it);
  98. if (starpu_worker_get_type(i) != arch)
  99. continue;
  100. unsigned impl;
  101. for (impl = 0; impl < STARPU_MAXIMPLEMENTATIONS; impl++)
  102. {
  103. /* We could call task->cl->can_execute(i, task, impl)
  104. here, it would definitely work. It is probably
  105. cheaper to check whether it is necessary in order to
  106. avoid a useless function call, though. */
  107. unsigned test_implementation = 0;
  108. switch (arch)
  109. {
  110. case STARPU_CPU_WORKER:
  111. if (task->cl->cpu_funcs[impl] != NULL)
  112. test_implementation = 1;
  113. break;
  114. case STARPU_CUDA_WORKER:
  115. if (task->cl->cuda_funcs[impl] != NULL)
  116. test_implementation = 1;
  117. break;
  118. case STARPU_OPENCL_WORKER:
  119. if (task->cl->opencl_funcs[impl] != NULL)
  120. test_implementation = 1;
  121. break;
  122. case STARPU_MIC_WORKER:
  123. if (task->cl->cpu_funcs_name[impl] != NULL || task->cl->mic_funcs[impl] != NULL)
  124. test_implementation = 1;
  125. break;
  126. case STARPU_MPI_WORKER:
  127. if (task->cl->cpu_funcs_name[impl] != NULL || task->cl->mpi_ms_funcs[impl] != NULL)
  128. test_implementation = 1;
  129. break;
  130. case STARPU_SCC_WORKER:
  131. if (task->cl->cpu_funcs_name[impl] != NULL || task->cl->scc_funcs[impl] != NULL)
  132. test_implementation = 1;
  133. break;
  134. default:
  135. STARPU_ABORT();
  136. }
  137. if (!test_implementation)
  138. continue;
  139. if (task->cl->can_execute)
  140. return task->cl->can_execute(i, task, impl);
  141. if(test_implementation)
  142. return 1;
  143. }
  144. }
  145. return 0;
  146. }
  147. /* in case a task is submitted, we may check whether there exists a worker
  148. that may execute the task or not */
  149. uint32_t _starpu_worker_exists(struct starpu_task *task)
  150. {
  151. _starpu_codelet_check_deprecated_fields(task->cl);
  152. if (task->cl->where == STARPU_NOWHERE)
  153. return 1;
  154. /* if the task belongs to the init context we can
  155. check out all the worker mask of the machine
  156. if not we should iterate on the workers of the ctx
  157. and verify if it exists a worker able to exec the task */
  158. if(task->sched_ctx == 0)
  159. {
  160. if (!(task->cl->where & _starpu_config.worker_mask))
  161. return 0;
  162. if (!task->cl->can_execute)
  163. return 1;
  164. }
  165. #if defined(STARPU_USE_CPU) || defined(STARPU_SIMGRID)
  166. if ((task->cl->where & STARPU_CPU) &&
  167. _starpu_worker_exists_and_can_execute(task, STARPU_CPU_WORKER))
  168. return 1;
  169. #endif
  170. #if defined(STARPU_USE_CUDA) || defined(STARPU_SIMGRID)
  171. if ((task->cl->where & STARPU_CUDA) &&
  172. _starpu_worker_exists_and_can_execute(task, STARPU_CUDA_WORKER))
  173. return 1;
  174. #endif
  175. #if defined(STARPU_USE_OPENCL) || defined(STARPU_SIMGRID)
  176. if ((task->cl->where & STARPU_OPENCL) &&
  177. _starpu_worker_exists_and_can_execute(task, STARPU_OPENCL_WORKER))
  178. return 1;
  179. #endif
  180. #ifdef STARPU_USE_MIC
  181. if ((task->cl->where & STARPU_MIC) &&
  182. _starpu_worker_exists_and_can_execute(task, STARPU_MIC_WORKER))
  183. return 1;
  184. #endif
  185. #ifdef STARPU_USE_MPI_MASTER_SLAVE
  186. if ((task->cl->where & STARPU_MPI) &&
  187. _starpu_worker_exists_and_can_execute(task, STARPU_MPI_WORKER))
  188. return 1;
  189. #endif
  190. #ifdef STARPU_USE_SCC
  191. if ((task->cl->where & STARPU_SCC) &&
  192. _starpu_worker_exists_and_can_execute(task, STARPU_SCC_WORKER))
  193. return 1;
  194. #endif
  195. return 0;
  196. }
  197. uint32_t _starpu_can_submit_cuda_task(void)
  198. {
  199. return (STARPU_CUDA & _starpu_config.worker_mask);
  200. }
  201. uint32_t _starpu_can_submit_cpu_task(void)
  202. {
  203. return (STARPU_CPU & _starpu_config.worker_mask);
  204. }
  205. uint32_t _starpu_can_submit_opencl_task(void)
  206. {
  207. return (STARPU_OPENCL & _starpu_config.worker_mask);
  208. }
  209. uint32_t _starpu_can_submit_scc_task(void)
  210. {
  211. return (STARPU_SCC & _starpu_config.worker_mask);
  212. }
  213. static inline int _starpu_can_use_nth_implementation(enum starpu_worker_archtype arch, struct starpu_codelet *cl, unsigned nimpl)
  214. {
  215. switch(arch)
  216. {
  217. case STARPU_ANY_WORKER:
  218. {
  219. int cpu_func_enabled=1, cuda_func_enabled=1, opencl_func_enabled=1;
  220. /* TODO: MIC/SCC */
  221. #if defined(STARPU_USE_CPU) || defined(STARPU_SIMGRID)
  222. starpu_cpu_func_t cpu_func = _starpu_task_get_cpu_nth_implementation(cl, nimpl);
  223. cpu_func_enabled = cpu_func != NULL && starpu_cpu_worker_get_count();
  224. #endif
  225. #if defined(STARPU_USE_CUDA) || defined(STARPU_SIMGRID)
  226. starpu_cuda_func_t cuda_func = _starpu_task_get_cuda_nth_implementation(cl, nimpl);
  227. cuda_func_enabled = cuda_func != NULL && starpu_cuda_worker_get_count();
  228. #endif
  229. #if defined(STARPU_USE_OPENCL) || defined(STARPU_SIMGRID)
  230. starpu_opencl_func_t opencl_func = _starpu_task_get_opencl_nth_implementation(cl, nimpl);
  231. opencl_func_enabled = opencl_func != NULL && starpu_opencl_worker_get_count();
  232. #endif
  233. return (cpu_func_enabled && cuda_func_enabled && opencl_func_enabled);
  234. }
  235. case STARPU_CPU_WORKER:
  236. {
  237. starpu_cpu_func_t func = _starpu_task_get_cpu_nth_implementation(cl, nimpl);
  238. return func != NULL;
  239. }
  240. case STARPU_CUDA_WORKER:
  241. {
  242. starpu_cuda_func_t func = _starpu_task_get_cuda_nth_implementation(cl, nimpl);
  243. return func != NULL;
  244. }
  245. case STARPU_OPENCL_WORKER:
  246. {
  247. starpu_opencl_func_t func = _starpu_task_get_opencl_nth_implementation(cl, nimpl);
  248. return func != NULL;
  249. }
  250. case STARPU_MIC_WORKER:
  251. {
  252. starpu_mic_func_t func = _starpu_task_get_mic_nth_implementation(cl, nimpl);
  253. const char *func_name = _starpu_task_get_cpu_name_nth_implementation(cl, nimpl);
  254. return func != NULL || func_name != NULL;
  255. }
  256. case STARPU_MPI_WORKER:
  257. {
  258. starpu_mpi_ms_func_t func = _starpu_task_get_mpi_ms_nth_implementation(cl, nimpl);
  259. const char *func_name = _starpu_task_get_cpu_name_nth_implementation(cl, nimpl);
  260. return func != NULL || func_name != NULL;
  261. }
  262. case STARPU_SCC_WORKER:
  263. {
  264. starpu_scc_func_t func = _starpu_task_get_scc_nth_implementation(cl, nimpl);
  265. const char *func_name = _starpu_task_get_cpu_name_nth_implementation(cl, nimpl);
  266. return func != NULL || func_name != NULL;
  267. }
  268. default:
  269. STARPU_ASSERT_MSG(0, "Unknown arch type %d", arch);
  270. }
  271. return 0;
  272. }
  273. int starpu_worker_can_execute_task(unsigned workerid, struct starpu_task *task, unsigned nimpl)
  274. {
  275. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(task->sched_ctx);
  276. /* if the worker is blocked in a parallel ctx don't submit tasks on it */
  277. if(sched_ctx->parallel_sect[workerid] ) return 0;
  278. /* TODO: check that the task operand sizes will fit on that device */
  279. return (task->cl->where & _starpu_config.workers[workerid].worker_mask) &&
  280. _starpu_can_use_nth_implementation(_starpu_config.workers[workerid].arch, task->cl, nimpl) &&
  281. (!task->cl->can_execute || task->cl->can_execute(workerid, task, nimpl));
  282. }
  283. int starpu_worker_can_execute_task_impl(unsigned workerid, struct starpu_task *task, unsigned *impl_mask)
  284. {
  285. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(task->sched_ctx);
  286. /* if the worker is blocked in a parallel ctx don't submit tasks on it */
  287. if(sched_ctx->parallel_sect[workerid]) return 0;
  288. unsigned mask;
  289. int i;
  290. enum starpu_worker_archtype arch;
  291. struct starpu_codelet *cl;
  292. /* TODO: check that the task operand sizes will fit on that device */
  293. cl = task->cl;
  294. if (!(cl->where & _starpu_config.workers[workerid].worker_mask)) return 0;
  295. mask = 0;
  296. arch = _starpu_config.workers[workerid].arch;
  297. if (!task->cl->can_execute)
  298. {
  299. for (i = 0; i < STARPU_MAXIMPLEMENTATIONS; i++)
  300. if (_starpu_can_use_nth_implementation(arch, cl, i))
  301. {
  302. mask |= 1U << i;
  303. if (!impl_mask)
  304. break;
  305. }
  306. }
  307. else
  308. {
  309. for (i = 0; i < STARPU_MAXIMPLEMENTATIONS; i++)
  310. if (_starpu_can_use_nth_implementation(arch, cl, i)
  311. && (!task->cl->can_execute || task->cl->can_execute(workerid, task, i)))
  312. {
  313. mask |= 1U << i;
  314. if (!impl_mask)
  315. break;
  316. }
  317. }
  318. if (impl_mask)
  319. *impl_mask = mask;
  320. return mask != 0;
  321. }
  322. int starpu_worker_can_execute_task_first_impl(unsigned workerid, struct starpu_task *task, unsigned *nimpl)
  323. {
  324. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(task->sched_ctx);
  325. int i;
  326. enum starpu_worker_archtype arch;
  327. struct starpu_codelet *cl;
  328. if(sched_ctx->parallel_sect[workerid]) return 0;
  329. /* TODO: check that the task operand sizes will fit on that device */
  330. cl = task->cl;
  331. if (!(cl->where & _starpu_config.workers[workerid].worker_mask)) return 0;
  332. arch = _starpu_config.workers[workerid].arch;
  333. if (!task->cl->can_execute)
  334. {
  335. for (i = 0; i < STARPU_MAXIMPLEMENTATIONS; i++)
  336. if (_starpu_can_use_nth_implementation(arch, cl, i))
  337. {
  338. if (nimpl)
  339. *nimpl = i;
  340. return 1;
  341. }
  342. }
  343. else
  344. {
  345. for (i = 0; i < STARPU_MAXIMPLEMENTATIONS; i++)
  346. if (_starpu_can_use_nth_implementation(arch, cl, i)
  347. && task->cl->can_execute(workerid, task, i))
  348. {
  349. if (nimpl)
  350. *nimpl = i;
  351. return 1;
  352. }
  353. }
  354. return 0;
  355. }
  356. int starpu_combined_worker_can_execute_task(unsigned workerid, struct starpu_task *task, unsigned nimpl)
  357. {
  358. /* TODO: check that the task operand sizes will fit on that device */
  359. struct starpu_codelet *cl = task->cl;
  360. unsigned nworkers = _starpu_config.topology.nworkers;
  361. /* Is this a parallel worker ? */
  362. if (workerid < nworkers)
  363. {
  364. return !!((task->cl->where & _starpu_config.workers[workerid].worker_mask) &&
  365. _starpu_can_use_nth_implementation(_starpu_config.workers[workerid].arch, task->cl, nimpl) &&
  366. (!task->cl->can_execute || task->cl->can_execute(workerid, task, nimpl)));
  367. }
  368. else
  369. {
  370. if (cl->type == STARPU_SPMD
  371. #ifdef STARPU_HAVE_HWLOC
  372. || cl->type == STARPU_FORKJOIN
  373. #else
  374. #ifdef __GLIBC__
  375. || cl->type == STARPU_FORKJOIN
  376. #endif
  377. #endif
  378. )
  379. {
  380. /* TODO we should add other types of constraints */
  381. /* Is the worker larger than requested ? */
  382. int worker_size = (int)_starpu_config.combined_workers[workerid - nworkers].worker_size;
  383. int worker0 = _starpu_config.combined_workers[workerid - nworkers].combined_workerid[0];
  384. return !!((worker_size <= task->cl->max_parallelism) &&
  385. _starpu_can_use_nth_implementation(_starpu_config.workers[worker0].arch, task->cl, nimpl) &&
  386. (!task->cl->can_execute || task->cl->can_execute(workerid, task, nimpl)));
  387. }
  388. else
  389. {
  390. /* We have a sequential task but a parallel worker */
  391. return 0;
  392. }
  393. }
  394. }
  395. /*
  396. * Runtime initialization methods
  397. */
  398. static void _starpu_init_worker_queue(struct _starpu_worker *workerarg)
  399. {
  400. starpu_pthread_cond_t *cond = &workerarg->sched_cond;
  401. starpu_pthread_mutex_t *mutex = &workerarg->sched_mutex;
  402. unsigned memory_node = workerarg->memory_node;
  403. _starpu_memory_node_register_condition(cond, mutex, memory_node);
  404. }
  405. /*
  406. * Returns 0 if the given driver is one of the drivers that must be launched by
  407. * the application itself, and not by StarPU, 1 otherwise.
  408. */
  409. static unsigned _starpu_may_launch_driver(struct starpu_conf *conf,
  410. struct starpu_driver *d)
  411. {
  412. if (conf->n_not_launched_drivers == 0 ||
  413. conf->not_launched_drivers == NULL)
  414. return 1;
  415. /* Is <d> in conf->not_launched_drivers ? */
  416. unsigned i;
  417. for (i = 0; i < conf->n_not_launched_drivers; i++)
  418. {
  419. if (d->type != conf->not_launched_drivers[i].type)
  420. continue;
  421. switch (d->type)
  422. {
  423. case STARPU_CPU_WORKER:
  424. if (d->id.cpu_id == conf->not_launched_drivers[i].id.cpu_id)
  425. return 0;
  426. break;
  427. case STARPU_CUDA_WORKER:
  428. if (d->id.cuda_id == conf->not_launched_drivers[i].id.cuda_id)
  429. return 0;
  430. break;
  431. #ifdef STARPU_USE_OPENCL
  432. case STARPU_OPENCL_WORKER:
  433. if (d->id.opencl_id == conf->not_launched_drivers[i].id.opencl_id)
  434. return 0;
  435. break;
  436. #endif
  437. default:
  438. STARPU_ABORT();
  439. }
  440. }
  441. return 1;
  442. }
  443. #ifdef STARPU_PERF_DEBUG
  444. struct itimerval prof_itimer;
  445. #endif
  446. static void _starpu_worker_init(struct _starpu_worker *workerarg, struct _starpu_machine_config *pconfig)
  447. {
  448. workerarg->config = pconfig;
  449. STARPU_PTHREAD_MUTEX_INIT(&workerarg->mutex, NULL);
  450. /* arch initialized by topology.c */
  451. /* worker_mask initialized by topology.c */
  452. /* perf_arch initialized by topology.c */
  453. /* worker_thread initialized by _starpu_launch_drivers */
  454. /* devid initialized by topology.c */
  455. /* subworkerid initialized by topology.c */
  456. /* bindid initialized by topology.c */
  457. /* workerid initialized by topology.c */
  458. workerarg->combined_workerid = workerarg->workerid;
  459. workerarg->current_rank = 0;
  460. workerarg->worker_size = 1;
  461. STARPU_PTHREAD_COND_INIT(&workerarg->started_cond, NULL);
  462. STARPU_PTHREAD_COND_INIT(&workerarg->ready_cond, NULL);
  463. /* memory_node initialized by topology.c */
  464. STARPU_PTHREAD_COND_INIT(&workerarg->sched_cond, NULL);
  465. STARPU_PTHREAD_MUTEX_INIT(&workerarg->sched_mutex, NULL);
  466. starpu_task_list_init(&workerarg->local_tasks);
  467. workerarg->local_ordered_tasks = NULL;
  468. workerarg->local_ordered_tasks_size = 0;
  469. workerarg->current_ordered_task = 0;
  470. workerarg->current_ordered_task_order = 1;
  471. workerarg->current_task = NULL;
  472. #ifdef STARPU_SIMGRID
  473. starpu_pthread_wait_init(&workerarg->wait);
  474. starpu_pthread_queue_register(&workerarg->wait, &_starpu_simgrid_task_queue[workerarg->workerid]);
  475. #endif
  476. workerarg->first_task = 0;
  477. workerarg->ntasks = 0;
  478. /* set initialized by topology.c */
  479. workerarg->pipeline_length = 0;
  480. workerarg->pipeline_stuck = 0;
  481. workerarg->worker_is_running = 0;
  482. workerarg->worker_is_initialized = 0;
  483. workerarg->status = STATUS_INITIALIZING;
  484. /* name initialized by driver */
  485. /* short_name initialized by driver */
  486. workerarg->run_by_starpu = 1;
  487. workerarg->sched_ctx_list = NULL;
  488. workerarg->tmp_sched_ctx = -1;
  489. workerarg->nsched_ctxs = 0;
  490. _starpu_barrier_counter_init(&workerarg->tasks_barrier, 0);
  491. workerarg->has_prev_init = 0;
  492. int ctx;
  493. for(ctx = 0; ctx < STARPU_NMAX_SCHED_CTXS; ctx++)
  494. workerarg->removed_from_ctx[ctx] = 0;
  495. workerarg->spinning_backoff = 1;
  496. for(ctx = 0; ctx < STARPU_NMAX_SCHED_CTXS; ctx++)
  497. {
  498. workerarg->shares_tasks_lists[ctx] = 0;
  499. workerarg->poped_in_ctx[ctx] = 0;
  500. }
  501. workerarg->reverse_phase[0] = 0;
  502. workerarg->reverse_phase[1] = 0;
  503. workerarg->pop_ctx_priority = 1;
  504. workerarg->sched_mutex_locked = 0;
  505. workerarg->blocked = 0;
  506. workerarg->is_slave_somewhere = 0;
  507. /* cpu_set/hwloc_cpu_set initialized in topology.c */
  508. }
  509. static void _starpu_worker_deinit(struct _starpu_worker *workerarg)
  510. {
  511. (void) workerarg;
  512. #ifdef STARPU_SIMGRID
  513. starpu_pthread_queue_unregister(&workerarg->wait, &_starpu_simgrid_task_queue[workerarg->workerid]);
  514. starpu_pthread_wait_destroy(&workerarg->wait);
  515. #endif
  516. }
  517. #ifdef STARPU_USE_FXT
  518. void _starpu_worker_start(struct _starpu_worker *worker, unsigned fut_key, unsigned sync)
  519. {
  520. unsigned devid = worker->devid;
  521. unsigned memnode = worker->memory_node;
  522. _STARPU_TRACE_WORKER_INIT_START(fut_key, worker->workerid, devid, memnode, worker->bindid, sync);
  523. }
  524. #endif
  525. void _starpu_driver_start(struct _starpu_worker *worker, unsigned fut_key, unsigned sync STARPU_ATTRIBUTE_UNUSED)
  526. {
  527. (void) fut_key;
  528. int devid = worker->devid;
  529. (void) devid;
  530. #ifdef STARPU_USE_FXT
  531. _starpu_fxt_register_thread(worker->bindid);
  532. _starpu_worker_start(worker, fut_key, sync);
  533. #endif
  534. _starpu_memory_node_set_local_key(&worker->memory_node);
  535. _starpu_set_local_worker_key(worker);
  536. STARPU_PTHREAD_MUTEX_LOCK(&worker->mutex);
  537. worker->worker_is_running = 1;
  538. STARPU_PTHREAD_COND_SIGNAL(&worker->started_cond);
  539. STARPU_PTHREAD_MUTEX_UNLOCK(&worker->mutex);
  540. _starpu_bind_thread_on_cpu(worker->config, worker->bindid, worker->workerid);
  541. #if defined(STARPU_PERF_DEBUG) && !defined(STARPU_SIMGRID)
  542. setitimer(ITIMER_PROF, &prof_itimer, NULL);
  543. #endif
  544. _STARPU_DEBUG("worker %p %d for dev %d is ready on logical cpu %d\n", worker, worker->workerid, devid, worker->bindid);
  545. #ifdef STARPU_HAVE_HWLOC
  546. _STARPU_DEBUG("worker %p %d cpuset start at %d\n", worker, worker->workerid, hwloc_bitmap_first(worker->hwloc_cpu_set));
  547. #endif
  548. }
  549. static void _starpu_launch_drivers(struct _starpu_machine_config *pconfig)
  550. {
  551. pconfig->running = 1;
  552. pconfig->pause_depth = 0;
  553. pconfig->submitting = 1;
  554. STARPU_HG_DISABLE_CHECKING(pconfig->watchdog_ok);
  555. unsigned nworkers = pconfig->topology.nworkers;
  556. /* Launch workers asynchronously */
  557. unsigned worker;
  558. #if defined(STARPU_PERF_DEBUG) && !defined(STARPU_SIMGRID)
  559. /* Get itimer of the main thread, to set it for the worker threads */
  560. getitimer(ITIMER_PROF, &prof_itimer);
  561. #endif
  562. STARPU_AYU_INIT();
  563. for (worker = 0; worker < nworkers; worker++)
  564. {
  565. struct _starpu_worker *workerarg = &pconfig->workers[worker];
  566. unsigned devid = workerarg->devid;
  567. #if defined(STARPU_USE_MIC) || defined(STARPU_USE_CUDA) || defined(STARPU_SIMGRID) || defined(STARPU_USE_MPI_MASTER_SLAVE)
  568. struct _starpu_worker_set *worker_set = workerarg->set;
  569. #endif
  570. _STARPU_DEBUG("initialising worker %u/%u\n", worker, nworkers);
  571. _starpu_init_worker_queue(workerarg);
  572. struct starpu_driver driver;
  573. driver.type = workerarg->arch;
  574. switch (workerarg->arch)
  575. {
  576. #if defined(STARPU_USE_CPU) || defined(STARPU_SIMGRID)
  577. case STARPU_CPU_WORKER:
  578. driver.id.cpu_id = devid;
  579. if (_starpu_may_launch_driver(&pconfig->conf, &driver))
  580. {
  581. STARPU_PTHREAD_CREATE_ON(
  582. workerarg->name,
  583. &workerarg->worker_thread,
  584. NULL,
  585. _starpu_cpu_worker,
  586. workerarg,
  587. _starpu_simgrid_get_host_by_worker(workerarg));
  588. #ifdef STARPU_USE_FXT
  589. /* In tracing mode, make sure the
  590. * thread is really started before
  591. * starting another one, to make sure
  592. * they appear in order in the trace.
  593. */
  594. STARPU_PTHREAD_MUTEX_LOCK(&workerarg->mutex);
  595. while (!workerarg->worker_is_running)
  596. STARPU_PTHREAD_COND_WAIT(&workerarg->started_cond, &workerarg->mutex);
  597. STARPU_PTHREAD_MUTEX_UNLOCK(&workerarg->mutex);
  598. #endif
  599. }
  600. else
  601. {
  602. workerarg->run_by_starpu = 0;
  603. }
  604. break;
  605. #endif
  606. #if defined(STARPU_USE_CUDA) || defined(STARPU_SIMGRID)
  607. case STARPU_CUDA_WORKER:
  608. driver.id.cuda_id = devid;
  609. /* We spawn only one thread per CUDA driver,
  610. * which will control all CUDA workers of this
  611. * driver. (by using a worker set). */
  612. if (worker_set->workers != workerarg)
  613. break;
  614. worker_set->nworkers = starpu_get_env_number_default("STARPU_NWORKER_PER_CUDA", 1);
  615. #ifndef STARPU_NON_BLOCKING_DRIVERS
  616. if (worker_set->nworkers > 1)
  617. {
  618. _STARPU_DISP("Warning: reducing STARPU_NWORKER_PER_CUDA to 1 because blocking drivers are enabled\n");
  619. worker_set->nworkers = 1;
  620. }
  621. #endif
  622. worker_set->set_is_initialized = 0;
  623. if (!_starpu_may_launch_driver(&pconfig->conf, &driver))
  624. {
  625. workerarg->run_by_starpu = 0;
  626. break;
  627. }
  628. STARPU_PTHREAD_CREATE_ON(
  629. workerarg->name,
  630. &worker_set->worker_thread,
  631. NULL,
  632. _starpu_cuda_worker,
  633. worker_set,
  634. _starpu_simgrid_get_host_by_worker(workerarg));
  635. #ifdef STARPU_USE_FXT
  636. STARPU_PTHREAD_MUTEX_LOCK(&workerarg->mutex);
  637. while (!workerarg->worker_is_running)
  638. STARPU_PTHREAD_COND_WAIT(&workerarg->started_cond, &workerarg->mutex);
  639. STARPU_PTHREAD_MUTEX_UNLOCK(&workerarg->mutex);
  640. #endif
  641. break;
  642. #endif
  643. #if defined(STARPU_USE_OPENCL) || defined(STARPU_SIMGRID)
  644. case STARPU_OPENCL_WORKER:
  645. #ifndef STARPU_SIMGRID
  646. starpu_opencl_get_device(devid, &driver.id.opencl_id);
  647. if (!_starpu_may_launch_driver(&pconfig->conf, &driver))
  648. {
  649. workerarg->run_by_starpu = 0;
  650. break;
  651. }
  652. #endif
  653. STARPU_PTHREAD_CREATE_ON(
  654. workerarg->name,
  655. &workerarg->worker_thread,
  656. NULL,
  657. _starpu_opencl_worker,
  658. workerarg,
  659. _starpu_simgrid_get_host_by_worker(workerarg));
  660. #ifdef STARPU_USE_FXT
  661. STARPU_PTHREAD_MUTEX_LOCK(&workerarg->mutex);
  662. while (!workerarg->worker_is_running)
  663. STARPU_PTHREAD_COND_WAIT(&workerarg->started_cond, &workerarg->mutex);
  664. STARPU_PTHREAD_MUTEX_UNLOCK(&workerarg->mutex);
  665. #endif
  666. break;
  667. #endif
  668. #ifdef STARPU_USE_MIC
  669. case STARPU_MIC_WORKER:
  670. /* We spawn only one thread
  671. * per MIC device, which will control all MIC
  672. * workers of this device. (by using a worker set). */
  673. if (worker_set->workers != workerarg)
  674. break;
  675. worker_set->nworkers = pconfig->topology.nmiccores[devid];
  676. worker_set->set_is_initialized = 0;
  677. STARPU_PTHREAD_CREATE_ON(
  678. workerarg->name,
  679. &worker_set->worker_thread,
  680. NULL,
  681. _starpu_mic_src_worker,
  682. worker_set,
  683. _starpu_simgrid_get_host_by_worker(workerarg));
  684. #ifdef STARPU_USE_FXT
  685. STARPU_PTHREAD_MUTEX_LOCK(&workerarg->mutex);
  686. while (!workerarg->worker_is_running)
  687. STARPU_PTHREAD_COND_WAIT(&workerarg->started_cond, &workerarg->mutex);
  688. STARPU_PTHREAD_MUTEX_UNLOCK(&workerarg->mutex);
  689. #endif
  690. STARPU_PTHREAD_MUTEX_LOCK(&worker_set->mutex);
  691. while (!worker_set->set_is_initialized)
  692. STARPU_PTHREAD_COND_WAIT(&worker_set->ready_cond,
  693. &worker_set->mutex);
  694. STARPU_PTHREAD_MUTEX_UNLOCK(&worker_set->mutex);
  695. worker_set->started = 1;
  696. break;
  697. #endif /* STARPU_USE_MIC */
  698. #ifdef STARPU_USE_SCC
  699. case STARPU_SCC_WORKER:
  700. workerarg->worker_is_initialized = 0;
  701. STARPU_PTHREAD_CREATE_ON(
  702. workerarg->name,
  703. &workerarg->worker_thread,
  704. NULL,
  705. _starpu_scc_src_worker,
  706. workerarg,
  707. _starpu_simgrid_get_host_by_worker(workerarg));
  708. #ifdef STARPU_USE_FXT
  709. STARPU_PTHREAD_MUTEX_LOCK(&workerarg->mutex);
  710. while (!workerarg->worker_is_running)
  711. STARPU_PTHREAD_COND_WAIT(&workerarg->started_cond, &workerarg->mutex);
  712. STARPU_PTHREAD_MUTEX_UNLOCK(&workerarg->mutex);
  713. #endif
  714. break;
  715. #endif /* STARPU_USE_SCC */
  716. #ifdef STARPU_USE_MPI_MASTER_SLAVE
  717. case STARPU_MPI_WORKER:
  718. /* We spawn only one thread
  719. * per MPI device, which will control all MPI
  720. * workers of this device. (by using a worker set). */
  721. if (worker_set->workers != workerarg)
  722. break;
  723. worker_set->nworkers = pconfig->topology.nmpicores[devid];
  724. worker_set->set_is_initialized = 0;
  725. #ifdef STARPU_MPI_MASTER_SLAVE_MULTIPLE_THREAD
  726. /* if MPI has multiple threads supports
  727. * we launch 1 thread per device
  728. * else
  729. * we launch one thread for all devices
  730. */
  731. STARPU_PTHREAD_CREATE_ON(
  732. workerarg->name,
  733. &worker_set->worker_thread,
  734. NULL,
  735. _starpu_mpi_src_worker,
  736. worker_set,
  737. _starpu_simgrid_get_host_by_worker(workerarg));
  738. #ifdef STARPU_USE_FXT
  739. STARPU_PTHREAD_MUTEX_LOCK(&workerarg->mutex);
  740. while (!workerarg->worker_is_running)
  741. STARPU_PTHREAD_COND_WAIT(&workerarg->started_cond, &workerarg->mutex);
  742. STARPU_PTHREAD_MUTEX_UNLOCK(&workerarg->mutex);
  743. #endif
  744. STARPU_PTHREAD_MUTEX_LOCK(&worker_set->mutex);
  745. while (!worker_set->set_is_initialized)
  746. STARPU_PTHREAD_COND_WAIT(&worker_set->ready_cond,
  747. &worker_set->mutex);
  748. STARPU_PTHREAD_MUTEX_UNLOCK(&worker_set->mutex);
  749. worker_set->started = 1;
  750. #endif /* STARPU_MPI_MASTER_SLAVE_MULTIPLE_THREAD */
  751. break;
  752. #endif /* STARPU_USE_MPI_MASTER_SLAVE */
  753. default:
  754. STARPU_ABORT();
  755. }
  756. }
  757. #if defined(STARPU_USE_MPI_MASTER_SLAVE) && !defined(STARPU_MPI_MASTER_SLAVE_MULTIPLE_THREAD)
  758. if (pconfig->topology.nmpidevices > 0)
  759. {
  760. struct _starpu_worker_set * worker_set_zero = &mpi_worker_set[0];
  761. struct _starpu_worker * worker_zero = &worker_set_zero->workers[0];
  762. STARPU_PTHREAD_CREATE_ON(
  763. worker_zero->name,
  764. &worker_set_zero->worker_thread,
  765. NULL,
  766. _starpu_mpi_src_worker,
  767. &mpi_worker_set,
  768. _starpu_simgrid_get_host_by_worker(worker_zero));
  769. /* We use the first worker to know if everything are finished */
  770. #ifdef STARPU_USE_FXT
  771. STARPU_PTHREAD_MUTEX_LOCK(&worker_zero->mutex);
  772. while (!worker_zero->worker_is_running)
  773. STARPU_PTHREAD_COND_WAIT(&worker_zero->started_cond, &worker_zero->mutex);
  774. STARPU_PTHREAD_MUTEX_UNLOCK(&worker_zero->mutex);
  775. #endif
  776. STARPU_PTHREAD_MUTEX_LOCK(&worker_set_zero->mutex);
  777. while (!worker_set_zero->set_is_initialized)
  778. STARPU_PTHREAD_COND_WAIT(&worker_set_zero->ready_cond,
  779. &worker_set_zero->mutex);
  780. STARPU_PTHREAD_MUTEX_UNLOCK(&worker_set_zero->mutex);
  781. int mpidevice;
  782. for (mpidevice = 0; mpidevice < pconfig->topology.nmpidevices; mpidevice++)
  783. {
  784. mpi_worker_set[mpidevice].started = 1;
  785. mpi_worker_set[mpidevice].worker_thread = mpi_worker_set[0].worker_thread;
  786. }
  787. }
  788. #endif
  789. for (worker = 0; worker < nworkers; worker++)
  790. {
  791. struct _starpu_worker *workerarg = &pconfig->workers[worker];
  792. struct starpu_driver driver;
  793. unsigned devid = workerarg->devid;
  794. driver.type = workerarg->arch;
  795. #if defined(STARPU_USE_CUDA) || defined(STARPU_SIMGRID)
  796. struct _starpu_worker_set *worker_set = workerarg->set;
  797. #endif
  798. switch (workerarg->arch)
  799. {
  800. case STARPU_CPU_WORKER:
  801. driver.id.cpu_id = devid;
  802. if (!_starpu_may_launch_driver(&pconfig->conf, &driver))
  803. break;
  804. _STARPU_DEBUG("waiting for worker %u initialization\n", worker);
  805. STARPU_PTHREAD_MUTEX_LOCK(&workerarg->mutex);
  806. while (!workerarg->worker_is_initialized)
  807. STARPU_PTHREAD_COND_WAIT(&workerarg->ready_cond, &workerarg->mutex);
  808. STARPU_PTHREAD_MUTEX_UNLOCK(&workerarg->mutex);
  809. break;
  810. #if defined(STARPU_USE_CUDA) || defined(STARPU_SIMGRID)
  811. case STARPU_CUDA_WORKER:
  812. #ifndef STARPU_SIMGRID
  813. driver.id.cuda_id = devid;
  814. if (!_starpu_may_launch_driver(&pconfig->conf, &driver))
  815. break;
  816. #endif
  817. _STARPU_DEBUG("waiting for worker %u initialization\n", worker);
  818. STARPU_PTHREAD_MUTEX_LOCK(&worker_set->mutex);
  819. while (!worker_set->set_is_initialized)
  820. STARPU_PTHREAD_COND_WAIT(&worker_set->ready_cond,
  821. &worker_set->mutex);
  822. STARPU_PTHREAD_MUTEX_UNLOCK(&worker_set->mutex);
  823. worker_set->started = 1;
  824. break;
  825. #endif
  826. #if defined(STARPU_USE_OPENCL) || defined(STARPU_SIMGRID)
  827. case STARPU_OPENCL_WORKER:
  828. #ifndef STARPU_SIMGRID
  829. starpu_opencl_get_device(devid, &driver.id.opencl_id);
  830. if (!_starpu_may_launch_driver(&pconfig->conf, &driver))
  831. break;
  832. #endif
  833. _STARPU_DEBUG("waiting for worker %u initialization\n", worker);
  834. STARPU_PTHREAD_MUTEX_LOCK(&workerarg->mutex);
  835. while (!workerarg->worker_is_initialized)
  836. STARPU_PTHREAD_COND_WAIT(&workerarg->ready_cond, &workerarg->mutex);
  837. STARPU_PTHREAD_MUTEX_UNLOCK(&workerarg->mutex);
  838. break;
  839. #endif
  840. case STARPU_MIC_WORKER:
  841. case STARPU_MPI_WORKER:
  842. /* Already waited above */
  843. break;
  844. case STARPU_SCC_WORKER:
  845. /* TODO: implement may_launch? */
  846. _STARPU_DEBUG("waiting for worker %u initialization\n", worker);
  847. STARPU_PTHREAD_MUTEX_LOCK(&workerarg->mutex);
  848. while (!workerarg->worker_is_initialized)
  849. STARPU_PTHREAD_COND_WAIT(&workerarg->ready_cond, &workerarg->mutex);
  850. STARPU_PTHREAD_MUTEX_UNLOCK(&workerarg->mutex);
  851. break;
  852. default:
  853. STARPU_ABORT();
  854. }
  855. }
  856. _STARPU_DEBUG("finished launching drivers\n");
  857. }
  858. /* Initialize the starpu_conf with default values */
  859. int starpu_conf_init(struct starpu_conf *conf)
  860. {
  861. if (!conf)
  862. return -EINVAL;
  863. memset(conf, 0, sizeof(*conf));
  864. conf->magic = 42;
  865. conf->sched_policy_name = starpu_getenv("STARPU_SCHED");
  866. conf->sched_policy = NULL;
  867. conf->global_sched_ctx_min_priority = starpu_get_env_number("STARPU_MIN_PRIO");
  868. conf->global_sched_ctx_max_priority = starpu_get_env_number("STARPU_MAX_PRIO");
  869. /* Note that starpu_get_env_number returns -1 in case the variable is
  870. * not defined */
  871. /* Backward compatibility: check the value of STARPU_NCPUS if
  872. * STARPU_NCPU is not set. */
  873. conf->ncpus = starpu_get_env_number("STARPU_NCPU");
  874. if (conf->ncpus == -1)
  875. conf->ncpus = starpu_get_env_number("STARPU_NCPUS");
  876. conf->ncuda = starpu_get_env_number("STARPU_NCUDA");
  877. conf->nopencl = starpu_get_env_number("STARPU_NOPENCL");
  878. conf->nmic = starpu_get_env_number("STARPU_NMIC");
  879. conf->nscc = starpu_get_env_number("STARPU_NSCC");
  880. conf->nmpi_ms = starpu_get_env_number("STARPU_NMPI_MS");
  881. conf->calibrate = starpu_get_env_number("STARPU_CALIBRATE");
  882. conf->bus_calibrate = starpu_get_env_number("STARPU_BUS_CALIBRATE");
  883. conf->mic_sink_program_path = starpu_getenv("STARPU_MIC_PROGRAM_PATH");
  884. if (conf->calibrate == -1)
  885. conf->calibrate = 0;
  886. if (conf->bus_calibrate == -1)
  887. conf->bus_calibrate = 0;
  888. conf->use_explicit_workers_bindid = 0; /* TODO */
  889. conf->use_explicit_workers_cuda_gpuid = 0; /* TODO */
  890. conf->use_explicit_workers_opencl_gpuid = 0; /* TODO */
  891. conf->use_explicit_workers_mic_deviceid = 0; /* TODO */
  892. conf->use_explicit_workers_scc_deviceid = 0; /* TODO */
  893. conf->use_explicit_workers_mpi_deviceid = 0; /* TODO */
  894. conf->single_combined_worker = starpu_get_env_number("STARPU_SINGLE_COMBINED_WORKER");
  895. if (conf->single_combined_worker == -1)
  896. conf->single_combined_worker = 0;
  897. #if defined(STARPU_DISABLE_ASYNCHRONOUS_COPY)
  898. conf->disable_asynchronous_copy = 1;
  899. #else
  900. conf->disable_asynchronous_copy = starpu_get_env_number("STARPU_DISABLE_ASYNCHRONOUS_COPY");
  901. if (conf->disable_asynchronous_copy == -1)
  902. conf->disable_asynchronous_copy = 0;
  903. #endif
  904. #if defined(STARPU_DISABLE_ASYNCHRONOUS_CUDA_COPY)
  905. conf->disable_asynchronous_cuda_copy = 1;
  906. #else
  907. conf->disable_asynchronous_cuda_copy = starpu_get_env_number("STARPU_DISABLE_ASYNCHRONOUS_CUDA_COPY");
  908. if (conf->disable_asynchronous_cuda_copy == -1)
  909. conf->disable_asynchronous_cuda_copy = 0;
  910. #endif
  911. #if defined(STARPU_DISABLE_ASYNCHRONOUS_OPENCL_COPY)
  912. conf->disable_asynchronous_opencl_copy = 1;
  913. #else
  914. conf->disable_asynchronous_opencl_copy = starpu_get_env_number("STARPU_DISABLE_ASYNCHRONOUS_OPENCL_COPY");
  915. if (conf->disable_asynchronous_opencl_copy == -1)
  916. conf->disable_asynchronous_opencl_copy = 0;
  917. #endif
  918. #if defined(STARPU_DISABLE_ASYNCHRONOUS_MIC_COPY)
  919. conf->disable_asynchronous_mic_copy = 1;
  920. #else
  921. conf->disable_asynchronous_mic_copy = starpu_get_env_number("STARPU_DISABLE_ASYNCHRONOUS_MIC_COPY");
  922. if (conf->disable_asynchronous_mic_copy == -1)
  923. conf->disable_asynchronous_mic_copy = 0;
  924. #endif
  925. /* 64MiB by default */
  926. conf->trace_buffer_size = starpu_get_env_number_default("STARPU_TRACE_BUFFER_SIZE", 64) << 20;
  927. return 0;
  928. }
  929. static void _starpu_conf_set_value_against_environment(char *name, int *value)
  930. {
  931. int number;
  932. number = starpu_get_env_number(name);
  933. if (number != -1)
  934. {
  935. *value = number;
  936. }
  937. }
  938. void _starpu_conf_check_environment(struct starpu_conf *conf)
  939. {
  940. char *sched = starpu_getenv("STARPU_SCHED");
  941. if (sched)
  942. {
  943. conf->sched_policy_name = sched;
  944. }
  945. _starpu_conf_set_value_against_environment("STARPU_NCPUS", &conf->ncpus);
  946. _starpu_conf_set_value_against_environment("STARPU_NCPU", &conf->ncpus);
  947. _starpu_conf_set_value_against_environment("STARPU_NCUDA", &conf->ncuda);
  948. _starpu_conf_set_value_against_environment("STARPU_NOPENCL", &conf->nopencl);
  949. _starpu_conf_set_value_against_environment("STARPU_CALIBRATE", &conf->calibrate);
  950. _starpu_conf_set_value_against_environment("STARPU_BUS_CALIBRATE", &conf->bus_calibrate);
  951. #ifdef STARPU_SIMGRID
  952. if (conf->calibrate == 2)
  953. {
  954. _STARPU_DISP("Warning: History will be cleared due to calibrate or STARPU_CALIBRATE being set to 2. This will prevent simgrid from having task simulation times!");
  955. }
  956. if (conf->bus_calibrate)
  957. {
  958. _STARPU_DISP("Warning: Bus calibration will be cleared due to bus_calibrate or STARPU_BUS_CALIBRATE being set. This will prevent simgrid from having data transfer simulation times!");
  959. }
  960. #endif
  961. _starpu_conf_set_value_against_environment("STARPU_SINGLE_COMBINED_WORKER", &conf->single_combined_worker);
  962. _starpu_conf_set_value_against_environment("STARPU_DISABLE_ASYNCHRONOUS_COPY", &conf->disable_asynchronous_copy);
  963. _starpu_conf_set_value_against_environment("STARPU_DISABLE_ASYNCHRONOUS_CUDA_COPY", &conf->disable_asynchronous_cuda_copy);
  964. _starpu_conf_set_value_against_environment("STARPU_DISABLE_ASYNCHRONOUS_OPENCL_COPY", &conf->disable_asynchronous_opencl_copy);
  965. _starpu_conf_set_value_against_environment("STARPU_DISABLE_ASYNCHRONOUS_MIC_COPY", &conf->disable_asynchronous_mic_copy);
  966. }
  967. struct starpu_tree* starpu_workers_get_tree(void)
  968. {
  969. return _starpu_config.topology.tree;
  970. }
  971. #ifdef STARPU_HAVE_HWLOC
  972. static void _fill_tree(struct starpu_tree *tree, hwloc_obj_t curr_obj, unsigned depth, hwloc_topology_t topology, struct starpu_tree *father)
  973. {
  974. unsigned i;
  975. if (curr_obj->arity == 1)
  976. {
  977. /* Nothing interestin here, skip level */
  978. _fill_tree(tree, curr_obj->children[0], depth+1, topology, father);
  979. return;
  980. }
  981. starpu_tree_insert(tree, curr_obj->logical_index, depth, curr_obj->type == HWLOC_OBJ_PU, curr_obj->arity, father);
  982. starpu_tree_prepare_children(curr_obj->arity, tree);
  983. for(i = 0; i < curr_obj->arity; i++)
  984. {
  985. /* char string[128]; */
  986. /* hwloc_obj_snprintf(string, sizeof(string), topology, curr_obj->children[i], "#", 0); */
  987. /* printf("%*s%s %d is_pu %d \n", 0, "", string, curr_obj->children[i]->logical_index, curr_obj->children[i]->type == HWLOC_OBJ_PU); */
  988. _fill_tree(&tree->nodes[i], curr_obj->children[i], depth+1, topology, tree);
  989. }
  990. }
  991. #endif
  992. static void _starpu_build_tree(void)
  993. {
  994. #ifdef STARPU_HAVE_HWLOC
  995. struct starpu_tree* tree = (struct starpu_tree*)malloc(sizeof(struct starpu_tree));
  996. _starpu_config.topology.tree = tree;
  997. hwloc_obj_t root = hwloc_get_root_obj(_starpu_config.topology.hwtopology);
  998. /* char string[128]; */
  999. /* hwloc_obj_snprintf(string, sizeof(string), topology, root, "#", 0); */
  1000. /* printf("%*s%s %d is_pu = %d \n", 0, "", string, root->logical_index, root->type == HWLOC_OBJ_PU); */
  1001. /* level, is_pu, is in the tree (it will be true only after add*/
  1002. _fill_tree(tree, root, 0, _starpu_config.topology.hwtopology, NULL);
  1003. #endif
  1004. }
  1005. int starpu_init(struct starpu_conf *user_conf)
  1006. {
  1007. return starpu_initialize(user_conf, NULL, NULL);
  1008. }
  1009. int starpu_initialize(struct starpu_conf *user_conf, int *argc, char ***argv)
  1010. {
  1011. int is_a_sink = 0; /* Always defined. If the MP infrastructure is not
  1012. * used, we cannot be a sink. */
  1013. unsigned worker;
  1014. (void)argc;
  1015. (void)argv;
  1016. /* This initializes _starpu_silent, thus needs to be early */
  1017. _starpu_util_init();
  1018. #ifdef STARPU_SIMGRID
  1019. /* This initializes the simgrid thread library, thus needs to be early */
  1020. _starpu_simgrid_init(argc, argv);
  1021. #endif
  1022. STARPU_PTHREAD_MUTEX_LOCK(&init_mutex);
  1023. while (initialized == CHANGING)
  1024. /* Wait for the other one changing it */
  1025. STARPU_PTHREAD_COND_WAIT(&init_cond, &init_mutex);
  1026. init_count++;
  1027. if (initialized == INITIALIZED)
  1028. {
  1029. /* He initialized it, don't do it again, and let the others get the mutex */
  1030. STARPU_PTHREAD_MUTEX_UNLOCK(&init_mutex);
  1031. return 0;
  1032. }
  1033. /* initialized == UNINITIALIZED */
  1034. initialized = CHANGING;
  1035. STARPU_PTHREAD_MUTEX_UNLOCK(&init_mutex);
  1036. #ifdef STARPU_USE_MP
  1037. _starpu_set_argc_argv(argc, argv);
  1038. # ifdef STARPU_USE_SCC
  1039. /* In SCC case we look at the rank to know if we are a sink */
  1040. if (_starpu_scc_common_mp_init() && !_starpu_scc_common_is_src_node())
  1041. setenv("STARPU_SINK", "STARPU_SCC", 1);
  1042. # endif
  1043. # ifdef STARPU_USE_MPI_MASTER_SLAVE
  1044. /* In MPI case we look at the rank to know if we are a sink */
  1045. if (_starpu_mpi_common_mp_init() && !_starpu_mpi_common_is_src_node())
  1046. setenv("STARPU_SINK", "STARPU_MPI_MS", 1);
  1047. # endif
  1048. /* If StarPU was configured to use MP sinks, we have to control the
  1049. * kind on node we are running on : host or sink ? */
  1050. if (starpu_getenv("STARPU_SINK"))
  1051. is_a_sink = 1;
  1052. #endif /* STARPU_USE_MP */
  1053. int ret;
  1054. #ifdef STARPU_OPENMP
  1055. _starpu_omp_dummy_init();
  1056. #endif
  1057. #ifdef STARPU_SIMGRID
  1058. /* Warn when the lots of stacks malloc()-ated by simgrid for transfer
  1059. * processes will take a long time to get initialized */
  1060. char *perturb = starpu_getenv("MALLOC_PERTURB_");
  1061. if (perturb && perturb[0] && atoi(perturb) != 0)
  1062. _STARPU_DISP("Warning: MALLOC_PERTURB_ is set to non-zero, this makes simgrid run very slow\n");
  1063. #else
  1064. #ifdef __GNUC__
  1065. #ifndef __OPTIMIZE__
  1066. _STARPU_DISP("Warning: StarPU was configured with --enable-debug (-O0), and is thus not optimized\n");
  1067. #endif
  1068. #endif
  1069. #ifdef STARPU_SPINLOCK_CHECK
  1070. _STARPU_DISP("Warning: StarPU was configured with --enable-spinlock-check, which slows down a bit\n");
  1071. #endif
  1072. #if 0
  1073. #ifndef STARPU_NO_ASSERT
  1074. _STARPU_DISP("Warning: StarPU was configured without --enable-fast\n");
  1075. #endif
  1076. #endif
  1077. #ifdef STARPU_MEMORY_STATS
  1078. _STARPU_DISP("Warning: StarPU was configured with --enable-memory-stats, which slows down a bit\n");
  1079. #endif
  1080. #ifdef STARPU_VERBOSE
  1081. _STARPU_DISP("Warning: StarPU was configured with --enable-verbose, which slows down a bit\n");
  1082. #endif
  1083. #ifdef STARPU_USE_FXT
  1084. _STARPU_DISP("Warning: StarPU was configured with --with-fxt, which slows down a bit\n");
  1085. #endif
  1086. #ifdef STARPU_PERF_DEBUG
  1087. _STARPU_DISP("Warning: StarPU was configured with --enable-perf-debug, which slows down a bit\n");
  1088. #endif
  1089. #ifdef STARPU_MODEL_DEBUG
  1090. _STARPU_DISP("Warning: StarPU was configured with --enable-model-debug, which slows down a bit\n");
  1091. #endif
  1092. #endif
  1093. if (starpu_getenv("STARPU_ENABLE_STATS"))
  1094. {
  1095. _STARPU_DISP("Warning: STARPU_ENABLE_STATS is enabled, which slows down a bit\n");
  1096. }
  1097. #if defined(_WIN32) && !defined(__CYGWIN__)
  1098. WSADATA wsadata;
  1099. WSAStartup(MAKEWORD(1,0), &wsadata);
  1100. #endif
  1101. srand(2008);
  1102. STARPU_AYU_PREINIT();
  1103. /* store the pointer to the user explicit configuration during the
  1104. * initialization */
  1105. if (user_conf == NULL)
  1106. starpu_conf_init(&_starpu_config.conf);
  1107. else
  1108. {
  1109. if (user_conf->magic != 42)
  1110. {
  1111. _STARPU_DISP("starpu_conf structure needs to be initialized with starpu_conf_init\n");
  1112. return -EINVAL;
  1113. }
  1114. _starpu_config.conf = *user_conf;
  1115. }
  1116. _starpu_conf_check_environment(&_starpu_config.conf);
  1117. /* Make a copy of arrays */
  1118. if (_starpu_config.conf.sched_policy_name)
  1119. _starpu_config.conf.sched_policy_name = strdup(_starpu_config.conf.sched_policy_name);
  1120. if (_starpu_config.conf.mic_sink_program_path)
  1121. _starpu_config.conf.mic_sink_program_path = strdup(_starpu_config.conf.mic_sink_program_path);
  1122. if (_starpu_config.conf.n_cuda_opengl_interoperability)
  1123. {
  1124. size_t size = _starpu_config.conf.n_cuda_opengl_interoperability * sizeof(*_starpu_config.conf.cuda_opengl_interoperability);
  1125. unsigned *copy = malloc(size);
  1126. memcpy(copy, _starpu_config.conf.cuda_opengl_interoperability, size);
  1127. _starpu_config.conf.cuda_opengl_interoperability = copy;
  1128. }
  1129. if (_starpu_config.conf.n_not_launched_drivers)
  1130. {
  1131. size_t size = _starpu_config.conf.n_not_launched_drivers * sizeof(*_starpu_config.conf.not_launched_drivers);
  1132. struct starpu_driver *copy = malloc(size);
  1133. memcpy(copy, _starpu_config.conf.not_launched_drivers, size);
  1134. _starpu_config.conf.not_launched_drivers = copy;
  1135. }
  1136. _starpu_sched_init();
  1137. _starpu_job_init();
  1138. _starpu_graph_init();
  1139. _starpu_init_all_sched_ctxs(&_starpu_config);
  1140. _starpu_init_progression_hooks();
  1141. _starpu_init_tags();
  1142. #ifdef STARPU_USE_FXT
  1143. _starpu_fxt_init_profiling(_starpu_config.conf.trace_buffer_size);
  1144. #endif
  1145. _starpu_open_debug_logfile();
  1146. _starpu_data_interface_init();
  1147. _starpu_timing_init();
  1148. _starpu_profiling_init();
  1149. _starpu_load_bus_performance_files();
  1150. /* Depending on whether we are a MP sink or not, we must build the
  1151. * topology with MP nodes or not. */
  1152. ret = _starpu_build_topology(&_starpu_config, is_a_sink);
  1153. if (ret)
  1154. {
  1155. starpu_perfmodel_free_sampling_directories();
  1156. STARPU_PTHREAD_MUTEX_LOCK(&init_mutex);
  1157. init_count--;
  1158. _starpu_destroy_machine_config(&_starpu_config);
  1159. #ifdef STARPU_USE_SCC
  1160. if (_starpu_scc_common_is_mp_initialized())
  1161. _starpu_scc_src_mp_deinit();
  1162. #endif
  1163. #ifdef STARPU_USE_MPI_MASTER_SLAVE
  1164. if (_starpu_mpi_common_is_mp_initialized())
  1165. _starpu_mpi_common_mp_deinit();
  1166. #endif
  1167. initialized = UNINITIALIZED;
  1168. /* Let somebody else try to do it */
  1169. STARPU_PTHREAD_COND_SIGNAL(&init_cond);
  1170. STARPU_PTHREAD_MUTEX_UNLOCK(&init_mutex);
  1171. return ret;
  1172. }
  1173. _starpu_task_init();
  1174. for (worker = 0; worker < _starpu_config.topology.nworkers; worker++)
  1175. _starpu_worker_init(&_starpu_config.workers[worker], &_starpu_config);
  1176. check_entire_platform = starpu_get_env_number("STARPU_CHECK_ENTIRE_PLATFORM");
  1177. _starpu_config.disable_kernels = starpu_get_env_number("STARPU_DISABLE_KERNELS");
  1178. STARPU_PTHREAD_KEY_CREATE(&_starpu_worker_key, NULL);
  1179. STARPU_PTHREAD_KEY_CREATE(&_starpu_worker_set_key, NULL);
  1180. _starpu_keys_initialized = 1;
  1181. _starpu_build_tree();
  1182. if (!is_a_sink)
  1183. {
  1184. struct starpu_sched_policy *selected_policy = _starpu_select_sched_policy(&_starpu_config, _starpu_config.conf.sched_policy_name);
  1185. _starpu_create_sched_ctx(selected_policy, NULL, -1, 1, "init", (_starpu_config.conf.global_sched_ctx_min_priority != -1), _starpu_config.conf.global_sched_ctx_min_priority, (_starpu_config.conf.global_sched_ctx_min_priority != -1), _starpu_config.conf.global_sched_ctx_max_priority, 1, _starpu_config.conf.sched_policy_init, NULL);
  1186. }
  1187. _starpu_initialize_registered_performance_models();
  1188. /* Launch "basic" workers (ie. non-combined workers) */
  1189. if (!is_a_sink)
  1190. _starpu_launch_drivers(&_starpu_config);
  1191. /* Allocate swap, if any */
  1192. _starpu_swap_init();
  1193. _starpu_watchdog_init();
  1194. _starpu_profiling_start();
  1195. STARPU_PTHREAD_MUTEX_LOCK(&init_mutex);
  1196. initialized = INITIALIZED;
  1197. /* Tell everybody that we initialized */
  1198. STARPU_PTHREAD_COND_BROADCAST(&init_cond);
  1199. STARPU_PTHREAD_MUTEX_UNLOCK(&init_mutex);
  1200. _STARPU_DEBUG("Initialisation finished\n");
  1201. #ifdef STARPU_USE_MP
  1202. /* Finally, if we are a MP sink, we never leave this function. Else,
  1203. * we enter an infinite event loop which listen for MP commands from
  1204. * the source. */
  1205. if (is_a_sink)
  1206. {
  1207. _starpu_sink_common_worker();
  1208. /* We should normally never leave the loop as we don't want to
  1209. * really initialize STARPU */
  1210. STARPU_ASSERT(0);
  1211. }
  1212. #endif
  1213. return 0;
  1214. }
  1215. /*
  1216. * Handle runtime termination
  1217. */
  1218. static void _starpu_terminate_workers(struct _starpu_machine_config *pconfig)
  1219. {
  1220. int status = 0;
  1221. unsigned workerid;
  1222. unsigned n;
  1223. for (workerid = 0; workerid < pconfig->topology.nworkers; workerid++)
  1224. {
  1225. starpu_wake_all_blocked_workers();
  1226. _STARPU_DEBUG("wait for worker %u\n", workerid);
  1227. struct _starpu_worker_set *set = pconfig->workers[workerid].set;
  1228. struct _starpu_worker *worker = &pconfig->workers[workerid];
  1229. /* in case StarPU termination code is called from a callback,
  1230. * we have to check if pthread_self() is the worker itself */
  1231. if (set)
  1232. {
  1233. if (set->started)
  1234. {
  1235. #ifdef STARPU_SIMGRID
  1236. status = starpu_pthread_join(set->worker_thread, NULL);
  1237. #else
  1238. if (!pthread_equal(pthread_self(), set->worker_thread))
  1239. status = starpu_pthread_join(set->worker_thread, NULL);
  1240. #endif
  1241. if (status)
  1242. {
  1243. #ifdef STARPU_VERBOSE
  1244. _STARPU_DEBUG("starpu_pthread_join -> %d\n", status);
  1245. #endif
  1246. }
  1247. set->started = 0;
  1248. }
  1249. }
  1250. else
  1251. {
  1252. if (!worker->run_by_starpu)
  1253. goto out;
  1254. #ifdef STARPU_SIMGRID
  1255. status = starpu_pthread_join(worker->worker_thread, NULL);
  1256. #else
  1257. if (!pthread_equal(pthread_self(), worker->worker_thread))
  1258. status = starpu_pthread_join(worker->worker_thread, NULL);
  1259. #endif
  1260. if (status)
  1261. {
  1262. #ifdef STARPU_VERBOSE
  1263. _STARPU_DEBUG("starpu_pthread_join -> %d\n", status);
  1264. #endif
  1265. }
  1266. }
  1267. out:
  1268. STARPU_ASSERT(starpu_task_list_empty(&worker->local_tasks));
  1269. for (n = 0; n < worker->local_ordered_tasks_size; n++)
  1270. STARPU_ASSERT(worker->local_ordered_tasks[n] == NULL);
  1271. _starpu_sched_ctx_list_delete(&worker->sched_ctx_list);
  1272. free(worker->local_ordered_tasks);
  1273. }
  1274. }
  1275. /* Condition variable and mutex used to pause/resume. */
  1276. static starpu_pthread_cond_t pause_cond = STARPU_PTHREAD_COND_INITIALIZER;
  1277. static starpu_pthread_mutex_t pause_mutex = STARPU_PTHREAD_MUTEX_INITIALIZER;
  1278. void _starpu_may_pause(void)
  1279. {
  1280. /* pause_depth is just protected by a memory barrier */
  1281. STARPU_RMB();
  1282. if (STARPU_UNLIKELY(_starpu_config.pause_depth > 0))
  1283. {
  1284. STARPU_PTHREAD_MUTEX_LOCK(&pause_mutex);
  1285. if (_starpu_config.pause_depth > 0)
  1286. {
  1287. STARPU_PTHREAD_COND_WAIT(&pause_cond, &pause_mutex);
  1288. }
  1289. STARPU_PTHREAD_MUTEX_UNLOCK(&pause_mutex);
  1290. }
  1291. }
  1292. void starpu_pause()
  1293. {
  1294. STARPU_HG_DISABLE_CHECKING(_starpu_config.pause_depth);
  1295. _starpu_config.pause_depth += 1;
  1296. }
  1297. void starpu_resume()
  1298. {
  1299. STARPU_PTHREAD_MUTEX_LOCK(&pause_mutex);
  1300. _starpu_config.pause_depth -= 1;
  1301. if (!_starpu_config.pause_depth)
  1302. {
  1303. STARPU_PTHREAD_COND_BROADCAST(&pause_cond);
  1304. }
  1305. STARPU_PTHREAD_MUTEX_UNLOCK(&pause_mutex);
  1306. }
  1307. unsigned _starpu_worker_can_block(unsigned memnode STARPU_ATTRIBUTE_UNUSED, struct _starpu_worker *worker STARPU_ATTRIBUTE_UNUSED)
  1308. {
  1309. #ifdef STARPU_NON_BLOCKING_DRIVERS
  1310. return 0;
  1311. #else
  1312. unsigned can_block = 1;
  1313. struct starpu_driver driver;
  1314. driver.type = worker->arch;
  1315. switch (driver.type)
  1316. {
  1317. case STARPU_CPU_WORKER:
  1318. driver.id.cpu_id = worker->devid;
  1319. break;
  1320. case STARPU_CUDA_WORKER:
  1321. driver.id.cuda_id = worker->devid;
  1322. break;
  1323. #ifdef STARPU_USE_OPENCL
  1324. case STARPU_OPENCL_WORKER:
  1325. starpu_opencl_get_device(worker->devid, &driver.id.opencl_id);
  1326. break;
  1327. #endif
  1328. default:
  1329. goto always_launch;
  1330. }
  1331. if (!_starpu_may_launch_driver(&_starpu_config.conf, &driver))
  1332. return 0;
  1333. always_launch:
  1334. #ifndef STARPU_SIMGRID
  1335. if (!_starpu_check_that_no_data_request_exists(memnode))
  1336. can_block = 0;
  1337. #endif
  1338. if (!_starpu_machine_is_running())
  1339. can_block = 0;
  1340. if (!_starpu_execute_registered_progression_hooks())
  1341. can_block = 0;
  1342. return can_block;
  1343. #endif
  1344. }
  1345. static void _starpu_kill_all_workers(struct _starpu_machine_config *pconfig)
  1346. {
  1347. /* set the flag which will tell workers to stop */
  1348. ANNOTATE_HAPPENS_AFTER(&_starpu_config.running);
  1349. pconfig->running = 0;
  1350. /* running is just protected by a memory barrier */
  1351. ANNOTATE_HAPPENS_BEFORE(&_starpu_config.running);
  1352. STARPU_WMB();
  1353. starpu_wake_all_blocked_workers();
  1354. }
  1355. void starpu_display_stats()
  1356. {
  1357. starpu_profiling_bus_helper_display_summary();
  1358. starpu_profiling_worker_helper_display_summary();
  1359. }
  1360. void starpu_shutdown(void)
  1361. {
  1362. unsigned worker;
  1363. STARPU_PTHREAD_MUTEX_LOCK(&init_mutex);
  1364. init_count--;
  1365. STARPU_ASSERT_MSG(init_count >= 0, "Number of calls to starpu_shutdown() can not be higher than the number of calls to starpu_init()\n");
  1366. if (init_count)
  1367. {
  1368. _STARPU_DEBUG("Still somebody needing StarPU, don't deinitialize\n");
  1369. STARPU_PTHREAD_MUTEX_UNLOCK(&init_mutex);
  1370. return;
  1371. }
  1372. /* We're last */
  1373. initialized = CHANGING;
  1374. STARPU_PTHREAD_MUTEX_UNLOCK(&init_mutex);
  1375. /* If the workers are frozen, no progress can be made. */
  1376. STARPU_ASSERT(_starpu_config.pause_depth <= 0);
  1377. starpu_task_wait_for_no_ready();
  1378. /* tell all workers to shutdown */
  1379. _starpu_kill_all_workers(&_starpu_config);
  1380. _starpu_free_all_automatically_allocated_buffers(STARPU_MAIN_RAM);
  1381. {
  1382. int stats = starpu_get_env_number("STARPU_STATS");
  1383. if (stats != 0)
  1384. {
  1385. _starpu_display_msi_stats();
  1386. _starpu_display_alloc_cache_stats();
  1387. }
  1388. }
  1389. starpu_profiling_bus_helper_display_summary();
  1390. starpu_profiling_worker_helper_display_summary();
  1391. _starpu_deinitialize_registered_performance_models();
  1392. _starpu_watchdog_shutdown();
  1393. /* wait for their termination */
  1394. _starpu_terminate_workers(&_starpu_config);
  1395. {
  1396. int stats = starpu_get_env_number("STARPU_MEMORY_STATS");
  1397. if (stats != 0)
  1398. {
  1399. // Display statistics on data which have not been unregistered
  1400. starpu_data_display_memory_stats();
  1401. }
  1402. }
  1403. _starpu_delete_all_sched_ctxs();
  1404. _starpu_sched_component_workers_destroy();
  1405. _starpu_top_shutdown();
  1406. for (worker = 0; worker < _starpu_config.topology.nworkers; worker++)
  1407. _starpu_worker_deinit(&_starpu_config.workers[worker]);
  1408. _starpu_profiling_terminate();
  1409. _starpu_disk_unregister();
  1410. #ifdef STARPU_HAVE_HWLOC
  1411. starpu_tree_free(_starpu_config.topology.tree);
  1412. free(_starpu_config.topology.tree);
  1413. #endif
  1414. _starpu_destroy_topology(&_starpu_config);
  1415. #ifdef STARPU_USE_FXT
  1416. _starpu_stop_fxt_profiling();
  1417. #endif
  1418. _starpu_data_interface_shutdown();
  1419. _starpu_job_fini();
  1420. /* Drop all remaining tags */
  1421. _starpu_tag_clear();
  1422. #ifdef STARPU_OPENMP
  1423. _starpu_omp_dummy_shutdown();
  1424. #endif
  1425. _starpu_close_debug_logfile();
  1426. _starpu_keys_initialized = 0;
  1427. STARPU_PTHREAD_KEY_DELETE(_starpu_worker_key);
  1428. STARPU_PTHREAD_KEY_DELETE(_starpu_worker_set_key);
  1429. _starpu_task_deinit();
  1430. STARPU_PTHREAD_MUTEX_LOCK(&init_mutex);
  1431. initialized = UNINITIALIZED;
  1432. /* Let someone else that wants to initialize it again do it */
  1433. STARPU_PTHREAD_COND_SIGNAL(&init_cond);
  1434. STARPU_PTHREAD_MUTEX_UNLOCK(&init_mutex);
  1435. /* Clear memory */
  1436. free((char*) _starpu_config.conf.sched_policy_name);
  1437. free(_starpu_config.conf.mic_sink_program_path);
  1438. if (_starpu_config.conf.n_cuda_opengl_interoperability)
  1439. free(_starpu_config.conf.cuda_opengl_interoperability);
  1440. if (_starpu_config.conf.n_not_launched_drivers)
  1441. free(_starpu_config.conf.not_launched_drivers);
  1442. STARPU_AYU_FINISH();
  1443. #ifdef STARPU_USE_SCC
  1444. if (_starpu_scc_common_is_mp_initialized())
  1445. _starpu_scc_src_mp_deinit();
  1446. #endif
  1447. _starpu_print_idle_time();
  1448. _STARPU_DEBUG("Shutdown finished\n");
  1449. #ifdef STARPU_SIMGRID
  1450. /* This finalizes the simgrid thread library, thus needs to be late */
  1451. _starpu_simgrid_deinit();
  1452. #endif
  1453. }
  1454. #undef starpu_worker_get_count
  1455. unsigned starpu_worker_get_count(void)
  1456. {
  1457. return _starpu_config.topology.nworkers;
  1458. }
  1459. unsigned starpu_worker_is_blocked(int workerid)
  1460. {
  1461. return _starpu_config.workers[workerid].blocked;
  1462. }
  1463. unsigned starpu_worker_is_slave_somewhere(int workerid)
  1464. {
  1465. return _starpu_config.workers[workerid].is_slave_somewhere;
  1466. }
  1467. int starpu_worker_get_count_by_type(enum starpu_worker_archtype type)
  1468. {
  1469. switch (type)
  1470. {
  1471. case STARPU_CPU_WORKER:
  1472. return _starpu_config.topology.ncpus;
  1473. case STARPU_CUDA_WORKER:
  1474. return _starpu_config.topology.ncudagpus;
  1475. case STARPU_OPENCL_WORKER:
  1476. return _starpu_config.topology.nopenclgpus;
  1477. case STARPU_MIC_WORKER:
  1478. return _starpu_config.topology.nmicdevices;
  1479. case STARPU_SCC_WORKER:
  1480. return _starpu_config.topology.nsccdevices;
  1481. case STARPU_MPI_WORKER:
  1482. return _starpu_config.topology.nmpidevices;
  1483. default:
  1484. return -EINVAL;
  1485. }
  1486. }
  1487. unsigned starpu_combined_worker_get_count(void)
  1488. {
  1489. return _starpu_config.topology.ncombinedworkers;
  1490. }
  1491. unsigned starpu_cpu_worker_get_count(void)
  1492. {
  1493. return _starpu_config.topology.ncpus;
  1494. }
  1495. unsigned starpu_cuda_worker_get_count(void)
  1496. {
  1497. return _starpu_config.topology.ncudagpus;
  1498. }
  1499. unsigned starpu_opencl_worker_get_count(void)
  1500. {
  1501. return _starpu_config.topology.nopenclgpus;
  1502. }
  1503. int starpu_asynchronous_copy_disabled(void)
  1504. {
  1505. return _starpu_config.conf.disable_asynchronous_copy;
  1506. }
  1507. int starpu_asynchronous_cuda_copy_disabled(void)
  1508. {
  1509. return _starpu_config.conf.disable_asynchronous_cuda_copy;
  1510. }
  1511. int starpu_asynchronous_opencl_copy_disabled(void)
  1512. {
  1513. return _starpu_config.conf.disable_asynchronous_opencl_copy;
  1514. }
  1515. int starpu_asynchronous_mic_copy_disabled(void)
  1516. {
  1517. return _starpu_config.conf.disable_asynchronous_mic_copy;
  1518. }
  1519. unsigned starpu_mic_worker_get_count(void)
  1520. {
  1521. int i = 0, count = 0;
  1522. for (i = 0; i < STARPU_MAXMICDEVS; i++)
  1523. count += _starpu_config.topology.nmiccores[i];
  1524. return count;
  1525. }
  1526. unsigned starpu_scc_worker_get_count(void)
  1527. {
  1528. return _starpu_config.topology.nsccdevices;
  1529. }
  1530. /* When analyzing performance, it is useful to see what is the processing unit
  1531. * that actually performed the task. This function returns the id of the
  1532. * processing unit actually executing it, therefore it makes no sense to use it
  1533. * within the callbacks of SPU functions for instance. If called by some thread
  1534. * that is not controlled by StarPU, starpu_worker_get_id returns -1. */
  1535. #undef starpu_worker_get_id
  1536. int starpu_worker_get_id(void)
  1537. {
  1538. struct _starpu_worker * worker;
  1539. worker = _starpu_get_local_worker_key();
  1540. if (worker)
  1541. {
  1542. return worker->workerid;
  1543. }
  1544. else
  1545. {
  1546. /* there is no worker associated to that thread, perhaps it is
  1547. * a thread from the application or this is some SPU worker */
  1548. return -1;
  1549. }
  1550. }
  1551. #define starpu_worker_get_id _starpu_worker_get_id
  1552. #undef _starpu_worker_get_id_check
  1553. unsigned _starpu_worker_get_id_check(const char *f, int l)
  1554. {
  1555. int id = _starpu_worker_get_id();
  1556. STARPU_ASSERT_MSG(id>=0, "%s:%u Cannot be called from outside a worker\n", f, l);
  1557. return id;
  1558. }
  1559. int starpu_combined_worker_get_id(void)
  1560. {
  1561. struct _starpu_worker *worker;
  1562. worker = _starpu_get_local_worker_key();
  1563. if (worker)
  1564. {
  1565. return worker->combined_workerid;
  1566. }
  1567. else
  1568. {
  1569. /* there is no worker associated to that thread, perhaps it is
  1570. * a thread from the application or this is some SPU worker */
  1571. return -1;
  1572. }
  1573. }
  1574. int starpu_combined_worker_get_size(void)
  1575. {
  1576. struct _starpu_worker *worker;
  1577. worker = _starpu_get_local_worker_key();
  1578. if (worker)
  1579. {
  1580. return worker->worker_size;
  1581. }
  1582. else
  1583. {
  1584. /* there is no worker associated to that thread, perhaps it is
  1585. * a thread from the application or this is some SPU worker */
  1586. return -1;
  1587. }
  1588. }
  1589. int starpu_combined_worker_get_rank(void)
  1590. {
  1591. struct _starpu_worker *worker;
  1592. worker = _starpu_get_local_worker_key();
  1593. if (worker)
  1594. {
  1595. return worker->current_rank;
  1596. }
  1597. else
  1598. {
  1599. /* there is no worker associated to that thread, perhaps it is
  1600. * a thread from the application or this is some SPU worker */
  1601. return -1;
  1602. }
  1603. }
  1604. int starpu_worker_get_subworkerid(int id)
  1605. {
  1606. return _starpu_config.workers[id].subworkerid;
  1607. }
  1608. int starpu_worker_get_devid(int id)
  1609. {
  1610. return _starpu_config.workers[id].devid;
  1611. }
  1612. unsigned starpu_worker_is_combined_worker(int id)
  1613. {
  1614. return id >= (int)_starpu_config.topology.nworkers;
  1615. }
  1616. struct _starpu_combined_worker *_starpu_get_combined_worker_struct(unsigned id)
  1617. {
  1618. unsigned basic_worker_count = starpu_worker_get_count();
  1619. //_STARPU_DEBUG("basic_worker_count:%d\n",basic_worker_count);
  1620. STARPU_ASSERT(id >= basic_worker_count);
  1621. return &_starpu_config.combined_workers[id - basic_worker_count];
  1622. }
  1623. enum starpu_worker_archtype starpu_worker_get_type(int id)
  1624. {
  1625. return _starpu_config.workers[id].arch;
  1626. }
  1627. int starpu_worker_get_ids_by_type(enum starpu_worker_archtype type, int *workerids, int maxsize)
  1628. {
  1629. unsigned nworkers = starpu_worker_get_count();
  1630. int cnt = 0;
  1631. unsigned id;
  1632. for (id = 0; id < nworkers; id++)
  1633. {
  1634. if (starpu_worker_get_type(id) == type)
  1635. {
  1636. /* Perhaps the array is too small ? */
  1637. if (cnt >= maxsize)
  1638. return -ERANGE;
  1639. workerids[cnt++] = id;
  1640. }
  1641. }
  1642. return cnt;
  1643. }
  1644. int starpu_worker_get_by_type(enum starpu_worker_archtype type, int num)
  1645. {
  1646. unsigned nworkers = starpu_worker_get_count();
  1647. int cnt = 0;
  1648. unsigned id;
  1649. for (id = 0; id < nworkers; id++)
  1650. {
  1651. if (starpu_worker_get_type(id) == type)
  1652. {
  1653. if (num == cnt)
  1654. return id;
  1655. cnt++;
  1656. }
  1657. }
  1658. /* Not found */
  1659. return -1;
  1660. }
  1661. int starpu_worker_get_by_devid(enum starpu_worker_archtype type, int devid)
  1662. {
  1663. unsigned nworkers = starpu_worker_get_count();
  1664. unsigned id;
  1665. for (id = 0; id < nworkers; id++)
  1666. if (starpu_worker_get_type(id) == type && starpu_worker_get_devid(id) == devid)
  1667. return id;
  1668. /* Not found */
  1669. return -1;
  1670. }
  1671. void starpu_worker_get_name(int id, char *dst, size_t maxlen)
  1672. {
  1673. char *name = _starpu_config.workers[id].name;
  1674. snprintf(dst, maxlen, "%s", name);
  1675. }
  1676. int starpu_worker_get_bindid(int workerid)
  1677. {
  1678. return _starpu_config.workers[workerid].bindid;
  1679. }
  1680. int starpu_bindid_get_workerids(int bindid, int **workerids)
  1681. {
  1682. if (bindid >= (int) _starpu_config.nbindid)
  1683. return 0;
  1684. *workerids = _starpu_config.bindid_workers[bindid].workerids;
  1685. return _starpu_config.bindid_workers[bindid].nworkers;
  1686. }
  1687. void starpu_worker_get_sched_condition(int workerid, starpu_pthread_mutex_t **sched_mutex, starpu_pthread_cond_t **sched_cond)
  1688. {
  1689. *sched_cond = &_starpu_config.workers[workerid].sched_cond;
  1690. *sched_mutex = &_starpu_config.workers[workerid].sched_mutex;
  1691. }
  1692. int starpu_wakeup_worker_locked(int workerid, starpu_pthread_cond_t *cond, starpu_pthread_mutex_t *mutex STARPU_ATTRIBUTE_UNUSED)
  1693. {
  1694. #ifdef STARPU_SIMGRID
  1695. starpu_pthread_queue_broadcast(&_starpu_simgrid_task_queue[workerid]);
  1696. #endif
  1697. if (_starpu_config.workers[workerid].status == STATUS_SLEEPING)
  1698. {
  1699. _starpu_config.workers[workerid].status = STATUS_WAKING_UP;
  1700. STARPU_PTHREAD_COND_SIGNAL(cond);
  1701. return 1;
  1702. }
  1703. return 0;
  1704. }
  1705. int starpu_wakeup_worker(int workerid, starpu_pthread_cond_t *cond, starpu_pthread_mutex_t *mutex)
  1706. {
  1707. int success;
  1708. STARPU_PTHREAD_MUTEX_LOCK_SCHED(mutex);
  1709. success = starpu_wakeup_worker_locked(workerid, cond, mutex);
  1710. STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(mutex);
  1711. return success;
  1712. }
  1713. int starpu_wake_worker_locked(int workerid)
  1714. {
  1715. starpu_pthread_mutex_t *sched_mutex;
  1716. starpu_pthread_cond_t *sched_cond;
  1717. starpu_worker_get_sched_condition(workerid, &sched_mutex, &sched_cond);
  1718. return starpu_wakeup_worker_locked(workerid, sched_cond, sched_mutex);
  1719. }
  1720. int starpu_wake_worker(int workerid)
  1721. {
  1722. starpu_pthread_mutex_t *sched_mutex;
  1723. starpu_pthread_cond_t *sched_cond;
  1724. starpu_worker_get_sched_condition(workerid, &sched_mutex, &sched_cond);
  1725. return starpu_wakeup_worker(workerid, sched_cond, sched_mutex);
  1726. }
  1727. int starpu_worker_get_nids_by_type(enum starpu_worker_archtype type, int *workerids, int maxsize)
  1728. {
  1729. unsigned nworkers = starpu_worker_get_count();
  1730. int cnt = 0;
  1731. unsigned id;
  1732. for (id = 0; id < nworkers; id++)
  1733. {
  1734. if (starpu_worker_get_type(id) == type)
  1735. {
  1736. /* Perhaps the array is too small ? */
  1737. if (cnt >= maxsize)
  1738. return cnt;
  1739. workerids[cnt++] = id;
  1740. }
  1741. }
  1742. return cnt;
  1743. }
  1744. int starpu_worker_get_nids_ctx_free_by_type(enum starpu_worker_archtype type, int *workerids, int maxsize)
  1745. {
  1746. unsigned nworkers = starpu_worker_get_count();
  1747. int cnt = 0;
  1748. unsigned id, worker;
  1749. unsigned found = 0;
  1750. for (id = 0; id < nworkers; id++)
  1751. {
  1752. found = 0;
  1753. if (starpu_worker_get_type(id) == type)
  1754. {
  1755. /* Perhaps the array is too small ? */
  1756. if (cnt >= maxsize)
  1757. return cnt;
  1758. int s;
  1759. for(s = 1; s < STARPU_NMAX_SCHED_CTXS; s++)
  1760. {
  1761. if(_starpu_config.sched_ctxs[s].id != STARPU_NMAX_SCHED_CTXS)
  1762. {
  1763. struct starpu_worker_collection *workers = _starpu_config.sched_ctxs[s].workers;
  1764. struct starpu_sched_ctx_iterator it;
  1765. workers->init_iterator(workers, &it);
  1766. while(workers->has_next(workers, &it))
  1767. {
  1768. worker = workers->get_next(workers, &it);
  1769. if(worker == id)
  1770. {
  1771. found = 1;
  1772. break;
  1773. }
  1774. }
  1775. if(found) break;
  1776. }
  1777. }
  1778. if(!found)
  1779. workerids[cnt++] = id;
  1780. }
  1781. }
  1782. return cnt;
  1783. }
  1784. int
  1785. starpu_driver_run(struct starpu_driver *d)
  1786. {
  1787. if (!d)
  1788. {
  1789. _STARPU_DEBUG("Invalid argument\n");
  1790. return -EINVAL;
  1791. }
  1792. void *worker = _starpu_get_worker_from_driver(d);
  1793. switch (d->type)
  1794. {
  1795. #ifdef STARPU_USE_CPU
  1796. case STARPU_CPU_WORKER:
  1797. return _starpu_run_cpu(worker);
  1798. #endif
  1799. #ifdef STARPU_USE_CUDA
  1800. case STARPU_CUDA_WORKER:
  1801. return _starpu_run_cuda(worker);
  1802. #endif
  1803. #ifdef STARPU_USE_OPENCL
  1804. case STARPU_OPENCL_WORKER:
  1805. return _starpu_run_opencl(worker);
  1806. #endif
  1807. default:
  1808. _STARPU_DEBUG("Invalid device type\n");
  1809. return -EINVAL;
  1810. }
  1811. }
  1812. int
  1813. starpu_driver_init(struct starpu_driver *d)
  1814. {
  1815. STARPU_ASSERT(d);
  1816. void *worker = _starpu_get_worker_from_driver(d);
  1817. switch (d->type)
  1818. {
  1819. #ifdef STARPU_USE_CPU
  1820. case STARPU_CPU_WORKER:
  1821. return _starpu_cpu_driver_init(worker);
  1822. #endif
  1823. #ifdef STARPU_USE_CUDA
  1824. case STARPU_CUDA_WORKER:
  1825. return _starpu_cuda_driver_init(worker);
  1826. #endif
  1827. #ifdef STARPU_USE_OPENCL
  1828. case STARPU_OPENCL_WORKER:
  1829. return _starpu_opencl_driver_init(worker);
  1830. #endif
  1831. default:
  1832. return -EINVAL;
  1833. }
  1834. }
  1835. int
  1836. starpu_driver_run_once(struct starpu_driver *d)
  1837. {
  1838. STARPU_ASSERT(d);
  1839. void *worker = _starpu_get_worker_from_driver(d);
  1840. switch (d->type)
  1841. {
  1842. #ifdef STARPU_USE_CPU
  1843. case STARPU_CPU_WORKER:
  1844. return _starpu_cpu_driver_run_once(worker);
  1845. #endif
  1846. #ifdef STARPU_USE_CUDA
  1847. case STARPU_CUDA_WORKER:
  1848. return _starpu_cuda_driver_run_once(worker);
  1849. #endif
  1850. #ifdef STARPU_USE_OPENCL
  1851. case STARPU_OPENCL_WORKER:
  1852. return _starpu_opencl_driver_run_once(worker);
  1853. #endif
  1854. default:
  1855. return -EINVAL;
  1856. }
  1857. }
  1858. int
  1859. starpu_driver_deinit(struct starpu_driver *d)
  1860. {
  1861. STARPU_ASSERT(d);
  1862. void *worker = _starpu_get_worker_from_driver(d);
  1863. switch (d->type)
  1864. {
  1865. #ifdef STARPU_USE_CPU
  1866. case STARPU_CPU_WORKER:
  1867. return _starpu_cpu_driver_deinit(worker);
  1868. #endif
  1869. #ifdef STARPU_USE_CUDA
  1870. case STARPU_CUDA_WORKER:
  1871. return _starpu_cuda_driver_deinit(worker);
  1872. #endif
  1873. #ifdef STARPU_USE_OPENCL
  1874. case STARPU_OPENCL_WORKER:
  1875. return _starpu_opencl_driver_deinit(worker);
  1876. #endif
  1877. default:
  1878. return -EINVAL;
  1879. }
  1880. }
  1881. void starpu_get_version(int *major, int *minor, int *release)
  1882. {
  1883. *major = STARPU_MAJOR_VERSION;
  1884. *minor = STARPU_MINOR_VERSION;
  1885. *release = STARPU_RELEASE_VERSION;
  1886. }
  1887. void _starpu_unlock_mutex_if_prev_locked()
  1888. {
  1889. int workerid = starpu_worker_get_id();
  1890. if(workerid != -1)
  1891. {
  1892. struct _starpu_worker *w = _starpu_get_worker_struct(workerid);
  1893. if(w->sched_mutex_locked)
  1894. {
  1895. STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(&w->sched_mutex);
  1896. _starpu_worker_set_flag_sched_mutex_locked(workerid, 1);
  1897. }
  1898. }
  1899. return;
  1900. }
  1901. void _starpu_relock_mutex_if_prev_locked()
  1902. {
  1903. int workerid = starpu_worker_get_id();
  1904. if(workerid != -1)
  1905. {
  1906. struct _starpu_worker *w = _starpu_get_worker_struct(workerid);
  1907. if(w->sched_mutex_locked)
  1908. STARPU_PTHREAD_MUTEX_LOCK_SCHED(&w->sched_mutex);
  1909. }
  1910. return;
  1911. }
  1912. unsigned starpu_worker_get_sched_ctx_list(int workerid, unsigned **sched_ctxs)
  1913. {
  1914. unsigned s = 0;
  1915. unsigned nsched_ctxs = _starpu_worker_get_nsched_ctxs(workerid);
  1916. *sched_ctxs = (unsigned*)malloc(nsched_ctxs*sizeof(unsigned));
  1917. struct _starpu_worker *worker = _starpu_get_worker_struct(workerid);
  1918. struct _starpu_sched_ctx_elt *e = NULL;
  1919. struct _starpu_sched_ctx_list_iterator list_it;
  1920. _starpu_sched_ctx_list_iterator_init(worker->sched_ctx_list, &list_it);
  1921. while (_starpu_sched_ctx_list_iterator_has_next(&list_it))
  1922. {
  1923. e = _starpu_sched_ctx_list_iterator_get_next(&list_it);
  1924. (*sched_ctxs)[s++] = e->sched_ctx;
  1925. }
  1926. return nsched_ctxs;
  1927. }
  1928. char *starpu_worker_get_type_as_string(enum starpu_worker_archtype type)
  1929. {
  1930. if (type == STARPU_CPU_WORKER) return "STARPU_CPU_WORKER";
  1931. if (type == STARPU_CUDA_WORKER) return "STARPU_CUDA_WORKER";
  1932. if (type == STARPU_OPENCL_WORKER) return "STARPU_OPENCL_WORKER";
  1933. if (type == STARPU_MIC_WORKER) return "STARPU_MIC_WORKER";
  1934. if (type == STARPU_MPI_WORKER) return "STARPU_MPI_WORKER";
  1935. if (type == STARPU_SCC_WORKER) return "STARPU_SCC_WORKER";
  1936. if (type == STARPU_ANY_WORKER) return "STARPU_ANY_WORKER";
  1937. return "STARPU_unknown_WORKER";
  1938. }