starpu_task.h 58 KB

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