starpu_task.h 58 KB

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