starpu.texi 103 KB

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