starpu_task.h 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2017 Inria
  4. * Copyright (C) 2009-2019 Université de Bordeaux
  5. * Copyright (C) 2010-2015,2017,2018,2019 CNRS
  6. * Copyright (C) 2011 Télécom-SudParis
  7. * Copyright (C) 2016 Uppsala University
  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. #ifndef __STARPU_TASK_H__
  21. #define __STARPU_TASK_H__
  22. #include <starpu.h>
  23. #include <errno.h>
  24. #include <assert.h>
  25. #if defined STARPU_USE_CUDA && !defined STARPU_DONT_INCLUDE_CUDA_HEADERS
  26. # include <cuda.h>
  27. #endif
  28. #ifdef __cplusplus
  29. extern "C"
  30. {
  31. #endif
  32. /**
  33. @defgroup API_Codelet_And_Tasks Codelet And Tasks
  34. @brief This section describes the interface to manipulate codelets
  35. and tasks.
  36. @{
  37. */
  38. /**
  39. To be used when setting the field starpu_codelet::where to specify
  40. that the codelet has no computation part, and thus does not need to
  41. be scheduled, and data does not need to be actually loaded. This is
  42. thus essentially used for synchronization tasks.
  43. */
  44. #define STARPU_NOWHERE ((1ULL)<<0)
  45. /**
  46. To be used when setting the field starpu_codelet::where (or
  47. starpu_task::where) to specify the codelet (or the task) may be
  48. executed on a CPU processing unit.
  49. */
  50. #define STARPU_CPU ((1ULL)<<1)
  51. /**
  52. To be used when setting the field starpu_codelet::where (or
  53. starpu_task::where) to specify the codelet (or the task) may be
  54. executed on a CUDA processing unit.
  55. */
  56. #define STARPU_CUDA ((1ULL)<<3)
  57. /**
  58. To be used when setting the field starpu_codelet::where (or
  59. starpu_task::where) to specify the codelet (or the task) may be
  60. executed on a OpenCL processing unit.
  61. */
  62. #define STARPU_OPENCL ((1ULL)<<6)
  63. /**
  64. To be used when setting the field starpu_codelet::where (or
  65. starpu_task::where) to specify the codelet (or the task) may be
  66. executed on a MIC processing unit.
  67. */
  68. #define STARPU_MIC ((1ULL)<<7)
  69. /**
  70. To be used when setting the field starpu_codelet::where (or
  71. starpu_task::where) to specify the codelet (or the task) may be
  72. executed on a MPI Slave processing unit.
  73. */
  74. #define STARPU_MPI_MS ((1ULL)<<9)
  75. /**
  76. Value to be set in starpu_codelet::flags to execute the codelet
  77. functions even in simgrid mode.
  78. */
  79. #define STARPU_CODELET_SIMGRID_EXECUTE (1<<0)
  80. /**
  81. Value to be set in starpu_codelet::flags to execute the codelet
  82. functions even in simgrid mode, and later inject the measured
  83. timing inside the simulation.
  84. */
  85. #define STARPU_CODELET_SIMGRID_EXECUTE_AND_INJECT (1<<1)
  86. /**
  87. Value to be set in starpu_codelet::flags to make starpu_task_submit()
  88. not submit automatic asynchronous partitioning/unpartitioning.
  89. */
  90. #define STARPU_CODELET_NOPLANS (1<<2)
  91. /**
  92. Value to be set in starpu_codelet::cuda_flags to allow asynchronous
  93. CUDA kernel execution.
  94. */
  95. #define STARPU_CUDA_ASYNC (1<<0)
  96. /**
  97. Value to be set in starpu_codelet::opencl_flags to allow
  98. asynchronous OpenCL kernel execution.
  99. */
  100. #define STARPU_OPENCL_ASYNC (1<<0)
  101. /**
  102. To be used when the RAM memory node is specified.
  103. */
  104. #define STARPU_MAIN_RAM 0
  105. /**
  106. Describe the type of parallel task. See \ref ParallelTasks for
  107. details.
  108. */
  109. enum starpu_codelet_type
  110. {
  111. STARPU_SEQ = 0, /**< (default) for classical sequential
  112. tasks.
  113. */
  114. STARPU_SPMD, /**< for a parallel task whose threads are
  115. handled by StarPU, the code has to use
  116. starpu_combined_worker_get_size() and
  117. starpu_combined_worker_get_rank() to
  118. distribute the work.
  119. */
  120. STARPU_FORKJOIN /**< for a parallel task whose threads are
  121. started by the codelet function, which has
  122. to use starpu_combined_worker_get_size() to
  123. determine how many threads should be
  124. started.
  125. */
  126. };
  127. enum starpu_task_status
  128. {
  129. STARPU_TASK_INVALID, /**< The task has just been initialized. */
  130. #define STARPU_TASK_INVALID 0
  131. STARPU_TASK_BLOCKED, /**< The task has just been
  132. submitted, and its dependencies has not been checked yet. */
  133. STARPU_TASK_READY, /**< The task is ready for execution. */
  134. STARPU_TASK_RUNNING, /**< The task is running on some worker. */
  135. STARPU_TASK_FINISHED, /**< The task is finished executing. */
  136. STARPU_TASK_BLOCKED_ON_TAG, /**< The task is waiting for a tag. */
  137. STARPU_TASK_BLOCKED_ON_TASK, /**< The task is waiting for a task. */
  138. STARPU_TASK_BLOCKED_ON_DATA, /**< The task is waiting for some data. */
  139. STARPU_TASK_STOPPED /**< The task is stopped. */
  140. };
  141. /**
  142. CPU implementation of a codelet.
  143. */
  144. typedef void (*starpu_cpu_func_t)(void **, void*);
  145. /**
  146. CUDA implementation of a codelet.
  147. */
  148. typedef void (*starpu_cuda_func_t)(void **, void*);
  149. /**
  150. OpenCL implementation of a codelet.
  151. */
  152. typedef void (*starpu_opencl_func_t)(void **, void*);
  153. /**
  154. MIC implementation of a codelet.
  155. */
  156. typedef void (*starpu_mic_kernel_t)(void **, void*);
  157. /**
  158. MIC kernel for a codelet
  159. */
  160. typedef starpu_mic_kernel_t (*starpu_mic_func_t)(void);
  161. /**
  162. MPI Master Slave kernel for a codelet
  163. */
  164. typedef void (*starpu_mpi_ms_kernel_t)(void **, void*);
  165. /**
  166. MPI Master Slave implementation of a codelet.
  167. */
  168. typedef starpu_mpi_ms_kernel_t (*starpu_mpi_ms_func_t)(void);
  169. /**
  170. @deprecated
  171. Setting the field starpu_codelet::cpu_func with this macro
  172. indicates the codelet will have several implementations. The use of
  173. this macro is deprecated. One should always only define the field
  174. starpu_codelet::cpu_funcs.
  175. */
  176. #define STARPU_MULTIPLE_CPU_IMPLEMENTATIONS ((starpu_cpu_func_t) -1)
  177. /**
  178. @deprecated
  179. Setting the field starpu_codelet::cuda_func with this macro
  180. indicates the codelet will have several implementations. The use of
  181. this macro is deprecated. One should always only define the field
  182. starpu_codelet::cuda_funcs.
  183. */
  184. #define STARPU_MULTIPLE_CUDA_IMPLEMENTATIONS ((starpu_cuda_func_t) -1)
  185. /**
  186. @deprecated
  187. Setting the field starpu_codelet::opencl_func with this macro
  188. indicates the codelet will have several implementations. The use of
  189. this macro is deprecated. One should always only define the field
  190. starpu_codelet::opencl_funcs.
  191. */
  192. #define STARPU_MULTIPLE_OPENCL_IMPLEMENTATIONS ((starpu_opencl_func_t) -1)
  193. /**
  194. Value to set in starpu_codelet::nbuffers to specify that the
  195. codelet can accept a variable number of buffers, specified in
  196. starpu_task::nbuffers.
  197. */
  198. #define STARPU_VARIABLE_NBUFFERS (-1)
  199. /**
  200. Value to be set in the field starpu_codelet::nodes to request
  201. StarPU to put the data in CPU-accessible memory (and let StarPU
  202. choose the NUMA node).
  203. */
  204. #define STARPU_SPECIFIC_NODE_LOCAL (-1)
  205. #define STARPU_SPECIFIC_NODE_CPU (-2)
  206. #define STARPU_SPECIFIC_NODE_SLOW (-3)
  207. #define STARPU_SPECIFIC_NODE_FAST (-4)
  208. struct starpu_task;
  209. /**
  210. The codelet structure describes a kernel that is possibly
  211. implemented on various targets. For compatibility, make sure to
  212. initialize the whole structure to zero, either by using explicit
  213. memset, or the function starpu_codelet_init(), or by letting the
  214. compiler implicitly do it in e.g. static storage case.
  215. */
  216. struct starpu_codelet
  217. {
  218. /**
  219. Optional field to indicate which types of processing units
  220. are able to execute the codelet. The different values
  221. ::STARPU_CPU, ::STARPU_CUDA, ::STARPU_OPENCL can be
  222. combined to specify on which types of processing units the
  223. codelet can be executed. ::STARPU_CPU|::STARPU_CUDA for
  224. instance indicates that the codelet is implemented for both
  225. CPU cores and CUDA devices while ::STARPU_OPENCL indicates
  226. that it is only available on OpenCL devices. If the field
  227. is unset, its value will be automatically set based on the
  228. availability of the XXX_funcs fields defined below. It can
  229. also be set to ::STARPU_NOWHERE to specify that no
  230. computation has to be actually done.
  231. */
  232. uint32_t where;
  233. /**
  234. Define a function which should return 1 if the worker
  235. designated by \p workerid can execute the \p nimpl -th
  236. implementation of \p task, 0 otherwise.
  237. */
  238. int (*can_execute)(unsigned workerid, struct starpu_task *task, unsigned nimpl);
  239. /**
  240. Optional field to specify the type of the codelet. The
  241. default is ::STARPU_SEQ, i.e. usual sequential
  242. implementation. Other values (::STARPU_SPMD or
  243. ::STARPU_FORKJOIN) declare that a parallel implementation is
  244. also available. See \ref ParallelTasks for details.
  245. */
  246. enum starpu_codelet_type type;
  247. /**
  248. Optional field. If a parallel implementation is available,
  249. this denotes the maximum combined worker size that StarPU
  250. will use to execute parallel tasks for this codelet.
  251. */
  252. int max_parallelism;
  253. /**
  254. @deprecated
  255. Optional field which has been made deprecated. One should
  256. use instead the field starpu_codelet::cpu_funcs.
  257. */
  258. starpu_cpu_func_t cpu_func STARPU_DEPRECATED;
  259. /**
  260. @deprecated
  261. Optional field which has been made deprecated. One should
  262. use instead the starpu_codelet::cuda_funcs field.
  263. */
  264. starpu_cuda_func_t cuda_func STARPU_DEPRECATED;
  265. /**
  266. @deprecated
  267. Optional field which has been made deprecated. One should
  268. use instead the starpu_codelet::opencl_funcs field.
  269. */
  270. starpu_opencl_func_t opencl_func STARPU_DEPRECATED;
  271. /**
  272. Optional array of function pointers to the CPU
  273. implementations of the codelet. The functions prototype
  274. must be:
  275. \code{.c}
  276. void cpu_func(void *buffers[], void *cl_arg)
  277. \endcode
  278. The first argument being the array of data managed by the
  279. data management library, and the second argument is a
  280. pointer to the argument passed from the field
  281. starpu_task::cl_arg. If the field starpu_codelet::where is
  282. set, then the field tarpu_codelet::cpu_funcs is ignored if
  283. ::STARPU_CPU does not appear in the field
  284. starpu_codelet::where, it must be non-<c>NULL</c> otherwise.
  285. */
  286. starpu_cpu_func_t cpu_funcs[STARPU_MAXIMPLEMENTATIONS];
  287. /**
  288. Optional array of function pointers to the CUDA
  289. implementations of the codelet. The functions must be
  290. host-functions written in the CUDA runtime API. Their
  291. prototype must be:
  292. \code{.c}
  293. void cuda_func(void *buffers[], void *cl_arg)
  294. \endcode
  295. If the field starpu_codelet::where is set, then the field
  296. starpu_codelet::cuda_funcs is ignored if ::STARPU_CUDA does
  297. not appear in the field starpu_codelet::where, it must be
  298. non-<c>NULL</c> otherwise.
  299. */
  300. starpu_cuda_func_t cuda_funcs[STARPU_MAXIMPLEMENTATIONS];
  301. /**
  302. Optional array of flags for CUDA execution. They specify
  303. some semantic details about CUDA kernel execution, such as
  304. asynchronous execution.
  305. */
  306. char cuda_flags[STARPU_MAXIMPLEMENTATIONS];
  307. /**
  308. Optional array of function pointers to the OpenCL
  309. implementations of the codelet. The functions prototype
  310. must be:
  311. \code{.c}
  312. void opencl_func(void *buffers[], void *cl_arg)
  313. \endcode
  314. If the field starpu_codelet::where field is set, then the
  315. field starpu_codelet::opencl_funcs is ignored if
  316. ::STARPU_OPENCL does not appear in the field
  317. starpu_codelet::where, it must be non-<c>NULL</c> otherwise.
  318. */
  319. starpu_opencl_func_t opencl_funcs[STARPU_MAXIMPLEMENTATIONS];
  320. /**
  321. Optional array of flags for OpenCL execution. They specify
  322. some semantic details about OpenCL kernel execution, such
  323. as asynchronous execution.
  324. */
  325. char opencl_flags[STARPU_MAXIMPLEMENTATIONS];
  326. /**
  327. Optional array of function pointers to a function which
  328. returns the MIC implementation of the codelet. The
  329. functions prototype must be:
  330. \code{.c}
  331. starpu_mic_kernel_t mic_func(struct starpu_codelet *cl, unsigned nimpl)
  332. \endcode
  333. If the field starpu_codelet::where is set, then the field
  334. starpu_codelet::mic_funcs is ignored if ::STARPU_MIC does
  335. not appear in the field starpu_codelet::where. It can be
  336. <c>NULL</c> if starpu_codelet::cpu_funcs_name is
  337. non-<c>NULL</c>, in which case StarPU will simply make a
  338. symbol lookup to get the implementation.
  339. */
  340. starpu_mic_func_t mic_funcs[STARPU_MAXIMPLEMENTATIONS];
  341. /**
  342. Optional array of function pointers to a function which
  343. returns the MPI Master Slave implementation of the codelet.
  344. The functions prototype must be:
  345. \code{.c}
  346. starpu_mpi_ms_kernel_t mpi_ms_func(struct starpu_codelet *cl, unsigned nimpl)
  347. \endcode
  348. If the field starpu_codelet::where is set, then the field
  349. starpu_codelet::mpi_ms_funcs is ignored if ::STARPU_MPI_MS
  350. does not appear in the field starpu_codelet::where. It can
  351. be <c>NULL</c> if starpu_codelet::cpu_funcs_name is
  352. non-<c>NULL</c>, in which case StarPU will simply make a
  353. symbol lookup to get the implementation.
  354. */
  355. starpu_mpi_ms_func_t mpi_ms_funcs[STARPU_MAXIMPLEMENTATIONS];
  356. /**
  357. Optional array of strings which provide the name of the CPU
  358. functions referenced in the array
  359. starpu_codelet::cpu_funcs. This can be used when running on
  360. MIC devices for StarPU to simply look
  361. up the MIC function implementation through its name.
  362. */
  363. const char *cpu_funcs_name[STARPU_MAXIMPLEMENTATIONS];
  364. /**
  365. Specify the number of arguments taken by the codelet. These
  366. arguments are managed by the DSM and are accessed from the
  367. <c>void *buffers[]</c> array. The constant argument passed
  368. with the field starpu_task::cl_arg is not counted in this
  369. number. This value should not be above \ref
  370. STARPU_NMAXBUFS. It may be set to \ref
  371. STARPU_VARIABLE_NBUFFERS to specify that the number of
  372. buffers and their access modes will be set in
  373. starpu_task::nbuffers and starpu_task::modes or
  374. starpu_task::dyn_modes, which thus permits to define
  375. codelets with a varying number of data.
  376. */
  377. int nbuffers;
  378. /**
  379. Is an array of ::starpu_data_access_mode. It describes the
  380. required access modes to the data neeeded by the codelet
  381. (e.g. ::STARPU_RW). The number of entries in this array
  382. must be specified in the field starpu_codelet::nbuffers,
  383. and should not exceed \ref STARPU_NMAXBUFS. If
  384. unsufficient, this value can be set with the configure
  385. option \ref enable-maxbuffers "--enable-maxbuffers".
  386. */
  387. enum starpu_data_access_mode modes[STARPU_NMAXBUFS];
  388. /**
  389. Is an array of ::starpu_data_access_mode. It describes the
  390. required access modes to the data needed by the codelet
  391. (e.g. ::STARPU_RW). The number of entries in this array
  392. must be specified in the field starpu_codelet::nbuffers.
  393. This field should be used for codelets having a number of
  394. datas greater than \ref STARPU_NMAXBUFS (see \ref
  395. SettingManyDataHandlesForATask). When defining a codelet,
  396. one should either define this field or the field
  397. starpu_codelet::modes defined above.
  398. */
  399. enum starpu_data_access_mode *dyn_modes;
  400. /**
  401. Default value is 0. If this flag is set, StarPU will not
  402. systematically send all data to the memory node where the
  403. task will be executing, it will read the
  404. starpu_codelet::nodes or starpu_codelet::dyn_nodes array to
  405. determine, for each data, whether to send it on the memory
  406. node where the task will be executing (-1), or on a
  407. specific node (!= -1).
  408. */
  409. unsigned specific_nodes;
  410. /**
  411. Optional field. When starpu_codelet::specific_nodes is 1,
  412. this specifies the memory nodes where each data should be
  413. sent to for task execution. The number of entries in this
  414. array is starpu_codelet::nbuffers, and should not exceed
  415. \ref STARPU_NMAXBUFS.
  416. */
  417. int nodes[STARPU_NMAXBUFS];
  418. /**
  419. Optional field. When starpu_codelet::specific_nodes is 1,
  420. this specifies the memory nodes where each data should be
  421. sent to for task execution. The number of entries in this
  422. array is starpu_codelet::nbuffers. This field should be
  423. used for codelets having a number of datas greater than
  424. \ref STARPU_NMAXBUFS (see \ref
  425. SettingManyDataHandlesForATask). When defining a codelet,
  426. one should either define this field or the field
  427. starpu_codelet::nodes defined above.
  428. */
  429. int *dyn_nodes;
  430. /**
  431. Optional pointer to the task duration performance model
  432. associated to this codelet. This optional field is ignored
  433. when set to <c>NULL</c> or when its field
  434. starpu_perfmodel::symbol is not set.
  435. */
  436. struct starpu_perfmodel *model;
  437. /**
  438. Optional pointer to the task energy consumption performance
  439. model associated to this codelet. This optional field is
  440. ignored when set to <c>NULL</c> or when its field
  441. starpu_perfmodel::symbol is not set. In the case of
  442. parallel codelets, this has to account for all processing
  443. units involved in the parallel execution.
  444. */
  445. struct starpu_perfmodel *energy_model;
  446. /**
  447. Optional array for statistics collected at runtime: this is
  448. filled by StarPU and should not be accessed directly, but
  449. for example by calling the function
  450. starpu_codelet_display_stats() (See
  451. starpu_codelet_display_stats() for details).
  452. */
  453. unsigned long per_worker_stats[STARPU_NMAXWORKERS];
  454. /**
  455. Optional name of the codelet. This can be useful for
  456. debugging purposes.
  457. */
  458. const char *name;
  459. /**
  460. Optional color of the codelet. This can be useful for
  461. debugging purposes.
  462. */
  463. unsigned color;
  464. /**
  465. Various flags for the codelet.
  466. */
  467. int flags;
  468. };
  469. /**
  470. Describe a data handle along with an access mode.
  471. */
  472. struct starpu_data_descr
  473. {
  474. starpu_data_handle_t handle; /**< data */
  475. enum starpu_data_access_mode mode; /**< access mode */
  476. };
  477. /**
  478. Describe a task that can be offloaded on the various processing
  479. units managed by StarPU. It instantiates a codelet. It can either
  480. be allocated dynamically with the function starpu_task_create(), or
  481. declared statically. In the latter case, the programmer has to zero
  482. the structure starpu_task and to fill the different fields
  483. properly. The indicated default values correspond to the
  484. configuration of a task allocated with starpu_task_create().
  485. */
  486. struct starpu_task
  487. {
  488. /**
  489. Optional name of the task. This can be useful for debugging
  490. purposes.
  491. With starpu_task_insert() and alike this can be specified thanks to
  492. ::STARPU_NAME followed by the const char *.
  493. */
  494. const char *name;
  495. /**
  496. Pointer to the corresponding structure starpu_codelet. This
  497. describes where the kernel should be executed, and supplies
  498. the appropriate implementations. When set to <c>NULL</c>,
  499. no code is executed during the tasks, such empty tasks can
  500. be useful for synchronization purposes.
  501. */
  502. struct starpu_codelet *cl;
  503. /**
  504. When set, specify where the task is allowed to be executed.
  505. When unset, take the value of starpu_codelet::where.
  506. With starpu_task_insert() and alike this can be specified thanks to
  507. ::STARPU_EXECUTE_WHERE followed by an unsigned long long.
  508. */
  509. int32_t where;
  510. /**
  511. Specify the number of buffers. This is only used when
  512. starpu_codelet::nbuffers is \ref STARPU_VARIABLE_NBUFFERS.
  513. With starpu_task_insert() and alike this is automatically computed
  514. when using ::STARPU_DATA_ARRAY and alike.
  515. */
  516. int nbuffers;
  517. /* Keep dyn_handles, dyn_interfaces and dyn_modes before the
  518. * equivalent static arrays, so we can detect dyn_handles
  519. * being NULL while nbuffers being bigger that STARPU_NMAXBUFS
  520. * (otherwise the overflow would put a non-NULL) */
  521. /**
  522. Array of ::starpu_data_handle_t. Specify the handles to the
  523. different pieces of data accessed by the task. The number
  524. of entries in this array must be specified in the field
  525. starpu_codelet::nbuffers. This field should be used for
  526. tasks having a number of datas greater than \ref
  527. STARPU_NMAXBUFS (see \ref SettingManyDataHandlesForATask).
  528. When defining a task, one should either define this field
  529. or the field starpu_task::handles defined below.
  530. With starpu_task_insert() and alike this is automatically filled
  531. when using ::STARPU_DATA_ARRAY and alike.
  532. */
  533. starpu_data_handle_t *dyn_handles;
  534. /**
  535. Array of data pointers to the memory node where execution
  536. will happen, managed by the DSM. Is used when the field
  537. starpu_task::dyn_handles is defined.
  538. This is filled by StarPU.
  539. */
  540. void **dyn_interfaces;
  541. /**
  542. Used only when starpu_codelet::nbuffers is \ref
  543. STARPU_VARIABLE_NBUFFERS.
  544. Array of ::starpu_data_access_mode which describes the
  545. required access modes to the data needed by the codelet
  546. (e.g. ::STARPU_RW). The number of entries in this array
  547. must be specified in the field starpu_codelet::nbuffers.
  548. This field should be used for codelets having a number of
  549. datas greater than \ref STARPU_NMAXBUFS (see \ref
  550. SettingManyDataHandlesForATask).
  551. When defining a codelet, one should either define this
  552. field or the field starpu_task::modes defined below.
  553. With starpu_task_insert() and alike this is automatically filled
  554. when using ::STARPU_DATA_MODE_ARRAY and alike.
  555. */
  556. enum starpu_data_access_mode *dyn_modes;
  557. /**
  558. Array of ::starpu_data_handle_t. Specify the handles to the
  559. different pieces of data accessed by the task. The number
  560. of entries in this array must be specified in the field
  561. starpu_codelet::nbuffers, and should not exceed
  562. \ref STARPU_NMAXBUFS. If unsufficient, this value can be
  563. set with the configure option \ref enable-maxbuffers
  564. "--enable-maxbuffers".
  565. With starpu_task_insert() and alike this is automatically filled
  566. when using ::STARPU_R and alike.
  567. */
  568. starpu_data_handle_t handles[STARPU_NMAXBUFS];
  569. /**
  570. Array of Data pointers to the memory node where execution
  571. will happen, managed by the DSM.
  572. This is filled by StarPU.
  573. */
  574. void *interfaces[STARPU_NMAXBUFS];
  575. /**
  576. Used only when starpu_codelet::nbuffers is \ref
  577. STARPU_VARIABLE_NBUFFERS.
  578. Array of ::starpu_data_access_mode which describes the
  579. required access modes to the data neeeded by the codelet
  580. (e.g. ::STARPU_RW). The number of entries in this array
  581. must be specified in the field starpu_task::nbuffers, and
  582. should not exceed \ref STARPU_NMAXBUFS. If unsufficient,
  583. this value can be set with the configure option
  584. \ref enable-maxbuffers "--enable-maxbuffers".
  585. With starpu_task_insert() and alike this is automatically filled
  586. when using ::STARPU_DATA_MODE_ARRAY and alike.
  587. */
  588. enum starpu_data_access_mode modes[STARPU_NMAXBUFS];
  589. /**
  590. Optional pointer to an array of characters which allows to
  591. define the sequential consistency for each handle for the
  592. current task.
  593. With starpu_task_insert() and alike this can be specified thanks to
  594. ::STARPU_HANDLES_SEQUENTIAL_CONSISTENCY followed by an unsigned char *
  595. */
  596. unsigned char *handles_sequential_consistency;
  597. /**
  598. Optional pointer which is passed to the codelet through the
  599. second argument of the codelet implementation (e.g.
  600. starpu_codelet::cpu_func or starpu_codelet::cuda_func). The
  601. default value is <c>NULL</c>. starpu_codelet_pack_args()
  602. and starpu_codelet_unpack_args() are helpers that can can
  603. be used to respectively pack and unpack data into and from
  604. it, but the application can manage it any way, the only
  605. requirement is that the size of the data must be set in
  606. starpu_task::cl_arg_size .
  607. With starpu_task_insert() and alike this can be specified thanks to
  608. ::STARPU_CL_ARGS followed by a void* and a size_t.
  609. */
  610. void *cl_arg;
  611. /**
  612. Optional field. For some specific drivers, the pointer
  613. starpu_task::cl_arg cannot not be directly given to the
  614. driver function. A buffer of size starpu_task::cl_arg_size
  615. needs to be allocated on the driver. This buffer is then
  616. filled with the starpu_task::cl_arg_size bytes starting at
  617. address starpu_task::cl_arg. In this case, the argument
  618. given to the codelet is therefore not the
  619. starpu_task::cl_arg pointer, but the address of the buffer
  620. in local store (LS) instead. This field is ignored for CPU,
  621. CUDA and OpenCL codelets, where the starpu_task::cl_arg
  622. pointer is given as such.
  623. With starpu_task_insert() and alike this can be specified thanks to
  624. ::STARPU_CL_ARGS followed by a void* and a size_t.
  625. */
  626. size_t cl_arg_size;
  627. /**
  628. Optional field, the default value is <c>NULL</c>. This is a
  629. function pointer of prototype <c>void (*f)(void *)</c>
  630. which specifies a possible callback. If this pointer is
  631. non-<c>NULL</c>, the callback function is executed on the
  632. host after the execution of the task. Tasks which depend on
  633. it might already be executing. The callback is passed the
  634. value contained in the starpu_task::callback_arg field. No
  635. callback is executed if the field is set to <c>NULL</c>.
  636. With starpu_task_insert() and alike this can be specified thanks to
  637. ::STARPU_CALLBACK followed by the function pointer, or thanks to
  638. ::STARPU_CALLBACK_WITH_ARG followed by the function pointer and the argument.
  639. */
  640. void (*callback_func)(void *);
  641. /**
  642. Optional field, the default value is <c>NULL</c>. This is
  643. the pointer passed to the callback function. This field is
  644. ignored if the field starpu_task::callback_func is set to
  645. <c>NULL</c>.
  646. With starpu_task_insert() and alike this can be specified thanks to
  647. ::STARPU_CALLBACK_ARG followed by the function pointer, or thanks to
  648. ::STARPU_CALLBACK_WITH_ARG followed by the function pointer and the argument.
  649. */
  650. void *callback_arg;
  651. /**
  652. Optional field, the default value is <c>NULL</c>. This is a
  653. function pointer of prototype <c>void (*f)(void *)</c>
  654. which specifies a possible callback. If this pointer is
  655. non-<c>NULL</c>, the callback function is executed on the
  656. host when the task becomes ready for execution, before
  657. getting scheduled. The callback is passed the value
  658. contained in the starpu_task::prologue_callback_arg field.
  659. No callback is executed if the field is set to <c>NULL</c>.
  660. With starpu_task_insert() and alike this can be specified thanks to
  661. ::STARPU_PROLOGUE_CALLBACK followed by the function pointer.
  662. */
  663. void (*prologue_callback_func)(void *);
  664. /**
  665. Optional field, the default value is <c>NULL</c>. This is
  666. the pointer passed to the prologue callback function. This
  667. field is ignored if the field
  668. starpu_task::prologue_callback_func is set to <c>NULL</c>.
  669. With starpu_task_insert() and alike this can be specified thanks to
  670. ::STARPU_PROLOGUE_CALLBACK followed by the function pointer.
  671. */
  672. void *prologue_callback_arg;
  673. void (*prologue_callback_pop_func)(void *);
  674. void *prologue_callback_pop_arg;
  675. /**
  676. Optional field. Contain the tag associated to the task if
  677. the field starpu_task::use_tag is set, ignored
  678. otherwise.
  679. With starpu_task_insert() and alike this can be specified thanks to
  680. ::STARPU_TAG followed by a starpu_tag_t.
  681. */
  682. starpu_tag_t tag_id;
  683. /**
  684. Optional field. In case starpu_task::cl_arg was allocated
  685. by the application through <c>malloc()</c>, setting
  686. starpu_task::cl_arg_free to 1 makes StarPU automatically
  687. call <c>free(cl_arg)</c> when destroying the task. This
  688. saves the user from defining a callback just for that. This
  689. is mostly useful when targetting MIC, where the
  690. codelet does not execute in the same memory space as the
  691. main thread.
  692. With starpu_task_insert() and alike this is set to 1 when using
  693. ::STARPU_CL_ARGS.
  694. */
  695. unsigned cl_arg_free:1;
  696. /**
  697. Optional field. In case starpu_task::callback_arg was
  698. allocated by the application through <c>malloc()</c>,
  699. setting starpu_task::callback_arg_free to 1 makes StarPU
  700. automatically call <c>free(callback_arg)</c> when
  701. destroying the task.
  702. TODO: does not have a starpu_task_insert() equivalent
  703. */
  704. unsigned callback_arg_free:1;
  705. /**
  706. Optional field. In case starpu_task::prologue_callback_arg
  707. was allocated by the application through <c>malloc()</c>,
  708. setting starpu_task::prologue_callback_arg_free to 1 makes
  709. StarPU automatically call
  710. <c>free(prologue_callback_arg)</c> when destroying the task.
  711. TODO: does not have a starpu_task_insert() equivalent
  712. */
  713. unsigned prologue_callback_arg_free:1;
  714. /**
  715. Optional field. In case starpu_task::prologue_callback_pop_arg
  716. was allocated by the application through <c>malloc()</c>,
  717. setting starpu_task::prologue_callback_pop_arg_free to 1 makes
  718. StarPU automatically call
  719. <c>free(prologue_callback_pop_arg)</c> when destroying the
  720. task.
  721. TODO: does not have a starpu_task_insert() equivalent
  722. */
  723. unsigned prologue_callback_pop_arg_free:1;
  724. /**
  725. Optional field, the default value is 0. If set, this flag
  726. indicates that the task should be associated with the tag
  727. contained in the starpu_task::tag_id field. Tag allow the
  728. application to synchronize with the task and to express
  729. task dependencies easily.
  730. With starpu_task_insert() and alike this is set to 1 when using
  731. ::STARPU_TAG.
  732. */
  733. unsigned use_tag:1;
  734. /**
  735. If this flag is set (which is the default), sequential
  736. consistency is enforced for the data parameters of this
  737. task for which sequential consistency is enabled. Clearing
  738. this flag permits to disable sequential consistency for
  739. this task, even if data have it enabled.
  740. TODO: does not have a starpu_task_insert() equivalent
  741. */
  742. unsigned sequential_consistency:1;
  743. /**
  744. If this flag is set, the function starpu_task_submit() is
  745. blocking and returns only when the task has been executed
  746. (or if no worker is able to process the task). Otherwise,
  747. starpu_task_submit() returns immediately.
  748. With starpu_task_insert() and alike this can be specified thanks to
  749. ::STARPU_TASK_SYNCHRONOUS followed an int.
  750. */
  751. unsigned synchronous:1;
  752. /**
  753. Default value is 0. If this flag is set, StarPU will bypass
  754. the scheduler and directly affect this task to the worker
  755. specified by the field starpu_task::workerid.
  756. With starpu_task_insert() and alike this is set to 1 when using
  757. ::STARPU_EXECUTE_ON_WORKER.
  758. */
  759. unsigned execute_on_a_specific_worker:1;
  760. /**
  761. Optional field, default value is 1. If this flag is set, it
  762. is not possible to synchronize with the task by the means
  763. of starpu_task_wait() later on. Internal data structures
  764. are only guaranteed to be freed once starpu_task_wait() is
  765. called if the flag is not set.
  766. With starpu_task_insert() and alike this is set to 1.
  767. */
  768. unsigned detach:1;
  769. /**
  770. Optional value. Default value is 0 for starpu_task_init(),
  771. and 1 for starpu_task_create(). If this flag is set, the
  772. task structure will automatically be freed, either after
  773. the execution of the callback if the task is detached, or
  774. during starpu_task_wait() otherwise. If this flag is not
  775. set, dynamically allocated data structures will not be
  776. freed until starpu_task_destroy() is called explicitly.
  777. Setting this flag for a statically allocated task structure
  778. will result in undefined behaviour. The flag is set to 1
  779. when the task is created by calling starpu_task_create().
  780. Note that starpu_task_wait_for_all() will not free any task.
  781. With starpu_task_insert() and alike this is set to 1.
  782. */
  783. unsigned destroy:1;
  784. /**
  785. Optional field. If this flag is set, the task will be
  786. re-submitted to StarPU once it has been executed. This flag
  787. must not be set if the flag starpu_task::destroy is set.
  788. This flag must be set before making another task depend on
  789. this one.
  790. With starpu_task_insert() and alike this is set to 0.
  791. */
  792. unsigned regenerate:1;
  793. /**
  794. @private
  795. This is only used for tasks that use multiformat handle.
  796. This should only be used by StarPU.
  797. */
  798. unsigned mf_skip:1;
  799. /**
  800. do not allocate a submitorder id for this task
  801. TODO: does not have a starpu_task_insert() equivalent
  802. */
  803. unsigned no_submitorder:1;
  804. /**
  805. Whether this task has failed and will thus have to be retried
  806. Set by StarPU.
  807. */
  808. unsigned failed:1;
  809. /**
  810. Whether the scheduler has pushed the task on some queue
  811. Set by StarPU.
  812. */
  813. unsigned scheduled:1;
  814. unsigned prefetched:1;
  815. /**
  816. Optional field. If the field
  817. starpu_task::execute_on_a_specific_worker is set, this
  818. field indicates the identifier of the worker that should
  819. process this task (as returned by starpu_worker_get_id()).
  820. This field is ignored if the field
  821. starpu_task::execute_on_a_specific_worker is set to 0.
  822. With starpu_task_insert() and alike this can be specified thanks to
  823. ::STARPU_EXECUTE_ON_WORKER followed by an int.
  824. */
  825. unsigned workerid;
  826. /**
  827. Optional field. If the field
  828. starpu_task::execute_on_a_specific_worker is set, this
  829. field indicates the per-worker consecutive order in which
  830. tasks should be executed on the worker. Tasks will be
  831. executed in consecutive starpu_task::workerorder values,
  832. thus ignoring the availability order or task priority. See
  833. \ref StaticScheduling for more details. This field is
  834. ignored if the field
  835. starpu_task::execute_on_a_specific_worker is set to 0.
  836. With starpu_task_insert() and alike this can be specified thanks to
  837. ::STARPU_WORKER_ORDER followed by an unsigned.
  838. */
  839. unsigned workerorder;
  840. /**
  841. Optional field. If the field starpu_task::workerids_len is
  842. different from 0, this field indicates an array of bits
  843. (stored as uint32_t values) which indicate the set of
  844. workers which are allowed to execute the task.
  845. starpu_task::workerid takes precedence over this.
  846. TODO: does not have a starpu_task_insert() equivalent
  847. */
  848. uint32_t *workerids;
  849. /**
  850. Optional field. This provides the number of uint32_t values
  851. in the starpu_task::workerids array.
  852. TODO: does not have a starpu_task_insert() equivalent
  853. */
  854. unsigned workerids_len;
  855. /**
  856. Optional field, the default value is ::STARPU_DEFAULT_PRIO.
  857. This field indicates a level of priority for the task. This
  858. is an integer value that must be set between the return
  859. values of the function starpu_sched_get_min_priority() for
  860. the least important tasks, and that of the function
  861. starpu_sched_get_max_priority() for the most important
  862. tasks (included). The ::STARPU_MIN_PRIO and
  863. ::STARPU_MAX_PRIO macros are provided for convenience and
  864. respectively return the value of
  865. starpu_sched_get_min_priority() and
  866. starpu_sched_get_max_priority(). Default priority is
  867. ::STARPU_DEFAULT_PRIO, which is always defined as 0 in
  868. order to allow static task initialization. Scheduling
  869. strategies that take priorities into account can use this
  870. parameter to take better scheduling decisions, but the
  871. scheduling policy may also ignore it.
  872. With starpu_task_insert() and alike this can be specified thanks to
  873. ::STARPU_PRIORITY followed by an unsigned long long.
  874. */
  875. int priority;
  876. /**
  877. Current state of the task.
  878. Set by StarPU.
  879. */
  880. enum starpu_task_status status;
  881. /**
  882. @private
  883. This field is set when initializing a task. The function
  884. starpu_task_submit() will fail if the field does not have
  885. the correct value. This will hence avoid submitting tasks
  886. which have not been properly initialised.
  887. */
  888. int magic;
  889. /**
  890. Allow to get the type of task, for filtering out tasks
  891. in profiling outputs, whether it is really internal to
  892. StarPU (::STARPU_TASK_TYPE_INTERNAL), a data acquisition
  893. synchronization task (::STARPU_TASK_TYPE_DATA_ACQUIRE), or
  894. a normal task (::STARPU_TASK_TYPE_NORMAL)
  895. Set by StarPU.
  896. */
  897. unsigned type;
  898. /**
  899. color of the task to be used in dag.dot.
  900. With starpu_task_insert() and alike this can be specified thanks to
  901. ::STARPU_TASK_COLOR followed by an int.
  902. */
  903. unsigned color;
  904. /**
  905. Scheduling context.
  906. With starpu_task_insert() and alike this can be specified thanks to
  907. ::STARPU_SCHED_CTX followed by an unsigned.
  908. */
  909. unsigned sched_ctx;
  910. /**
  911. Help the hypervisor monitor the execution of this task.
  912. With starpu_task_insert() and alike this can be specified thanks to
  913. ::STARPU_HYPERVISOR_TAG followed by an int.
  914. */
  915. int hypervisor_tag;
  916. /**
  917. TODO: related with sched contexts and parallel tasks
  918. With starpu_task_insert() and alike this can be specified thanks to
  919. ::STARPU_POSSIBLY_PARALLEL followed by an unsigned.
  920. */
  921. unsigned possibly_parallel;
  922. /**
  923. Optional field. The bundle that includes this task. If no
  924. bundle is used, this should be <c>NULL</c>.
  925. */
  926. starpu_task_bundle_t bundle;
  927. /**
  928. Optional field. Profiling information for the task.
  929. TODO: does not have a starpu_task_insert() equivalent
  930. */
  931. struct starpu_profiling_task_info *profiling_info;
  932. /**
  933. This can be set to the number of floating points operations
  934. that the task will have to achieve. This is useful for
  935. easily getting GFlops curves from the tool
  936. <c>starpu_perfmodel_plot</c>, and for the hypervisor load
  937. balancing.
  938. With starpu_task_insert() and alike this can be specified thanks to
  939. ::STARPU_FLOPS followed by a double.
  940. */
  941. double flops;
  942. /**
  943. Output field. Predicted duration of the task. This field is
  944. only set if the scheduling strategy uses performance
  945. models.
  946. Set by StarPU.
  947. */
  948. double predicted;
  949. /**
  950. Output field. Predicted data transfer duration for the task in
  951. microseconds. This field is only valid if the scheduling
  952. strategy uses performance models.
  953. Set by StarPU.
  954. */
  955. double predicted_transfer;
  956. double predicted_start;
  957. /**
  958. @private
  959. A pointer to the previous task. This should only be used by
  960. StarPU schedulers.
  961. */
  962. struct starpu_task *prev;
  963. /**
  964. @private
  965. A pointer to the next task. This should only be used by
  966. StarPU schedulers.
  967. */
  968. struct starpu_task *next;
  969. /**
  970. @private
  971. This is private to StarPU, do not modify.
  972. */
  973. void *starpu_private;
  974. #ifdef STARPU_OPENMP
  975. /**
  976. @private
  977. This is private to StarPU, do not modify.
  978. */
  979. struct starpu_omp_task *omp_task;
  980. #else
  981. void *omp_task;
  982. #endif
  983. /**
  984. @private
  985. This is private to StarPU, do not modify.
  986. */
  987. unsigned nb_termination_call_required;
  988. /**
  989. This field is managed by the scheduler, is it allowed to do
  990. whatever with it. Typically, some area would be allocated on push, and released on pop.
  991. */
  992. void *sched_data;
  993. };
  994. #define STARPU_TASK_TYPE_NORMAL 0
  995. #define STARPU_TASK_TYPE_INTERNAL (1<<0)
  996. #define STARPU_TASK_TYPE_DATA_ACQUIRE (1<<1)
  997. /**
  998. Value to be used to initialize statically allocated tasks. This is
  999. equivalent to initializing a structure starpu_task
  1000. with the function starpu_task_init().
  1001. */
  1002. /* Note: remember to update starpu_task_init as well */
  1003. #define STARPU_TASK_INITIALIZER \
  1004. { \
  1005. .cl = NULL, \
  1006. .where = -1, \
  1007. .cl_arg = NULL, \
  1008. .cl_arg_size = 0, \
  1009. .callback_func = NULL, \
  1010. .callback_arg = NULL, \
  1011. .priority = STARPU_DEFAULT_PRIO, \
  1012. .use_tag = 0, \
  1013. .sequential_consistency = 1, \
  1014. .synchronous = 0, \
  1015. .execute_on_a_specific_worker = 0, \
  1016. .workerorder = 0, \
  1017. .bundle = NULL, \
  1018. .detach = 1, \
  1019. .destroy = 0, \
  1020. .regenerate = 0, \
  1021. .status = STARPU_TASK_INVALID, \
  1022. .profiling_info = NULL, \
  1023. .predicted = NAN, \
  1024. .predicted_transfer = NAN, \
  1025. .predicted_start = NAN, \
  1026. .starpu_private = NULL, \
  1027. .magic = 42, \
  1028. .type = 0, \
  1029. .color = 0, \
  1030. .sched_ctx = STARPU_NMAX_SCHED_CTXS, \
  1031. .hypervisor_tag = 0, \
  1032. .flops = 0.0, \
  1033. .scheduled = 0, \
  1034. .prefetched = 0, \
  1035. .dyn_handles = NULL, \
  1036. .dyn_interfaces = NULL, \
  1037. .dyn_modes = NULL, \
  1038. .name = NULL, \
  1039. .possibly_parallel = 0 \
  1040. }
  1041. /**
  1042. Return the number of buffers for \p task, i.e.
  1043. starpu_codelet::nbuffers, or starpu_task::nbuffers if the former is
  1044. \ref STARPU_VARIABLE_NBUFFERS.
  1045. */
  1046. #define STARPU_TASK_GET_NBUFFERS(task) ((unsigned)((task)->cl->nbuffers == STARPU_VARIABLE_NBUFFERS ? ((task)->nbuffers) : ((task)->cl->nbuffers)))
  1047. /**
  1048. Return the \p i -th data handle of \p task. If \p task is defined
  1049. with a static or dynamic number of handles, will either return the
  1050. \p i -th element of the field starpu_task::handles or the \p i -th
  1051. element of the field starpu_task::dyn_handles (see \ref
  1052. SettingManyDataHandlesForATask)
  1053. */
  1054. #define STARPU_TASK_GET_HANDLE(task, i) (((task)->dyn_handles) ? (task)->dyn_handles[i] : (task)->handles[i])
  1055. #define STARPU_TASK_GET_HANDLES(task) (((task)->dyn_handles) ? (task)->dyn_handles : (task)->handles)
  1056. /**
  1057. Set the \p i -th data handle of \p task with \p handle. If \p task
  1058. is defined with a static or dynamic number of handles, will either
  1059. set the \p i -th element of the field starpu_task::handles or the
  1060. \p i -th element of the field starpu_task::dyn_handles
  1061. (see \ref SettingManyDataHandlesForATask)
  1062. */
  1063. #define STARPU_TASK_SET_HANDLE(task, handle, i) \
  1064. do { if ((task)->dyn_handles) (task)->dyn_handles[i] = handle; else (task)->handles[i] = handle; } while(0)
  1065. /**
  1066. Return the access mode of the \p i -th data handle of \p codelet.
  1067. If \p codelet is defined with a static or dynamic number of
  1068. handles, will either return the \p i -th element of the field
  1069. starpu_codelet::modes or the \p i -th element of the field
  1070. starpu_codelet::dyn_modes (see \ref SettingManyDataHandlesForATask)
  1071. */
  1072. #define STARPU_CODELET_GET_MODE(codelet, i) \
  1073. (((codelet)->dyn_modes) ? (codelet)->dyn_modes[i] : (assert(i < STARPU_NMAXBUFS), (codelet)->modes[i]))
  1074. /**
  1075. Set the access mode of the \p i -th data handle of \p codelet. If
  1076. \p codelet is defined with a static or dynamic number of handles,
  1077. will either set the \p i -th element of the field
  1078. starpu_codelet::modes or the \p i -th element of the field
  1079. starpu_codelet::dyn_modes (see \ref SettingManyDataHandlesForATask)
  1080. */
  1081. #define STARPU_CODELET_SET_MODE(codelet, mode, i) \
  1082. do { if ((codelet)->dyn_modes) (codelet)->dyn_modes[i] = mode; else (codelet)->modes[i] = mode; } while(0)
  1083. /**
  1084. Return the access mode of the \p i -th data handle of \p task. If
  1085. \p task is defined with a static or dynamic number of handles, will
  1086. either return the \p i -th element of the field starpu_task::modes
  1087. or the \p i -th element of the field starpu_task::dyn_modes (see
  1088. \ref SettingManyDataHandlesForATask)
  1089. */
  1090. #define STARPU_TASK_GET_MODE(task, i) \
  1091. ((task)->cl->nbuffers == STARPU_VARIABLE_NBUFFERS || (task)->dyn_modes ? \
  1092. (((task)->dyn_modes) ? (task)->dyn_modes[i] : (task)->modes[i]) : \
  1093. STARPU_CODELET_GET_MODE((task)->cl, i) )
  1094. /**
  1095. Set the access mode of the \p i -th data handle of \p task. If \p
  1096. task is defined with a static or dynamic number of handles, will
  1097. either set the \p i -th element of the field starpu_task::modes or
  1098. the \p i -th element of the field starpu_task::dyn_modes (see \ref
  1099. SettingManyDataHandlesForATask)
  1100. */
  1101. #define STARPU_TASK_SET_MODE(task, mode, i) \
  1102. do { \
  1103. if ((task)->cl->nbuffers == STARPU_VARIABLE_NBUFFERS || (task)->cl->nbuffers > STARPU_NMAXBUFS) \
  1104. if ((task)->dyn_modes) (task)->dyn_modes[i] = mode; else (task)->modes[i] = mode; \
  1105. else \
  1106. STARPU_CODELET_SET_MODE((task)->cl, mode, i); \
  1107. } while(0)
  1108. /**
  1109. Return the target node of the \p i -th data handle of \p codelet.
  1110. If \p node is defined with a static or dynamic number of handles,
  1111. will either return the \p i -th element of the field
  1112. starpu_codelet::nodes or the \p i -th element of the field
  1113. starpu_codelet::dyn_nodes (see \ref SettingManyDataHandlesForATask)
  1114. */
  1115. #define STARPU_CODELET_GET_NODE(codelet, i) (((codelet)->dyn_nodes) ? (codelet)->dyn_nodes[i] : (codelet)->nodes[i])
  1116. /**
  1117. Set the target node of the \p i -th data handle of \p codelet. If
  1118. \p codelet is defined with a static or dynamic number of handles,
  1119. will either set the \p i -th element of the field
  1120. starpu_codelet::nodes or the \p i -th element of the field
  1121. starpu_codelet::dyn_nodes (see \ref SettingManyDataHandlesForATask)
  1122. */
  1123. #define STARPU_CODELET_SET_NODE(codelet, __node, i) \
  1124. do { if ((codelet)->dyn_nodes) (codelet)->dyn_nodes[i] = __node; else (codelet)->nodes[i] = __node; } while(0)
  1125. /**
  1126. Initialize \p task with default values. This function is implicitly
  1127. called by starpu_task_create(). By default, tasks initialized with
  1128. starpu_task_init() must be deinitialized explicitly with
  1129. starpu_task_clean(). Tasks can also be initialized statically,
  1130. using ::STARPU_TASK_INITIALIZER.
  1131. */
  1132. void starpu_task_init(struct starpu_task *task);
  1133. /**
  1134. Release all the structures automatically allocated to execute \p
  1135. task, but not the task structure itself and values set by the user
  1136. remain unchanged. It is thus useful for statically allocated tasks
  1137. for instance. It is also useful when users want to execute the same
  1138. operation several times with as least overhead as possible. It is
  1139. called automatically by starpu_task_destroy(). It has to be called
  1140. only after explicitly waiting for the task or after
  1141. starpu_shutdown() (waiting for the callback is not enough, since
  1142. StarPU still manipulates the task after calling the callback).
  1143. */
  1144. void starpu_task_clean(struct starpu_task *task);
  1145. /**
  1146. Allocate a task structure and initialize it with default values.
  1147. Tasks allocated dynamically with starpu_task_create() are
  1148. automatically freed when the task is terminated. This means that
  1149. the task pointer can not be used any more once the task is
  1150. submitted, since it can be executed at any time (unless
  1151. dependencies make it wait) and thus freed at any time. If the field
  1152. starpu_task::destroy is explicitly unset, the resources used by the
  1153. task have to be freed by calling starpu_task_destroy().
  1154. */
  1155. struct starpu_task *starpu_task_create(void) STARPU_ATTRIBUTE_MALLOC;
  1156. /**
  1157. Free the resource allocated during starpu_task_create() and
  1158. associated with \p task. This function is called automatically
  1159. after the execution of a task when the field starpu_task::destroy
  1160. is set, which is the default for tasks created by
  1161. starpu_task_create(). Calling this function on a statically
  1162. allocated task results in an undefined behaviour.
  1163. */
  1164. void starpu_task_destroy(struct starpu_task *task);
  1165. /**
  1166. Submit \p task to StarPU. Calling this function does not mean that
  1167. the task will be executed immediately as there can be data or task
  1168. (tag) dependencies that are not fulfilled yet: StarPU will take
  1169. care of scheduling this task with respect to such dependencies.
  1170. This function returns immediately if the field
  1171. starpu_task::synchronous is set to 0, and block until the
  1172. termination of the task otherwise. It is also possible to
  1173. synchronize the application with asynchronous tasks by the means of
  1174. tags, using the function starpu_tag_wait() function for instance.
  1175. In case of success, this function returns 0, a return value of
  1176. <c>-ENODEV</c> means that there is no worker able to process this
  1177. task (e.g. there is no GPU available and this task is only
  1178. implemented for CUDA devices). starpu_task_submit() can be called
  1179. from anywhere, including codelet functions and callbacks, provided
  1180. that the field starpu_task::synchronous is set to 0.
  1181. */
  1182. int starpu_task_submit(struct starpu_task *task) STARPU_WARN_UNUSED_RESULT;
  1183. /**
  1184. Submit \p task to StarPU with dependency bypass.
  1185. This can only be called on behalf of another task which has already taken the
  1186. proper dependencies, e.g. this task is just an attempt of doing the actual
  1187. computation of that task.
  1188. */
  1189. int starpu_task_submit_nodeps(struct starpu_task *task) STARPU_WARN_UNUSED_RESULT;
  1190. /**
  1191. Submit \p task to the context \p sched_ctx_id. By default,
  1192. starpu_task_submit() submits the task to a global context that is
  1193. created automatically by StarPU.
  1194. */
  1195. int starpu_task_submit_to_ctx(struct starpu_task *task, unsigned sched_ctx_id);
  1196. int starpu_task_finished(struct starpu_task *task) STARPU_WARN_UNUSED_RESULT;
  1197. /**
  1198. Block until \p task has been executed. It is not possible to
  1199. synchronize with a task more than once. It is not possible to wait
  1200. for synchronous or detached tasks. Upon successful completion, this
  1201. function returns 0. Otherwise, <c>-EINVAL</c> indicates that the
  1202. specified task was either synchronous or detached.
  1203. */
  1204. int starpu_task_wait(struct starpu_task *task) STARPU_WARN_UNUSED_RESULT;
  1205. /**
  1206. Allow to wait for an array of tasks. Upon successful completion,
  1207. this function returns 0. Otherwise, <c>-EINVAL</c> indicates that
  1208. one of the tasks was either synchronous or detached.
  1209. */
  1210. int starpu_task_wait_array(struct starpu_task **tasks, unsigned nb_tasks) STARPU_WARN_UNUSED_RESULT;
  1211. /**
  1212. Block until all the tasks that were submitted (to the current
  1213. context or the global one if there is no current context) are
  1214. terminated. It does not destroy these tasks.
  1215. */
  1216. int starpu_task_wait_for_all(void);
  1217. /**
  1218. Block until there are \p n submitted tasks left (to the current
  1219. context or the global one if there is no current context) to be
  1220. executed. It does not destroy these tasks.
  1221. */
  1222. int starpu_task_wait_for_n_submitted(unsigned n);
  1223. /**
  1224. Wait until all the tasks that were already submitted to the context
  1225. \p sched_ctx_id have been terminated.
  1226. */
  1227. int starpu_task_wait_for_all_in_ctx(unsigned sched_ctx_id);
  1228. /**
  1229. Wait until there are \p n tasks submitted left to be
  1230. executed that were already submitted to the context \p
  1231. sched_ctx_id.
  1232. */
  1233. int starpu_task_wait_for_n_submitted_in_ctx(unsigned sched_ctx_id, unsigned n);
  1234. /**
  1235. Wait until there is no more ready task.
  1236. */
  1237. int starpu_task_wait_for_no_ready(void);
  1238. /**
  1239. Return the number of submitted tasks which are ready for execution
  1240. are already executing. It thus does not include tasks waiting for
  1241. dependencies.
  1242. */
  1243. int starpu_task_nready(void);
  1244. /**
  1245. Return the number of submitted tasks which have not completed yet.
  1246. */
  1247. int starpu_task_nsubmitted(void);
  1248. /**
  1249. Set the iteration number for all the tasks to be submitted after
  1250. this call. This is typically called at the beginning of a task
  1251. submission loop. This number will then show up in tracing tools. A
  1252. corresponding starpu_iteration_pop() call must be made to match the
  1253. call to starpu_iteration_push(), at the end of the same task
  1254. submission loop, typically.
  1255. Nested calls to starpu_iteration_push() and starpu_iteration_pop()
  1256. are allowed, to describe a loop nest for instance, provided that
  1257. they match properly.
  1258. */
  1259. void starpu_iteration_push(unsigned long iteration);
  1260. /**
  1261. Drop the iteration number for submitted tasks. This must match a
  1262. previous call to starpu_iteration_push(), and is typically called
  1263. at the end of a task submission loop.
  1264. */
  1265. void starpu_iteration_pop(void);
  1266. void starpu_do_schedule(void);
  1267. /**
  1268. Initialize \p cl with default values. Codelets should preferably be
  1269. initialized statically as shown in \ref DefiningACodelet. However
  1270. such a initialisation is not always possible, e.g. when using C++.
  1271. */
  1272. void starpu_codelet_init(struct starpu_codelet *cl);
  1273. /**
  1274. Output on \c stderr some statistics on the codelet \p cl.
  1275. */
  1276. void starpu_codelet_display_stats(struct starpu_codelet *cl);
  1277. /**
  1278. Return the task currently executed by the worker, or <c>NULL</c> if
  1279. it is called either from a thread that is not a task or simply
  1280. because there is no task being executed at the moment.
  1281. */
  1282. struct starpu_task *starpu_task_get_current(void);
  1283. /**
  1284. Return the memory node number of parameter \p i of the task
  1285. currently executed, or -1 if it is called either from a thread that
  1286. is not a task or simply because there is no task being executed at
  1287. the moment.
  1288. Usually, the returned memory node number is simply the memory node
  1289. for the current worker. That may however be different when using
  1290. e.g. starpu_codelet::specific_nodes.
  1291. */
  1292. int starpu_task_get_current_data_node(unsigned i);
  1293. /**
  1294. Return the name of the performance model of \p task.
  1295. */
  1296. const char *starpu_task_get_model_name(struct starpu_task *task);
  1297. /**
  1298. Return the name of \p task, i.e. either its starpu_task::name
  1299. field, or the name of the corresponding performance model.
  1300. */
  1301. const char *starpu_task_get_name(struct starpu_task *task);
  1302. /**
  1303. Allocate a task structure which is the exact duplicate of \p task.
  1304. */
  1305. struct starpu_task *starpu_task_dup(struct starpu_task *task);
  1306. /**
  1307. This function should be called by schedulers to specify the
  1308. codelet implementation to be executed when executing \p task.
  1309. */
  1310. void starpu_task_set_implementation(struct starpu_task *task, unsigned impl);
  1311. /**
  1312. Return the codelet implementation to be executed
  1313. when executing \p task.
  1314. */
  1315. unsigned starpu_task_get_implementation(struct starpu_task *task);
  1316. /**
  1317. Create (and submit) an empty task that unlocks a tag once all its
  1318. dependencies are fulfilled.
  1319. */
  1320. void starpu_create_sync_task(starpu_tag_t sync_tag, unsigned ndeps, starpu_tag_t *deps, void (*callback)(void *), void *callback_arg);
  1321. /**
  1322. Function to be used as a prologue callback to enable fault tolerance for the
  1323. task. This prologue will create a try-task, i.e a duplicate of the task,
  1324. which will to the actual computation.
  1325. The prologue argument can be set to a check_ft function that will be
  1326. called on termination of the duplicate, which can check the result of the
  1327. task, and either confirm success, or resubmit another attempt.
  1328. If it is not set, the default implementation is to just resubmit a new
  1329. try-task.
  1330. */
  1331. void starpu_task_ft_prologue(void *check_ft);
  1332. /**
  1333. Create a try-task for a \p meta_task, given a \p template_task task
  1334. template. The meta task can be passed as template on the first call, but
  1335. since it is mangled by starpu_task_ft_create_retry(), further calls
  1336. (typically made by the check_ft callback) need to be passed the previous
  1337. try-task as template task.
  1338. \p check_ft is similar to the prologue argument of
  1339. starpu_task_ft_prologue(), and is typicall set to the very function calling
  1340. starpu_task_ft_create_retry().
  1341. The try-task is returned, and can be modified (e.g. to change scheduling
  1342. parameters) before being submitted with starpu_task_submit_nodeps().
  1343. */
  1344. struct starpu_task * starpu_task_ft_create_retry(const struct starpu_task *meta_task, const struct starpu_task *template_task, void (*check_ft)(void*));
  1345. /**
  1346. Record that this task failed, and should thus be retried.
  1347. This is usually called from the task codelet function itself, after checking
  1348. the result and noticing that the computation went wrong, and thus the task
  1349. should be retried. The performance of this task execution will not be
  1350. recorded for performance models.
  1351. This can only be called for a task whose data access modes are either
  1352. STARPU_R and STARPU_W.
  1353. */
  1354. void starpu_task_ft_failed(struct starpu_task *task);
  1355. /**
  1356. Notify that the try-task was successful and thus the meta-task was
  1357. successful.
  1358. */
  1359. void starpu_task_ft_success(struct starpu_task *meta_task);
  1360. /** @} */
  1361. #ifdef __cplusplus
  1362. }
  1363. #endif
  1364. #endif /* __STARPU_TASK_H__ */