codelet_and_tasks.doxy 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  1. /*
  2. * This file is part of the StarPU Handbook.
  3. * Copyright (C) 2009--2011 Universit@'e de Bordeaux
  4. * Copyright (C) 2010, 2011, 2012, 2013, 2014 Centre National de la Recherche Scientifique
  5. * Copyright (C) 2011, 2012 Institut National de Recherche en Informatique et Automatique
  6. * See the file version.doxy for copying conditions.
  7. */
  8. /*! \defgroup API_Codelet_And_Tasks Codelet And Tasks
  9. \brief This section describes the interface to manipulate codelets and tasks.
  10. \enum starpu_codelet_type
  11. \ingroup API_Codelet_And_Tasks
  12. Describes the type of parallel task. See \ref ParallelTasks for details.
  13. \var starpu_codelet_type::STARPU_SEQ
  14. \ingroup API_Codelet_And_Tasks
  15. (default) for classical sequential tasks.
  16. \var starpu_codelet_type::STARPU_SPMD
  17. \ingroup API_Codelet_And_Tasks
  18. for a parallel task whose threads are handled by StarPU, the code has
  19. to use starpu_combined_worker_get_size() and
  20. starpu_combined_worker_get_rank() to distribute the work.
  21. \var starpu_codelet_type::STARPU_FORKJOIN
  22. \ingroup API_Codelet_And_Tasks
  23. for a parallel task whose threads are started by the codelet function,
  24. which has to use starpu_combined_worker_get_size() to determine how
  25. many threads should be started.
  26. \enum starpu_task_status
  27. \ingroup API_Codelet_And_Tasks
  28. Task status
  29. \var starpu_task_status::STARPU_TASK_INVALID
  30. \ingroup API_Codelet_And_Tasks
  31. The task has just been initialized.
  32. \var starpu_task_status::STARPU_TASK_BLOCKED
  33. \ingroup API_Codelet_And_Tasks
  34. The task has just been submitted, and its dependencies has not been
  35. checked yet.
  36. \var starpu_task_status::STARPU_TASK_READY
  37. \ingroup API_Codelet_And_Tasks
  38. The task is ready for execution.
  39. \var starpu_task_status::STARPU_TASK_RUNNING
  40. \ingroup API_Codelet_And_Tasks
  41. The task is running on some worker.
  42. \var starpu_task_status::STARPU_TASK_FINISHED
  43. \ingroup API_Codelet_And_Tasks
  44. The task is finished executing.
  45. \var starpu_task_status::STARPU_TASK_BLOCKED_ON_TAG
  46. \ingroup API_Codelet_And_Tasks
  47. The task is waiting for a tag.
  48. \var starpu_task_status::STARPU_TASK_BLOCKED_ON_TASK
  49. \ingroup API_Codelet_And_Tasks
  50. The task is waiting for a task.
  51. \var starpu_task_status::STARPU_TASK_BLOCKED_ON_DATA
  52. \ingroup API_Codelet_And_Tasks
  53. The task is waiting for some data.
  54. \def STARPU_CPU
  55. \ingroup API_Codelet_And_Tasks
  56. This macro is used when setting the field starpu_codelet::where
  57. to specify the codelet may be executed on a CPU processing unit.
  58. \def STARPU_CUDA
  59. \ingroup API_Codelet_And_Tasks
  60. This macro is used when setting the field starpu_codelet::where
  61. to specify the codelet may be executed on a CUDA processing unit.
  62. \def STARPU_OPENCL
  63. \ingroup API_Codelet_And_Tasks
  64. This macro is used when setting the field starpu_codelet::where to
  65. specify the codelet may be executed on a OpenCL processing unit.
  66. \def STARPU_MIC
  67. \ingroup API_Codelet_And_Tasks
  68. This macro is used when setting the field starpu_codelet::where to
  69. specify the codelet may be executed on a MIC processing unit.
  70. \def STARPU_SCC
  71. \ingroup API_Codelet_And_Tasks
  72. This macro is used when setting the field starpu_codelet::where to
  73. specify the codelet may be executed on an SCC processing unit.
  74. \def STARPU_MAIN_RAM
  75. \ingroup API_Codelet_And_Tasks
  76. This macro is used when the RAM memory node is specified.
  77. \def STARPU_MULTIPLE_CPU_IMPLEMENTATIONS
  78. \deprecated
  79. \ingroup API_Codelet_And_Tasks
  80. Setting the field starpu_codelet::cpu_func with this macro
  81. indicates the codelet will have several implementations. The use of
  82. this macro is deprecated. One should always only define the field
  83. starpu_codelet::cpu_funcs.
  84. \def STARPU_MULTIPLE_CUDA_IMPLEMENTATIONS
  85. \deprecated
  86. \ingroup API_Codelet_And_Tasks
  87. Setting the field starpu_codelet::cuda_func with this macro
  88. indicates the codelet will have several implementations. The use of
  89. this macro is deprecated. One should always only define the field
  90. starpu_codelet::cuda_funcs.
  91. \def STARPU_MULTIPLE_OPENCL_IMPLEMENTATIONS
  92. \deprecated
  93. \ingroup API_Codelet_And_Tasks
  94. Setting the field starpu_codelet::opencl_func with
  95. this macro indicates the codelet will have several implementations.
  96. The use of this macro is deprecated. One should always only define the
  97. field starpu_codelet::opencl_funcs.
  98. \def STARPU_NMAXBUFS
  99. \ingroup API_Codelet_And_Tasks
  100. Defines the maximum number of buffers that tasks will be able to take
  101. as parameters. The default value is 8, it can be changed by using the
  102. configure option \ref enable-maxbuffers "--enable-maxbuffers".
  103. \def STARPU_VARIABLE_NBUFFERS
  104. \ingroup API_Codelet_And_Tasks
  105. Value to set in starpu_codelet::nbuffers to specify that the codelet can accept
  106. a variable number of buffers, specified in starpu_task::nbuffers.
  107. \def STARPU_CUDA_ASYNC
  108. Value to be set in starpu_codelet::cuda_flags to allow asynchronous CUDA kernel execution.
  109. \def STARPU_OPENCL_ASYNC
  110. Value to be set in starpu_codelet::opencl_flags to allow asynchronous OpenCL kernel execution.
  111. \typedef starpu_cpu_func_t
  112. \ingroup API_Codelet_And_Tasks
  113. CPU implementation of a codelet.
  114. \typedef starpu_cuda_func_t
  115. \ingroup API_Codelet_And_Tasks
  116. CUDA implementation of a codelet.
  117. \typedef starpu_opencl_func_t
  118. \ingroup API_Codelet_And_Tasks
  119. OpenCL implementation of a codelet.
  120. \typedef starpu_mic_func_t
  121. \ingroup API_Codelet_And_Tasks
  122. MIC implementation of a codelet.
  123. \typedef starpu_scc_func_t
  124. \ingroup API_Codelet_And_Tasks
  125. SCC implementation of a codelet.
  126. \typedef starpu_mic_kernel_t
  127. \ingroup API_Codelet_And_Tasks
  128. MIC kernel for a codelet
  129. \typedef *starpu_scc_kernel_t
  130. \ingroup API_Codelet_And_Tasks
  131. SCC kernel for a codelet
  132. \struct starpu_codelet
  133. The codelet structure describes a kernel that is possibly
  134. implemented on various targets. For compatibility, make sure to
  135. initialize the whole structure to zero, either by using explicit
  136. memset, or the function starpu_codelet_init(), or by letting the
  137. compiler implicitly do it in e.g. static storage case.
  138. \ingroup API_Codelet_And_Tasks
  139. \var uint32_t starpu_codelet::where
  140. Optional field to indicate which types of processing units are able to
  141. execute the codelet. The different values ::STARPU_CPU, ::STARPU_CUDA,
  142. ::STARPU_OPENCL can be combined to specify on which types of processing
  143. units the codelet can be executed. ::STARPU_CPU|::STARPU_CUDA for instance
  144. indicates that the codelet is implemented for both CPU cores and CUDA
  145. devices while ::STARPU_OPENCL indicates that it is only available on
  146. OpenCL devices. If the field is unset, its value will be automatically
  147. set based on the availability of the XXX_funcs fields defined below.
  148. \var int (*starpu_codelet::can_execute)(unsigned workerid, struct starpu_task *task, unsigned nimpl)
  149. Define a function which should return 1 if the worker designated by
  150. workerid can execute the <c>nimpl</c>th implementation of the given
  151. task, 0 otherwise.
  152. \var enum starpu_codelet_type starpu_codelet::type
  153. Optional field to specify the type of the codelet. The default is
  154. ::STARPU_SEQ, i.e. usual sequential implementation. Other values
  155. (::STARPU_SPMD or ::STARPU_FORKJOIN declare that a parallel implementation
  156. is also available. See \ref ParallelTasks for details.
  157. \var int starpu_codelet::max_parallelism
  158. Optional field. If a parallel implementation is available, this
  159. denotes the maximum combined worker size that StarPU will use to
  160. execute parallel tasks for this codelet.
  161. \var starpu_cpu_func_t starpu_codelet::cpu_func
  162. \deprecated
  163. Optional field which has been made deprecated. One should use instead
  164. the field starpu_codelet::cpu_funcs.
  165. \var starpu_cuda_func_t starpu_codelet::cuda_func
  166. \deprecated
  167. Optional field which has been made deprecated. One should use instead
  168. the starpu_codelet::cuda_funcs field.
  169. \var starpu_opencl_func_t starpu_codelet::opencl_func
  170. \deprecated
  171. Optional field which has been made deprecated. One should use instead
  172. the starpu_codelet::opencl_funcs field.
  173. \var starpu_cpu_func_t starpu_codelet::cpu_funcs[STARPU_MAXIMPLEMENTATIONS]
  174. Optional array of function pointers to the CPU implementations of the
  175. codelet. The functions prototype must be:
  176. \code{.c}
  177. void cpu_func(void *buffers[], void *cl_arg)
  178. \endcode
  179. The first argument being the array of data managed by the data
  180. management library, and the second argument is a pointer to the
  181. argument passed from the field starpu_task::cl_arg. If the field
  182. starpu_codelet::where is set, then the field starpu_codelet::cpu_funcs
  183. is ignored if ::STARPU_CPU does not appear in the field
  184. starpu_codelet::where, it must be non-null otherwise.
  185. \var char *starpu_codelet::cpu_funcs_name[STARPU_MAXIMPLEMENTATIONS]
  186. Optional array of strings which provide the name of the CPU functions
  187. referenced in the array starpu_codelet::cpu_funcs. This can be used
  188. when running on MIC devices or the SCC platform, for StarPU to simply
  189. look up the MIC function implementation through its name.
  190. \var starpu_cuda_func_t starpu_codelet::cuda_funcs[STARPU_MAXIMPLEMENTATIONS]
  191. Optional array of function pointers to the CUDA implementations of the
  192. codelet. The functions must be
  193. host-functions written in the CUDA runtime API. Their prototype must
  194. be:
  195. \code{.c}
  196. void cuda_func(void *buffers[], void *cl_arg)
  197. \endcode
  198. If the field starpu_codelet::where is set, then the field
  199. starpu_codelet::cuda_funcs is ignored if ::STARPU_CUDA does not appear
  200. in the field starpu_codelet::where, it must be non-null otherwise.
  201. \var char starpu_codelet::cuda_flags[STARPU_MAXIMPLEMENTATIONS]
  202. Optional array of flags for CUDA execution. They specify some semantic details
  203. about CUDA kernel execution, such as asynchronous execution.
  204. \var starpu_opencl_func_t starpu_codelet::opencl_funcs[STARPU_MAXIMPLEMENTATIONS]
  205. Optional array of function pointers to the OpenCL implementations of
  206. the codelet. The functions
  207. prototype must be:
  208. \code{.c}
  209. void opencl_func(void *buffers[], void *cl_arg)
  210. \endcode
  211. If the field starpu_codelet::where field is set, then the field
  212. starpu_codelet::opencl_funcs is ignored if ::STARPU_OPENCL does not
  213. appear in the field starpu_codelet::where, it must be non-null
  214. otherwise.
  215. \var char starpu_codelet::opencl_flags[STARPU_MAXIMPLEMENTATIONS]
  216. Optional array of flags for OpenCL execution. They specify some semantic details
  217. about OpenCL kernel execution, such as asynchronous execution.
  218. \var starpu_mic_func_t starpu_codelet::mic_funcs[STARPU_MAXIMPLEMENTATIONS]
  219. Optional array of function pointers to a function which returns the
  220. MIC implementation of the codelet. The functions prototype must be:
  221. \code{.c}
  222. starpu_mic_kernel_t mic_func(struct starpu_codelet *cl, unsigned nimpl)
  223. \endcode
  224. If the field starpu_codelet::where is set, then the field
  225. starpu_codelet::mic_funcs is ignored if ::STARPU_MIC does not appear
  226. in the field starpu_codelet::where. It can be null if
  227. starpu_codelet::cpu_funcs_name is non-NULL, in which case StarPU will
  228. simply make a symbol lookup to get the implementation.
  229. \var starpu_scc_func_t starpu_codelet::scc_funcs[STARPU_MAXIMPLEMENTATIONS]
  230. Optional array of function pointers to a function which returns the
  231. SCC implementation of the codelet. The functions prototype must be:
  232. \code{.c}
  233. starpu_scc_kernel_t scc_func(struct starpu_codelet *cl, unsigned nimpl)
  234. \endcode
  235. If the field starpu_codelet::where is set, then the field
  236. starpu_codelet::scc_funcs is ignored if ::STARPU_SCC does not appear
  237. in the field starpu_codelet::where. It can be null if
  238. starpu_codelet::cpu_funcs_name is non-NULL, in which case StarPU will
  239. simply make a symbol lookup to get the implementation.
  240. \var int starpu_codelet::nbuffers
  241. Specify the number of arguments taken by the codelet. These arguments are
  242. managed by the DSM and are accessed from the <c>void *buffers[]</c> array. The
  243. constant argument passed with the field starpu_task::cl_arg is not counted in
  244. this number. This value should not be above \ref STARPU_NMAXBUFS. It may be set
  245. to STARPU_VARIABLE_NBUFFERS to specify that the number of buffers and their
  246. access modes will be set in starpu_task::nbuffers and starpu_task::modes or
  247. starpu_task::dyn_modes, which thus permits to define codelets with a varying
  248. number of data.
  249. \var enum starpu_data_access_mode starpu_codelet::modes[STARPU_NMAXBUFS]
  250. Is an array of ::starpu_data_access_mode. It describes the required
  251. access modes to the data neeeded by the codelet (e.g. ::STARPU_RW). The
  252. number of entries in this array must be specified in the field
  253. starpu_codelet::nbuffers, and should not exceed \ref STARPU_NMAXBUFS. If
  254. unsufficient, this value can be set with the configure option
  255. \ref enable-maxbuffers "--enable-maxbuffers".
  256. \var enum starpu_data_access_mode *starpu_codelet::dyn_modes
  257. Is an array of ::starpu_data_access_mode. It describes the required
  258. access modes to the data needed by the codelet (e.g. ::STARPU_RW).
  259. The number of entries in this array must be specified in the field
  260. starpu_codelet::nbuffers. This field should be used for codelets having a
  261. number of datas greater than \ref STARPU_NMAXBUFS (see \ref
  262. SettingTheDataHandlesForATask). When defining a codelet, one
  263. should either define this field or the field starpu_codelet::modes defined above.
  264. \var unsigned starpu_codelet::specific_nodes
  265. Default value is 0. If this flag is set, StarPU will not systematically
  266. send all data to the memory node where the task will be executing, it
  267. will read the starpu_codelet::nodes or starpu_codelet::dyn_nodes array to
  268. determine, for each data, whether to send it on the memory node where the task
  269. will be executing (-1), or on a specific node (!= -1).
  270. \var int starpu_codelet::nodes[STARPU_NMAXBUFS]
  271. Optional field. When starpu_codelet::specific_nodes is 1, this specifies
  272. the memory nodes where each data should be sent to for task execution.
  273. The number of entries in this array is starpu_codelet::nbuffers, and should
  274. not exceed \ref STARPU_NMAXBUFS.
  275. \var int *starpu_codelet::dyn_nodes
  276. Optional field. When starpu_codelet::specific_nodes is 1, this specifies
  277. the memory nodes where each data should be sent to for task execution.
  278. The number of entries in this array is starpu_codelet::nbuffers.
  279. This field should be used for codelets having a
  280. number of datas greater than \ref STARPU_NMAXBUFS (see \ref
  281. SettingTheDataHandlesForATask). When defining a codelet, one
  282. should either define this field or the field starpu_codelet::nodes defined
  283. above.
  284. \var struct starpu_perfmodel *starpu_codelet::model
  285. Optional pointer to the task duration performance model associated to
  286. this codelet. This optional field is ignored when set to <c>NULL</c> or when
  287. its field starpu_perfmodel::symbol is not set.
  288. \var struct starpu_perfmodel *starpu_codelet::power_model
  289. Optional pointer to the task power consumption performance model
  290. associated to this codelet. This optional field is ignored when set to
  291. <c>NULL</c> or when its field starpu_perfmodel::field is not set. In
  292. the case of parallel codelets, this has to account for all processing
  293. units involved in the parallel execution.
  294. \var unsigned long starpu_codelet::per_worker_stats[STARPU_NMAXWORKERS]
  295. Optional array for statistics collected at runtime: this is filled by
  296. StarPU and should not be accessed directly, but for example by calling
  297. the function starpu_codelet_display_stats() (See
  298. starpu_codelet_display_stats() for details).
  299. \var const char *starpu_codelet::name
  300. Optional name of the codelet. This can be useful for debugging
  301. purposes.
  302. \fn void starpu_codelet_init(struct starpu_codelet *cl)
  303. \ingroup API_Codelet_And_Tasks
  304. Initialize \p cl with default values. Codelets should
  305. preferably be initialized statically as shown in \ref
  306. DefiningACodelet. However such a initialisation is not always
  307. possible, e.g. when using C++.
  308. \struct starpu_data_descr
  309. \ingroup API_Codelet_And_Tasks
  310. This type is used to describe a data handle along with an access mode.
  311. \var starpu_data_handle_t starpu_data_descr::handle
  312. describes a data
  313. \var enum starpu_data_access_mode starpu_data_descr::mode
  314. describes its access mode
  315. \struct starpu_task
  316. \ingroup API_Codelet_And_Tasks
  317. The structure describes a task that can be offloaded on the
  318. various processing units managed by StarPU. It instantiates a codelet.
  319. It can either be allocated dynamically with the function
  320. starpu_task_create(), or declared statically. In the latter case, the
  321. programmer has to zero the structure starpu_task and to fill the
  322. different fields properly. The indicated default values correspond to
  323. the configuration of a task allocated with starpu_task_create().
  324. \var const char *starpu_task::name
  325. Optional name of the task. This can be useful for debugging
  326. purposes.
  327. \var struct starpu_codelet *starpu_task::cl
  328. Is a pointer to the corresponding structure starpu_codelet. This
  329. describes where the kernel should be executed, and supplies the
  330. appropriate implementations. When set to NULL, no code is executed
  331. during the tasks, such empty tasks can be useful for synchronization
  332. purposes.
  333. This field has been made deprecated. One should use instead the
  334. field starpu_task::handles to specify the data handles accessed
  335. by the task. The access modes are now defined in the field
  336. starpu_codelet::modes.
  337. \var int starpu_task::nbuffers
  338. Specifies the number of buffers. This is only used when starpu_codelet::nbuffers
  339. is STARPU_VARIABLE_NBUFFERS.
  340. \var starpu_data_handle_t starpu_task::handles[STARPU_NMAXBUFS]
  341. Is an array of ::starpu_data_handle_t. It specifies the handles to the
  342. different pieces of data accessed by the task. The number of entries
  343. in this array must be specified in the field starpu_codelet::nbuffers,
  344. and should not exceed \ref STARPU_NMAXBUFS. If unsufficient, this value can
  345. be set with the configure option \ref enable-maxbuffers "--enable-maxbuffers".
  346. \var starpu_data_handle_t *starpu_task::dyn_handles
  347. Is an array of ::starpu_data_handle_t. It specifies the handles to the
  348. different pieces of data accessed by the task. The number of entries
  349. in this array must be specified in the field starpu_codelet::nbuffers.
  350. This field should be used for tasks having a number of datas greater
  351. than \ref STARPU_NMAXBUFS (see \ref SettingTheDataHandlesForATask).
  352. When defining a task, one should either define this field or the field
  353. starpu_task::handles defined above.
  354. \var void *starpu_task::interfaces[STARPU_NMAXBUFS]
  355. The actual data pointers to the memory node where execution will
  356. happen, managed by the DSM.
  357. \var void **starpu_task::dyn_interfaces
  358. The actual data pointers to the memory node where execution will
  359. happen, managed by the DSM. Is used when the field
  360. starpu_task::dyn_handles is defined.
  361. \var enum starpu_data_access_mode starpu_task::modes[STARPU_NMAXBUFS]
  362. Is used only when starpu_codelet::nbuffers is STARPU_VARIABLE_NBUFFERS.
  363. It is an array of ::starpu_data_access_mode. It describes the required
  364. access modes to the data neeeded by the codelet (e.g. ::STARPU_RW). The
  365. number of entries in this array must be specified in the field
  366. starpu_task::nbuffers, and should not exceed \ref STARPU_NMAXBUFS. If
  367. unsufficient, this value can be set with the configure option
  368. \ref enable-maxbuffers "--enable-maxbuffers".
  369. \var enum starpu_data_access_mode *starpu_task::dyn_modes
  370. Is used only when starpu_codelet::nbuffers is STARPU_VARIABLE_NBUFFERS.
  371. It is an array of ::starpu_data_access_mode. It describes the required
  372. access modes to the data needed by the codelet (e.g. ::STARPU_RW).
  373. The number of entries in this array must be specified in the field
  374. starpu_codelet::nbuffers. This field should be used for codelets having a
  375. number of datas greater than \ref STARPU_NMAXBUFS (see \ref
  376. SettingTheDataHandlesForATask). When defining a codelet, one
  377. should either define this field or the field starpu_task::modes defined above.
  378. \var void *starpu_task::cl_arg
  379. Optional pointer which is passed to the codelet through the second
  380. argument of the codelet implementation (e.g. starpu_codelet::cpu_func
  381. or starpu_codelet::cuda_func). The default value is <c>NULL</c>.
  382. \var size_t starpu_task::cl_arg_size
  383. Optional field. For some specific drivers, the pointer
  384. starpu_task::cl_arg cannot not be directly given to the driver
  385. function. A buffer of size starpu_task::cl_arg_size needs to be
  386. allocated on the driver. This buffer is then filled with the
  387. starpu_task::cl_arg_size bytes starting at address
  388. starpu_task::cl_arg. In this case, the argument given to the codelet
  389. is therefore not the starpu_task::cl_arg pointer, but the address of
  390. the buffer in local store (LS) instead. This field is ignored for CPU,
  391. CUDA and OpenCL codelets, where the starpu_task::cl_arg pointer is
  392. given as such.
  393. \var unsigned starpu_task::cl_arg_free
  394. Optional field. In case starpu_task::cl_arg was allocated by the
  395. application through <c>malloc()</c>, setting starpu_task::cl_arg_free
  396. to 1 makes StarPU automatically call <c>free(cl_arg)</c> when
  397. destroying the task. This saves the user from defining a callback just
  398. for that. This is mostly useful when targetting MIC or SCC, where the
  399. codelet does not execute in the same memory space as the main thread.
  400. \var void (*starpu_task::callback_func)(void *)
  401. Optional field, the default value is <c>NULL</c>. This is a function
  402. pointer of prototype <c>void (*f)(void *)</c> which specifies a
  403. possible callback. If this pointer is non-null, the callback function
  404. is executed on the host after the execution of the task. Tasks which
  405. depend on it might already be executing. The callback is passed the
  406. value contained in the starpu_task::callback_arg field. No callback is
  407. executed if the field is set to NULL.
  408. \var void *starpu_task::callback_arg (optional) (default: NULL)
  409. Optional field, the default value is <c>NULL</c>. This is the pointer
  410. passed to the callback function. This field is ignored if the field
  411. starpu_task::callback_func is set to <c>NULL</c>.
  412. \var unsigned starpu_task::callback_arg_free
  413. Optional field. In case starpu_task::callback_arg was allocated by the
  414. application through <c>malloc()</c>, setting starpu_task::callback_arg_free
  415. to 1 makes StarPU automatically call <c>free(callback_arg)</c> when
  416. destroying the task.
  417. \var void (*starpu_task::prologue_callback_func)(void *)
  418. Optional field, the default value is <c>NULL</c>. This is a function
  419. pointer of prototype <c>void (*f)(void *)</c> which specifies a
  420. possible callback.
  421. If this pointer is non-null, the callback function
  422. is executed on the host when the task becomes ready for execution,
  423. before getting scheduled. The callback is passed the
  424. value contained in the starpu_task::prologue_callback_arg field. No callback is
  425. executed if the field is set to NULL.
  426. \var void *starpu_task::prologue_callback_arg (optional) (default: NULL)
  427. Optional field, the default value is <c>NULL</c>. This is the pointer
  428. passed to the prologue callback function. This field is ignored if the field
  429. starpu_task::prologue_callback_func is set to <c>NULL</c>.
  430. \var unsigned starpu_task::prologue_callback_arg_free
  431. Optional field. In case starpu_task::prologue_callback_arg was allocated by the
  432. application through <c>malloc()</c>, setting starpu_task::prologue_callback_arg_free
  433. to 1 makes StarPU automatically call <c>free(prologue_callback_arg)</c> when
  434. destroying the task.
  435. \var unsigned starpu_task::use_tag
  436. Optional field, the default value is 0. If set, this flag indicates
  437. that the task should be associated with the tag contained in the
  438. starpu_task::tag_id field. Tag allow the application to synchronize
  439. with the task and to express task dependencies easily.
  440. \var starpu_tag_t starpu_task::tag_id
  441. This optional field contains the tag associated to the task if the
  442. field starpu_task::use_tag is set, it is ignored otherwise.
  443. \var unsigned starpu_task::sequential_consistency
  444. If this flag is set (which is the default), sequential consistency is
  445. enforced for the data parameters of this task for which sequential
  446. consistency is enabled. Clearing this flag permits to disable
  447. sequential consistency for this task, even if data have it enabled.
  448. \var unsigned starpu_task::synchronous
  449. If this flag is set, the function starpu_task_submit() is blocking and
  450. returns only when the task has been executed (or if no worker is able
  451. to process the task). Otherwise, starpu_task_submit() returns
  452. immediately.
  453. \var int starpu_task::priority
  454. Optional field, the default value is ::STARPU_DEFAULT_PRIO. This field
  455. indicates a level of priority for the task. This is an integer value
  456. that must be set between the return values of the function
  457. starpu_sched_get_min_priority() for the least important tasks, and
  458. that of the function starpu_sched_get_max_priority() for the most
  459. important tasks (included). The ::STARPU_MIN_PRIO and ::STARPU_MAX_PRIO
  460. macros are provided for convenience and respectively returns the value
  461. of starpu_sched_get_min_priority() and
  462. starpu_sched_get_max_priority(). Default priority is
  463. ::STARPU_DEFAULT_PRIO, which is always defined as 0 in order to allow
  464. static task initialization. Scheduling strategies that take priorities
  465. into account can use this parameter to take better scheduling
  466. decisions, but the scheduling policy may also ignore it.
  467. \var unsigned starpu_task::execute_on_a_specific_worker
  468. Default value is 0. If this flag is set, StarPU will bypass the
  469. scheduler and directly affect this task to the worker specified by the
  470. field starpu_task::workerid.
  471. \var unsigned starpu_task::workerid
  472. Optional field. If the field starpu_task::execute_on_a_specific_worker
  473. is set, this field indicates the identifier of the worker that should
  474. process this task (as returned by starpu_worker_get_id()). This field
  475. is ignored if the field starpu_task::execute_on_a_specific_worker is
  476. set to 0.
  477. \var unsigned starpu_task::workerorder
  478. Optional field. If the field starpu_task::execute_on_a_specific_worker is
  479. set, this field indicates the per-worker consecutive order in which tasks
  480. should be executed on the worker. Tasks will be executed in consecutive
  481. starpu_task::workerorder values, thus ignoring the availability order or task
  482. priority. See \ref StaticScheduling for more details. This field is ignored if
  483. the field starpu_task::execute_on_a_specific_worker is set to 0.
  484. \var starpu_task_bundle_t starpu_task::bundle
  485. Optional field. The bundle that includes this task. If no bundle is
  486. used, this should be NULL.
  487. \var unsigned starpu_task::detach
  488. Optional field, default value is 1. If this flag is set, it is not
  489. possible to synchronize with the task by the means of starpu_task_wait()
  490. later on. Internal data structures are only guaranteed to be freed
  491. once starpu_task_wait() is called if the flag is not set.
  492. \var unsigned starpu_task::destroy
  493. Optional value. Default value is 0 for starpu_task_init(), and 1 for
  494. starpu_task_create(). If this flag is set, the task structure will
  495. automatically be freed, either after the execution of the callback if
  496. the task is detached, or during starpu_task_wait() otherwise. If this
  497. flag is not set, dynamically allocated data structures will not be
  498. freed until starpu_task_destroy() is called explicitly. Setting this
  499. flag for a statically allocated task structure will result in
  500. undefined behaviour. The flag is set to 1 when the task is created by
  501. calling starpu_task_create(). Note that starpu_task_wait_for_all()
  502. will not free any task.
  503. \var unsigned starpu_task::regenerate
  504. Optional field. If this flag is set, the task will be re-submitted to
  505. StarPU once it has been executed. This flag must not be set if the
  506. flag starpu_task::destroy is set. This flag must be set before making another
  507. task depend on this one.
  508. \var enum starpu_task_status starpu_task::status
  509. Optional field. Current state of the task.
  510. \var struct starpu_profiling_task_info *starpu_task::profiling_info
  511. Optional field. Profiling information for the task.
  512. \var double starpu_task::predicted
  513. Output field. Predicted duration of the task. This field is only set
  514. if the scheduling strategy uses performance models.
  515. \var double starpu_task::predicted_transfer
  516. Optional field. Predicted data transfer duration for the task in
  517. microseconds. This field is only valid if the scheduling strategy uses
  518. performance models.
  519. \var struct starpu_task *starpu_task::prev
  520. \private
  521. A pointer to the previous task. This should only be used by StarPU.
  522. \var struct starpu_task *starpu_task::next
  523. \private
  524. A pointer to the next task. This should only be used by StarPU.
  525. \var unsigned int starpu_task::mf_skip
  526. \private
  527. This is only used for tasks that use multiformat handle. This should
  528. only be used by StarPU.
  529. \var double starpu_task::flops
  530. This can be set to the number of floating points operations that the
  531. task will have to achieve. This is useful for easily getting GFlops
  532. curves from the tool <c>starpu_perfmodel_plot</c>, and for the
  533. hypervisor load balancing.
  534. \var void *starpu_task::starpu_private
  535. \private
  536. This is private to StarPU, do not modify. If the task is allocated by
  537. hand (without starpu_task_create()), this field should be set to NULL.
  538. \var int starpu_task::magic
  539. \private
  540. This field is set when initializing a task. The function
  541. starpu_task_submit() will fail if the field does not have the right
  542. value. This will hence avoid submitting tasks which have not been
  543. properly initialised.
  544. \var unsigned starpu_task::sched_ctx
  545. Scheduling context.
  546. \var int starpu_task::hypervisor_tag
  547. Helps the hypervisor monitor the execution of this task.
  548. \var unsigned starpu_task::scheduled
  549. Whether the scheduler has pushed the task on some queue
  550. \fn void starpu_task_init(struct starpu_task *task)
  551. \ingroup API_Codelet_And_Tasks
  552. Initialize task with default values. This function is
  553. implicitly called by starpu_task_create(). By default, tasks initialized
  554. with starpu_task_init() must be deinitialized explicitly with
  555. starpu_task_clean(). Tasks can also be initialized statically, using
  556. ::STARPU_TASK_INITIALIZER.
  557. \def STARPU_TASK_INITIALIZER
  558. \ingroup API_Codelet_And_Tasks
  559. It is possible to initialize statically allocated tasks with
  560. this value. This is equivalent to initializing a structure starpu_task
  561. with the function starpu_task_init() function.
  562. \def STARPU_TASK_GET_NBUFFERS(task)
  563. \ingroup API_Codelet_And_Tasks
  564. Return the number of buffers for this task, i.e. starpu_codelet::nbuffers, or
  565. starpu_task::nbuffers if the former is STARPU_VARIABLE_BUFFERS.
  566. \def STARPU_TASK_GET_HANDLE(task, i)
  567. \ingroup API_Codelet_And_Tasks
  568. Return the \p i th data handle of the given task. If the task
  569. is defined with a static or dynamic number of handles, will either
  570. return the \p i th element of the field starpu_task::handles or the \p
  571. i th element of the field starpu_task::dyn_handles (see \ref
  572. SettingTheDataHandlesForATask)
  573. \def STARPU_TASK_SET_HANDLE(task, handle, i)
  574. \ingroup API_Codelet_And_Tasks
  575. Set the \p i th data handle of the given task with the given
  576. dat handle. If the task is defined with a static or dynamic number of
  577. handles, will either set the \p i th element of the field
  578. starpu_task::handles or the \p i th element of the field
  579. starpu_task::dyn_handles (see \ref
  580. SettingTheDataHandlesForATask)
  581. \def STARPU_CODELET_GET_MODE(codelet, i)
  582. \ingroup API_Codelet_And_Tasks
  583. Return the access mode of the \p i th data handle of the given
  584. codelet. If the codelet is defined with a static or dynamic number of
  585. handles, will either return the \p i th element of the field
  586. starpu_codelet::modes or the \p i th element of the field
  587. starpu_codelet::dyn_modes (see \ref
  588. SettingTheDataHandlesForATask)
  589. \def STARPU_CODELET_SET_MODE(codelet, mode, i)
  590. \ingroup API_Codelet_And_Tasks
  591. Set the access mode of the \p i th data handle of the given
  592. codelet. If the codelet is defined with a static or dynamic number of
  593. handles, will either set the \p i th element of the field
  594. starpu_codelet::modes or the \p i th element of the field
  595. starpu_codelet::dyn_modes (see \ref
  596. SettingTheDataHandlesForATask)
  597. \def STARPU_TASK_GET_MODE(task, i)
  598. \ingroup API_Codelet_And_Tasks
  599. Return the access mode of the \p i th data handle of the given
  600. task. If the task is defined with a static or dynamic number of
  601. handles, will either return the \p i th element of the field
  602. starpu_task::modes or the \p i th element of the field
  603. starpu_task::dyn_modes (see \ref
  604. SettingTheDataHandlesForATask)
  605. \def STARPU_TASK_SET_MODE(task, mode, i)
  606. \ingroup API_Codelet_And_Tasks
  607. Set the access mode of the \p i th data handle of the given
  608. task. If the task is defined with a static or dynamic number of
  609. handles, will either set the \p i th element of the field
  610. starpu_task::modes or the \p i th element of the field
  611. starpu_task::dyn_modes (see \ref
  612. SettingTheDataHandlesForATask)
  613. \fn struct starpu_task *starpu_task_create(void)
  614. \ingroup API_Codelet_And_Tasks
  615. Allocate a task structure and initialize it with default
  616. values. Tasks allocated dynamically with starpu_task_create() are
  617. automatically freed when the task is terminated. This means that the
  618. task pointer can not be used any more once the task is submitted,
  619. since it can be executed at any time (unless dependencies make it
  620. wait) and thus freed at any time. If the field starpu_task::destroy is
  621. explicitly unset, the resources used by the task have to be freed by
  622. calling starpu_task_destroy().
  623. \fn struct starpu_task *starpu_task_dup(struct starpu_task *task)
  624. \ingroup API_Codelet_And_Tasks
  625. Allocate a task structure which is the exact duplicate of the
  626. given task.
  627. \fn void starpu_task_clean(struct starpu_task *task)
  628. \ingroup API_Codelet_And_Tasks
  629. Release all the structures automatically allocated to execute
  630. task, but not the task structure itself and values set by the user
  631. remain unchanged. It is thus useful for statically allocated tasks for
  632. instance. It is also useful when users want to execute the same
  633. operation several times with as least overhead as possible. It is
  634. called automatically by starpu_task_destroy(). It has to be called
  635. only after explicitly waiting for the task or after starpu_shutdown()
  636. (waiting for the callback is not enough, since StarPU still
  637. manipulates the task after calling the callback).
  638. \fn void starpu_task_destroy(struct starpu_task *task)
  639. \ingroup API_Codelet_And_Tasks
  640. Free the resource allocated during starpu_task_create() and
  641. associated with task. This function is already called automatically
  642. after the execution of a task when the field starpu_task::destroy is
  643. set, which is the default for tasks created by starpu_task_create().
  644. Calling this function on a statically allocated task results in an
  645. undefined behaviour.
  646. \fn int starpu_task_wait(struct starpu_task *task)
  647. \ingroup API_Codelet_And_Tasks
  648. This function blocks until \p task has been executed. It is not
  649. possible to synchronize with a task more than once. It is not possible
  650. to wait for synchronous or detached tasks. Upon successful completion,
  651. this function returns 0. Otherwise, <c>-EINVAL</c> indicates that the
  652. specified task was either synchronous or detached.
  653. \fn int starpu_task_submit(struct starpu_task *task)
  654. \ingroup API_Codelet_And_Tasks
  655. This function submits task to StarPU. Calling this function
  656. does not mean that the task will be executed immediately as there can
  657. be data or task (tag) dependencies that are not fulfilled yet: StarPU
  658. will take care of scheduling this task with respect to such
  659. dependencies. This function returns immediately if the field
  660. starpu_task::synchronous is set to 0, and block until the
  661. termination of the task otherwise. It is also possible to synchronize
  662. the application with asynchronous tasks by the means of tags, using
  663. the function starpu_tag_wait() function for instance. In case of
  664. success, this function returns 0, a return value of <c>-ENODEV</c>
  665. means that there is no worker able to process this task (e.g. there is
  666. no GPU available and this task is only implemented for CUDA devices).
  667. starpu_task_submit() can be called from anywhere, including codelet
  668. functions and callbacks, provided that the field
  669. starpu_task::synchronous is set to 0.
  670. \fn int starpu_task_submit_to_ctx(struct starpu_task *task, unsigned sched_ctx_id)
  671. \ingroup API_Codelet_And_Tasks
  672. This function submits a task to StarPU to the context <c> sched_ctx_id </c>.
  673. By default starpu_task_submit submits the task to a global context that is
  674. created automatically by StarPU.
  675. \fn int starpu_task_wait_for_all(void)
  676. \ingroup API_Codelet_And_Tasks
  677. This function blocks until all the tasks that were submitted
  678. (to the current context or the global one if there aren't any) are
  679. terminated. It does not destroy these tasks.
  680. \fn int starpu_task_wait_for_all_in_ctx(unsigned sched_ctx_id)
  681. \ingroup API_Codelet_And_Tasks
  682. This function waits until all the tasks that were already
  683. submitted to the context \p sched_ctx_id have been executed
  684. \fn int starpu_task_nready(void)
  685. \ingroup API_Codelet_And_Tasks
  686. TODO
  687. \fn int starpu_task_nsubmitted(void)
  688. \ingroup API_Codelet_And_Tasks
  689. Return the number of submitted tasks which have not completed yet.
  690. \fn int starpu_task_nready(void)
  691. \ingroup API_Codelet_And_Tasks
  692. Return the number of submitted tasks which are ready for
  693. execution are already executing. It thus does not include tasks
  694. waiting for dependencies.
  695. \fn struct starpu_task *starpu_task_get_current(void)
  696. \ingroup API_Codelet_And_Tasks
  697. This function returns the task currently executed by the
  698. worker, or <c>NULL</c> if it is called either from a thread that is not a
  699. task or simply because there is no task being executed at the moment.
  700. \fn void starpu_codelet_display_stats(struct starpu_codelet *cl)
  701. \ingroup API_Codelet_And_Tasks
  702. Output on stderr some statistics on the codelet \p cl.
  703. \fn int starpu_task_wait_for_no_ready(void)
  704. \ingroup API_Codelet_And_Tasks
  705. This function waits until there is no more ready task.
  706. \fn void starpu_task_set_implementation(struct starpu_task *task, unsigned impl)
  707. \ingroup API_Codelet_And_Tasks
  708. This function should be called by schedulers to specify the
  709. codelet implementation to be executed when executing the task.
  710. \fn unsigned starpu_task_get_implementation(struct starpu_task *task)
  711. \ingroup API_Codelet_And_Tasks
  712. This function return the codelet implementation to be executed
  713. when executing the task.
  714. \fn void starpu_create_sync_task(starpu_tag_t sync_tag, unsigned ndeps, starpu_tag_t *deps, void (*callback)(void *), void *callback_arg)
  715. \ingroup API_Codelet_And_Tasks
  716. This creates (and submits) an empty task that unlocks a tag once all
  717. its dependencies are fulfilled.
  718. */