starpu_task.h 58 KB

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