starpu.texi 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186
  1. \input texinfo @c -*-texinfo-*-
  2. @c %**start of header
  3. @setfilename starpu.info
  4. @settitle StarPU
  5. @c %**end of header
  6. @setchapternewpage odd
  7. @titlepage
  8. @title StarPU
  9. @page
  10. @vskip 0pt plus 1filll
  11. @comment For the @value{version-GCC} Version*
  12. @end titlepage
  13. @summarycontents
  14. @contents
  15. @page
  16. @node Top
  17. @top Preface
  18. @cindex Preface
  19. This manual documents the usage of StarPU
  20. @comment
  21. @comment When you add a new menu item, please keep the right hand
  22. @comment aligned to the same column. Do not use tabs. This provides
  23. @comment better formatting.
  24. @comment
  25. @menu
  26. * Introduction:: A basic introduction to using StarPU.
  27. * Installing StarPU:: How to configure, build and install StarPU.
  28. * Configuration options:: Configurations options
  29. * Environment variables:: Environment variables used by StarPU.
  30. * StarPU API:: The API to use StarPU.
  31. * Basic Examples:: Basic examples of the use of StarPU.
  32. * Advanced Topics:: Advanced use of StarPU.
  33. @end menu
  34. @c ---------------------------------------------------------------------
  35. @c Introduction to StarPU
  36. @c ---------------------------------------------------------------------
  37. @node Introduction
  38. @chapter Introduction to StarPU
  39. @menu
  40. * Motivation:: Why StarPU ?
  41. * StarPU in a Nutshell:: The Fundamentals of StarPU
  42. @end menu
  43. @node Motivation
  44. @section Motivation
  45. @c complex machines with heterogeneous cores/devices
  46. The use of specialized hardware such as accelerators or coprocessors offers an
  47. interesting approach to overcome the physical limits encountered by processor
  48. architects. As a result, many machines are now equipped with one or several
  49. accelerators (eg. a GPU), in addition to the usual processor(s). While a lot of
  50. efforts have been devoted to offload computation onto such accelerators, very
  51. little attention as been paid to portability concerns on the one hand, and to the
  52. possibility of having heterogeneous accelerators and processors to interact on the other hand.
  53. StarPU is a runtime system that offers support for heterogeneous multicore
  54. architectures, it not only offers a unified view of the computational resources
  55. (ie. CPUs and accelerators at the same time), but it also takes care to
  56. efficiently map and execute tasks onto an heterogeneous machine while
  57. transparently handling low-level issues in a portable fashion.
  58. @c this leads to a complicated distributed memory design
  59. @c which is not (easily) manageable by hand
  60. @c added value/benefits of StarPU
  61. @c - portability
  62. @c - scheduling, perf. portability
  63. @node StarPU in a Nutshell
  64. @section StarPU in a Nutshell
  65. From a programming point of view, StarPU is not a new language but a library
  66. that executes tasks explicitly submitted by the application. The data that a
  67. task manipulate are automatically transferred onto the accelerator so that the
  68. programmer does not have to take care of complex data movements. StarPU also
  69. takes particular care of scheduling those tasks efficiently and allows
  70. scheduling experts to implement custom scheduling policies in a portable
  71. fashion.
  72. @c explain the notion of codelet and task (ie. g(A, B)
  73. @subsection Codelet and Tasks
  74. One of StarPU primary data structure is the @b{codelet}. A codelet describes a
  75. computational kernel that can possibly be implemented on multiple architectures
  76. such as a CPU, a CUDA device or a Cell's SPU.
  77. @c TODO insert illustration f : f_spu, f_cpu, ...
  78. Another important data structure is the @b{task}. Executing a StarPU task
  79. consists in applying a codelet on a data set, on one of the architecture on
  80. which the codelet is implemented. In addition to the codelet that a task
  81. implements, it also describes which data are accessed, and how they are
  82. accessed during the computation (read and/or write).
  83. StarPU tasks are asynchronous: submitting a task to StarPU is a non-blocking
  84. operation. The task structure can also specify a @b{callback} function that is
  85. called once StarPU has properly executed the task. It also contains optional
  86. fields that the application may use to give hints to the scheduler (such as
  87. priority levels).
  88. A task may be identified by a unique 64-bit number which we refer as a @b{tag}.
  89. Task dependencies can be enforced either by the means of callback functions, or
  90. by expressing dependencies between tags.
  91. @c TODO insert illustration f(Ar, Brw, Cr) + ..
  92. @c DSM
  93. @subsection StarPU Data Management Library
  94. Because StarPU schedules tasks at runtime, data transfers have to be
  95. done automatically and ``just-in-time'' between processing units,
  96. relieving the application programmer from explicit data transfers.
  97. Moreover, to avoid unnecessary transfers, StarPU keeps data
  98. where it was last needed, even if was modified there, and it
  99. allows multiple copies of the same data to reside at the same time on
  100. several processing units as long as it is not modified.
  101. @c ---------------------------------------------------------------------
  102. @c Installing StarPU
  103. @c ---------------------------------------------------------------------
  104. @node Installing StarPU
  105. @chapter Installing StarPU
  106. StarPU can be built and installed by the standard means of the GNU
  107. autotools. The following chapter is intended to briefly remind how these tools
  108. can be used to install StarPU.
  109. @section Configuring StarPU
  110. @subsection Generating Makefiles and configuration scripts
  111. This step is not necessary when using the tarball releases of StarPU. If you
  112. are using the source code from the svn repository, you first need to generate
  113. the configure scripts and the Makefiles.
  114. @example
  115. $ autoreconf -vfi
  116. @end example
  117. @subsection Configuring StarPU
  118. @example
  119. $ ./configure
  120. @end example
  121. @c TODO enumerate the list of interesting options: refer to a specific section
  122. @section Building and Installing StarPU
  123. @subsection Building
  124. @example
  125. $ make
  126. @end example
  127. @subsection Sanity Checks
  128. In order to make sure that StarPU is working properly on the system, it is also
  129. possible to run a test suite.
  130. @example
  131. $ make check
  132. @end example
  133. @subsection Installing
  134. In order to install StarPU at the location that was specified during
  135. configuration:
  136. @example
  137. $ make install
  138. @end example
  139. @subsection pkg-config configuration
  140. It is possible that compiling and linking an application against StarPU
  141. requires to use specific flags or libraries (for instance @code{CUDA} or
  142. @code{libspe2}). Therefore, it is possible to use the @code{pkg-config} tool.
  143. If StarPU was not installed at some standard location, the path of StarPU's
  144. library must be specified in the @code{PKG_CONFIG_PATH} environment variable so
  145. that @code{pkg-config} can find it. So if StarPU was installed in
  146. @code{$(prefix_dir)}:
  147. @example
  148. @c TODO: heu, c'est vraiment du shell ça ? :)
  149. $ PKG_CONFIG_PATH = @{PKG_CONFIG_PATH@}:$(prefix_dir)/lib/
  150. @end example
  151. The flags required to compiled or linked against StarPU are then
  152. accessible with the following commands:
  153. @example
  154. $ pkg-config --cflags libstarpu # options for the compiler
  155. $ pkg-config --libs libstarpu # options for the linker
  156. @end example
  157. @c ---------------------------------------------------------------------
  158. @c Configuration options
  159. @c ---------------------------------------------------------------------
  160. @node Configuration options
  161. @chapter Configuration options
  162. TODO
  163. @c ---------------------------------------------------------------------
  164. @c Environment variables
  165. @c ---------------------------------------------------------------------
  166. @node Environment variables
  167. @chapter Environment variables
  168. @menu
  169. * Workers:: Configuring workers
  170. * Scheduling:: Configuring the Scheduling engine
  171. * Misc:: Miscellaneous and debug
  172. @end menu
  173. TODO, explicit configuration (passed to starpu_init) overrides env variables.
  174. @node Workers
  175. @section Configuring workers
  176. @menu
  177. * NCPUS :: Number of CPU workers
  178. * NCUDA :: Number of CUDA workers
  179. * NGORDON :: Number of SPU workers (Cell)
  180. * WORKERS_CPUID :: Bind workers to specific CPUs
  181. * WORKERS_GPUID :: Select specific CUDA devices
  182. @end menu
  183. @node NCPUS
  184. @subsection @code{NCPUS} -- Number of CPU workers
  185. @table @asis
  186. @item @emph{Description}:
  187. TODO
  188. @end table
  189. @node NCUDA
  190. @subsection @code{NCUDA} -- Number of CUDA workers
  191. @table @asis
  192. @item @emph{Description}:
  193. TODO
  194. @end table
  195. @node NGORDON
  196. @subsection @code{NGORDON} -- Number of SPU workers (Cell)
  197. @table @asis
  198. @item @emph{Description}:
  199. TODO
  200. @end table
  201. @node WORKERS_CPUID
  202. @subsection @code{WORKERS_CPUID} -- Bind workers to specific CPUs
  203. @table @asis
  204. @item @emph{Description}:
  205. TODO
  206. @end table
  207. @node WORKERS_GPUID
  208. @subsection @code{WORKERS_GPUID} -- Select specific CUDA devices
  209. @table @asis
  210. @item @emph{Description}:
  211. TODO
  212. @end table
  213. @node Scheduling
  214. @section Configuring the Scheduling engine
  215. @menu
  216. * SCHED :: Scheduling policy
  217. * CALIBRATE :: Calibrate performance models
  218. * PREFETCH :: Use data prefetch
  219. @end menu
  220. @node SCHED
  221. @subsection @code{SCHED} -- Scheduling policy
  222. @table @asis
  223. @item @emph{Description}:
  224. TODO
  225. @end table
  226. @node CALIBRATE
  227. @subsection @code{CALIBRATE} -- Calibrate performance models
  228. @table @asis
  229. @item @emph{Description}:
  230. TODO
  231. @end table
  232. @node PREFETCH
  233. @subsection @code{PREFETCH} -- Use data prefetch
  234. @table @asis
  235. @item @emph{Description}:
  236. TODO
  237. @end table
  238. @node Misc
  239. @section Miscellaneous and debug
  240. @menu
  241. * LOGFILENAME :: Select debug file name
  242. @end menu
  243. @node LOGFILENAME
  244. @subsection @code{LOGFILENAME} -- Select debug file name
  245. @table @asis
  246. @item @emph{Description}:
  247. TODO
  248. @end table
  249. @c ---------------------------------------------------------------------
  250. @c StarPU API
  251. @c ---------------------------------------------------------------------
  252. @node StarPU API
  253. @chapter StarPU API
  254. @menu
  255. * Initialization and Termination:: Initialization and Termination methods
  256. * Workers' Properties:: Methods to enumerate workers' properties
  257. * Data Library:: Methods to manipulate data
  258. * Codelets and Tasks:: Methods to construct tasks
  259. * Tags:: Task dependencies
  260. @end menu
  261. @node Initialization and Termination
  262. @section Initialization and Termination
  263. @menu
  264. * starpu_init:: Initialize StarPU
  265. * struct starpu_conf:: StarPU runtime configuration
  266. * starpu_shutdown:: Terminate StarPU
  267. @end menu
  268. @node starpu_init
  269. @subsection @code{starpu_init} -- Initialize StarPU
  270. @table @asis
  271. @item @emph{Description}:
  272. This is StarPU initialization method, which must be called prior to any other
  273. StarPU call. It is possible to specify StarPU's configuration (eg. scheduling
  274. policy, number of cores, ...) by passing a non-null argument. Default
  275. configuration is used if the passed argument is @code{NULL}.
  276. @item @emph{Return value}:
  277. Upon successful completion, this function returns 0. Otherwise, @code{-ENODEV}
  278. indicates that no worker was available (so that StarPU was not be initialized).
  279. @item @emph{Prototype}:
  280. @code{int starpu_init(struct starpu_conf *conf);}
  281. @end table
  282. @node struct starpu_conf
  283. @subsection @code{struct starpu_conf} -- StarPU runtime configuration
  284. @table @asis
  285. @item @emph{Description}:
  286. This structure is passed to the @code{starpu_init} function in order configure
  287. StarPU. When the default value is used, StarPU automatically select the number
  288. of processing units and takes the default scheduling policy. This parameters
  289. overwrite the equivalent environnement variables.
  290. @item @emph{Fields}:
  291. @table @asis
  292. @item @code{sched_policy} (default = NULL):
  293. This is the name of the scheduling policy. This can also be specified with the
  294. @code{SCHED} environment variable.
  295. @item @code{ncpus} (default = -1):
  296. This is the maximum number of CPU cores that StarPU can use. This can also be
  297. specified with the @code{NCPUS} environment variable.
  298. @item @code{ncuda} (default = -1):
  299. This is the maximum number of CUDA devices that StarPU can use. This can also be
  300. specified with the @code{NCUDA} environment variable.
  301. @item @code{nspus} (default = -1):
  302. This is the maximum number of Cell SPUs that StarPU can use. This can also be
  303. specified with the @code{NGORDON} environment variable.
  304. @item @code{calibrate} (default = 0):
  305. If this flag is set, StarPU will calibrate the performance models when
  306. executing tasks. This can also be specified with the @code{CALIBRATE}
  307. environment variable.
  308. @end table
  309. @end table
  310. @node starpu_shutdown
  311. @subsection @code{starpu_shutdown} -- Terminate StarPU
  312. @table @asis
  313. @item @emph{Description}:
  314. This is StarPU termination method. It must be called at the end of the
  315. application: statistics and other post-mortem debugging information are not
  316. garanteed to be available until this method has been called.
  317. @item @emph{Prototype}:
  318. @code{void starpu_shutdown(void);}
  319. @end table
  320. @node Workers' Properties
  321. @section Workers' Properties
  322. @menu
  323. * starpu_get_worker_count:: Get the number of processing units
  324. * starpu_get_worker_id:: Get the identifier of the current worker
  325. * starpu_get_worker_type:: Get the type of processing unit associated to a worker
  326. * starpu_get_worker_name:: Get the name of a worker
  327. @end menu
  328. @node starpu_get_worker_count
  329. @subsection @code{starpu_get_worker_count} -- Get the number of processing units
  330. @table @asis
  331. @item @emph{Description}:
  332. This function returns the number of workers (ie. processing units executing
  333. StarPU tasks). The returned value should be at most @code{STARPU_NMAXWORKERS}.
  334. @item @emph{Prototype}:
  335. @code{unsigned starpu_get_worker_count(void);}
  336. @end table
  337. @node starpu_get_worker_id
  338. @subsection @code{starpu_get_worker_id} -- Get the identifier of the current worker
  339. @table @asis
  340. @item @emph{Description}:
  341. This function returns the identifier of the worker associated to the calling
  342. thread. The returned value is either -1 if the current context is not a StarPU
  343. worker (ie. when called from the application outside a task or a callback), or
  344. an integer between 0 and @code{starpu_get_worker_count() - 1}.
  345. @item @emph{Prototype}:
  346. @code{int starpu_get_worker_count(void);}
  347. @end table
  348. @node starpu_get_worker_type
  349. @subsection @code{starpu_get_worker_type} -- Get the type of processing unit associated to a worker
  350. @table @asis
  351. @item @emph{Description}:
  352. This function returns the type of worker associated to an identifier (as
  353. returned by the @code{starpu_get_worker_id} function). The returned value
  354. indicates the architecture of the worker: @code{STARPU_CORE_WORKER} for a CPU
  355. core, @code{STARPU_CUDA_WORKER} for a CUDA device, and
  356. @code{STARPU_GORDON_WORKER} for a Cell SPU. The value returned for an invalid
  357. identifier is unspecified.
  358. @item @emph{Prototype}:
  359. @code{enum starpu_archtype starpu_get_worker_type(int id);}
  360. @end table
  361. @node starpu_get_worker_name
  362. @subsection @code{starpu_get_worker_name} -- Get the name of a worker
  363. @table @asis
  364. @item @emph{Description}:
  365. StarPU associates a unique human readable string to each processing unit. This
  366. function copies at most the @code{maxlen} first bytes of the unique string
  367. associated to a worker identified by its identifier @code{id} into the
  368. @code{dst} buffer. The caller is responsible for ensuring that the @code{dst}
  369. is a valid pointer to a buffer of @code{maxlen} bytes at least. Calling this
  370. function on an invalid identifier results in an unspecified behaviour.
  371. @item @emph{Prototype}:
  372. @code{void starpu_get_worker_name(int id, char *dst, size_t maxlen);}
  373. @end table
  374. @node Data Library
  375. @section Data Library
  376. @c data_handle_t
  377. @c void starpu_delete_data(struct starpu_data_state_t *state);
  378. @c user interaction with the DSM
  379. @c void starpu_sync_data_with_mem(struct starpu_data_state_t *state);
  380. @c void starpu_notify_data_modification(struct starpu_data_state_t *state, uint32_t modifying_node);
  381. @node Codelets and Tasks
  382. @section Codelets and Tasks
  383. @menu
  384. * struct starpu_codelet:: StarPU codelet structure
  385. * struct starpu_task:: StarPU task structure
  386. * starpu_task_init:: Initialize a Task
  387. * starpu_task_create:: Allocate and Initialize a Task
  388. * starpu_task_destroy:: Destroy a dynamically allocated Task
  389. * starpu_submit_task:: Submit a Task
  390. * starpu_wait_task:: Wait for the termination of a Task
  391. * starpu_wait_all_tasks:: Wait for the termination of all Tasks
  392. @end menu
  393. @c struct starpu_task
  394. @c struct starpu_codelet
  395. @node struct starpu_codelet
  396. @subsection @code{struct starpu_codelet} -- StarPU codelet structure
  397. @table @asis
  398. @item @emph{Description}:
  399. The codelet structure describes a kernel that is possibly implemented on
  400. various targets.
  401. @item @emph{Fields}:
  402. @table @asis
  403. @item @code{where}:
  404. Indicates which types of processing units are able to execute that codelet.
  405. @code{CORE|CUDA} for instance indicates that the codelet is implemented for
  406. both CPU cores and CUDA devices while @code{GORDON} indicates that it is only
  407. available on Cell SPUs.
  408. @item @code{core_func} (optionnal):
  409. Is a function pointer to the CPU implementation of the codelet. Its prototype
  410. must be: @code{void core_func(starpu_data_interface_t *descr, void *arg)}. The
  411. first argument being the array of data managed by the data management library,
  412. and the second argument is a pointer to the argument (possibly a copy of it)
  413. passed from the @code{.cl_arg} field of the @code{starpu_task} structure. This
  414. pointer is ignored if @code{CORE} does not appear in the @code{.where} field,
  415. it must be non-null otherwise.
  416. @item @code{cuda_func} (optionnal):
  417. Is a function pointer to the CUDA implementation of the codelet. @emph{This
  418. must be a host-function written in the CUDA runtime API}. Its prototype must
  419. be: @code{void cuda_func(starpu_data_interface_t *descr, void *arg);}. This
  420. pointer is ignored if @code{CUDA} does not appear in the @code{.where} field,
  421. it must be non-null otherwise.
  422. @item @code{gordon_func} (optionnal):
  423. This is the index of the Cell SPU implementation within the Gordon library.
  424. TODO
  425. @item @code{nbuffers}:
  426. Specifies the number of arguments taken by the codelet. These arguments are
  427. managed by the DSM and are accessed from the @code{starpu_data_interface_t *}
  428. array. The constant argument passed with the @code{.cl_arg} field of the
  429. @code{starpu_task} structure is not counted in this number. This value should
  430. not be above @code{STARPU_NMAXBUFS}.
  431. @item @code{model} (optionnal):
  432. This is a pointer to the performance model associated to this codelet. This
  433. optionnal field is ignored when null. TODO
  434. @end table
  435. @end table
  436. @node struct starpu_task
  437. @subsection @code{struct starpu_task} -- StarPU task structure
  438. @table @asis
  439. @item @emph{Description}:
  440. The starpu_task structure describes a task that can be offloaded on the various
  441. processing units managed by StarPU. It instanciates a codelet. It can either be
  442. allocated dynamically with the @code{starpu_task_create} method, or declared
  443. statically. In the latter case, the programmer has to zero the
  444. @code{starpu_task} structure and to fill the different fields properly. The
  445. indicated default values correspond to the configuration of a task allocated
  446. with @code{starpu_task_create}.
  447. @item @emph{Fields}:
  448. @table @asis
  449. @item @code{cl}:
  450. Is a pointer to the corresponding @code{starpu_codelet} data structure. This
  451. describes where the kernel should be executed, and supplies the appropriate
  452. implementations. When set to @code{NULL}, no code is executed during the tasks,
  453. such empty tasks can be useful for synchronization purposes.
  454. @item @code{buffers}:
  455. TODO
  456. @item @code{cl_arg} (optional) (default = NULL):
  457. TODO
  458. @item @code{cl_arg_size} (optional):
  459. TODO
  460. @c ignored if only executable on CPUs or CUDA ...
  461. @item @code{callback_func} (optional) (default = @code{NULL}):
  462. This is a function pointer of prototype @code{void (*f)(void *)} which
  463. specifies a possible callback. If that pointer is non-null, the callback
  464. function is executed @emph{on the host} after the execution of the task. The
  465. callback is passed the value contained in the @code{callback_arg} field. No
  466. callback is executed if that field is null.
  467. @item @code{callback_arg} (optional) (default = @code{NULL}):
  468. This is the pointer passed to the callback function. This field is ignored if
  469. the @code{callback_func} is null.
  470. @item @code{use_tag} (optional) (default = 0):
  471. If set, this flag indicates that the task should be associated with the tag
  472. conained in the @code{tag_id} field. Tag allow the application to synchronize
  473. with the task and to express task dependencies easily.
  474. @item @code{tag_id}:
  475. This fields contains the tag associated to the tag if the @code{use_tag} field
  476. was set, it is ignored otherwise.
  477. @item @code{synchronous}:
  478. If this flag is set, the @code{starpu_submit_task} function is blocking and
  479. returns only when the task has been executed (or if no worker is able to
  480. process the task). Otherwise, @code{starpu_submit_task} returns immediately.
  481. @item @code{priority} (optionnal) (default = @code{DEFAULT_PRIO}):
  482. This field indicates a level of priority for the task. This is an integer value
  483. that must be selected between @code{MIN_PRIO} (for the least important tasks)
  484. and @code{MAX_PRIO} (for the most important tasks) included. Default priority
  485. is @code{DEFAULT_PRIO}. Scheduling strategies that take priorities into
  486. account can use this parameter to take better scheduling decisions, but the
  487. scheduling policy may also ignore it.
  488. @item @code{execute_on_a_specific_worker} (default = 0):
  489. If this flag is set, StarPU will bypass the scheduler and directly affect this
  490. task to the worker specified by the @code{workerid} field.
  491. @item @code{workerid} (optional):
  492. If the @code{execute_on_a_specific_worker} field is set, this field indicates
  493. which is the identifier of the worker that should process this task (as
  494. returned by @code{starpu_get_worker_id}). This field is ignored if
  495. @code{execute_on_a_specific_worker} field is set to 0.
  496. @item @code{detach} (optional) (default = 1):
  497. If this flag is set, it is not possible to synchronize with the task
  498. by the means of @code{starpu_wait_task} later on. Internal data structures
  499. are only garanteed to be liberated once @code{starpu_wait_task} is called
  500. if that flag is not set.
  501. @item @code{destroy} (optional) (default = 1):
  502. If that flag is set, the task structure will automatically be liberated, either
  503. after the execution of the callback if the task is detached, or during
  504. @code{starpu_task_wait} otherwise. If this flag is not set, dynamically allocated data
  505. structures will not be liberated until @code{starpu_task_destroy} is called
  506. explicitely. Setting this flag for a statically allocated task structure will
  507. result in undefined behaviour.
  508. @end table
  509. @end table
  510. @node starpu_task_init
  511. @subsection @code{starpu_task_init} -- Initialize a Task
  512. @table @asis
  513. @item @emph{Description}:
  514. TODO
  515. @item @emph{Prototype}:
  516. @code{void starpu_task_init(struct starpu_task *task);}
  517. @end table
  518. @node starpu_task_create
  519. @subsection @code{starpu_task_create} -- Allocate and Initialize a Task
  520. @table @asis
  521. @item @emph{Description}:
  522. TODO
  523. (Describe the different default fields ...)
  524. @item @emph{Prototype}:
  525. @code{struct starpu_task *starpu_task_create(void);}
  526. @end table
  527. @node starpu_task_destroy
  528. @subsection @code{starpu_task_destroy} -- Destroy a dynamically allocated Task
  529. @table @asis
  530. @item @emph{Description}:
  531. Liberate the ressource allocated during starpu_task_create. This function can
  532. be called automatically after the execution of a task by setting the
  533. @code{.destroy} flag of the @code{starpu_task} structure (default behaviour).
  534. Calling this function on a statically allocated task results in an undefined
  535. behaviour.
  536. @item @emph{Prototype}:
  537. @code{void starpu_task_destroy(struct starpu_task *task);}
  538. @end table
  539. @node starpu_wait_task
  540. @subsection @code{starpu_wait_task} -- Wait for the termination of a Task
  541. @table @asis
  542. @item @emph{Description}:
  543. This function blocks until the task was executed. It is not possible to
  544. synchronize with a task more than once. It is not possible to wait
  545. synchronous or detached tasks.
  546. @item @emph{Return value}:
  547. Upon successful completion, this function returns 0. Otherwise, @code{-EINVAL}
  548. indicates that the waited task was either synchronous or detached.
  549. @item @emph{Prototype}:
  550. @code{int starpu_wait_task(struct starpu_task *task);}
  551. @end table
  552. @node starpu_submit_task
  553. @subsection @code{starpu_submit_task} -- Submit a Task
  554. @table @asis
  555. @item @emph{Description}:
  556. This function submits task @code{task} to StarPU. Calling this function does
  557. not mean that the task will be executed immediatly as there can be data or task
  558. (tag) dependencies that are not fulfilled yet: StarPU will take care to
  559. schedule this task with respect to such dependencies.
  560. This function returns immediately if the @code{synchronous} field of the
  561. @code{starpu_task} structure was set to 0, and block until the termination of
  562. the task otherwise. It is also possible to synchronize the application with
  563. asynchronous tasks by the means of tags, using the @code{starpu_tag_wait}
  564. function for instance.
  565. In case of success, this function returns 0, a return value of @code{-ENODEV}
  566. means that there is no worker able to process that task (eg. there is no GPU
  567. available and this task is only implemented on top of CUDA).
  568. @item @emph{Prototype}:
  569. @code{int starpu_submit_task(struct starpu_task *task);}
  570. @end table
  571. @node starpu_wait_all_tasks
  572. @subsection @code{starpu_wait_all_tasks} -- Wait for the termination of all Tasks
  573. @table @asis
  574. @item @emph{Description}:
  575. This function blocks until all the tasks that were submitted are terminated.
  576. @item @emph{Prototype}:
  577. @code{void starpu_wait_all_tasks(void);}
  578. @end table
  579. @c Callbacks : what can we put in callbacks ?
  580. @node Tags
  581. @section Tags
  582. @menu
  583. * starpu_tag_t:: Task identifier
  584. * starpu_tag_declare_deps:: Declare the Dependencies of a Tag
  585. * starpu_tag_declare_deps_array:: Declare the Dependencies of a Tag
  586. * starpu_tag_wait:: Block until a Tag is terminated
  587. * starpu_tag_wait_array:: Block until a set of Tags is terminated
  588. * starpu_tag_remove:: Destroy a Tag
  589. * starpu_tag_notify_from_apps:: Feed a tag explicitely
  590. @end menu
  591. @node starpu_tag_t
  592. @subsection @code{starpu_tag_t} -- Task identifier
  593. @table @asis
  594. @item @emph{Description}:
  595. It is possible to associate a task with a unique "tag" and to express
  596. dependencies between tasks by the means of those tags. To do so, fill the
  597. @code{tag_id} field of the @code{starpu_task} structure with a tag number (can
  598. be arbitrary) and set the @code{use_tag} field to 1.
  599. If @code{starpu_tag_declare_deps} is called with that tag number, the task will
  600. not be started until the task which wears the declared dependency tags are
  601. complete.
  602. @end table
  603. @node starpu_tag_declare_deps
  604. @subsection @code{starpu_tag_declare_deps} -- Declare the Dependencies of a Tag
  605. @table @asis
  606. @item @emph{Description}:
  607. Specify the dependencies of the task identified by tag @code{id}. The first
  608. argument specifies the tag which is configured, the second argument gives the
  609. number of tag(s) on which @code{id} depends. The following arguments are the
  610. tags which have to terminated to unlock the task.
  611. This function must be called before the associated task is submitted to StarPU
  612. with @code{starpu_submit_task}.
  613. @item @emph{Remark}
  614. Because of the variable arity of @code{starpu_tag_declare_deps}, note that the
  615. last arguments @emph{must} be of type @code{starpu_tag_t}: constant values
  616. typically need to be explicitely casted. Using the
  617. @code{starpu_tag_declare_deps_array} function avoids this hazard.
  618. @item @emph{Prototype}:
  619. @code{void starpu_tag_declare_deps(starpu_tag_t id, unsigned ndeps, ...);}
  620. @item @emph{Example}:
  621. @example
  622. @c @cartouche
  623. /* Tag 0x1 depends on tags 0x32 and 0x52 */
  624. starpu_tag_declare_deps((starpu_tag_t)0x1,
  625. 2, (starpu_tag_t)0x32, (starpu_tag_t)0x52);
  626. @c @end cartouche
  627. @end example
  628. @end table
  629. @node starpu_tag_declare_deps_array
  630. @subsection @code{starpu_tag_declare_deps_array} -- Declare the Dependencies of a Tag
  631. @table @asis
  632. @item @emph{Description}:
  633. This function is similar to @code{starpu_tag_declare_deps}, except that its
  634. does not take a variable number of arguments but an array of tags of size
  635. @code{ndeps}.
  636. @item @emph{Prototype}:
  637. @code{void starpu_tag_declare_deps_array(starpu_tag_t id, unsigned ndeps, starpu_tag_t *array);}
  638. @item @emph{Example}:
  639. @example
  640. @c @cartouche
  641. /* Tag 0x1 depends on tags 0x32 and 0x52 */
  642. starpu_tag_t tag_array[2] = @{0x32, 0x52@};
  643. starpu_tag_declare_deps((starpu_tag_t)0x1, 2, tag_array);
  644. @c @end cartouche
  645. @end example
  646. @end table
  647. @node starpu_tag_wait
  648. @subsection @code{starpu_tag_wait} -- Block until a Tag is terminated
  649. @table @asis
  650. @item @emph{Description}:
  651. This function blocks until the task associated to tag @code{id} has been
  652. executed. This is a blocking call which must therefore not be called within
  653. tasks or callbacks, but only from the application directly. It is possible to
  654. synchronize with the same tag multiple times, as long as the
  655. @code{starpu_tag_remove} function is not called. Note that it is still
  656. possible to synchronize wih a tag associated to a task which @code{starpu_task}
  657. data structure was liberated (eg. if the @code{destroy} flag of the
  658. @code{starpu_task} was enabled).
  659. @item @emph{Prototype}:
  660. @code{void starpu_tag_wait(starpu_tag_t id);}
  661. @end table
  662. @node starpu_tag_wait_array
  663. @subsection @code{starpu_tag_wait_array} -- Block until a set of Tags is terminated
  664. @table @asis
  665. @item @emph{Description}:
  666. This function is similar to @code{starpu_tag_wait} except that it blocks until
  667. @emph{all} the @code{ntags} tags contained in the @code{id} array are
  668. terminated.
  669. @item @emph{Prototype}:
  670. @code{void starpu_tag_wait_array(unsigned ntags, starpu_tag_t *id);}
  671. @end table
  672. @node starpu_tag_remove
  673. @subsection @code{starpu_tag_remove} -- Destroy a Tag
  674. @table @asis
  675. @item @emph{Description}:
  676. This function release the resources associated to tag @code{id}. It can be
  677. called once the corresponding task has been executed and when there is no tag
  678. that depend on that one anymore.
  679. @item @emph{Prototype}:
  680. @code{void starpu_tag_remove(starpu_tag_t id);}
  681. @end table
  682. @node starpu_tag_notify_from_apps
  683. @subsection @code{starpu_tag_notify_from_apps} -- Feed a Tag explicitely
  684. @table @asis
  685. @item @emph{Description}:
  686. This function explicitely unlocks tag @code{id}. It may be useful in the
  687. case of applications which execute part of their computation outside StarPU
  688. tasks (eg. third-party libraries). It is also provided as a
  689. convenient tool for the programmer, for instance to entirely construct the task
  690. DAG before actually giving StarPU the opportunity to execute the tasks.
  691. @item @emph{Prototype}:
  692. @code{void starpu_tag_notify_from_apps(starpu_tag_t id);}
  693. @end table
  694. @section Extensions
  695. @subsection CUDA extensions
  696. @c void starpu_malloc_pinned_if_possible(float **A, size_t dim);
  697. @subsection Cell extensions
  698. @c ---------------------------------------------------------------------
  699. @c Basic Examples
  700. @c ---------------------------------------------------------------------
  701. @node Basic Examples
  702. @chapter Basic Examples
  703. @menu
  704. * Compiling and linking:: Compiling and Linking Options
  705. * Hello World:: Submitting Tasks
  706. * Scaling a Vector:: Manipulating Data
  707. * Scaling a Vector (hybrid):: Handling Heterogeneous Architectures
  708. @end menu
  709. @node Compiling and linking
  710. @section Compiling and linking options
  711. The Makefile could for instance contain the following lines to define which
  712. options must be given to the compiler and to the linker:
  713. @example
  714. @c @cartouche
  715. CFLAGS+=$$(pkg-config --cflags libstarpu)
  716. LIBS+=$$(pkg-config --libs libstarpu)
  717. @c @end cartouche
  718. @end example
  719. @node Hello World
  720. @section Hello World
  721. In this section, we show how to implement a simple program that submits a task to StarPU.
  722. @subsection Required Headers
  723. The @code{starpu.h} header should be included in any code using StarPU.
  724. @example
  725. @c @cartouche
  726. #include <starpu.h>
  727. @c @end cartouche
  728. @end example
  729. @subsection Defining a Codelet
  730. @example
  731. @c @cartouche
  732. void cpu_func(starpu_data_interface_t *buffers, void *func_arg)
  733. @{
  734. float *array = func_arg;
  735. printf("Hello world (array = @{%f, %f@} )\n", array[0], array[1]);
  736. @}
  737. starpu_codelet cl =
  738. @{
  739. .where = CORE,
  740. .core_func = cpu_func,
  741. .nbuffers = 0
  742. @};
  743. @c @end cartouche
  744. @end example
  745. A codelet is a structure that represents a computational kernel. Such a codelet
  746. may contain an implementation of the same kernel on different architectures
  747. (eg. CUDA, Cell's SPU, x86, ...).
  748. The ''@code{.nbuffers}'' field specifies the number of data buffers that are
  749. manipulated by the codelet: here the codelet does not access or modify any data
  750. that is controlled by our data management library. Note that the argument
  751. passed to the codelet (the ''@code{.cl_arg}'' field of the @code{starpu_task}
  752. structure) does not count as a buffer since it is not managed by our data
  753. management library.
  754. @c TODO need a crossref to the proper description of "where" see bla for more ...
  755. We create a codelet which may only be executed on the CPUs. The ''@code{.where}''
  756. field is a bitmask that defines where the codelet may be executed. Here, the
  757. @code{CORE} value means that only CPUs can execute this codelet
  758. (@pxref{Codelets and Tasks} for more details on that field).
  759. When a CPU core executes a codelet, it calls the @code{.core_func} function,
  760. which @emph{must} have the following prototype:
  761. @code{void (*core_func)(starpu_data_interface_t *, void *)}
  762. In this example, we can ignore the first argument of this function which gives a
  763. description of the input and output buffers (eg. the size and the location of
  764. the matrices). The second argument is a pointer to a buffer passed as an
  765. argument to the codelet by the means of the ''@code{.cl_arg}'' field of the
  766. @code{starpu_task} structure. Be aware that this may be a pointer to a
  767. @emph{copy} of the actual buffer, and not the pointer given by the programmer:
  768. if the codelet modifies this buffer, there is no garantee that the initial
  769. buffer will be modified as well: this for instance implies that the buffer
  770. cannot be used as a synchronization medium.
  771. @subsection Submitting a Task
  772. @example
  773. @c @cartouche
  774. void callback_func(void *callback_arg)
  775. @{
  776. printf("Callback function (arg %x)\n", callback_arg);
  777. @}
  778. int main(int argc, char **argv)
  779. @{
  780. /* initialize StarPU */
  781. starpu_init(NULL);
  782. struct starpu_task *task = starpu_task_create();
  783. task->cl = &cl;
  784. float array[2] = @{1.0f, -1.0f@};
  785. task->cl_arg = &array;
  786. task->cl_arg_size = 2*sizeof(float);
  787. task->callback_func = callback_func;
  788. task->callback_arg = 0x42;
  789. /* starpu_submit_task will be a blocking call */
  790. task->synchronous = 1;
  791. /* submit the task to StarPU */
  792. starpu_submit_task(task);
  793. /* terminate StarPU */
  794. starpu_shutdown();
  795. return 0;
  796. @}
  797. @c @end cartouche
  798. @end example
  799. Before submitting any tasks to StarPU, @code{starpu_init} must be called. The
  800. @code{NULL} argument specifies that we use default configuration. Tasks cannot
  801. be submitted after the termination of StarPU by a call to
  802. @code{starpu_shutdown}.
  803. In the example above, a task structure is allocated by a call to
  804. @code{starpu_task_create}. This function only allocates and fills the
  805. corresponding structure with the default settings (@pxref{starpu_task_create}),
  806. but it does not submit the task to StarPU.
  807. @c not really clear ;)
  808. The ''@code{.cl}'' field is a pointer to the codelet which the task will
  809. execute: in other words, the codelet structure describes which computational
  810. kernel should be offloaded on the different architectures, and the task
  811. structure is a wrapper containing a codelet and the piece of data on which the
  812. codelet should operate.
  813. The optional ''@code{.cl_arg}'' field is a pointer to a buffer (of size
  814. @code{.cl_arg_size}) with some parameters for the kernel
  815. described by the codelet. For instance, if a codelet implements a computational
  816. kernel that multiplies its input vector by a constant, the constant could be
  817. specified by the means of this buffer.
  818. Once a task has been executed, an optional callback function can be called.
  819. While the computational kernel could be offloaded on various architectures, the
  820. callback function is always executed on a CPU. The ''@code{.callback_arg}''
  821. pointer is passed as an argument of the callback. The prototype of a callback
  822. function must be:
  823. @example
  824. void (*callback_function)(void *);
  825. @end example
  826. If the @code{.synchronous} field is non-null, task submission will be
  827. synchronous: the @code{starpu_submit_task} function will not return until the
  828. task was executed. Note that the @code{starpu_shutdown} method does not
  829. guarantee that asynchronous tasks have been executed before it returns.
  830. @node Scaling a Vector
  831. @section Manipulating Data: Scaling a Vector
  832. The previous example has shown how to submit tasks. In this section we show how
  833. StarPU tasks can manipulate data.
  834. Programmers can describe the data layout of their application so that StarPU is
  835. responsible for enforcing data coherency and availability accross the machine.
  836. Instead of handling complex (and non-portable) mechanisms to perform data
  837. movements, programmers only declare which piece of data is accessed and/or
  838. modified by a task, and StarPU makes sure that when a computational kernel
  839. starts somewhere (eg. on a GPU), its data are available locally.
  840. Before submitting those tasks, the programmer first needs to declare the
  841. different pieces of data to StarPU using the @code{starpu_register_*_data}
  842. functions. To ease the development of applications for StarPU, it is possible
  843. to describe multiple types of data layout. A type of data layout is called an
  844. @b{interface}. By default, there are different interfaces available in StarPU:
  845. here we will consider the @b{vector interface}.
  846. The following lines show how to declare an array of @code{n} elements of type
  847. @code{float} using the vector interface:
  848. @example
  849. float tab[n];
  850. starpu_data_handle tab_handle;
  851. starpu_register_vector_data(&tab_handle, 0, tab, n, sizeof(float));
  852. @end example
  853. The first argument, called the @b{data handle}, is an opaque pointer which
  854. designates the array in StarPU. This is also the structure which is used to
  855. describe which data is used by a task.
  856. @c TODO: what is 0 ?
  857. It is possible to construct a StarPU
  858. task that multiplies this vector by a constant factor:
  859. @example
  860. float factor;
  861. struct starpu_task *task = starpu_task_create();
  862. task->cl = &cl;
  863. task->buffers[0].handle = tab_handle;
  864. task->buffers[0].mode = STARPU_RW;
  865. task->cl_arg = &factor;
  866. task->cl_arg_size = sizeof(float);
  867. @end example
  868. Since the factor is constant, it does not need a preliminary declaration, and
  869. can just be passed through the @code{cl_arg} pointer like in the previous
  870. example. The vector parameter is described by its handle.
  871. There are two fields in each element of the @code{buffers} array.
  872. @code{.handle} is the handle of the data, and @code{.mode} specifies how the
  873. kernel will access the data (@code{STARPU_R} for read-only, @code{STARPU_W} for
  874. write-only and @code{STARPU_RW} for read and write access).
  875. The definition of the codelet can be written as follows:
  876. @example
  877. void scal_func(starpu_data_interface_t *buffers, void *arg)
  878. @{
  879. unsigned i;
  880. float *factor = arg;
  881. /* length of the vector */
  882. unsigned n = buffers[0].vector.nx;
  883. /* local copy of the vector pointer */
  884. float *val = (float *)buffers[0].vector.ptr;
  885. for (i = 0; i < n; i++)
  886. val[i] *= *factor;
  887. @}
  888. starpu_codelet cl = @{
  889. .where = CORE,
  890. .core_func = scal_func,
  891. .nbuffers = 1
  892. @};
  893. @end example
  894. The second argument of the @code{scal_func} function contains a pointer to the
  895. parameters of the codelet (given in @code{task->cl_arg}), so that we read the
  896. constant factor from this pointer. The first argument is an array that gives
  897. a description of every buffers passed in the @code{task->buffers}@ array, the
  898. number of which is given by the @code{.nbuffers} field of the codelet structure.
  899. In the @b{vector interface}, the location of the vector (resp. its length)
  900. is accessible in the @code{.vector.ptr} (resp. @code{.vector.nx}) of this
  901. array. Since the vector is accessed in a read-write fashion, any modification
  902. will automatically affect future accesses to that vector made by other tasks.
  903. @node Scaling a Vector (hybrid)
  904. @section Vector Scaling on an Hybrid CPU/GPU Machine
  905. Contrary to the previous examples, the task submitted in the example may not
  906. only be executed by the CPUs, but also by a CUDA device.
  907. TODO
  908. @c ---------------------------------------------------------------------
  909. @c Advanced Topics
  910. @c ---------------------------------------------------------------------
  911. @node Advanced Topics
  912. @chapter Advanced Topics
  913. @bye