starpu.texi 96 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833
  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. * Using StarPU:: How to run StarPU application
  29. * Configuring StarPU:: How to configure StarPU
  30. * StarPU API:: The API to use StarPU
  31. * Advanced Topics:: Advanced use of StarPU
  32. * Basic Examples:: Basic examples of the use of StarPU
  33. * Full source code for the 'Scaling a Vector' example::
  34. @end menu
  35. @c ---------------------------------------------------------------------
  36. @c Introduction to StarPU
  37. @c ---------------------------------------------------------------------
  38. @node Introduction
  39. @chapter Introduction to StarPU
  40. @menu
  41. * Motivation:: Why StarPU ?
  42. * StarPU in a Nutshell:: The Fundamentals of StarPU
  43. @end menu
  44. @node Motivation
  45. @section Motivation
  46. @c complex machines with heterogeneous cores/devices
  47. The use of specialized hardware such as accelerators or coprocessors offers an
  48. interesting approach to overcome the physical limits encountered by processor
  49. architects. As a result, many machines are now equipped with one or several
  50. accelerators (e.g. a GPU), in addition to the usual processor(s). While a lot of
  51. efforts have been devoted to offload computation onto such accelerators, very
  52. little attention as been paid to portability concerns on the one hand, and to the
  53. possibility of having heterogeneous accelerators and processors to interact on the other hand.
  54. StarPU is a runtime system that offers support for heterogeneous multicore
  55. architectures, it not only offers a unified view of the computational resources
  56. (i.e. CPUs and accelerators at the same time), but it also takes care of
  57. efficiently mapping and executing tasks onto an heterogeneous machine while
  58. transparently handling low-level issues in a portable fashion.
  59. @c this leads to a complicated distributed memory design
  60. @c which is not (easily) manageable by hand
  61. @c added value/benefits of StarPU
  62. @c - portability
  63. @c - scheduling, perf. portability
  64. @node StarPU in a Nutshell
  65. @section StarPU in a Nutshell
  66. @menu
  67. * Codelet and Tasks::
  68. * StarPU Data Management Library::
  69. @end menu
  70. From a programming point of view, StarPU is not a new language but a library
  71. that executes tasks explicitly submitted by the application. The data that a
  72. task manipulates are automatically transferred onto the accelerator so that the
  73. programmer does not have to take care of complex data movements. StarPU also
  74. takes particular care of scheduling those tasks efficiently and allows
  75. scheduling experts to implement custom scheduling policies in a portable
  76. fashion.
  77. @c explain the notion of codelet and task (i.e. g(A, B)
  78. @node Codelet and Tasks
  79. @subsection Codelet and Tasks
  80. One of StarPU primary data structure is the @b{codelet}. A codelet describes a
  81. computational kernel that can possibly be implemented on multiple architectures
  82. such as a CPU, a CUDA device or a Cell's SPU.
  83. @c TODO insert illustration f : f_spu, f_cpu, ...
  84. Another important data structure is the @b{task}. Executing a StarPU task
  85. consists in applying a codelet on a data set, on one of the architectures on
  86. which the codelet is implemented. In addition to the codelet that a task
  87. implements, it also describes which data are accessed, and how they are
  88. accessed during the computation (read and/or write).
  89. StarPU tasks are asynchronous: submitting a task to StarPU is a non-blocking
  90. operation. The task structure can also specify a @b{callback} function that is
  91. called once StarPU has properly executed the task. It also contains optional
  92. fields that the application may use to give hints to the scheduler (such as
  93. priority levels).
  94. A task may be identified by a unique 64-bit number which we refer as a @b{tag}.
  95. Task dependencies can be enforced either by the means of callback functions, or
  96. by expressing dependencies between tags.
  97. @c TODO insert illustration f(Ar, Brw, Cr) + ..
  98. @c DSM
  99. @node StarPU Data Management Library
  100. @subsection StarPU Data Management Library
  101. Because StarPU schedules tasks at runtime, data transfers have to be
  102. done automatically and ``just-in-time'' between processing units,
  103. relieving the application programmer from explicit data transfers.
  104. Moreover, to avoid unnecessary transfers, StarPU keeps data
  105. where it was last needed, even if was modified there, and it
  106. allows multiple copies of the same data to reside at the same time on
  107. several processing units as long as it is not modified.
  108. @c ---------------------------------------------------------------------
  109. @c Installing StarPU
  110. @c ---------------------------------------------------------------------
  111. @node Installing StarPU
  112. @chapter Installing StarPU
  113. @menu
  114. * Configuration of StarPU::
  115. * Building and Installing StarPU::
  116. @end menu
  117. StarPU can be built and installed by the standard means of the GNU
  118. autotools. The following chapter is intended to briefly remind how these tools
  119. can be used to install StarPU.
  120. @node Configuration of StarPU
  121. @section Configuration of StarPU
  122. @menu
  123. * Generating Makefiles and configuration scripts::
  124. * Running the configuration::
  125. @end menu
  126. @node Generating Makefiles and configuration scripts
  127. @subsection Generating Makefiles and configuration scripts
  128. This step is not necessary when using the tarball releases of StarPU. If you
  129. are using the source code from the svn repository, you first need to generate
  130. the configure scripts and the Makefiles.
  131. @example
  132. % autoreconf -vfi
  133. @end example
  134. @node Running the configuration
  135. @subsection Running the configuration
  136. @example
  137. % ./configure
  138. @end example
  139. Details about options that are useful to give to @code{./configure} are given in
  140. @ref{Compilation configuration}.
  141. @node Building and Installing StarPU
  142. @section Building and Installing StarPU
  143. @menu
  144. * Building::
  145. * Sanity Checks::
  146. * Installing::
  147. @end menu
  148. @node Building
  149. @subsection Building
  150. @example
  151. % make
  152. @end example
  153. @node Sanity Checks
  154. @subsection Sanity Checks
  155. In order to make sure that StarPU is working properly on the system, it is also
  156. possible to run a test suite.
  157. @example
  158. % make check
  159. @end example
  160. @node Installing
  161. @subsection Installing
  162. In order to install StarPU at the location that was specified during
  163. configuration:
  164. @example
  165. % make install
  166. @end example
  167. @c ---------------------------------------------------------------------
  168. @c Using StarPU
  169. @c ---------------------------------------------------------------------
  170. @node Using StarPU
  171. @chapter Using StarPU
  172. @menu
  173. * Setting flags for compiling and linking applications::
  174. * Running a basic StarPU application::
  175. @end menu
  176. @node Setting flags for compiling and linking applications
  177. @section Setting flags for compiling and linking applications
  178. Compiling and linking an application against StarPU may require to use
  179. specific flags or libraries (for instance @code{CUDA} or @code{libspe2}).
  180. To this end, it is possible to use the @code{pkg-config} tool.
  181. If StarPU was not installed at some standard location, the path of StarPU's
  182. library must be specified in the @code{PKG_CONFIG_PATH} environment variable so
  183. that @code{pkg-config} can find it. For example if StarPU was installed in
  184. @code{$prefix_dir}:
  185. @example
  186. % PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$prefix_dir/lib/pkgconfig
  187. @end example
  188. The flags required to compile or link against StarPU are then
  189. accessible with the following commands:
  190. @example
  191. % pkg-config --cflags libstarpu # options for the compiler
  192. % pkg-config --libs libstarpu # options for the linker
  193. @end example
  194. @node Running a basic StarPU application
  195. @section Running a basic StarPU application
  196. Basic examples using StarPU have been built in the directory
  197. @code{$prefix_dir/lib/starpu/examples/}. You can for example run the
  198. example @code{vector_scal}.
  199. @example
  200. % $prefix_dir/lib/starpu/examples/vector_scal
  201. BEFORE : First element was 1.000000
  202. AFTER First element is 3.140000
  203. %
  204. @end example
  205. @c ---------------------------------------------------------------------
  206. @c Configuration options
  207. @c ---------------------------------------------------------------------
  208. @node Configuring StarPU
  209. @chapter Configuring StarPU
  210. @menu
  211. * Compilation configuration::
  212. * Execution configuration through environment variables::
  213. @end menu
  214. @node Compilation configuration
  215. @section Compilation configuration
  216. The following arguments can be given to the @code{configure} script.
  217. @menu
  218. * Common configuration::
  219. * Configuring workers::
  220. * Advanced configuration::
  221. @end menu
  222. @node Common configuration
  223. @subsection Common configuration
  224. @menu
  225. * --enable-debug::
  226. * --enable-fast::
  227. * --enable-verbose::
  228. * --enable-coverage::
  229. @end menu
  230. @node --enable-debug
  231. @subsubsection @code{--enable-debug}
  232. @table @asis
  233. @item @emph{Description}:
  234. Enable debugging messages.
  235. @end table
  236. @node --enable-fast
  237. @subsubsection @code{--enable-fast}
  238. @table @asis
  239. @item @emph{Description}:
  240. Do not enforce assertions, saves a lot of time spent to compute them otherwise.
  241. @end table
  242. @node --enable-verbose
  243. @subsubsection @code{--enable-verbose}
  244. @table @asis
  245. @item @emph{Description}:
  246. Augment the verbosity of the debugging messages.
  247. @end table
  248. @node --enable-coverage
  249. @subsubsection @code{--enable-coverage}
  250. @table @asis
  251. @item @emph{Description}:
  252. Enable flags for the coverage tool.
  253. @end table
  254. @node Configuring workers
  255. @subsection Configuring workers
  256. @menu
  257. * --disable-cpu::
  258. * --enable-maxcudadev::
  259. * --disable-cuda::
  260. * --with-cuda-dir::
  261. * --enable-maxopencldev::
  262. * --disable-opencl::
  263. * --with-opencl-dir::
  264. * --enable-gordon::
  265. * --with-gordon-dir::
  266. @end menu
  267. @node --disable-cpu
  268. @subsubsection @code{--disable-cpu}
  269. @table @asis
  270. @item @emph{Description}:
  271. Disable the use of CPUs of the machine. Only GPUs etc. will be used.
  272. @end table
  273. @node --enable-maxcudadev
  274. @subsubsection @code{--enable-maxcudadev=<number>}
  275. @table @asis
  276. @item @emph{Description}:
  277. Defines the maximum number of CUDA devices that StarPU will support, then
  278. available as the @code{STARPU_MAXCUDADEVS} macro.
  279. @end table
  280. @node --disable-cuda
  281. @subsubsection @code{--disable-cuda}
  282. @table @asis
  283. @item @emph{Description}:
  284. Disable the use of CUDA, even if a valid CUDA installation was detected.
  285. @end table
  286. @node --with-cuda-dir
  287. @subsubsection @code{--with-cuda-dir=<path>}
  288. @table @asis
  289. @item @emph{Description}:
  290. Specify the directory where CUDA is installed. This directory should notably contain
  291. @code{include/cuda.h}.
  292. @end table
  293. @node --enable-maxopencldev
  294. @subsubsection @code{--enable-maxopencldev=<number>}
  295. @table @asis
  296. @item @emph{Description}:
  297. Defines the maximum number of OpenCL devices that StarPU will support, then
  298. available as the @code{STARPU_MAXOPENCLDEVS} macro.
  299. @end table
  300. @node --disable-opencl
  301. @subsubsection @code{--disable-opencl}
  302. @table @asis
  303. @item @emph{Description}:
  304. Disable the use of OpenCL, even if the SDK is detected.
  305. @end table
  306. @node --with-opencl-dir
  307. @subsubsection @code{--with-opencl-dir=<path>}
  308. @table @asis
  309. @item @emph{Description}:
  310. Specify the location of the OpenCL SDK. This directory should notably contain
  311. @code{include/CL/cl.h}.
  312. @end table
  313. @node --enable-gordon
  314. @subsubsection @code{--enable-gordon}
  315. @table @asis
  316. @item @emph{Description}:
  317. Enable the use of the Gordon runtime for Cell SPUs.
  318. @c TODO: rather default to enabled when detected
  319. @end table
  320. @node --with-gordon-dir
  321. @subsubsection @code{--with-gordon-dir=<path>}
  322. @table @asis
  323. @item @emph{Description}:
  324. Specify the location of the Gordon SDK.
  325. @end table
  326. @node Advanced configuration
  327. @subsection Advanced configuration
  328. @menu
  329. * --enable-perf-debug::
  330. * --enable-model-debug::
  331. * --enable-stats::
  332. * --enable-maxbuffers::
  333. * --enable-allocation-cache::
  334. * --enable-opengl-render::
  335. * --enable-blas-lib::
  336. * --with-magma::
  337. * --with-fxt::
  338. * --with-perf-model-dir::
  339. * --with-mpicc::
  340. * --with-mpi::
  341. * --with-goto-dir::
  342. * --with-atlas-dir::
  343. @end menu
  344. @node --enable-perf-debug
  345. @subsubsection @code{--enable-perf-debug}
  346. @table @asis
  347. @item @emph{Description}:
  348. Enable performance debugging.
  349. @end table
  350. @node --enable-model-debug
  351. @subsubsection @code{--enable-model-debug}
  352. @table @asis
  353. @item @emph{Description}:
  354. Enable performance model debugging.
  355. @end table
  356. @node --enable-stats
  357. @subsubsection @code{--enable-stats}
  358. @table @asis
  359. @item @emph{Description}:
  360. Enable statistics.
  361. @end table
  362. @node --enable-maxbuffers
  363. @subsubsection @code{--enable-maxbuffers=<nbuffers>}
  364. @table @asis
  365. @item @emph{Description}:
  366. Define the maximum number of buffers that tasks will be able to take
  367. as parameters, then available as the @code{STARPU_NMAXBUFS} macro.
  368. @end table
  369. @node --enable-allocation-cache
  370. @subsubsection @code{--enable-allocation-cache}
  371. @table @asis
  372. @item @emph{Description}:
  373. Enable the use of a data allocation cache to avoid the cost of it with
  374. CUDA. Still experimental.
  375. @end table
  376. @node --enable-opengl-render
  377. @subsubsection @code{--enable-opengl-render}
  378. @table @asis
  379. @item @emph{Description}:
  380. Enable the use of OpenGL for the rendering of some examples.
  381. @c TODO: rather default to enabled when detected
  382. @end table
  383. @node --enable-blas-lib
  384. @subsubsection @code{--enable-blas-lib=<name>}
  385. @table @asis
  386. @item @emph{Description}:
  387. Specify the blas library to be used by some of the examples. The
  388. library has to be 'atlas' or 'goto'.
  389. @end table
  390. @node --with-magma
  391. @subsubsection @code{--with-magma=<path>}
  392. @table @asis
  393. @item @emph{Description}:
  394. Specify where magma is installed.
  395. @end table
  396. @node --with-fxt
  397. @subsubsection @code{--with-fxt=<path>}
  398. @table @asis
  399. @item @emph{Description}:
  400. Specify the location of FxT (for generating traces and rendering them
  401. using ViTE). This directory should notably contain
  402. @code{include/fxt/fxt.h}.
  403. @end table
  404. @node --with-perf-model-dir
  405. @subsubsection @code{--with-perf-model-dir=<dir>}
  406. @table @asis
  407. @item @emph{Description}:
  408. Specify where performance models should be stored (instead of defaulting to the
  409. current user's home).
  410. @end table
  411. @node --with-mpicc
  412. @subsubsection @code{--with-mpicc=<path to mpicc>}
  413. @table @asis
  414. @item @emph{Description}:
  415. Specify the location of the @code{mpicc} compiler to be used for starpumpi.
  416. @c TODO: also just use AC_PROG
  417. @end table
  418. @node --with-mpi
  419. @subsubsection @code{--with-mpi}
  420. @table @asis
  421. @item @emph{Description}:
  422. Enable building libstarpumpi.
  423. @c TODO: rather just use the availability of mpicc instead of a second option
  424. @end table
  425. @node --with-goto-dir
  426. @subsubsection @code{--with-goto-dir=<dir>}
  427. @table @asis
  428. @item @emph{Description}:
  429. Specify the location of GotoBLAS.
  430. @end table
  431. @node --with-atlas-dir
  432. @subsubsection @code{--with-atlas-dir=<dir>}
  433. @table @asis
  434. @item @emph{Description}:
  435. Specify the location of ATLAS. This directory should notably contain
  436. @code{include/cblas.h}.
  437. @end table
  438. @c ---------------------------------------------------------------------
  439. @c Environment variables
  440. @c ---------------------------------------------------------------------
  441. @node Execution configuration through environment variables
  442. @section Execution configuration through environment variables
  443. @menu
  444. * Workers:: Configuring workers
  445. * Scheduling:: Configuring the Scheduling engine
  446. * Misc:: Miscellaneous and debug
  447. @end menu
  448. Note: the values given in @code{starpu_conf} structure passed when
  449. calling @code{starpu_init} will override the values of the environment
  450. variables.
  451. @node Workers
  452. @subsection Configuring workers
  453. @menu
  454. * STARPU_NCPUS:: Number of CPU workers
  455. * STARPU_NCUDA:: Number of CUDA workers
  456. * STARPU_NOPENCL:: Number of OpenCL workers
  457. * STARPU_NGORDON:: Number of SPU workers (Cell)
  458. * STARPU_WORKERS_CPUID:: Bind workers to specific CPUs
  459. * STARPU_WORKERS_CUDAID:: Select specific CUDA devices
  460. * STARPU_WORKERS_OPENCLID:: Select specific OpenCL devices
  461. @end menu
  462. @node STARPU_NCPUS
  463. @subsubsection @code{STARPU_NCPUS} -- Number of CPU workers
  464. @table @asis
  465. @item @emph{Description}:
  466. Specify the maximum number of CPU workers. Note that StarPU will not allocate
  467. more CPUs than there are physical CPUs, and that some CPUs are used to control
  468. the accelerators.
  469. @end table
  470. @node STARPU_NCUDA
  471. @subsubsection @code{STARPU_NCUDA} -- Number of CUDA workers
  472. @table @asis
  473. @item @emph{Description}:
  474. Specify the maximum number of CUDA devices that StarPU can use. If
  475. @code{STARPU_NCUDA} is lower than the number of physical devices, it is
  476. possible to select which CUDA devices should be used by the means of the
  477. @code{STARPU_WORKERS_CUDAID} environment variable.
  478. @end table
  479. @node STARPU_NOPENCL
  480. @subsubsection @code{STARPU_NOPENCL} -- Number of OpenCL workers
  481. @table @asis
  482. @item @emph{Description}:
  483. OpenCL equivalent of the @code{STARPU_NCUDA} environment variable.
  484. @end table
  485. @node STARPU_NGORDON
  486. @subsubsection @code{STARPU_NGORDON} -- Number of SPU workers (Cell)
  487. @table @asis
  488. @item @emph{Description}:
  489. Specify the maximum number of SPUs that StarPU can use.
  490. @end table
  491. @node STARPU_WORKERS_CPUID
  492. @subsubsection @code{STARPU_WORKERS_CPUID} -- Bind workers to specific CPUs
  493. @table @asis
  494. @item @emph{Description}:
  495. Passing an array of integers (starting from 0) in @code{STARPU_WORKERS_CPUID}
  496. specifies on which logical CPU the different workers should be
  497. bound. For instance, if @code{STARPU_WORKERS_CPUID = "1 3 0 2"}, the first
  498. worker will be bound to logical CPU #1, the second CPU worker will be bound to
  499. logical CPU #3 and so on. Note that the logical ordering of the CPUs is either
  500. determined by the OS, or provided by the @code{hwloc} library in case it is
  501. available.
  502. Note that the first workers correspond to the CUDA workers, then come the
  503. OpenCL and the SPU, and finally the CPU workers. For example if
  504. we have @code{STARPU_NCUDA=1}, @code{STARPU_NOPENCL=1}, @code{STARPU_NCPUS=2}
  505. and @code{STARPU_WORKERS_CPUID = "0 2 1 3"}, the CUDA device will be controlled
  506. by logical CPU #0, the OpenCL device will be controlled by logical CPU #2, and
  507. the logical CPUs #1 and #3 will be used by the CPU workers.
  508. If the number of workers is larger than the array given in
  509. @code{STARPU_WORKERS_CPUID}, the workers are bound to the logical CPUs in a
  510. round-robin fashion: if @code{STARPU_WORKERS_CPUID = "0 1"}, the first and the
  511. third (resp. second and fourth) workers will be put on CPU #0 (resp. CPU #1).
  512. This variable is ignored if the @code{use_explicit_workers_bindid} flag of the
  513. @code{starpu_conf} structure passed to @code{starpu_init} is set.
  514. @end table
  515. @node STARPU_WORKERS_CUDAID
  516. @subsubsection @code{STARPU_WORKERS_CUDAID} -- Select specific CUDA devices
  517. @table @asis
  518. @item @emph{Description}:
  519. Similarly to the @code{STARPU_WORKERS_CPUID} environment variable, it is
  520. possible to select which CUDA devices should be used by StarPU. On a machine
  521. equipped with 4 GPUs, setting @code{STARPU_WORKERS_CUDAID = "1 3"} and
  522. @code{STARPU_NCUDA=2} specifies that 2 CUDA workers should be created, and that
  523. they should use CUDA devices #1 and #3 (the logical ordering of the devices is
  524. the one reported by CUDA).
  525. This variable is ignored if the @code{use_explicit_workers_cuda_gpuid} flag of
  526. the @code{starpu_conf} structure passed to @code{starpu_init} is set.
  527. @end table
  528. @node STARPU_WORKERS_OPENCLID
  529. @subsubsection @code{STARPU_WORKERS_OPENCLID} -- Select specific OpenCL devices
  530. @table @asis
  531. @item @emph{Description}:
  532. OpenCL equivalent of the @code{STARPU_WORKERS_CUDAID} environment variable.
  533. This variable is ignored if the @code{use_explicit_workers_opencl_gpuid} flag of
  534. the @code{starpu_conf} structure passed to @code{starpu_init} is set.
  535. @end table
  536. @node Scheduling
  537. @subsection Configuring the Scheduling engine
  538. @menu
  539. * STARPU_SCHED:: Scheduling policy
  540. * STARPU_CALIBRATE:: Calibrate performance models
  541. * STARPU_PREFETCH:: Use data prefetch
  542. * STARPU_SCHED_ALPHA:: Computation factor
  543. * STARPU_SCHED_BETA:: Communication factor
  544. @end menu
  545. @node STARPU_SCHED
  546. @subsubsection @code{STARPU_SCHED} -- Scheduling policy
  547. @table @asis
  548. @item @emph{Description}:
  549. This chooses between the different scheduling policies proposed by StarPU: work
  550. random, stealing, greedy, with performance models, etc.
  551. Use @code{STARPU_SCHED=help} to get the list of available schedulers.
  552. @end table
  553. @node STARPU_CALIBRATE
  554. @subsubsection @code{STARPU_CALIBRATE} -- Calibrate performance models
  555. @table @asis
  556. @item @emph{Description}:
  557. If this variable is set to 1, the performance models are calibrated during
  558. the execution. If it is set to 2, the previous values are dropped to restart
  559. calibration from scratch.
  560. Note: this currently only applies to dm and dmda scheduling policies.
  561. @end table
  562. @node STARPU_PREFETCH
  563. @subsubsection @code{STARPU_PREFETCH} -- Use data prefetch
  564. @table @asis
  565. @item @emph{Description}:
  566. If this variable is set, data prefetching will be enabled, that is when a task is
  567. scheduled to be executed e.g. on a GPU, StarPU will request an asynchronous
  568. transfer in advance, so that data is already present on the GPU when the task
  569. starts. As a result, computation and data transfers are overlapped.
  570. @end table
  571. @node STARPU_SCHED_ALPHA
  572. @subsubsection @code{STARPU_SCHED_ALPHA} -- Computation factor
  573. @table @asis
  574. @item @emph{Description}:
  575. To estimate the cost of a task StarPU takes into account the estimated
  576. computation time (obtained thanks to performance models). The alpha factor is
  577. the coefficient to be applied to it before adding it to the communication part.
  578. @end table
  579. @node STARPU_SCHED_BETA
  580. @subsubsection @code{STARPU_SCHED_BETA} -- Communication factor
  581. @table @asis
  582. @item @emph{Description}:
  583. To estimate the cost of a task StarPU takes into account the estimated
  584. data transfer time (obtained thanks to performance models). The beta factor is
  585. the coefficient to be applied to it before adding it to the computation part.
  586. @end table
  587. @node Misc
  588. @subsection Miscellaneous and debug
  589. @menu
  590. * STARPU_LOGFILENAME:: Select debug file name
  591. @end menu
  592. @node STARPU_LOGFILENAME
  593. @subsubsection @code{STARPU_LOGFILENAME} -- Select debug file name
  594. @table @asis
  595. @item @emph{Description}:
  596. This variable specify in which file the debugging output should be saved to.
  597. @end table
  598. @c ---------------------------------------------------------------------
  599. @c StarPU API
  600. @c ---------------------------------------------------------------------
  601. @node StarPU API
  602. @chapter StarPU API
  603. @menu
  604. * Initialization and Termination:: Initialization and Termination methods
  605. * Workers' Properties:: Methods to enumerate workers' properties
  606. * Data Library:: Methods to manipulate data
  607. * Data Interfaces::
  608. * Data Partition::
  609. * Codelets and Tasks:: Methods to construct tasks
  610. * Explicit Dependencies:: Explicit Dependencies
  611. * Implicit Data Dependencies:: Implicit Data Dependencies
  612. * Profiling API:: Profiling API
  613. * CUDA extensions:: CUDA extensions
  614. * OpenCL extensions:: OpenCL extensions
  615. * Cell extensions:: Cell extensions
  616. * Miscellaneous helpers::
  617. @end menu
  618. @node Initialization and Termination
  619. @section Initialization and Termination
  620. @menu
  621. * starpu_init:: Initialize StarPU
  622. * struct starpu_conf:: StarPU runtime configuration
  623. * starpu_shutdown:: Terminate StarPU
  624. @end menu
  625. @node starpu_init
  626. @subsection @code{starpu_init} -- Initialize StarPU
  627. @table @asis
  628. @item @emph{Description}:
  629. This is StarPU initialization method, which must be called prior to any other
  630. StarPU call. It is possible to specify StarPU's configuration (e.g. scheduling
  631. policy, number of cores, ...) by passing a non-null argument. Default
  632. configuration is used if the passed argument is @code{NULL}.
  633. @item @emph{Return value}:
  634. Upon successful completion, this function returns 0. Otherwise, @code{-ENODEV}
  635. indicates that no worker was available (so that StarPU was not initialized).
  636. @item @emph{Prototype}:
  637. @code{int starpu_init(struct starpu_conf *conf);}
  638. @end table
  639. @node struct starpu_conf
  640. @subsection @code{struct starpu_conf} -- StarPU runtime configuration
  641. @table @asis
  642. @item @emph{Description}:
  643. This structure is passed to the @code{starpu_init} function in order
  644. to configure StarPU.
  645. When the default value is used, StarPU automatically selects the number
  646. of processing units and takes the default scheduling policy. This parameter
  647. overwrites the equivalent environment variables.
  648. @item @emph{Fields}:
  649. @table @asis
  650. @item @code{sched_policy_name} (default = NULL):
  651. This is the name of the scheduling policy. This can also be specified with the
  652. @code{STARPU_SCHED} environment variable.
  653. @item @code{sched_policy} (default = NULL):
  654. This is the definition of the scheduling policy. This field is ignored
  655. if @code{sched_policy_name} is set.
  656. @item @code{ncpus} (default = -1):
  657. This is the maximum number of CPU cores that StarPU can use. This can also be
  658. specified with the @code{STARPU_NCPUS} environment variable.
  659. @item @code{ncuda} (default = -1):
  660. This is the maximum number of CUDA devices that StarPU can use. This can also be
  661. specified with the @code{STARPU_NCUDA} environment variable.
  662. @item @code{nopencl} (default = -1):
  663. This is the maximum number of OpenCL devices that StarPU can use. This can also be
  664. specified with the @code{STARPU_NOPENCL} environment variable.
  665. @item @code{nspus} (default = -1):
  666. This is the maximum number of Cell SPUs that StarPU can use. This can also be
  667. specified with the @code{STARPU_NGORDON} environment variable.
  668. @item @code{use_explicit_workers_bindid} (default = 0)
  669. If this flag is set, the @code{workers_bindid} array indicates where the
  670. different workers are bound, otherwise StarPU automatically selects where to
  671. bind the different workers unless the @code{STARPU_WORKERS_CPUID} environment
  672. variable is set. The @code{STARPU_WORKERS_CPUID} environment variable is
  673. ignored if the @code{use_explicit_workers_bindid} flag is set.
  674. @item @code{workers_bindid[STARPU_NMAXWORKERS]}
  675. If the @code{use_explicit_workers_bindid} flag is set, this array indicates
  676. where to bind the different workers. The i-th entry of the
  677. @code{workers_bindid} indicates the logical identifier of the processor which
  678. should execute the i-th worker. Note that the logical ordering of the CPUs is
  679. either determined by the OS, or provided by the @code{hwloc} library in case it
  680. is available.
  681. When this flag is set, the @ref{STARPU_WORKERS_CPUID} environment variable is
  682. ignored.
  683. @item @code{use_explicit_workers_cuda_gpuid} (default = 0)
  684. If this flag is set, the CUDA workers will be attached to the CUDA devices
  685. specified in the @code{workers_cuda_gpuid} array. Otherwise, StarPU affects the
  686. CUDA devices in a round-robin fashion.
  687. When this flag is set, the @ref{STARPU_WORKERS_CUDAID} environment variable is
  688. ignored.
  689. @item @code{workers_cuda_gpuid[STARPU_NMAXWORKERS]}
  690. If the @code{use_explicit_workers_cuda_gpuid} flag is set, this array contains
  691. the logical identifiers of the CUDA devices (as used by @code{cudaGetDevice}).
  692. @item @code{use_explicit_workers_opencl_gpuid} (default = 0)
  693. If this flag is set, the OpenCL workers will be attached to the OpenCL devices
  694. specified in the @code{workers_opencl_gpuid} array. Otherwise, StarPU affects the
  695. OpenCL devices in a round-robin fashion.
  696. @item @code{workers_opencl_gpuid[STARPU_NMAXWORKERS]}:
  697. @item @code{calibrate} (default = 0):
  698. If this flag is set, StarPU will calibrate the performance models when
  699. executing tasks. This can also be specified with the @code{STARPU_CALIBRATE}
  700. environment variable.
  701. @end table
  702. @end table
  703. @node starpu_shutdown
  704. @subsection @code{starpu_shutdown} -- Terminate StarPU
  705. @table @asis
  706. @item @emph{Description}:
  707. This is StarPU termination method. It must be called at the end of the
  708. application: statistics and other post-mortem debugging information are not
  709. guaranteed to be available until this method has been called.
  710. @item @emph{Prototype}:
  711. @code{void starpu_shutdown(void);}
  712. @end table
  713. @node Workers' Properties
  714. @section Workers' Properties
  715. @menu
  716. * starpu_worker_get_count:: Get the number of processing units
  717. * starpu_cpu_worker_get_count:: Get the number of CPU controlled by StarPU
  718. * starpu_cuda_worker_get_count:: Get the number of CUDA devices controlled by StarPU
  719. * starpu_opencl_worker_get_count:: Get the number of OpenCL devices controlled by StarPU
  720. * starpu_spu_worker_get_count:: Get the number of Cell SPUs controlled by StarPU
  721. * starpu_worker_get_id:: Get the identifier of the current worker
  722. * starpu_worker_get_devid:: Get the device identifier of a worker
  723. * starpu_worker_get_type:: Get the type of processing unit associated to a worker
  724. * starpu_worker_get_name:: Get the name of a worker
  725. * starpu_worker_get_memory_node:: Get the memory node of a worker
  726. @end menu
  727. @node starpu_worker_get_count
  728. @subsection @code{starpu_worker_get_count} -- Get the number of processing units
  729. @table @asis
  730. @item @emph{Description}:
  731. This function returns the number of workers (i.e. processing units executing
  732. StarPU tasks). The returned value should be at most @code{STARPU_NMAXWORKERS}.
  733. @item @emph{Prototype}:
  734. @code{unsigned starpu_worker_get_count(void);}
  735. @end table
  736. @node starpu_cpu_worker_get_count
  737. @subsection @code{starpu_cpu_worker_get_count} -- Get the number of CPU controlled by StarPU
  738. @table @asis
  739. @item @emph{Description}:
  740. This function returns the number of CPUs controlled by StarPU. The returned
  741. value should be at most @code{STARPU_NMAXCPUS}.
  742. @item @emph{Prototype}:
  743. @code{unsigned starpu_cpu_worker_get_count(void);}
  744. @end table
  745. @node starpu_cuda_worker_get_count
  746. @subsection @code{starpu_cuda_worker_get_count} -- Get the number of CUDA devices controlled by StarPU
  747. @table @asis
  748. @item @emph{Description}:
  749. This function returns the number of CUDA devices controlled by StarPU. The returned
  750. value should be at most @code{STARPU_MAXCUDADEVS}.
  751. @item @emph{Prototype}:
  752. @code{unsigned starpu_cuda_worker_get_count(void);}
  753. @end table
  754. @node starpu_opencl_worker_get_count
  755. @subsection @code{starpu_opencl_worker_get_count} -- Get the number of OpenCL devices controlled by StarPU
  756. @table @asis
  757. @item @emph{Description}:
  758. This function returns the number of OpenCL devices controlled by StarPU. The returned
  759. value should be at most @code{STARPU_MAXOPENCLDEVS}.
  760. @item @emph{Prototype}:
  761. @code{unsigned starpu_opencl_worker_get_count(void);}
  762. @end table
  763. @node starpu_spu_worker_get_count
  764. @subsection @code{starpu_spu_worker_get_count} -- Get the number of Cell SPUs controlled by StarPU
  765. @table @asis
  766. @item @emph{Description}:
  767. This function returns the number of Cell SPUs controlled by StarPU.
  768. @item @emph{Prototype}:
  769. @code{unsigned starpu_opencl_worker_get_count(void);}
  770. @end table
  771. @node starpu_worker_get_id
  772. @subsection @code{starpu_worker_get_id} -- Get the identifier of the current worker
  773. @table @asis
  774. @item @emph{Description}:
  775. This function returns the identifier of the worker associated to the calling
  776. thread. The returned value is either -1 if the current context is not a StarPU
  777. worker (i.e. when called from the application outside a task or a callback), or
  778. an integer between 0 and @code{starpu_worker_get_count() - 1}.
  779. @item @emph{Prototype}:
  780. @code{int starpu_worker_get_id(void);}
  781. @end table
  782. @node starpu_worker_get_devid
  783. @subsection @code{starpu_worker_get_devid} -- Get the device identifier of a worker
  784. @table @asis
  785. @item @emph{Description}:
  786. This functions returns the device id of the worker associated to an identifier
  787. (as returned by the @code{starpu_worker_get_id} function). In the case of a
  788. CUDA worker, this device identifier is the logical device identifier exposed by
  789. CUDA (used by the @code{cudaGetDevice} function for instance). The device
  790. identifier of a CPU worker is the logical identifier of the core on which the
  791. worker was bound; this identifier is either provided by the OS or by the
  792. @code{hwloc} library in case it is available.
  793. @item @emph{Prototype}:
  794. @code{int starpu_worker_get_devid(int id);}
  795. @end table
  796. @node starpu_worker_get_type
  797. @subsection @code{starpu_worker_get_type} -- Get the type of processing unit associated to a worker
  798. @table @asis
  799. @item @emph{Description}:
  800. This function returns the type of worker associated to an identifier (as
  801. returned by the @code{starpu_worker_get_id} function). The returned value
  802. indicates the architecture of the worker: @code{STARPU_CPU_WORKER} for a CPU
  803. core, @code{STARPU_CUDA_WORKER} for a CUDA device,
  804. @code{STARPU_OPENCL_WORKER} for a OpenCL device, and
  805. @code{STARPU_GORDON_WORKER} for a Cell SPU. The value returned for an invalid
  806. identifier is unspecified.
  807. @item @emph{Prototype}:
  808. @code{enum starpu_archtype starpu_worker_get_type(int id);}
  809. @end table
  810. @node starpu_worker_get_name
  811. @subsection @code{starpu_worker_get_name} -- Get the name of a worker
  812. @table @asis
  813. @item @emph{Description}:
  814. StarPU associates a unique human readable string to each processing unit. This
  815. function copies at most the @code{maxlen} first bytes of the unique string
  816. associated to a worker identified by its identifier @code{id} into the
  817. @code{dst} buffer. The caller is responsible for ensuring that the @code{dst}
  818. is a valid pointer to a buffer of @code{maxlen} bytes at least. Calling this
  819. function on an invalid identifier results in an unspecified behaviour.
  820. @item @emph{Prototype}:
  821. @code{void starpu_worker_get_name(int id, char *dst, size_t maxlen);}
  822. @end table
  823. @node starpu_worker_get_memory_node
  824. @subsection @code{starpu_worker_get_memory_node} -- Get the memory node of a worker
  825. @table @asis
  826. @item @emph{Description}:
  827. This function returns the identifier of the memory node associated to the
  828. worker identified by @code{workerid}.
  829. @item @emph{Prototype}:
  830. @code{unsigned starpu_worker_get_memory_node(unsigned workerid);}
  831. @end table
  832. @node Data Library
  833. @section Data Library
  834. This section describes the data management facilities provided by StarPU.
  835. We show how to use existing data interfaces in @ref{Data Interfaces}, but developers can
  836. design their own data interfaces if required.
  837. @menu
  838. * starpu_access_mode:: starpu_access_mode
  839. * unsigned memory_node:: Memory node
  840. * starpu_data_handle:: StarPU opaque data handle
  841. * void *interface:: StarPU data interface
  842. * starpu_data_register:: Register a piece of data to StarPU
  843. * starpu_data_unregister:: Unregister a piece of data from StarPU
  844. @end menu
  845. @node starpu_access_mode
  846. @subsection @code{starpu_access_mode} -- Data access mode
  847. This datatype describes a data access mode. The different available modes are:
  848. @table @asis
  849. @table @asis
  850. @item @code{STARPU_R} read-only mode.
  851. @item @code{STARPU_W} write-only mode.
  852. @item @code{STARPU_RW} read-write mode. This is equivalent to @code{STARPU_R|STARPU_W}.
  853. @item @code{STARPU_SCRATCH} scratch memory. A temporary buffer is allocated for the task, but StarPU does not enforce data consistency.
  854. @end table
  855. @end table
  856. @node unsigned memory_node
  857. @subsection @code{unsigned memory_node} -- Memory node
  858. @table @asis
  859. @item @emph{Description}:
  860. Every worker is associated to a memory node which is a logical abstraction of
  861. the address space from which the processing unit gets its data. For instance,
  862. the memory node associated to the different CPU workers represents main memory
  863. (RAM), the memory node associated to a GPU is DRAM embedded on the device.
  864. Every memory node is identified by a logical index which is accessible from the
  865. @code{starpu_worker_get_memory_node} function. When registering a piece of data
  866. to StarPU, the specified memory node indicates where the piece of data
  867. initially resides (we also call this memory node the home node of a piece of
  868. data).
  869. @end table
  870. @node starpu_data_handle
  871. @subsection @code{starpu_data_handle} -- StarPU opaque data handle
  872. @table @asis
  873. @item @emph{Description}:
  874. StarPU uses @code{starpu_data_handle} as an opaque handle to manage a piece of
  875. data. Once a piece of data has been registered to StarPU, it is associated to a
  876. @code{starpu_data_handle} which keeps track of the state of the piece of data
  877. over the entire machine, so that we can maintain data consistency and locate
  878. data replicates for instance.
  879. @end table
  880. @node void *interface
  881. @subsection @code{void *interface} -- StarPU data interface
  882. @table @asis
  883. @item @emph{Description}:
  884. Data management is done at a high-level in StarPU: rather than accessing a mere
  885. list of contiguous buffers, the tasks may manipulate data that are described by
  886. a high-level construct which we call data interface.
  887. An example of data interface is the "vector" interface which describes a
  888. contiguous data array on a spefic memory node. This interface is a simple
  889. structure containing the number of elements in the array, the size of the
  890. elements, and the address of the array in the appropriate address space (this
  891. address may be invalid if there is no valid copy of the array in the memory
  892. node). More informations on the data interfaces provided by StarPU are
  893. given in @ref{Data Interfaces}.
  894. When a piece of data managed by StarPU is used by a task, the task
  895. implementation is given a pointer to an interface describing a valid copy of
  896. the data that is accessible from the current processing unit.
  897. @end table
  898. @node starpu_data_register
  899. @subsection @code{starpu_data_register} -- Register a piece of data to StarPU
  900. @table @asis
  901. @item @emph{Description}:
  902. Register a piece of data into the handle located at the @code{handleptr}
  903. address. The @code{interface} buffer contains the initial description of the
  904. data in the home node. The @code{ops} argument is a pointer to a structure
  905. describing the different methods used to manipulate this type of interface. See
  906. @ref{struct starpu_data_interface_ops_t} for more details on this structure.
  907. If @code{home_node} is not a valid memory node, StarPU will automatically
  908. allocate the memory described by the interface the data handle is used for the
  909. first time in write-only mode. Once such data handle has been automatically
  910. allocated, it is possible to access it using any access mode.
  911. Note that StarPU supplies a set of predefined types of interface (eg. vector or
  912. matrix) which can be registered by the means of helper functions (eg.
  913. @code{starpu_vector_data_register} or @code{starpu_matrix_data_register}).
  914. @item @emph{Prototype}:
  915. @code{void starpu_data_register(starpu_data_handle *handleptr,
  916. uint32_t home_node,
  917. void *interface,
  918. struct starpu_data_interface_ops_t *ops);}
  919. @end table
  920. @node starpu_data_unregister
  921. @subsection @code{starpu_data_unregister} -- Unregister a piece of data from StarPU
  922. @table @asis
  923. @item @emph{Description}:
  924. This function unregisters a data handle from StarPU. If the data was
  925. automatically allocated by StarPU because the home node was not valid, all
  926. automatically allocated buffers are freed. Otherwise, a valid copy of the data
  927. is put back into the home node in the buffer that was initially registered.
  928. Using a data handle that has been unregistered from StarPU results in an
  929. undefined behaviour.
  930. @item @emph{Prototype}:
  931. @code{void starpu_data_unregister(starpu_data_handle handle);}
  932. @end table
  933. @c user interaction with the DSM
  934. @c void starpu_data_sync_with_mem(struct starpu_data_state_t *state);
  935. @c void starpu_notify_data_modification(struct starpu_data_state_t *state, uint32_t modifying_node);
  936. @c struct starpu_data_interface_ops_t *ops
  937. @node Data Interfaces
  938. @section Data Interfaces
  939. @menu
  940. * Variable Interface::
  941. * Vector Interface::
  942. * Matrix Interface::
  943. * BCSR Interface for Sparse Matrices (Blocked Compressed Sparse Row Representation)::
  944. * CSR Interface for Sparse Matrices (Compressed Sparse Row Representation)::
  945. * Block Interface::
  946. @end menu
  947. @node Variable Interface
  948. @subsection Variable Interface
  949. @table @asis
  950. @item @emph{Description}:
  951. @item @emph{Prototype}:
  952. @code{void starpu_variable_data_register(starpu_data_handle *handle,
  953. uint32_t home_node,
  954. uintptr_t ptr, size_t elemsize);}
  955. @item @emph{Example}:
  956. @cartouche
  957. @smallexample
  958. float var;
  959. starpu_data_handle var_handle;
  960. starpu_variable_data_register(&var_handle, 0, (uintptr_t)&var, sizeof(var));
  961. @end smallexample
  962. @end cartouche
  963. @end table
  964. @node Vector Interface
  965. @subsection Vector Interface
  966. @table @asis
  967. @item @emph{Description}:
  968. @item @emph{Prototype}:
  969. @code{void starpu_vector_data_register(starpu_data_handle *handle, uint32_t home_node,
  970. uintptr_t ptr, uint32_t nx, size_t elemsize);}
  971. @item @emph{Example}:
  972. @cartouche
  973. @smallexample
  974. float vector[NX];
  975. starpu_data_handle vector_handle;
  976. starpu_vector_data_register(&vector_handle, 0, (uintptr_t)vector, NX,
  977. sizeof(vector[0]));
  978. @end smallexample
  979. @end cartouche
  980. @end table
  981. @node Matrix Interface
  982. @subsection Matrix Interface
  983. @table @asis
  984. @item @emph{Description}:
  985. @item @emph{Prototype}:
  986. @code{void starpu_matrix_data_register(starpu_data_handle *handle, uint32_t home_node,
  987. uintptr_t ptr, uint32_t ld, uint32_t nx,
  988. uint32_t ny, size_t elemsize);}
  989. @item @emph{Example}:
  990. @cartouche
  991. @smallexample
  992. float *matrix;
  993. starpu_data_handle matrix_handle;
  994. matrix = (float*)malloc(width * height * sizeof(float));
  995. starpu_matrix_data_register(&matrix_handle, 0, (uintptr_t)matrix,
  996. width, width, height, sizeof(float));
  997. @end smallexample
  998. @end cartouche
  999. @end table
  1000. @node BCSR Interface for Sparse Matrices (Blocked Compressed Sparse Row Representation)
  1001. @subsection BCSR Interface for Sparse Matrices (Blocked Compressed Sparse Row Representation)
  1002. @table @asis
  1003. @item @emph{Description}:
  1004. @item @emph{Prototype}:
  1005. @code{void starpu_bcsr_data_register(starpu_data_handle *handle, uint32_t home_node, uint32_t nnz, uint32_t nrow,
  1006. uintptr_t nzval, uint32_t *colind, uint32_t *rowptr, uint32_t firstentry, uint32_t r, uint32_t c, size_t elemsize);}
  1007. @item @emph{Example}:
  1008. @cartouche
  1009. @smallexample
  1010. @end smallexample
  1011. @end cartouche
  1012. @end table
  1013. @node CSR Interface for Sparse Matrices (Compressed Sparse Row Representation)
  1014. @subsection CSR Interface for Sparse Matrices (Compressed Sparse Row Representation)
  1015. @table @asis
  1016. @item @emph{Description}:
  1017. @item @emph{Prototype}:
  1018. @code{void starpu_csr_data_register(starpu_data_handle *handle, uint32_t home_node, uint32_t nnz, uint32_t nrow,
  1019. uintptr_t nzval, uint32_t *colind, uint32_t *rowptr, uint32_t firstentry, size_t elemsize);}
  1020. @item @emph{Example}:
  1021. @cartouche
  1022. @smallexample
  1023. @end smallexample
  1024. @end cartouche
  1025. @end table
  1026. @node Block Interface
  1027. @subsection Block Interface
  1028. @table @asis
  1029. @item @emph{Description}:
  1030. @item @emph{Prototype}:
  1031. @code{void starpu_block_data_register(starpu_data_handle *handle, uint32_t home_node,
  1032. uintptr_t ptr, uint32_t ldy, uint32_t ldz, uint32_t nx,
  1033. uint32_t ny, uint32_t nz, size_t elemsize);}
  1034. @item @emph{Example}:
  1035. @cartouche
  1036. @smallexample
  1037. float *block;
  1038. starpu_data_handle block_handle;
  1039. block = (float*)malloc(nx*ny*nz*sizeof(float));
  1040. starpu_block_data_register(&block_handle, 0, (uintptr_t)block,
  1041. nx, nx*ny, nx, ny, nz, sizeof(float));
  1042. @end smallexample
  1043. @end cartouche
  1044. @end table
  1045. @node Data Partition
  1046. @section Data Partition
  1047. @menu
  1048. * struct starpu_data_filter:: StarPU filter structure
  1049. * starpu_data_partition:: Partition Data
  1050. * starpu_data_unpartition:: Unpartition Data
  1051. * starpu_data_get_nb_children::
  1052. * starpu_data_get_sub_data::
  1053. @end menu
  1054. @node struct starpu_data_filter
  1055. @subsection @code{struct starpu_data_filter} -- StarPU filter structure
  1056. @table @asis
  1057. @item @emph{Description}:
  1058. The filter structure describes a data partitioning function.
  1059. @item @emph{Fields}:
  1060. @table @asis
  1061. @item @code{filter_func}:
  1062. @code{void (*filter_func)(void *father_interface, void* child_interface, struct starpu_data_filter *, unsigned id, unsigned nparts);}
  1063. @item @code{get_nchildren}:
  1064. @code{unsigned (*get_nchildren)(struct starpu_data_filter *, starpu_data_handle initial_handle);}
  1065. @item @code{get_child_ops}:
  1066. @code{struct starpu_data_interface_ops_t *(*get_child_ops)(struct starpu_data_filter *, unsigned id);}
  1067. @item @code{filter_arg}:
  1068. @item @code{nchildren}:
  1069. @item @code{filter_arg_ptr}:
  1070. @end table
  1071. @end table
  1072. @node starpu_data_partition
  1073. @subsection starpu_data_partition -- Partition Data
  1074. @table @asis
  1075. @item @emph{Description}:
  1076. @item @emph{Prototype}:
  1077. @code{void starpu_data_partition(starpu_data_handle initial_handle, struct starpu_data_filter *f);}
  1078. @end table
  1079. @node starpu_data_unpartition
  1080. @subsection starpu_data_unpartition -- Unpartition data
  1081. @table @asis
  1082. @item @emph{Description}:
  1083. @item @emph{Prototype}:
  1084. @code{void starpu_data_unpartition(starpu_data_handle root_data, uint32_t gathering_node);}
  1085. @end table
  1086. @node starpu_data_get_nb_children
  1087. @subsection starpu_data_get_nb_children
  1088. @table @asis
  1089. @item @emph{Description}:
  1090. @item @emph{Return value}:
  1091. This function returns returns the number of children.
  1092. @item @emph{Prototype}:
  1093. @code{int starpu_data_get_nb_children(starpu_data_handle handle);}
  1094. @end table
  1095. @c starpu_data_handle starpu_data_get_child(starpu_data_handle handle, unsigned i);
  1096. @node starpu_data_get_sub_data
  1097. @subsection starpu_data_get_sub_data
  1098. @table @asis
  1099. @item @emph{Description}:
  1100. @item @emph{Return value}:
  1101. Upon successful completion, this function returns ...
  1102. @item @emph{Prototype}:
  1103. @code{starpu_data_handle starpu_data_get_sub_data(starpu_data_handle root_data, unsigned depth, ... );}
  1104. @end table
  1105. @node Codelets and Tasks
  1106. @section Codelets and Tasks
  1107. @menu
  1108. * struct starpu_codelet:: StarPU codelet structure
  1109. * struct starpu_task:: StarPU task structure
  1110. * starpu_task_init:: Initialize a Task
  1111. * starpu_task_create:: Allocate and Initialize a Task
  1112. * starpu_task_deinit:: Release all the resources used by a Task
  1113. * starpu_task_destroy:: Destroy a dynamically allocated Task
  1114. * starpu_task_wait:: Wait for the termination of a Task
  1115. * starpu_task_submit:: Submit a Task
  1116. * starpu_task_wait_for_all:: Wait for the termination of all Tasks
  1117. @end menu
  1118. @node struct starpu_codelet
  1119. @subsection @code{struct starpu_codelet} -- StarPU codelet structure
  1120. @table @asis
  1121. @item @emph{Description}:
  1122. The codelet structure describes a kernel that is possibly implemented on
  1123. various targets.
  1124. @item @emph{Fields}:
  1125. @table @asis
  1126. @item @code{where}:
  1127. Indicates which types of processing units are able to execute the codelet.
  1128. @code{STARPU_CPU|STARPU_CUDA} for instance indicates that the codelet is
  1129. implemented for both CPU cores and CUDA devices while @code{STARPU_GORDON}
  1130. indicates that it is only available on Cell SPUs.
  1131. @item @code{cpu_func} (optional):
  1132. Is a function pointer to the CPU implementation of the codelet. Its prototype
  1133. must be: @code{void cpu_func(void *buffers[], void *cl_arg)}. The first
  1134. argument being the array of data managed by the data management library, and
  1135. the second argument is a pointer to the argument passed from the @code{cl_arg}
  1136. field of the @code{starpu_task} structure.
  1137. The @code{cpu_func} field is ignored if @code{STARPU_CPU} does not appear in
  1138. the @code{where} field, it must be non-null otherwise.
  1139. @item @code{cuda_func} (optional):
  1140. Is a function pointer to the CUDA implementation of the codelet. @emph{This
  1141. must be a host-function written in the CUDA runtime API}. Its prototype must
  1142. be: @code{void cuda_func(void *buffers[], void *cl_arg);}. The @code{cuda_func}
  1143. field is ignored if @code{STARPU_CUDA} does not appear in the @code{where}
  1144. field, it must be non-null otherwise.
  1145. @item @code{opencl_func} (optional):
  1146. Is a function pointer to the OpenCL implementation of the codelet. Its
  1147. prototype must be:
  1148. @code{void opencl_func(starpu_data_interface_t *descr, void *arg);}.
  1149. This pointer is ignored if @code{STARPU_OPENCL} does not appear in the
  1150. @code{where} field, it must be non-null otherwise.
  1151. @item @code{gordon_func} (optional):
  1152. This is the index of the Cell SPU implementation within the Gordon library.
  1153. See Gordon documentation for more details on how to register a kernel and
  1154. retrieve its index.
  1155. @item @code{nbuffers}:
  1156. Specifies the number of arguments taken by the codelet. These arguments are
  1157. managed by the DSM and are accessed from the @code{void *buffers[]}
  1158. array. The constant argument passed with the @code{cl_arg} field of the
  1159. @code{starpu_task} structure is not counted in this number. This value should
  1160. not be above @code{STARPU_NMAXBUFS}.
  1161. @item @code{model} (optional):
  1162. This is a pointer to the performance model associated to this codelet. This
  1163. optional field is ignored when set to @code{NULL}. TODO
  1164. @end table
  1165. @end table
  1166. @node struct starpu_task
  1167. @subsection @code{struct starpu_task} -- StarPU task structure
  1168. @table @asis
  1169. @item @emph{Description}:
  1170. The @code{starpu_task} structure describes a task that can be offloaded on the various
  1171. processing units managed by StarPU. It instantiates a codelet. It can either be
  1172. allocated dynamically with the @code{starpu_task_create} method, or declared
  1173. statically. In the latter case, the programmer has to zero the
  1174. @code{starpu_task} structure and to fill the different fields properly. The
  1175. indicated default values correspond to the configuration of a task allocated
  1176. with @code{starpu_task_create}.
  1177. @item @emph{Fields}:
  1178. @table @asis
  1179. @item @code{cl}:
  1180. Is a pointer to the corresponding @code{starpu_codelet} data structure. This
  1181. describes where the kernel should be executed, and supplies the appropriate
  1182. implementations. When set to @code{NULL}, no code is executed during the tasks,
  1183. such empty tasks can be useful for synchronization purposes.
  1184. @item @code{buffers}:
  1185. Is an array of @code{starpu_buffer_descr_t} structures. It describes the
  1186. different pieces of data accessed by the task, and how they should be accessed.
  1187. The @code{starpu_buffer_descr_t} structure is composed of two fields, the
  1188. @code{handle} field specifies the handle of the piece of data, and the
  1189. @code{mode} field is the required access mode (eg @code{STARPU_RW}). The number
  1190. of entries in this array must be specified in the @code{nbuffers} field of the
  1191. @code{starpu_codelet} structure, and should not excede @code{STARPU_NMAXBUFS}.
  1192. If unsufficient, this value can be set with the @code{--enable-maxbuffers}
  1193. option when configuring StarPU.
  1194. @item @code{cl_arg} (optional) (default = NULL):
  1195. This pointer is passed to the codelet through the second argument
  1196. of the codelet implementation (e.g. @code{cpu_func} or @code{cuda_func}).
  1197. In the specific case of the Cell processor, see the @code{cl_arg_size}
  1198. argument.
  1199. @item @code{cl_arg_size} (optional, Cell specific):
  1200. In the case of the Cell processor, the @code{cl_arg} pointer is not directly
  1201. given to the SPU function. A buffer of size @code{cl_arg_size} is allocated on
  1202. the SPU. This buffer is then filled with the @code{cl_arg_size} bytes starting
  1203. at address @code{cl_arg}. In this case, the argument given to the SPU codelet
  1204. is therefore not the @code{cl_arg} pointer, but the address of the buffer in
  1205. local store (LS) instead. This field is ignored for CPU, CUDA and OpenCL
  1206. codelets.
  1207. @item @code{callback_func} (optional) (default = @code{NULL}):
  1208. This is a function pointer of prototype @code{void (*f)(void *)} which
  1209. specifies a possible callback. If this pointer is non-null, the callback
  1210. function is executed @emph{on the host} after the execution of the task. The
  1211. callback is passed the value contained in the @code{callback_arg} field. No
  1212. callback is executed if the field is set to @code{NULL}.
  1213. @item @code{callback_arg} (optional) (default = @code{NULL}):
  1214. This is the pointer passed to the callback function. This field is ignored if
  1215. the @code{callback_func} is set to @code{NULL}.
  1216. @item @code{use_tag} (optional) (default = 0):
  1217. If set, this flag indicates that the task should be associated with the tag
  1218. contained in the @code{tag_id} field. Tag allow the application to synchronize
  1219. with the task and to express task dependencies easily.
  1220. @item @code{tag_id}:
  1221. This fields contains the tag associated to the task if the @code{use_tag} field
  1222. was set, it is ignored otherwise.
  1223. @item @code{synchronous}:
  1224. If this flag is set, the @code{starpu_task_submit} function is blocking and
  1225. returns only when the task has been executed (or if no worker is able to
  1226. process the task). Otherwise, @code{starpu_task_submit} returns immediately.
  1227. @item @code{priority} (optional) (default = @code{STARPU_DEFAULT_PRIO}):
  1228. This field indicates a level of priority for the task. This is an integer value
  1229. that must be set between @code{STARPU_MIN_PRIO} (for the least important
  1230. tasks) and @code{STARPU_MAX_PRIO} (for the most important tasks) included.
  1231. Default priority is @code{STARPU_DEFAULT_PRIO}. Scheduling strategies that
  1232. take priorities into account can use this parameter to take better scheduling
  1233. decisions, but the scheduling policy may also ignore it.
  1234. @item @code{execute_on_a_specific_worker} (default = 0):
  1235. If this flag is set, StarPU will bypass the scheduler and directly affect this
  1236. task to the worker specified by the @code{workerid} field.
  1237. @item @code{workerid} (optional):
  1238. If the @code{execute_on_a_specific_worker} field is set, this field indicates
  1239. which is the identifier of the worker that should process this task (as
  1240. returned by @code{starpu_worker_get_id}). This field is ignored if
  1241. @code{execute_on_a_specific_worker} field is set to 0.
  1242. @item @code{detach} (optional) (default = 1):
  1243. If this flag is set, it is not possible to synchronize with the task
  1244. by the means of @code{starpu_task_wait} later on. Internal data structures
  1245. are only guaranteed to be freed once @code{starpu_task_wait} is called if the
  1246. flag is not set.
  1247. @item @code{destroy} (optional) (default = 1):
  1248. If this flag is set, the task structure will automatically be freed, either
  1249. after the execution of the callback if the task is detached, or during
  1250. @code{starpu_task_wait} otherwise. If this flag is not set, dynamically
  1251. allocated data structures will not be freed until @code{starpu_task_destroy} is
  1252. called explicitly. Setting this flag for a statically allocated task structure
  1253. will result in undefined behaviour.
  1254. @end table
  1255. @end table
  1256. @node starpu_task_init
  1257. @subsection @code{starpu_task_init} -- Initialize a Task
  1258. @table @asis
  1259. @item @emph{Description}:
  1260. Initialize a task structure with default values. This function is implicitly
  1261. called by @code{starpu_task_create}. By default, tasks initialized with
  1262. @code{starpu_task_init} must be deinitialized explicitly with
  1263. @code{starpu_task_deinit}. Tasks can also be initialized statically, using the
  1264. constant @code{STARPU_TASK_INITIALIZER}.
  1265. @item @emph{Prototype}:
  1266. @code{void starpu_task_init(struct starpu_task *task);}
  1267. @end table
  1268. @node starpu_task_create
  1269. @subsection @code{starpu_task_create} -- Allocate and Initialize a Task
  1270. @table @asis
  1271. @item @emph{Description}:
  1272. Allocate a task structure and initialize it with default values. Tasks
  1273. allocated dynamically with @code{starpu_task_create} are automatically freed when the
  1274. task is terminated. If the destroy flag is explicitly unset, the resources used
  1275. by the task are freed by calling
  1276. @code{starpu_task_destroy}.
  1277. @item @emph{Prototype}:
  1278. @code{struct starpu_task *starpu_task_create(void);}
  1279. @end table
  1280. @node starpu_task_deinit
  1281. @subsection @code{starpu_task_deinit} -- Release all the resources used by a Task
  1282. @table @asis
  1283. @item @emph{Description}:
  1284. Release all the structures automatically allocated to execute the task. This is
  1285. called automatically by @code{starpu_task_destroy}, but the task structure itself is not
  1286. freed. This should be used for statically allocated tasks for instance.
  1287. @item @emph{Prototype}:
  1288. @code{void starpu_task_deinit(struct starpu_task *task);}
  1289. @end table
  1290. @node starpu_task_destroy
  1291. @subsection @code{starpu_task_destroy} -- Destroy a dynamically allocated Task
  1292. @table @asis
  1293. @item @emph{Description}:
  1294. Free the resource allocated during @code{starpu_task_create}. This function can be
  1295. called automatically after the execution of a task by setting the
  1296. @code{destroy} flag of the @code{starpu_task} structure (default behaviour).
  1297. Calling this function on a statically allocated task results in an undefined
  1298. behaviour.
  1299. @item @emph{Prototype}:
  1300. @code{void starpu_task_destroy(struct starpu_task *task);}
  1301. @end table
  1302. @node starpu_task_wait
  1303. @subsection @code{starpu_task_wait} -- Wait for the termination of a Task
  1304. @table @asis
  1305. @item @emph{Description}:
  1306. This function blocks until the task has been executed. It is not possible to
  1307. synchronize with a task more than once. It is not possible to wait for
  1308. synchronous or detached tasks.
  1309. @item @emph{Return value}:
  1310. Upon successful completion, this function returns 0. Otherwise, @code{-EINVAL}
  1311. indicates that the specified task was either synchronous or detached.
  1312. @item @emph{Prototype}:
  1313. @code{int starpu_task_wait(struct starpu_task *task);}
  1314. @end table
  1315. @node starpu_task_submit
  1316. @subsection @code{starpu_task_submit} -- Submit a Task
  1317. @table @asis
  1318. @item @emph{Description}:
  1319. This function submits a task to StarPU. Calling this function does
  1320. not mean that the task will be executed immediately as there can be data or task
  1321. (tag) dependencies that are not fulfilled yet: StarPU will take care of
  1322. scheduling this task with respect to such dependencies.
  1323. This function returns immediately if the @code{synchronous} field of the
  1324. @code{starpu_task} structure was set to 0, and block until the termination of
  1325. the task otherwise. It is also possible to synchronize the application with
  1326. asynchronous tasks by the means of tags, using the @code{starpu_tag_wait}
  1327. function for instance.
  1328. @item @emph{Return value}:
  1329. In case of success, this function returns 0, a return value of @code{-ENODEV}
  1330. means that there is no worker able to process this task (e.g. there is no GPU
  1331. available and this task is only implemented for CUDA devices).
  1332. @item @emph{Prototype}:
  1333. @code{int starpu_task_submit(struct starpu_task *task);}
  1334. @end table
  1335. @node starpu_task_wait_for_all
  1336. @subsection @code{starpu_task_wait_for_all} -- Wait for the termination of all Tasks
  1337. @table @asis
  1338. @item @emph{Description}:
  1339. This function blocks until all the tasks that were submitted are terminated.
  1340. @item @emph{Prototype}:
  1341. @code{void starpu_task_wait_for_all(void);}
  1342. @end table
  1343. @c Callbacks : what can we put in callbacks ?
  1344. @node Explicit Dependencies
  1345. @section Explicit Dependencies
  1346. @menu
  1347. * starpu_task_declare_deps_array:: starpu_task_declare_deps_array
  1348. * starpu_tag_t:: Task logical identifier
  1349. * starpu_tag_declare_deps:: Declare the Dependencies of a Tag
  1350. * starpu_tag_declare_deps_array:: Declare the Dependencies of a Tag
  1351. * starpu_tag_wait:: Block until a Tag is terminated
  1352. * starpu_tag_wait_array:: Block until a set of Tags is terminated
  1353. * starpu_tag_remove:: Destroy a Tag
  1354. * starpu_tag_notify_from_apps:: Feed a tag explicitly
  1355. @end menu
  1356. @node starpu_task_declare_deps_array
  1357. @subsection @code{starpu_task_declare_deps_array} -- Declare task dependencies
  1358. @table @asis
  1359. @item @emph{Description}:
  1360. Declare task dependencies between a @code{task} and an array of tasks of length
  1361. @code{ndeps}. This function must be called prior to the submission of the task,
  1362. but it may called after the submission or the execution of the tasks in the
  1363. array provided the tasks are still valid (ie. they were not automatically
  1364. destroyed). Calling this function on a task that was already submitted or with
  1365. an entry of @code{task_array} that is not a valid task anymore results in an
  1366. undefined behaviour. If @code{ndeps} is null, no dependency is added. It is
  1367. possible to call @code{starpu_task_declare_deps_array} multiple times on the
  1368. same task, in this case, the dependencies are added. It is possible to have
  1369. redundancy in the task dependencies.
  1370. @item @emph{Prototype}:
  1371. @code{void starpu_task_declare_deps_array(struct starpu_task *task, unsigned ndeps, struct starpu_task *task_array[]);}
  1372. @end table
  1373. @node starpu_tag_t
  1374. @subsection @code{starpu_tag_t} -- Task logical identifier
  1375. @table @asis
  1376. @item @emph{Description}:
  1377. It is possible to associate a task with a unique ``tag'' and to express
  1378. dependencies between tasks by the means of those tags. To do so, fill the
  1379. @code{tag_id} field of the @code{starpu_task} structure with a tag number (can
  1380. be arbitrary) and set the @code{use_tag} field to 1.
  1381. If @code{starpu_tag_declare_deps} is called with this tag number, the task will
  1382. not be started until the tasks which holds the declared dependency tags are
  1383. completed.
  1384. @end table
  1385. @node starpu_tag_declare_deps
  1386. @subsection @code{starpu_tag_declare_deps} -- Declare the Dependencies of a Tag
  1387. @table @asis
  1388. @item @emph{Description}:
  1389. Specify the dependencies of the task identified by tag @code{id}. The first
  1390. argument specifies the tag which is configured, the second argument gives the
  1391. number of tag(s) on which @code{id} depends. The following arguments are the
  1392. tags which have to be terminated to unlock the task.
  1393. This function must be called before the associated task is submitted to StarPU
  1394. with @code{starpu_task_submit}.
  1395. @item @emph{Remark}
  1396. Because of the variable arity of @code{starpu_tag_declare_deps}, note that the
  1397. last arguments @emph{must} be of type @code{starpu_tag_t}: constant values
  1398. typically need to be explicitly casted. Using the
  1399. @code{starpu_tag_declare_deps_array} function avoids this hazard.
  1400. @item @emph{Prototype}:
  1401. @code{void starpu_tag_declare_deps(starpu_tag_t id, unsigned ndeps, ...);}
  1402. @item @emph{Example}:
  1403. @cartouche
  1404. @example
  1405. /* Tag 0x1 depends on tags 0x32 and 0x52 */
  1406. starpu_tag_declare_deps((starpu_tag_t)0x1,
  1407. 2, (starpu_tag_t)0x32, (starpu_tag_t)0x52);
  1408. @end example
  1409. @end cartouche
  1410. @end table
  1411. @node starpu_tag_declare_deps_array
  1412. @subsection @code{starpu_tag_declare_deps_array} -- Declare the Dependencies of a Tag
  1413. @table @asis
  1414. @item @emph{Description}:
  1415. This function is similar to @code{starpu_tag_declare_deps}, except that its
  1416. does not take a variable number of arguments but an array of tags of size
  1417. @code{ndeps}.
  1418. @item @emph{Prototype}:
  1419. @code{void starpu_tag_declare_deps_array(starpu_tag_t id, unsigned ndeps, starpu_tag_t *array);}
  1420. @item @emph{Example}:
  1421. @cartouche
  1422. @example
  1423. /* Tag 0x1 depends on tags 0x32 and 0x52 */
  1424. starpu_tag_t tag_array[2] = @{0x32, 0x52@};
  1425. starpu_tag_declare_deps_array((starpu_tag_t)0x1, 2, tag_array);
  1426. @end example
  1427. @end cartouche
  1428. @end table
  1429. @node starpu_tag_wait
  1430. @subsection @code{starpu_tag_wait} -- Block until a Tag is terminated
  1431. @table @asis
  1432. @item @emph{Description}:
  1433. This function blocks until the task associated to tag @code{id} has been
  1434. executed. This is a blocking call which must therefore not be called within
  1435. tasks or callbacks, but only from the application directly. It is possible to
  1436. synchronize with the same tag multiple times, as long as the
  1437. @code{starpu_tag_remove} function is not called. Note that it is still
  1438. possible to synchronize with a tag associated to a task which @code{starpu_task}
  1439. data structure was freed (e.g. if the @code{destroy} flag of the
  1440. @code{starpu_task} was enabled).
  1441. @item @emph{Prototype}:
  1442. @code{void starpu_tag_wait(starpu_tag_t id);}
  1443. @end table
  1444. @node starpu_tag_wait_array
  1445. @subsection @code{starpu_tag_wait_array} -- Block until a set of Tags is terminated
  1446. @table @asis
  1447. @item @emph{Description}:
  1448. This function is similar to @code{starpu_tag_wait} except that it blocks until
  1449. @emph{all} the @code{ntags} tags contained in the @code{id} array are
  1450. terminated.
  1451. @item @emph{Prototype}:
  1452. @code{void starpu_tag_wait_array(unsigned ntags, starpu_tag_t *id);}
  1453. @end table
  1454. @node starpu_tag_remove
  1455. @subsection @code{starpu_tag_remove} -- Destroy a Tag
  1456. @table @asis
  1457. @item @emph{Description}:
  1458. This function releases the resources associated to tag @code{id}. It can be
  1459. called once the corresponding task has been executed and when there is
  1460. no other tag that depend on this tag anymore.
  1461. @item @emph{Prototype}:
  1462. @code{void starpu_tag_remove(starpu_tag_t id);}
  1463. @end table
  1464. @node starpu_tag_notify_from_apps
  1465. @subsection @code{starpu_tag_notify_from_apps} -- Feed a Tag explicitly
  1466. @table @asis
  1467. @item @emph{Description}:
  1468. This function explicitly unlocks tag @code{id}. It may be useful in the
  1469. case of applications which execute part of their computation outside StarPU
  1470. tasks (e.g. third-party libraries). It is also provided as a
  1471. convenient tool for the programmer, for instance to entirely construct the task
  1472. DAG before actually giving StarPU the opportunity to execute the tasks.
  1473. @item @emph{Prototype}:
  1474. @code{void starpu_tag_notify_from_apps(starpu_tag_t id);}
  1475. @end table
  1476. @node Implicit Data Dependencies
  1477. @section Implicit Data Dependencies
  1478. @menu
  1479. * starpu_data_set_default_sequential_consistency_flag:: starpu_data_set_default_sequential_consistency_flag
  1480. * starpu_data_get_default_sequential_consistency_flag:: starpu_data_get_default_sequential_consistency_flag
  1481. * starpu_data_set_sequential_consistency_flag:: starpu_data_set_sequential_consistency_flag
  1482. @end menu
  1483. In this section, we describe how StarPU makes it possible to insert implicit
  1484. task dependencies in order to enforce sequential data consistency. When this
  1485. data consistency is enabled on a specific data handle, any data access will
  1486. appear as sequentially consistent from the application. For instance, if the
  1487. application submits two tasks that access the same piece of data in read-only
  1488. mode, and then a third task that access it in write mode, dependencies will be
  1489. added between the two first tasks and the third one. Implicit data dependencies
  1490. are also inserted in the case of data accesses from the application.
  1491. @node starpu_data_set_default_sequential_consistency_flag
  1492. @subsection @code{starpu_data_set_default_sequential_consistency_flag} -- Set default sequential consistency flag
  1493. @table @asis
  1494. @item @emph{Description}:
  1495. Set the default sequential consistency flag. If a non-null value is passed, a
  1496. sequential data consistency will be enforced for all handles registered after
  1497. this function call, otherwise it is disabled. By default, StarPU enables
  1498. sequential data consistency. It is also possible to select the data consistency
  1499. mode of a specific data handle with the
  1500. @code{starpu_data_set_sequential_consistency_flag} function.
  1501. @item @emph{Prototype}:
  1502. @code{void starpu_data_set_default_sequential_consistency_flag(unsigned flag);}
  1503. @end table
  1504. @node starpu_data_get_default_sequential_consistency_flag
  1505. @subsection @code{starpu_data_get_default_sequential_consistency_flag} -- Get current default sequential consistency flag
  1506. @table @asis
  1507. @item @emph{Description}:
  1508. This function returns the current default sequential consistency flag.
  1509. @item @emph{Prototype}:
  1510. @code{unsigned starpu_data_set_default_sequential_consistency_flag(void);}
  1511. @end table
  1512. @node starpu_data_set_sequential_consistency_flag
  1513. @subsection @code{starpu_data_set_sequential_consistency_flag} -- Set data sequential consistency mode
  1514. @table @asis
  1515. @item @emph{Description}:
  1516. Select the data consistency mode associated to a data handle. The consistency
  1517. mode set using this function has the priority over the default mode which can
  1518. be set with @code{starpu_data_set_sequential_consistency_flag}.
  1519. @item @emph{Prototype}:
  1520. @code{void starpu_data_set_sequential_consistency_flag(starpu_data_handle handle, unsigned flag);}
  1521. @end table
  1522. @node Profiling API
  1523. @section Profiling API
  1524. @menu
  1525. * starpu_profiling_status_set:: starpu_profiling_status_set
  1526. * starpu_profiling_status_get:: starpu_profiling_status_get
  1527. * struct starpu_task_profiling_info:: task profiling information
  1528. * struct starpu_worker_profiling_info:: worker profiling information
  1529. * starpu_worker_get_profiling_info:: starpu_worker_get_profiling_info
  1530. * struct starpu_bus_profiling_info:: bus profiling information
  1531. @end menu
  1532. @node starpu_profiling_status_set
  1533. @subsection @code{starpu_profiling_status_set} -- Set current profiling status
  1534. @table @asis
  1535. @item @emph{Description}:
  1536. Thie function sets the profiling status. Profiling is activated by passing
  1537. @code{STARPU_PROFILING_ENABLE} in @code{status}. Passing
  1538. @code{STARPU_PROFILING_DISABLE} disables profiling. Calling this function
  1539. resets all profiling measurements. When profiling is enabled, the
  1540. @code{profiling_info} field of the @code{struct starpu_task} structure points
  1541. to a valid @code{struct starpu_task_profiling_info} structure containing
  1542. information about the execution of the task.
  1543. @item @emph{Return value}:
  1544. Negative return values indicate an error, otherwise the previous status is
  1545. returned.
  1546. @item @emph{Prototype}:
  1547. @code{int starpu_profiling_status_set(int status);}
  1548. @end table
  1549. @node starpu_profiling_status_get
  1550. @subsection @code{starpu_profiling_status_get} -- Get current profiling status
  1551. @table @asis
  1552. @item @emph{Description}:
  1553. Return the current profiling status or a negative value in case there was an error.
  1554. @item @emph{Prototype}:
  1555. @code{int starpu_profiling_status_get(void);}
  1556. @end table
  1557. @node struct starpu_task_profiling_info
  1558. @subsection @code{struct starpu_task_profiling_info} -- Task profiling information
  1559. @table @asis
  1560. @item @emph{Description}:
  1561. This structure contains information about the execution of a task. It is
  1562. accessible from the @code{.profiling_info} field of the @code{starpu_task}
  1563. structure if profiling was enabled.
  1564. @item @emph{Fields}:
  1565. @table @asis
  1566. @item @code{submit_time}:
  1567. Date of task submission (relative to the initialization of StarPU).
  1568. @item @code{start_time}:
  1569. Date of task execution beginning (relative to the initialization of StarPU).
  1570. @item @code{end_time}:
  1571. Date of task execution termination (relative to the initialization of StarPU).
  1572. @item @code{workerid}:
  1573. Identifier of the worker which has executed the task.
  1574. @end table
  1575. @end table
  1576. @node struct starpu_worker_profiling_info
  1577. @subsection @code{struct starpu_worker_profiling_info} -- Worker profiling information
  1578. @table @asis
  1579. @item @emph{Description}:
  1580. This structure contains the profiling information associated to a worker.
  1581. @item @emph{Fields}:
  1582. @table @asis
  1583. @item @code{start_time}:
  1584. Starting date for the reported profiling measurements.
  1585. @item @code{total_time}:
  1586. Duration of the profiling measurement interval.
  1587. @item @code{executing_time}:
  1588. Time spent by the worker to execute tasks during the profiling measurement interval.
  1589. @item @code{sleeping_time}:
  1590. Time spent idling by the worker during the profiling measurement interval.
  1591. @item @code{executed_tasks}:
  1592. Number of tasks executed by the worker during the profiling measurement interval.
  1593. @end table
  1594. @end table
  1595. @node starpu_worker_get_profiling_info
  1596. @subsection @code{starpu_worker_get_profiling_info} -- Get worker profiling info
  1597. @table @asis
  1598. @item @emph{Description}:
  1599. Get the profiling info associated to the worker identified by @code{workerid},
  1600. and reset the profiling measurements. If the @code{worker_info} argument is
  1601. NULL, only reset the counters associated to worker @code{workerid}.
  1602. @item @emph{Return value}:
  1603. Upon successful completion, this function returns 0. Otherwise, a negative
  1604. value is returned.
  1605. @item @emph{Prototype}:
  1606. @code{int starpu_worker_get_profiling_info(int workerid, struct starpu_worker_profiling_info *worker_info);}
  1607. @end table
  1608. @node struct starpu_bus_profiling_info
  1609. @subsection @code{struct starpu_bus_profiling_info} -- Bus profiling information
  1610. @table @asis
  1611. @item @emph{Description}:
  1612. TODO
  1613. @item @emph{Fields}:
  1614. @table @asis
  1615. @item @code{start_time}:
  1616. TODO
  1617. @item @code{total_time}:
  1618. TODO
  1619. @item @code{transferred_bytes}:
  1620. TODO
  1621. @item @code{transfer_count}:
  1622. TODO
  1623. @end table
  1624. @end table
  1625. @node CUDA extensions
  1626. @section CUDA extensions
  1627. @c void starpu_data_malloc_pinned_if_possible(float **A, size_t dim);
  1628. @menu
  1629. * starpu_cuda_get_local_stream:: Get current worker's CUDA stream
  1630. * starpu_helper_cublas_init:: Initialize CUBLAS on every CUDA device
  1631. * starpu_helper_cublas_shutdown:: Deinitialize CUBLAS on every CUDA device
  1632. @end menu
  1633. @node starpu_cuda_get_local_stream
  1634. @subsection @code{starpu_cuda_get_local_stream} -- Get current worker's CUDA stream
  1635. @table @asis
  1636. @item @emph{Description}:
  1637. StarPU provides a stream for every CUDA device controlled by StarPU. This
  1638. function is only provided for convenience so that programmers can easily use
  1639. asynchronous operations within codelets without having to create a stream by
  1640. hand. Note that the application is not forced to use the stream provided by
  1641. @code{starpu_cuda_get_local_stream} and may also create its own streams.
  1642. @item @emph{Prototype}:
  1643. @code{cudaStream_t *starpu_cuda_get_local_stream(void);}
  1644. @end table
  1645. @node starpu_helper_cublas_init
  1646. @subsection @code{starpu_helper_cublas_init} -- Initialize CUBLAS on every CUDA device
  1647. @table @asis
  1648. @item @emph{Description}:
  1649. The CUBLAS library must be initialized prior to any CUBLAS call. Calling
  1650. @code{starpu_helper_cublas_init} will initialize CUBLAS on every CUDA device
  1651. controlled by StarPU. This call blocks until CUBLAS has been properly
  1652. initialized on every device.
  1653. @item @emph{Prototype}:
  1654. @code{void starpu_helper_cublas_init(void);}
  1655. @end table
  1656. @node starpu_helper_cublas_shutdown
  1657. @subsection @code{starpu_helper_cublas_shutdown} -- Deinitialize CUBLAS on every CUDA device
  1658. @table @asis
  1659. @item @emph{Description}:
  1660. This function synchronously deinitializes the CUBLAS library on every CUDA device.
  1661. @item @emph{Prototype}:
  1662. @code{void starpu_helper_cublas_shutdown(void);}
  1663. @end table
  1664. @node OpenCL extensions
  1665. @section OpenCL extensions
  1666. @menu
  1667. * Enabling OpenCL:: Enabling OpenCL
  1668. * Compiling OpenCL codelets:: Compiling OpenCL codelets
  1669. @end menu
  1670. @node Enabling OpenCL
  1671. @subsection Enabling OpenCL
  1672. On GPU devices which can run both CUDA and OpenCL, CUDA will be
  1673. enabled by default. To enable OpenCL, you need either to disable CUDA
  1674. when configuring StarPU:
  1675. @example
  1676. % ./configure --disable-cuda
  1677. @end example
  1678. or when running applications:
  1679. @example
  1680. % STARPU_NCUDA=0 ./application
  1681. @end example
  1682. OpenCL will automatically be started on any device not yet used by
  1683. CUDA. So on a machine running 4 GPUS, it is therefore possible to
  1684. enable CUDA on 2 devices, and OpenCL on the 2 other devices by doing
  1685. so:
  1686. @example
  1687. % STARPU_NCUDA=2 ./application
  1688. @end example
  1689. @node Compiling OpenCL codelets
  1690. @subsection Compiling OpenCL codelets
  1691. TODO
  1692. @node Cell extensions
  1693. @section Cell extensions
  1694. nothing yet.
  1695. @node Miscellaneous helpers
  1696. @section Miscellaneous helpers
  1697. @menu
  1698. * starpu_execute_on_each_worker:: Execute a function on a subset of workers
  1699. @end menu
  1700. @node starpu_execute_on_each_worker
  1701. @subsection @code{starpu_execute_on_each_worker} -- Execute a function on a subset of workers
  1702. @table @asis
  1703. @item @emph{Description}:
  1704. When calling this method, the offloaded function specified by the first argument is
  1705. executed by every StarPU worker that may execute the function.
  1706. The second argument is passed to the offloaded function.
  1707. The last argument specifies on which types of processing units the function
  1708. should be executed. Similarly to the @code{where} field of the
  1709. @code{starpu_codelet} structure, it is possible to specify that the function
  1710. should be executed on every CUDA device and every CPU by passing
  1711. @code{STARPU_CPU|STARPU_CUDA}.
  1712. This function blocks until the function has been executed on every appropriate
  1713. processing units, so that it may not be called from a callback function for
  1714. instance.
  1715. @item @emph{Prototype}:
  1716. @code{void starpu_execute_on_each_worker(void (*func)(void *), void *arg, uint32_t where);}
  1717. @end table
  1718. @c ---------------------------------------------------------------------
  1719. @c Basic Examples
  1720. @c ---------------------------------------------------------------------
  1721. @node Basic Examples
  1722. @chapter Basic Examples
  1723. @menu
  1724. * Compiling and linking options::
  1725. * Hello World:: Submitting Tasks
  1726. * Scaling a Vector:: Manipulating Data
  1727. * Vector Scaling on an Hybrid CPU/GPU Machine:: Handling Heterogeneous Architectures
  1728. * Filtering data:: Partitionning data
  1729. @end menu
  1730. @node Compiling and linking options
  1731. @section Compiling and linking options
  1732. Let's suppose StarPU has been installed in the directory
  1733. @code{$STARPU_DIR}. As explained in @ref{Setting flags for compiling and linking applications},
  1734. the variable @code{PKG_CONFIG_PATH} needs to be set. It is also
  1735. necessary to set the variable @code{LD_LIBRARY_PATH} to locate dynamic
  1736. libraries at runtime.
  1737. @example
  1738. % PKG_CONFIG_PATH=$STARPU_DIR/lib/pkgconfig:$PKG_CONFIG_PATH
  1739. % LD_LIBRARY_PATH=$STARPU_DIR/lib:$LD_LIBRARY_PATH
  1740. @end example
  1741. The Makefile could for instance contain the following lines to define which
  1742. options must be given to the compiler and to the linker:
  1743. @cartouche
  1744. @example
  1745. CFLAGS += $$(pkg-config --cflags libstarpu)
  1746. LDFLAGS += $$(pkg-config --libs libstarpu)
  1747. @end example
  1748. @end cartouche
  1749. @node Hello World
  1750. @section Hello World
  1751. @menu
  1752. * Required Headers::
  1753. * Defining a Codelet::
  1754. * Submitting a Task::
  1755. * Execution of Hello World::
  1756. @end menu
  1757. In this section, we show how to implement a simple program that submits a task to StarPU.
  1758. @node Required Headers
  1759. @subsection Required Headers
  1760. The @code{starpu.h} header should be included in any code using StarPU.
  1761. @cartouche
  1762. @smallexample
  1763. #include <starpu.h>
  1764. @end smallexample
  1765. @end cartouche
  1766. @node Defining a Codelet
  1767. @subsection Defining a Codelet
  1768. @cartouche
  1769. @smallexample
  1770. void cpu_func(void *buffers[], void *cl_arg)
  1771. @{
  1772. float *array = cl_arg;
  1773. printf("Hello world (array = @{%f, %f@} )\n", array[0], array[1]);
  1774. @}
  1775. starpu_codelet cl =
  1776. @{
  1777. .where = STARPU_CPU,
  1778. .cpu_func = cpu_func,
  1779. .nbuffers = 0
  1780. @};
  1781. @end smallexample
  1782. @end cartouche
  1783. A codelet is a structure that represents a computational kernel. Such a codelet
  1784. may contain an implementation of the same kernel on different architectures
  1785. (e.g. CUDA, Cell's SPU, x86, ...).
  1786. The @code{nbuffers} field specifies the number of data buffers that are
  1787. manipulated by the codelet: here the codelet does not access or modify any data
  1788. that is controlled by our data management library. Note that the argument
  1789. passed to the codelet (the @code{cl_arg} field of the @code{starpu_task}
  1790. structure) does not count as a buffer since it is not managed by our data
  1791. management library.
  1792. @c TODO need a crossref to the proper description of "where" see bla for more ...
  1793. We create a codelet which may only be executed on the CPUs. The @code{where}
  1794. field is a bitmask that defines where the codelet may be executed. Here, the
  1795. @code{STARPU_CPU} value means that only CPUs can execute this codelet
  1796. (@pxref{Codelets and Tasks} for more details on this field).
  1797. When a CPU core executes a codelet, it calls the @code{cpu_func} function,
  1798. which @emph{must} have the following prototype:
  1799. @code{void (*cpu_func)(void *buffers[], void *cl_arg);}
  1800. In this example, we can ignore the first argument of this function which gives a
  1801. description of the input and output buffers (e.g. the size and the location of
  1802. the matrices). The second argument is a pointer to a buffer passed as an
  1803. argument to the codelet by the means of the @code{cl_arg} field of the
  1804. @code{starpu_task} structure.
  1805. @c TODO rewrite so that it is a little clearer ?
  1806. Be aware that this may be a pointer to a
  1807. @emph{copy} of the actual buffer, and not the pointer given by the programmer:
  1808. if the codelet modifies this buffer, there is no guarantee that the initial
  1809. buffer will be modified as well: this for instance implies that the buffer
  1810. cannot be used as a synchronization medium.
  1811. @node Submitting a Task
  1812. @subsection Submitting a Task
  1813. @cartouche
  1814. @smallexample
  1815. void callback_func(void *callback_arg)
  1816. @{
  1817. printf("Callback function (arg %x)\n", callback_arg);
  1818. @}
  1819. int main(int argc, char **argv)
  1820. @{
  1821. /* @b{initialize StarPU} */
  1822. starpu_init(NULL);
  1823. struct starpu_task *task = starpu_task_create();
  1824. task->cl = &cl; /* @b{Pointer to the codelet defined above} */
  1825. float array[2] = @{1.0f, -1.0f@};
  1826. task->cl_arg = &array;
  1827. task->cl_arg_size = sizeof(array);
  1828. task->callback_func = callback_func;
  1829. task->callback_arg = 0x42;
  1830. /* @b{starpu_task_submit will be a blocking call} */
  1831. task->synchronous = 1;
  1832. /* @b{submit the task to StarPU} */
  1833. starpu_task_submit(task);
  1834. /* @b{terminate StarPU} */
  1835. starpu_shutdown();
  1836. return 0;
  1837. @}
  1838. @end smallexample
  1839. @end cartouche
  1840. Before submitting any tasks to StarPU, @code{starpu_init} must be called. The
  1841. @code{NULL} argument specifies that we use default configuration. Tasks cannot
  1842. be submitted after the termination of StarPU by a call to
  1843. @code{starpu_shutdown}.
  1844. In the example above, a task structure is allocated by a call to
  1845. @code{starpu_task_create}. This function only allocates and fills the
  1846. corresponding structure with the default settings (@pxref{starpu_task_create}),
  1847. but it does not submit the task to StarPU.
  1848. @c not really clear ;)
  1849. The @code{cl} field is a pointer to the codelet which the task will
  1850. execute: in other words, the codelet structure describes which computational
  1851. kernel should be offloaded on the different architectures, and the task
  1852. structure is a wrapper containing a codelet and the piece of data on which the
  1853. codelet should operate.
  1854. The optional @code{cl_arg} field is a pointer to a buffer (of size
  1855. @code{cl_arg_size}) with some parameters for the kernel
  1856. described by the codelet. For instance, if a codelet implements a computational
  1857. kernel that multiplies its input vector by a constant, the constant could be
  1858. specified by the means of this buffer, instead of registering it.
  1859. Once a task has been executed, an optional callback function can be called.
  1860. While the computational kernel could be offloaded on various architectures, the
  1861. callback function is always executed on a CPU. The @code{callback_arg}
  1862. pointer is passed as an argument of the callback. The prototype of a callback
  1863. function must be:
  1864. @code{void (*callback_function)(void *);}
  1865. If the @code{synchronous} field is non-null, task submission will be
  1866. synchronous: the @code{starpu_task_submit} function will not return until the
  1867. task was executed. Note that the @code{starpu_shutdown} method does not
  1868. guarantee that asynchronous tasks have been executed before it returns.
  1869. @node Execution of Hello World
  1870. @subsection Execution of Hello World
  1871. @smallexample
  1872. % make helloWorld
  1873. cc $(pkg-config --cflags libstarpu) $(pkg-config --libs libstarpu) helloWorld.c -o helloWorld
  1874. % ./helloWorld
  1875. Hello world (array = @{1.000000, -1.000000@} )
  1876. Callback function (arg 42)
  1877. @end smallexample
  1878. @node Scaling a Vector
  1879. @section Manipulating Data: Scaling a Vector
  1880. The previous example has shown how to submit tasks. In this section,
  1881. we show how StarPU tasks can manipulate data. The full source code for
  1882. this example is given in @ref{Full source code for the 'Scaling a Vector' example}.
  1883. @menu
  1884. * Source code of Vector Scaling::
  1885. * Execution of Vector Scaling::
  1886. @end menu
  1887. @node Source code of Vector Scaling
  1888. @subsection Source code of Vector Scaling
  1889. Programmers can describe the data layout of their application so that StarPU is
  1890. responsible for enforcing data coherency and availability across the machine.
  1891. Instead of handling complex (and non-portable) mechanisms to perform data
  1892. movements, programmers only declare which piece of data is accessed and/or
  1893. modified by a task, and StarPU makes sure that when a computational kernel
  1894. starts somewhere (e.g. on a GPU), its data are available locally.
  1895. Before submitting those tasks, the programmer first needs to declare the
  1896. different pieces of data to StarPU using the @code{starpu_*_data_register}
  1897. functions. To ease the development of applications for StarPU, it is possible
  1898. to describe multiple types of data layout. A type of data layout is called an
  1899. @b{interface}. By default, there are different interfaces available in StarPU:
  1900. here we will consider the @b{vector interface}.
  1901. The following lines show how to declare an array of @code{NX} elements of type
  1902. @code{float} using the vector interface:
  1903. @cartouche
  1904. @smallexample
  1905. float vector[NX];
  1906. starpu_data_handle vector_handle;
  1907. starpu_vector_data_register(&vector_handle, 0, (uintptr_t)vector, NX,
  1908. sizeof(vector[0]));
  1909. @end smallexample
  1910. @end cartouche
  1911. The first argument, called the @b{data handle}, is an opaque pointer which
  1912. designates the array in StarPU. This is also the structure which is used to
  1913. describe which data is used by a task. The second argument is the node number
  1914. where the data currently resides. Here it is 0 since the @code{vector} array is in
  1915. the main memory. Then comes the pointer @code{vector} where the data can be found,
  1916. the number of elements in the vector and the size of each element.
  1917. It is possible to construct a StarPU task that will manipulate the
  1918. vector and a constant factor.
  1919. @cartouche
  1920. @smallexample
  1921. float factor = 3.14;
  1922. struct starpu_task *task = starpu_task_create();
  1923. task->cl = &cl; /* @b{Pointer to the codelet defined below} */
  1924. task->buffers[0].handle = vector_handle; /* @b{First parameter of the codelet} */
  1925. task->buffers[0].mode = STARPU_RW;
  1926. task->cl_arg = &factor;
  1927. task->cl_arg_size = sizeof(factor);
  1928. task->synchronous = 1;
  1929. starpu_task_submit(task);
  1930. @end smallexample
  1931. @end cartouche
  1932. Since the factor is a mere float value parameter, it does not need a preliminary registration, and
  1933. can just be passed through the @code{cl_arg} pointer like in the previous
  1934. example. The vector parameter is described by its handle.
  1935. There are two fields in each element of the @code{buffers} array.
  1936. @code{handle} is the handle of the data, and @code{mode} specifies how the
  1937. kernel will access the data (@code{STARPU_R} for read-only, @code{STARPU_W} for
  1938. write-only and @code{STARPU_RW} for read and write access).
  1939. The definition of the codelet can be written as follows:
  1940. @cartouche
  1941. @smallexample
  1942. void scal_cpu_func(void *buffers[], void *cl_arg)
  1943. @{
  1944. unsigned i;
  1945. float *factor = cl_arg;
  1946. /* length of the vector */
  1947. unsigned n = STARPU_GET_VECTOR_NX(buffers[0]);
  1948. /* local copy of the vector pointer */
  1949. float *val = (float *)STARPU_GET_VECTOR_PTR(buffers[0]);
  1950. for (i = 0; i < n; i++)
  1951. val[i] *= *factor;
  1952. @}
  1953. starpu_codelet cl = @{
  1954. .where = STARPU_CPU,
  1955. .cpu_func = scal_cpu_func,
  1956. .nbuffers = 1
  1957. @};
  1958. @end smallexample
  1959. @end cartouche
  1960. The second argument of the @code{scal_cpu_func} function contains a pointer to the
  1961. parameters of the codelet (given in @code{task->cl_arg}), so that we read the
  1962. constant factor from this pointer. The first argument is an array that gives
  1963. a description of all the buffers passed in the @code{task->buffers}@ array. The
  1964. size of this array is given by the @code{nbuffers} field of the codelet
  1965. structure. For the sake of generality, this array contains pointers to the
  1966. different interfaces describing each buffer. In the case of the @b{vector
  1967. interface}, the location of the vector (resp. its length) is accessible in the
  1968. @code{ptr} (resp. @code{nx}) of this array. Since the vector is accessed in a
  1969. read-write fashion, any modification will automatically affect future accesses
  1970. to this vector made by other tasks.
  1971. @node Execution of Vector Scaling
  1972. @subsection Execution of Vector Scaling
  1973. @smallexample
  1974. % make vector
  1975. cc $(pkg-config --cflags libstarpu) $(pkg-config --libs libstarpu) vector.c -o vector
  1976. % ./vector
  1977. 0.000000 3.000000 6.000000 9.000000 12.000000
  1978. @end smallexample
  1979. @node Vector Scaling on an Hybrid CPU/GPU Machine
  1980. @section Vector Scaling on an Hybrid CPU/GPU Machine
  1981. Contrary to the previous examples, the task submitted in this example may not
  1982. only be executed by the CPUs, but also by a CUDA device.
  1983. @menu
  1984. * Definition of the CUDA Codelet::
  1985. * Definition of the OpenCL Codelet::
  1986. * Definition of the Main Code::
  1987. * Compilation and execution of Hybrid Vector Scaling::
  1988. @end menu
  1989. @node Definition of the CUDA Codelet
  1990. @subsection Definition of the CUDA Codelet
  1991. The CUDA implementation can be written as follows. It needs to be
  1992. compiled with a CUDA compiler such as nvcc, the NVIDIA CUDA compiler
  1993. driver.
  1994. @cartouche
  1995. @smallexample
  1996. #include <starpu.h>
  1997. static __global__ void vector_mult_cuda(float *val, unsigned n,
  1998. float factor)
  1999. @{
  2000. unsigned i;
  2001. for(i = 0 ; i < n ; i++)
  2002. val[i] *= factor;
  2003. @}
  2004. extern "C" void scal_cuda_func(void *buffers[], void *_args)
  2005. @{
  2006. float *factor = (float *)_args;
  2007. /* length of the vector */
  2008. unsigned n = STARPU_GET_VECTOR_NX(buffers[0]);
  2009. /* local copy of the vector pointer */
  2010. float *val = (float *)STARPU_GET_VECTOR_PTR(buffers[0]);
  2011. @i{ vector_mult_cuda<<<1,1>>>(val, n, *factor);}
  2012. @i{ cudaThreadSynchronize();}
  2013. @}
  2014. @end smallexample
  2015. @end cartouche
  2016. @node Definition of the OpenCL Codelet
  2017. @subsection Definition of the OpenCL Codelet
  2018. The OpenCL implementation can be written as follows. StarPU provides
  2019. tools to compile a OpenCL codelet stored in a file.
  2020. @cartouche
  2021. @smallexample
  2022. __kernel void vector_mult_opencl(__global float* val, int nx, float factor)
  2023. @{
  2024. const int i = get_global_id(0);
  2025. if (i < nx) @{
  2026. val[i] *= factor;
  2027. @}
  2028. @}
  2029. @end smallexample
  2030. @end cartouche
  2031. @cartouche
  2032. @smallexample
  2033. #include <starpu.h>
  2034. @i{#include <starpu_opencl.h>}
  2035. @i{extern struct starpu_opencl_program programs;}
  2036. void scal_opencl_func(void *buffers[], void *_args)
  2037. @{
  2038. float *factor = _args;
  2039. @i{ int id, devid, err;}
  2040. @i{ cl_kernel kernel;}
  2041. @i{ cl_command_queue queue;}
  2042. /* length of the vector */
  2043. unsigned n = STARPU_GET_VECTOR_NX(buffers[0]);
  2044. /* local copy of the vector pointer */
  2045. float *val = (float *)STARPU_GET_VECTOR_PTR(buffers[0]);
  2046. @i{ id = starpu_worker_get_id();}
  2047. @i{ devid = starpu_worker_get_devid(id);}
  2048. @i{ err = starpu_opencl_load_kernel(&kernel, &queue, &programs,}
  2049. @i{ "vector_mult_opencl", devid); /* @b{Name of the codelet defined above} */}
  2050. @i{ if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);}
  2051. @i{ err = clSetKernelArg(kernel, 0, sizeof(cl_mem), &val);}
  2052. @i{ err |= clSetKernelArg(kernel, 1, sizeof(n), &n);}
  2053. @i{ err |= clSetKernelArg(kernel, 2, sizeof(*factor), factor);}
  2054. @i{ if (err) STARPU_OPENCL_REPORT_ERROR(err);}
  2055. @i{ @{}
  2056. @i{ size_t global=1;}
  2057. @i{ size_t local=1;}
  2058. @i{ err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &global, &local, 0, NULL, NULL);}
  2059. @i{ if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);}
  2060. @i{ @}}
  2061. @i{ clFinish(queue);}
  2062. @i{ starpu_opencl_release_kernel(kernel);}
  2063. @}
  2064. @end smallexample
  2065. @end cartouche
  2066. @node Definition of the Main Code
  2067. @subsection Definition of the Main Code
  2068. The CPU implementation is the same as in the previous section.
  2069. Here is the source of the main application. You can notice the value of the
  2070. field @code{where} for the codelet. We specify
  2071. @code{STARPU_CPU|STARPU_CUDA|STARPU_OPENCL} to indicate to StarPU that the codelet
  2072. can be executed either on a CPU or on a CUDA or an OpenCL device.
  2073. @cartouche
  2074. @smallexample
  2075. #include <starpu.h>
  2076. #define NX 2048
  2077. extern void scal_cuda_func(void *buffers[], void *_args);
  2078. extern void scal_cpu_func(void *buffers[], void *_args);
  2079. extern void scal_opencl_func(void *buffers[], void *_args);
  2080. /* @b{Definition of the codelet} */
  2081. static starpu_codelet cl = @{
  2082. .where = STARPU_CPU|STARPU_CUDA|STARPU_OPENCL; /* @b{It can be executed on a CPU,} */
  2083. /* @b{on a CUDA device, or on an OpenCL device} */
  2084. .cuda_func = scal_cuda_func;
  2085. .cpu_func = scal_cpu_func;
  2086. .opencl_func = scal_opencl_func;
  2087. .nbuffers = 1;
  2088. @}
  2089. #ifdef STARPU_USE_OPENCL
  2090. /* @b{The compiled version of the OpenCL program} */
  2091. struct starpu_opencl_program programs;
  2092. #endif
  2093. int main(int argc, char **argv)
  2094. @{
  2095. float *vector;
  2096. int i, ret;
  2097. float factor=3.0;
  2098. struct starpu_task *task;
  2099. starpu_data_handle vector_handle;
  2100. starpu_init(NULL); /* @b{Initialising StarPU} */
  2101. #ifdef STARPU_USE_OPENCL
  2102. starpu_opencl_load_opencl_from_file("examples/basic_examples/vector_scal_opencl_codelet.cl",
  2103. &programs);
  2104. #endif
  2105. vector = malloc(NX*sizeof(vector[0]));
  2106. assert(vector);
  2107. for(i=0 ; i<NX ; i++) vector[i] = i;
  2108. @end smallexample
  2109. @end cartouche
  2110. @cartouche
  2111. @smallexample
  2112. /* @b{Registering data within StarPU} */
  2113. starpu_vector_data_register(&vector_handle, 0, (uintptr_t)vector,
  2114. NX, sizeof(vector[0]));
  2115. /* @b{Definition of the task} */
  2116. task = starpu_task_create();
  2117. task->cl = &cl;
  2118. task->buffers[0].handle = vector_handle;
  2119. task->buffers[0].mode = STARPU_RW;
  2120. task->cl_arg = &factor;
  2121. task->cl_arg_size = sizeof(factor);
  2122. @end smallexample
  2123. @end cartouche
  2124. @cartouche
  2125. @smallexample
  2126. /* @b{Submitting the task} */
  2127. ret = starpu_task_submit(task);
  2128. if (ret == -ENODEV) @{
  2129. fprintf(stderr, "No worker may execute this task\n");
  2130. return 1;
  2131. @}
  2132. /* @b{Waiting for its termination} */
  2133. starpu_task_wait_for_all();
  2134. /* @b{Update the vector in RAM} */
  2135. starpu_data_sync_with_mem(vector_handle, STARPU_R);
  2136. @end smallexample
  2137. @end cartouche
  2138. @cartouche
  2139. @smallexample
  2140. /* @b{Access the data} */
  2141. for(i=0 ; i<NX; i++) @{
  2142. fprintf(stderr, "%f ", vector[i]);
  2143. @}
  2144. fprintf(stderr, "\n");
  2145. /* @b{Release the data and shutdown StarPU} */
  2146. starpu_data_release_from_mem(vector_handle);
  2147. starpu_shutdown();
  2148. return 0;
  2149. @}
  2150. @end smallexample
  2151. @end cartouche
  2152. @node Compilation and execution of Hybrid Vector Scaling
  2153. @subsection Compilation and execution of Hybrid Vector Scaling
  2154. The Makefile given at the beginning of the section must be extended to
  2155. give the rules to compile the CUDA source code.
  2156. @cartouche
  2157. @smallexample
  2158. CFLAGS += $(shell pkg-config --cflags libstarpu)
  2159. LDFLAGS += $(shell pkg-config --libs libstarpu)
  2160. CC = gcc
  2161. vector: vector.o vector_cpu.o vector_cuda.o
  2162. %.o: %.cu
  2163. nvcc $(CFLAGS) $< -c $@
  2164. clean:
  2165. rm -f vector *.o
  2166. @end smallexample
  2167. @end cartouche
  2168. @smallexample
  2169. % make
  2170. @end smallexample
  2171. and to execute it, with the default configuration:
  2172. @smallexample
  2173. % ./vector
  2174. 0.000000 3.000000 6.000000 9.000000 12.000000
  2175. @end smallexample
  2176. or for example, by disabling CPU devices:
  2177. @smallexample
  2178. % STARPU_NCPUS=0 ./vector
  2179. 0.000000 3.000000 6.000000 9.000000 12.000000
  2180. @end smallexample
  2181. or by disabling CUDA devices:
  2182. @smallexample
  2183. % STARPU_NCUDA=0 ./vector
  2184. 0.000000 3.000000 6.000000 9.000000 12.000000
  2185. @end smallexample
  2186. @c TODO: Add performance model example (and update basic_examples)
  2187. @node Filtering data
  2188. @section Filtering data
  2189. @cartouche
  2190. @smallexample
  2191. int vector[NX];
  2192. starpu_data_handle handle;
  2193. /* Declare data to StarPU */
  2194. starpu_vector_data_register(&handle, 0, (uintptr_t)vector, NX, sizeof(vector[0]));
  2195. /* Partition the vector in PARTS sub-vectors */
  2196. starpu_filter f =
  2197. @{
  2198. .filter_func = starpu_block_filter_func_vector,
  2199. .nchildren = PARTS,
  2200. .get_nchildren = NULL,
  2201. .get_child_ops = NULL
  2202. @};
  2203. starpu_data_partition(handle, &f);
  2204. @end smallexample
  2205. @end cartouche
  2206. @cartouche
  2207. @smallexample
  2208. /* Submit a task on each sub-vector */
  2209. for (i=0; i<starpu_data_get_nb_children(handle); i++) @{
  2210. starpu_data_handle sub_handle = starpu_data_get_sub_data(handle, 1, i);
  2211. struct starpu_task *task = starpu_task_create();
  2212. task->buffers[0].handle = sub_handle;
  2213. task->buffers[0].mode = STARPU_RW;
  2214. task->cl = &cl;
  2215. task->synchronous = 1;
  2216. task->cl_arg = &factor;
  2217. task->cl_arg_size = sizeof(factor);
  2218. starpu_task_submit(task);
  2219. @}
  2220. @end smallexample
  2221. @end cartouche
  2222. @c ---------------------------------------------------------------------
  2223. @c Advanced Topics
  2224. @c ---------------------------------------------------------------------
  2225. @node Advanced Topics
  2226. @chapter Advanced Topics
  2227. @menu
  2228. * Defining a new data interface::
  2229. * Defining a new scheduling policy::
  2230. @end menu
  2231. @node Defining a new data interface
  2232. @section Defining a new data interface
  2233. @menu
  2234. * struct starpu_data_interface_ops_t:: Per-interface methods
  2235. * struct starpu_data_copy_methods:: Per-interface data transfer methods
  2236. * An example of data interface:: An example of data interface
  2237. @end menu
  2238. @c void *starpu_data_get_interface_on_node(starpu_data_handle handle, unsigned memory_node); TODO
  2239. @node struct starpu_data_interface_ops_t
  2240. @subsection @code{struct starpu_data_interface_ops_t} -- Per-interface methods
  2241. @table @asis
  2242. @item @emph{Description}:
  2243. TODO describe all the different fields
  2244. @end table
  2245. @node struct starpu_data_copy_methods
  2246. @subsection @code{struct starpu_data_copy_methods} -- Per-interface data transfer methods
  2247. @table @asis
  2248. @item @emph{Description}:
  2249. TODO describe all the different fields
  2250. @end table
  2251. @node An example of data interface
  2252. @subsection An example of data interface
  2253. @table @asis
  2254. TODO
  2255. @end table
  2256. @node Defining a new scheduling policy
  2257. @section Defining a new scheduling policy
  2258. TODO
  2259. @c ---------------------------------------------------------------------
  2260. @c Appendices
  2261. @c ---------------------------------------------------------------------
  2262. @c ---------------------------------------------------------------------
  2263. @c Full source code for the 'Scaling a Vector' example
  2264. @c ---------------------------------------------------------------------
  2265. @node Full source code for the 'Scaling a Vector' example
  2266. @appendix Full source code for the 'Scaling a Vector' example
  2267. @menu
  2268. * Main application::
  2269. * CPU Codelet::
  2270. * CUDA Codelet::
  2271. * OpenCL Codelet::
  2272. @end menu
  2273. @node Main application
  2274. @section Main application
  2275. @smallexample
  2276. @include vector_scal_c.texi
  2277. @end smallexample
  2278. @node CPU Codelet
  2279. @section CPU Codelet
  2280. @smallexample
  2281. @include vector_scal_cpu.texi
  2282. @end smallexample
  2283. @node CUDA Codelet
  2284. @section CUDA Codelet
  2285. @smallexample
  2286. @include vector_scal_cuda.texi
  2287. @end smallexample
  2288. @node OpenCL Codelet
  2289. @section OpenCL Codelet
  2290. @menu
  2291. * Invoking the kernel::
  2292. * Source of the kernel::
  2293. @end menu
  2294. @node Invoking the kernel
  2295. @subsection Invoking the kernel
  2296. @smallexample
  2297. @include vector_scal_opencl.texi
  2298. @end smallexample
  2299. @node Source of the kernel
  2300. @subsection Source of the kernel
  2301. @smallexample
  2302. @include vector_scal_opencl_codelet.texi
  2303. @end smallexample
  2304. @bye