codelet_and_tasks.doxy 42 KB

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