starpu_task.h 60 KB

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