codelet_and_tasks.doxy 41 KB

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