starpu_task.h 58 KB

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