starpu.texi 132 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817
  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 1fill
  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. * Basic Examples:: Basic examples of the use of StarPU
  30. * Performance feedback:: Performance debugging tools
  31. * Configuring StarPU:: How to configure StarPU
  32. * StarPU API:: The API to use StarPU
  33. * Advanced Topics:: Advanced use of StarPU
  34. * Full source code for the 'Scaling a Vector' example::
  35. @end menu
  36. @c ---------------------------------------------------------------------
  37. @c Introduction to StarPU
  38. @c ---------------------------------------------------------------------
  39. @node Introduction
  40. @chapter Introduction to StarPU
  41. @menu
  42. * Motivation:: Why StarPU ?
  43. * StarPU in a Nutshell:: The Fundamentals of StarPU
  44. @end menu
  45. @node Motivation
  46. @section Motivation
  47. @c complex machines with heterogeneous cores/devices
  48. The use of specialized hardware such as accelerators or coprocessors offers an
  49. interesting approach to overcome the physical limits encountered by processor
  50. architects. As a result, many machines are now equipped with one or several
  51. accelerators (e.g. a GPU), in addition to the usual processor(s). While a lot of
  52. efforts have been devoted to offload computation onto such accelerators, very
  53. little attention as been paid to portability concerns on the one hand, and to the
  54. possibility of having heterogeneous accelerators and processors to interact on the other hand.
  55. StarPU is a runtime system that offers support for heterogeneous multicore
  56. architectures, it not only offers a unified view of the computational resources
  57. (i.e. CPUs and accelerators at the same time), but it also takes care of
  58. efficiently mapping and executing tasks onto an heterogeneous machine while
  59. transparently handling low-level issues in a portable fashion.
  60. @c this leads to a complicated distributed memory design
  61. @c which is not (easily) manageable by hand
  62. @c added value/benefits of StarPU
  63. @c - portability
  64. @c - scheduling, perf. portability
  65. @node StarPU in a Nutshell
  66. @section StarPU in a Nutshell
  67. @menu
  68. * Codelet and Tasks::
  69. * StarPU Data Management Library::
  70. * Research Papers::
  71. @end menu
  72. From a programming point of view, StarPU is not a new language but a library
  73. that executes tasks explicitly submitted by the application. The data that a
  74. task manipulates are automatically transferred onto the accelerator so that the
  75. programmer does not have to take care of complex data movements. StarPU also
  76. takes particular care of scheduling those tasks efficiently and allows
  77. scheduling experts to implement custom scheduling policies in a portable
  78. fashion.
  79. @c explain the notion of codelet and task (i.e. g(A, B)
  80. @node Codelet and Tasks
  81. @subsection Codelet and Tasks
  82. One of StarPU primary data structure is the @b{codelet}. A codelet describes a
  83. computational kernel that can possibly be implemented on multiple architectures
  84. such as a CPU, a CUDA device or a Cell's SPU.
  85. @c TODO insert illustration f : f_spu, f_cpu, ...
  86. Another important data structure is the @b{task}. Executing a StarPU task
  87. consists in applying a codelet on a data set, on one of the architectures on
  88. which the codelet is implemented. In addition to the codelet that a task
  89. implements, it also describes which data are accessed, and how they are
  90. accessed during the computation (read and/or write).
  91. StarPU tasks are asynchronous: submitting a task to StarPU is a non-blocking
  92. operation. The task structure can also specify a @b{callback} function that is
  93. called once StarPU has properly executed the task. It also contains optional
  94. fields that the application may use to give hints to the scheduler (such as
  95. priority levels).
  96. A task may be identified by a unique 64-bit number which we refer as a @b{tag}.
  97. Task dependencies can be enforced either by the means of callback functions, or
  98. by expressing dependencies between tags.
  99. @c TODO insert illustration f(Ar, Brw, Cr) + ..
  100. @c DSM
  101. @node StarPU Data Management Library
  102. @subsection StarPU Data Management Library
  103. Because StarPU schedules tasks at runtime, data transfers have to be
  104. done automatically and ``just-in-time'' between processing units,
  105. relieving the application programmer from explicit data transfers.
  106. Moreover, to avoid unnecessary transfers, StarPU keeps data
  107. where it was last needed, even if was modified there, and it
  108. allows multiple copies of the same data to reside at the same time on
  109. several processing units as long as it is not modified.
  110. @node Research Papers
  111. @subsection Research Papers
  112. Research papers about StarPU can be found at
  113. @indicateurl{http://runtime.bordeaux.inria.fr/Publis/Keyword/STARPU.html}
  114. Notably a good overview in the research report
  115. @indicateurl{http://hal.archives-ouvertes.fr/inria-00467677}
  116. @c ---------------------------------------------------------------------
  117. @c Installing StarPU
  118. @c ---------------------------------------------------------------------
  119. @node Installing StarPU
  120. @chapter Installing StarPU
  121. @menu
  122. * Downloading StarPU::
  123. * Configuration of StarPU::
  124. * Building and Installing StarPU::
  125. @end menu
  126. StarPU can be built and installed by the standard means of the GNU
  127. autotools. The following chapter is intended to briefly remind how these tools
  128. can be used to install StarPU.
  129. @node Downloading StarPU
  130. @section Downloading StarPU
  131. @menu
  132. * Getting Sources::
  133. * Optional dependencies::
  134. @end menu
  135. @node Getting Sources
  136. @subsection Getting Sources
  137. The source code is managed by a Subversion server hosted by the
  138. InriaGforge. To get the source code, you need:
  139. @itemize
  140. @item
  141. To install the client side of the software Subversion if it is
  142. not already available on your system. The software can be obtained from
  143. @indicateurl{http://subversion.tigris.org}.
  144. @item
  145. You can check out the project's SVN repository through anonymous
  146. access. This will provide you with a read access to the
  147. repository.
  148. You can also choose to become a member of the project @code{starpu}.
  149. For this, you first need to get an account to the gForge server. You
  150. can then send a request to join the project
  151. (@indicateurl{https://gforge.inria.fr/project/request.php?group_id=1570}).
  152. @item
  153. More information on how to get a gForge account, to become a member of
  154. a project, or on any other related task can be obtained from the
  155. InriaGforge at @indicateurl{https://gforge.inria.fr/}. The most important
  156. thing is to upload your public SSH key on the gForge server (see the
  157. FAQ at @indicateurl{http://siteadmin.gforge.inria.fr/FAQ.html#Q6} for
  158. instructions).
  159. @end itemize
  160. You can now check out the latest version from the Subversion server:
  161. @itemize
  162. @item
  163. using the anonymous access via svn:
  164. @example
  165. % svn checkout svn://scm.gforge.inria.fr/svn/starpu/trunk
  166. @end example
  167. @item
  168. using the anonymous access via https:
  169. @example
  170. % svn checkout --username anonsvn https://scm.gforge.inria.fr/svn/starpu/trunk
  171. @end example
  172. The password is @code{anonsvn}.
  173. @item
  174. using your gForge account
  175. @example
  176. % svn checkout svn+ssh://<login>@@scm.gforge.inria.fr/svn/starpu/trunk
  177. @end example
  178. @end itemize
  179. These steps require to run autoconf and automake to generate the
  180. @code{./configure} script. This can be done by calling
  181. @code{./autogen.sh}. The required version for autoconf is 2.60 or
  182. higher.
  183. @example
  184. % ./autogen.sh
  185. @end example
  186. If the autotools are not available on your machine or not recent
  187. enough, you can choose to download the latest nightly tarball, which
  188. is provided with a @code{configure} script.
  189. @example
  190. % wget http://starpu.gforge.inria.fr/testing/starpu-nightly-latest.tar.gz
  191. @end example
  192. @node Optional dependencies
  193. @subsection Optional dependencies
  194. The topology discovery library, @code{hwloc}, is not mandatory to use StarPU
  195. but strongly recommended. It allows to increase performance, and to
  196. perform some topology aware scheduling.
  197. @code{hwloc} is available in major distributions and for most OSes and can be
  198. downloaded from @indicateurl{http://www.open-mpi.org/software/hwloc}.
  199. @node Configuration of StarPU
  200. @section Configuration of StarPU
  201. @menu
  202. * Generating Makefiles and configuration scripts::
  203. * Running the configuration::
  204. @end menu
  205. @node Generating Makefiles and configuration scripts
  206. @subsection Generating Makefiles and configuration scripts
  207. This step is not necessary when using the tarball releases of StarPU. If you
  208. are using the source code from the svn repository, you first need to generate
  209. the configure scripts and the Makefiles.
  210. @example
  211. % ./autogen.sh
  212. @end example
  213. @node Running the configuration
  214. @subsection Running the configuration
  215. @example
  216. % ./configure
  217. @end example
  218. Details about options that are useful to give to @code{./configure} are given in
  219. @ref{Compilation configuration}.
  220. @node Building and Installing StarPU
  221. @section Building and Installing StarPU
  222. @menu
  223. * Building::
  224. * Sanity Checks::
  225. * Installing::
  226. @end menu
  227. @node Building
  228. @subsection Building
  229. @example
  230. % make
  231. @end example
  232. @node Sanity Checks
  233. @subsection Sanity Checks
  234. In order to make sure that StarPU is working properly on the system, it is also
  235. possible to run a test suite.
  236. @example
  237. % make check
  238. @end example
  239. @node Installing
  240. @subsection Installing
  241. In order to install StarPU at the location that was specified during
  242. configuration:
  243. @example
  244. % make install
  245. @end example
  246. @c ---------------------------------------------------------------------
  247. @c Using StarPU
  248. @c ---------------------------------------------------------------------
  249. @node Using StarPU
  250. @chapter Using StarPU
  251. @menu
  252. * Setting flags for compiling and linking applications::
  253. * Running a basic StarPU application::
  254. @end menu
  255. @node Setting flags for compiling and linking applications
  256. @section Setting flags for compiling and linking applications
  257. Compiling and linking an application against StarPU may require to use
  258. specific flags or libraries (for instance @code{CUDA} or @code{libspe2}).
  259. To this end, it is possible to use the @code{pkg-config} tool.
  260. If StarPU was not installed at some standard location, the path of StarPU's
  261. library must be specified in the @code{PKG_CONFIG_PATH} environment variable so
  262. that @code{pkg-config} can find it. For example if StarPU was installed in
  263. @code{$prefix_dir}:
  264. @example
  265. % PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$prefix_dir/lib/pkgconfig
  266. @end example
  267. The flags required to compile or link against StarPU are then
  268. accessible with the following commands:
  269. @example
  270. % pkg-config --cflags libstarpu # options for the compiler
  271. % pkg-config --libs libstarpu # options for the linker
  272. @end example
  273. @node Running a basic StarPU application
  274. @section Running a basic StarPU application
  275. Basic examples using StarPU have been built in the directory
  276. @code{$prefix_dir/lib/starpu/examples/}. You can for example run the
  277. example @code{vector_scal}.
  278. @example
  279. % $prefix_dir/lib/starpu/examples/vector_scal
  280. BEFORE : First element was 1.000000
  281. AFTER First element is 3.140000
  282. %
  283. @end example
  284. When StarPU is used for the first time, the directory
  285. @code{$HOME/.starpu/} is created, performance models will be stored in
  286. that directory.
  287. Please note that buses are benchmarked when StarPU is launched for the
  288. first time. This may take a few minutes, or less if @code{hwloc} is
  289. installed. This step is done only once per user and per machine.
  290. @c ---------------------------------------------------------------------
  291. @c Basic Examples
  292. @c ---------------------------------------------------------------------
  293. @node Basic Examples
  294. @chapter Basic Examples
  295. @menu
  296. * Compiling and linking options::
  297. * Hello World:: Submitting Tasks
  298. * Scaling a Vector:: Manipulating Data
  299. * Vector Scaling on an Hybrid CPU/GPU Machine:: Handling Heterogeneous Architectures
  300. * Task and Worker Profiling::
  301. * Partitioning Data:: Partitioning Data
  302. * Performance model example::
  303. * Theoretical lower bound on execution time::
  304. * More examples:: More examples shipped with StarPU
  305. @end menu
  306. @node Compiling and linking options
  307. @section Compiling and linking options
  308. Let's suppose StarPU has been installed in the directory
  309. @code{$STARPU_DIR}. As explained in @ref{Setting flags for compiling and linking applications},
  310. the variable @code{PKG_CONFIG_PATH} needs to be set. It is also
  311. necessary to set the variable @code{LD_LIBRARY_PATH} to locate dynamic
  312. libraries at runtime.
  313. @example
  314. % PKG_CONFIG_PATH=$STARPU_DIR/lib/pkgconfig:$PKG_CONFIG_PATH
  315. % LD_LIBRARY_PATH=$STARPU_DIR/lib:$LD_LIBRARY_PATH
  316. @end example
  317. The Makefile could for instance contain the following lines to define which
  318. options must be given to the compiler and to the linker:
  319. @cartouche
  320. @example
  321. CFLAGS += $$(pkg-config --cflags libstarpu)
  322. LDFLAGS += $$(pkg-config --libs libstarpu)
  323. @end example
  324. @end cartouche
  325. @node Hello World
  326. @section Hello World
  327. @menu
  328. * Required Headers::
  329. * Defining a Codelet::
  330. * Submitting a Task::
  331. * Execution of Hello World::
  332. @end menu
  333. In this section, we show how to implement a simple program that submits a task to StarPU.
  334. @node Required Headers
  335. @subsection Required Headers
  336. The @code{starpu.h} header should be included in any code using StarPU.
  337. @cartouche
  338. @smallexample
  339. #include <starpu.h>
  340. @end smallexample
  341. @end cartouche
  342. @node Defining a Codelet
  343. @subsection Defining a Codelet
  344. @cartouche
  345. @smallexample
  346. void cpu_func(void *buffers[], void *cl_arg)
  347. @{
  348. float *array = cl_arg;
  349. printf("Hello world (array = @{%f, %f@} )\n", array[0], array[1]);
  350. @}
  351. starpu_codelet cl =
  352. @{
  353. .where = STARPU_CPU,
  354. .cpu_func = cpu_func,
  355. .nbuffers = 0
  356. @};
  357. @end smallexample
  358. @end cartouche
  359. A codelet is a structure that represents a computational kernel. Such a codelet
  360. may contain an implementation of the same kernel on different architectures
  361. (e.g. CUDA, Cell's SPU, x86, ...).
  362. The @code{nbuffers} field specifies the number of data buffers that are
  363. manipulated by the codelet: here the codelet does not access or modify any data
  364. that is controlled by our data management library. Note that the argument
  365. passed to the codelet (the @code{cl_arg} field of the @code{starpu_task}
  366. structure) does not count as a buffer since it is not managed by our data
  367. management library.
  368. @c TODO need a crossref to the proper description of "where" see bla for more ...
  369. We create a codelet which may only be executed on the CPUs. The @code{where}
  370. field is a bitmask that defines where the codelet may be executed. Here, the
  371. @code{STARPU_CPU} value means that only CPUs can execute this codelet
  372. (@pxref{Codelets and Tasks} for more details on this field).
  373. When a CPU core executes a codelet, it calls the @code{cpu_func} function,
  374. which @emph{must} have the following prototype:
  375. @code{void (*cpu_func)(void *buffers[], void *cl_arg);}
  376. In this example, we can ignore the first argument of this function which gives a
  377. description of the input and output buffers (e.g. the size and the location of
  378. the matrices). The second argument is a pointer to a buffer passed as an
  379. argument to the codelet by the means of the @code{cl_arg} field of the
  380. @code{starpu_task} structure.
  381. @c TODO rewrite so that it is a little clearer ?
  382. Be aware that this may be a pointer to a
  383. @emph{copy} of the actual buffer, and not the pointer given by the programmer:
  384. if the codelet modifies this buffer, there is no guarantee that the initial
  385. buffer will be modified as well: this for instance implies that the buffer
  386. cannot be used as a synchronization medium.
  387. @node Submitting a Task
  388. @subsection Submitting a Task
  389. @cartouche
  390. @smallexample
  391. void callback_func(void *callback_arg)
  392. @{
  393. printf("Callback function (arg %x)\n", callback_arg);
  394. @}
  395. int main(int argc, char **argv)
  396. @{
  397. /* @b{initialize StarPU} */
  398. starpu_init(NULL);
  399. struct starpu_task *task = starpu_task_create();
  400. task->cl = &cl; /* @b{Pointer to the codelet defined above} */
  401. float array[2] = @{1.0f, -1.0f@};
  402. task->cl_arg = &array;
  403. task->cl_arg_size = sizeof(array);
  404. task->callback_func = callback_func;
  405. task->callback_arg = 0x42;
  406. /* @b{starpu_task_submit will be a blocking call} */
  407. task->synchronous = 1;
  408. /* @b{submit the task to StarPU} */
  409. starpu_task_submit(task);
  410. /* @b{terminate StarPU} */
  411. starpu_shutdown();
  412. return 0;
  413. @}
  414. @end smallexample
  415. @end cartouche
  416. Before submitting any tasks to StarPU, @code{starpu_init} must be called. The
  417. @code{NULL} argument specifies that we use default configuration. Tasks cannot
  418. be submitted after the termination of StarPU by a call to
  419. @code{starpu_shutdown}.
  420. In the example above, a task structure is allocated by a call to
  421. @code{starpu_task_create}. This function only allocates and fills the
  422. corresponding structure with the default settings (@pxref{starpu_task_create}),
  423. but it does not submit the task to StarPU.
  424. @c not really clear ;)
  425. The @code{cl} field is a pointer to the codelet which the task will
  426. execute: in other words, the codelet structure describes which computational
  427. kernel should be offloaded on the different architectures, and the task
  428. structure is a wrapper containing a codelet and the piece of data on which the
  429. codelet should operate.
  430. The optional @code{cl_arg} field is a pointer to a buffer (of size
  431. @code{cl_arg_size}) with some parameters for the kernel
  432. described by the codelet. For instance, if a codelet implements a computational
  433. kernel that multiplies its input vector by a constant, the constant could be
  434. specified by the means of this buffer, instead of registering it.
  435. Once a task has been executed, an optional callback function can be called.
  436. While the computational kernel could be offloaded on various architectures, the
  437. callback function is always executed on a CPU. The @code{callback_arg}
  438. pointer is passed as an argument of the callback. The prototype of a callback
  439. function must be:
  440. @code{void (*callback_function)(void *);}
  441. If the @code{synchronous} field is non-null, task submission will be
  442. synchronous: the @code{starpu_task_submit} function will not return until the
  443. task was executed. Note that the @code{starpu_shutdown} method does not
  444. guarantee that asynchronous tasks have been executed before it returns.
  445. @node Execution of Hello World
  446. @subsection Execution of Hello World
  447. @smallexample
  448. % make hello_world
  449. cc $(pkg-config --cflags libstarpu) $(pkg-config --libs libstarpu) hello_world.c -o hello_world
  450. % ./hello_world
  451. Hello world (array = @{1.000000, -1.000000@} )
  452. Callback function (arg 42)
  453. @end smallexample
  454. @node Scaling a Vector
  455. @section Manipulating Data: Scaling a Vector
  456. The previous example has shown how to submit tasks. In this section,
  457. we show how StarPU tasks can manipulate data. The full source code for
  458. this example is given in @ref{Full source code for the 'Scaling a Vector' example}.
  459. @menu
  460. * Source code of Vector Scaling::
  461. * Execution of Vector Scaling::
  462. @end menu
  463. @node Source code of Vector Scaling
  464. @subsection Source code of Vector Scaling
  465. Programmers can describe the data layout of their application so that StarPU is
  466. responsible for enforcing data coherency and availability across the machine.
  467. Instead of handling complex (and non-portable) mechanisms to perform data
  468. movements, programmers only declare which piece of data is accessed and/or
  469. modified by a task, and StarPU makes sure that when a computational kernel
  470. starts somewhere (e.g. on a GPU), its data are available locally.
  471. Before submitting those tasks, the programmer first needs to declare the
  472. different pieces of data to StarPU using the @code{starpu_*_data_register}
  473. functions. To ease the development of applications for StarPU, it is possible
  474. to describe multiple types of data layout. A type of data layout is called an
  475. @b{interface}. By default, there are different interfaces available in StarPU:
  476. here we will consider the @b{vector interface}.
  477. The following lines show how to declare an array of @code{NX} elements of type
  478. @code{float} using the vector interface:
  479. @cartouche
  480. @smallexample
  481. float vector[NX];
  482. starpu_data_handle vector_handle;
  483. starpu_vector_data_register(&vector_handle, 0, (uintptr_t)vector, NX,
  484. sizeof(vector[0]));
  485. @end smallexample
  486. @end cartouche
  487. The first argument, called the @b{data handle}, is an opaque pointer which
  488. designates the array in StarPU. This is also the structure which is used to
  489. describe which data is used by a task. The second argument is the node number
  490. where the data currently resides. Here it is 0 since the @code{vector} array is in
  491. the main memory. Then comes the pointer @code{vector} where the data can be found,
  492. the number of elements in the vector and the size of each element.
  493. It is possible to construct a StarPU task that will manipulate the
  494. vector and a constant factor.
  495. @cartouche
  496. @smallexample
  497. float factor = 3.14;
  498. struct starpu_task *task = starpu_task_create();
  499. task->cl = &cl; /* @b{Pointer to the codelet defined below} */
  500. task->buffers[0].handle = vector_handle; /* @b{First parameter of the codelet} */
  501. task->buffers[0].mode = STARPU_RW;
  502. task->cl_arg = &factor;
  503. task->cl_arg_size = sizeof(factor);
  504. task->synchronous = 1;
  505. starpu_task_submit(task);
  506. @end smallexample
  507. @end cartouche
  508. Since the factor is a mere float value parameter, it does not need a preliminary registration, and
  509. can just be passed through the @code{cl_arg} pointer like in the previous
  510. example. The vector parameter is described by its handle.
  511. There are two fields in each element of the @code{buffers} array.
  512. @code{handle} is the handle of the data, and @code{mode} specifies how the
  513. kernel will access the data (@code{STARPU_R} for read-only, @code{STARPU_W} for
  514. write-only and @code{STARPU_RW} for read and write access).
  515. The definition of the codelet can be written as follows:
  516. @cartouche
  517. @smallexample
  518. void scal_cpu_func(void *buffers[], void *cl_arg)
  519. @{
  520. unsigned i;
  521. float *factor = cl_arg;
  522. /* length of the vector */
  523. unsigned n = STARPU_VECTOR_GET_NX(buffers[0]);
  524. /* local copy of the vector pointer */
  525. float *val = (float *)STARPU_VECTOR_GET_PTR(buffers[0]);
  526. for (i = 0; i < n; i++)
  527. val[i] *= *factor;
  528. @}
  529. starpu_codelet cl = @{
  530. .where = STARPU_CPU,
  531. .cpu_func = scal_cpu_func,
  532. .nbuffers = 1
  533. @};
  534. @end smallexample
  535. @end cartouche
  536. The second argument of the @code{scal_cpu_func} function contains a pointer to the
  537. parameters of the codelet (given in @code{task->cl_arg}), so that we read the
  538. constant factor from this pointer. The first argument is an array that gives
  539. a description of all the buffers passed in the @code{task->buffers}@ array. The
  540. size of this array is given by the @code{nbuffers} field of the codelet
  541. structure. For the sake of generality, this array contains pointers to the
  542. different interfaces describing each buffer. In the case of the @b{vector
  543. interface}, the location of the vector (resp. its length) is accessible in the
  544. @code{ptr} (resp. @code{nx}) of this array. Since the vector is accessed in a
  545. read-write fashion, any modification will automatically affect future accesses
  546. to this vector made by other tasks.
  547. @node Execution of Vector Scaling
  548. @subsection Execution of Vector Scaling
  549. @smallexample
  550. % make vector_scal
  551. cc $(pkg-config --cflags libstarpu) $(pkg-config --libs libstarpu) vector_scal.c -o vector_scal
  552. % ./vector_scal
  553. 0.000000 3.000000 6.000000 9.000000 12.000000
  554. @end smallexample
  555. @node Vector Scaling on an Hybrid CPU/GPU Machine
  556. @section Vector Scaling on an Hybrid CPU/GPU Machine
  557. Contrary to the previous examples, the task submitted in this example may not
  558. only be executed by the CPUs, but also by a CUDA device.
  559. @menu
  560. * Definition of the CUDA Codelet::
  561. * Definition of the OpenCL Codelet::
  562. * Definition of the Main Code::
  563. * Execution of Hybrid Vector Scaling::
  564. @end menu
  565. @node Definition of the CUDA Codelet
  566. @subsection Definition of the CUDA Codelet
  567. The CUDA implementation can be written as follows. It needs to be
  568. compiled with a CUDA compiler such as nvcc, the NVIDIA CUDA compiler
  569. driver.
  570. @cartouche
  571. @smallexample
  572. #include <starpu.h>
  573. static __global__ void vector_mult_cuda(float *val, unsigned n,
  574. float factor)
  575. @{
  576. unsigned i;
  577. for(i = 0 ; i < n ; i++)
  578. val[i] *= factor;
  579. @}
  580. extern "C" void scal_cuda_func(void *buffers[], void *_args)
  581. @{
  582. float *factor = (float *)_args;
  583. /* length of the vector */
  584. unsigned n = STARPU_VECTOR_GET_NX(buffers[0]);
  585. /* local copy of the vector pointer */
  586. float *val = (float *)STARPU_VECTOR_GET_PTR(buffers[0]);
  587. @i{ vector_mult_cuda<<<1,1>>>(val, n, *factor);}
  588. @i{ cudaThreadSynchronize();}
  589. @}
  590. @end smallexample
  591. @end cartouche
  592. @node Definition of the OpenCL Codelet
  593. @subsection Definition of the OpenCL Codelet
  594. The OpenCL implementation can be written as follows. StarPU provides
  595. tools to compile a OpenCL codelet stored in a file.
  596. @cartouche
  597. @smallexample
  598. __kernel void vector_mult_opencl(__global float* val, int nx, float factor)
  599. @{
  600. const int i = get_global_id(0);
  601. if (i < nx) @{
  602. val[i] *= factor;
  603. @}
  604. @}
  605. @end smallexample
  606. @end cartouche
  607. @cartouche
  608. @smallexample
  609. #include <starpu.h>
  610. @i{#include <starpu_opencl.h>}
  611. @i{extern struct starpu_opencl_program programs;}
  612. void scal_opencl_func(void *buffers[], void *_args)
  613. @{
  614. float *factor = _args;
  615. @i{ int id, devid, err;}
  616. @i{ cl_kernel kernel;}
  617. @i{ cl_command_queue queue;}
  618. /* length of the vector */
  619. unsigned n = STARPU_VECTOR_GET_NX(buffers[0]);
  620. /* local copy of the vector pointer */
  621. float *val = (float *)STARPU_VECTOR_GET_PTR(buffers[0]);
  622. @i{ id = starpu_worker_get_id();}
  623. @i{ devid = starpu_worker_get_devid(id);}
  624. @i{ err = starpu_opencl_load_kernel(&kernel, &queue, &programs,}
  625. @i{ "vector_mult_opencl", devid); /* @b{Name of the codelet defined above} */}
  626. @i{ if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);}
  627. @i{ err = clSetKernelArg(kernel, 0, sizeof(cl_mem), &val);}
  628. @i{ err |= clSetKernelArg(kernel, 1, sizeof(n), &n);}
  629. @i{ err |= clSetKernelArg(kernel, 2, sizeof(*factor), factor);}
  630. @i{ if (err) STARPU_OPENCL_REPORT_ERROR(err);}
  631. @i{ @{}
  632. @i{ size_t global=1;}
  633. @i{ size_t local=1;}
  634. @i{ err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &global, &local, 0, NULL, NULL);}
  635. @i{ if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);}
  636. @i{ @}}
  637. @i{ clFinish(queue);}
  638. @i{ starpu_opencl_release_kernel(kernel);}
  639. @}
  640. @end smallexample
  641. @end cartouche
  642. @node Definition of the Main Code
  643. @subsection Definition of the Main Code
  644. The CPU implementation is the same as in the previous section.
  645. Here is the source of the main application. You can notice the value of the
  646. field @code{where} for the codelet. We specify
  647. @code{STARPU_CPU|STARPU_CUDA|STARPU_OPENCL} to indicate to StarPU that the codelet
  648. can be executed either on a CPU or on a CUDA or an OpenCL device.
  649. @cartouche
  650. @smallexample
  651. #include <starpu.h>
  652. #define NX 2048
  653. extern void scal_cuda_func(void *buffers[], void *_args);
  654. extern void scal_cpu_func(void *buffers[], void *_args);
  655. extern void scal_opencl_func(void *buffers[], void *_args);
  656. /* @b{Definition of the codelet} */
  657. static starpu_codelet cl = @{
  658. .where = STARPU_CPU|STARPU_CUDA|STARPU_OPENCL; /* @b{It can be executed on a CPU,} */
  659. /* @b{on a CUDA device, or on an OpenCL device} */
  660. .cuda_func = scal_cuda_func;
  661. .cpu_func = scal_cpu_func;
  662. .opencl_func = scal_opencl_func;
  663. .nbuffers = 1;
  664. @}
  665. #ifdef STARPU_USE_OPENCL
  666. /* @b{The compiled version of the OpenCL program} */
  667. struct starpu_opencl_program programs;
  668. #endif
  669. int main(int argc, char **argv)
  670. @{
  671. float *vector;
  672. int i, ret;
  673. float factor=3.0;
  674. struct starpu_task *task;
  675. starpu_data_handle vector_handle;
  676. starpu_init(NULL); /* @b{Initialising StarPU} */
  677. #ifdef STARPU_USE_OPENCL
  678. starpu_opencl_load_opencl_from_file("examples/basic_examples/vector_scal_opencl_codelet.cl",
  679. &programs);
  680. #endif
  681. vector = malloc(NX*sizeof(vector[0]));
  682. assert(vector);
  683. for(i=0 ; i<NX ; i++) vector[i] = i;
  684. @end smallexample
  685. @end cartouche
  686. @cartouche
  687. @smallexample
  688. /* @b{Registering data within StarPU} */
  689. starpu_vector_data_register(&vector_handle, 0, (uintptr_t)vector,
  690. NX, sizeof(vector[0]));
  691. /* @b{Definition of the task} */
  692. task = starpu_task_create();
  693. task->cl = &cl;
  694. task->buffers[0].handle = vector_handle;
  695. task->buffers[0].mode = STARPU_RW;
  696. task->cl_arg = &factor;
  697. task->cl_arg_size = sizeof(factor);
  698. @end smallexample
  699. @end cartouche
  700. @cartouche
  701. @smallexample
  702. /* @b{Submitting the task} */
  703. ret = starpu_task_submit(task);
  704. if (ret == -ENODEV) @{
  705. fprintf(stderr, "No worker may execute this task\n");
  706. return 1;
  707. @}
  708. /* @b{Waiting for its termination} */
  709. starpu_task_wait_for_all();
  710. /* @b{Update the vector in RAM} */
  711. starpu_data_acquire(vector_handle, STARPU_R);
  712. @end smallexample
  713. @end cartouche
  714. @cartouche
  715. @smallexample
  716. /* @b{Access the data} */
  717. for(i=0 ; i<NX; i++) @{
  718. fprintf(stderr, "%f ", vector[i]);
  719. @}
  720. fprintf(stderr, "\n");
  721. /* @b{Release the data and shutdown StarPU} */
  722. starpu_data_release(vector_handle);
  723. starpu_shutdown();
  724. return 0;
  725. @}
  726. @end smallexample
  727. @end cartouche
  728. @node Execution of Hybrid Vector Scaling
  729. @subsection Execution of Hybrid Vector Scaling
  730. The Makefile given at the beginning of the section must be extended to
  731. give the rules to compile the CUDA source code. Note that the source
  732. file of the OpenCL codelet does not need to be compiled now, it will
  733. be compiled at run-time when calling the function
  734. @code{starpu_opencl_load_opencl_from_file()} (@pxref{starpu_opencl_load_opencl_from_file}).
  735. @cartouche
  736. @smallexample
  737. CFLAGS += $(shell pkg-config --cflags libstarpu)
  738. LDFLAGS += $(shell pkg-config --libs libstarpu)
  739. CC = gcc
  740. vector_scal: vector_scal.o vector_scal_cpu.o vector_scal_cuda.o vector_scal_opencl.o
  741. %.o: %.cu
  742. nvcc $(CFLAGS) $< -c $@
  743. clean:
  744. rm -f vector_scal *.o
  745. @end smallexample
  746. @end cartouche
  747. @smallexample
  748. % make
  749. @end smallexample
  750. and to execute it, with the default configuration:
  751. @smallexample
  752. % ./vector_scal
  753. 0.000000 3.000000 6.000000 9.000000 12.000000
  754. @end smallexample
  755. or for example, by disabling CPU devices:
  756. @smallexample
  757. % STARPU_NCPUS=0 ./vector_scal
  758. 0.000000 3.000000 6.000000 9.000000 12.000000
  759. @end smallexample
  760. or by disabling CUDA devices:
  761. @smallexample
  762. % STARPU_NCUDA=0 ./vector_scal
  763. 0.000000 3.000000 6.000000 9.000000 12.000000
  764. @end smallexample
  765. @node Task and Worker Profiling
  766. @section Task and Worker Profiling
  767. A full example showing how to use the profiling API is available in
  768. the StarPU sources in the directory @code{examples/profiling/}.
  769. @cartouche
  770. @smallexample
  771. struct starpu_task *task = starpu_task_create();
  772. task->cl = &cl;
  773. task->synchronous = 1;
  774. /* We will destroy the task structure by hand so that we can
  775. * query the profiling info before the task is destroyed. */
  776. task->destroy = 0;
  777. starpu_task_submit(task);
  778. /* The task is finished, get profiling information */
  779. struct starpu_task_profiling_info *info = task->profiling_info;
  780. /* How much time did it take before the task started ? */
  781. double delay += starpu_timing_timespec_delay_us(&info->submit_time, &info->start_time);
  782. /* How long was the task execution ? */
  783. double length += starpu_timing_timespec_delay_us(&info->start_time, &info->end_time);
  784. /* We don't need the task structure anymore */
  785. starpu_task_destroy(task);
  786. @end smallexample
  787. @end cartouche
  788. @cartouche
  789. @smallexample
  790. /* Display the occupancy of all workers during the test */
  791. int worker;
  792. for (worker = 0; worker < starpu_worker_get_count(); worker++)
  793. @{
  794. struct starpu_worker_profiling_info worker_info;
  795. int ret = starpu_worker_get_profiling_info(worker, &worker_info);
  796. STARPU_ASSERT(!ret);
  797. double total_time = starpu_timing_timespec_to_us(&worker_info.total_time);
  798. double executing_time = starpu_timing_timespec_to_us(&worker_info.executing_time);
  799. double sleeping_time = starpu_timing_timespec_to_us(&worker_info.sleeping_time);
  800. float executing_ratio = 100.0*executing_time/total_time;
  801. float sleeping_ratio = 100.0*sleeping_time/total_time;
  802. char workername[128];
  803. starpu_worker_get_name(worker, workername, 128);
  804. fprintf(stderr, "Worker %s:\n", workername);
  805. fprintf(stderr, "\ttotal time : %.2lf ms\n", total_time*1e-3);
  806. fprintf(stderr, "\texec time : %.2lf ms (%.2f %%)\n", executing_time*1e-3,
  807. executing_ratio);
  808. fprintf(stderr, "\tblocked time : %.2lf ms (%.2f %%)\n", sleeping_time*1e-3,
  809. sleeping_ratio);
  810. @}
  811. @end smallexample
  812. @end cartouche
  813. @node Partitioning Data
  814. @section Partitioning Data
  815. An existing piece of data can be partitioned in sub parts to be used by different tasks, for instance:
  816. @cartouche
  817. @smallexample
  818. int vector[NX];
  819. starpu_data_handle handle;
  820. /* Declare data to StarPU */
  821. starpu_vector_data_register(&handle, 0, (uintptr_t)vector, NX, sizeof(vector[0]));
  822. /* Partition the vector in PARTS sub-vectors */
  823. starpu_filter f =
  824. @{
  825. .filter_func = starpu_block_filter_func_vector,
  826. .nchildren = PARTS,
  827. .get_nchildren = NULL,
  828. .get_child_ops = NULL
  829. @};
  830. starpu_data_partition(handle, &f);
  831. @end smallexample
  832. @end cartouche
  833. @cartouche
  834. @smallexample
  835. /* Submit a task on each sub-vector */
  836. for (i=0; i<starpu_data_get_nb_children(handle); i++) @{
  837. starpu_data_handle sub_handle = starpu_data_get_sub_data(handle, 1, i);
  838. struct starpu_task *task = starpu_task_create();
  839. task->buffers[0].handle = sub_handle;
  840. task->buffers[0].mode = STARPU_RW;
  841. task->cl = &cl;
  842. task->synchronous = 1;
  843. task->cl_arg = &factor;
  844. task->cl_arg_size = sizeof(factor);
  845. starpu_task_submit(task);
  846. @}
  847. @end smallexample
  848. @end cartouche
  849. Partitioning can be applied several times, see
  850. @code{examples/basic_examples/mult.c} and @code{examples/filters/}.
  851. @node Performance model example
  852. @section Performance model example
  853. To achieve good scheduling, StarPU scheduling policies need to be able to
  854. estimate in advance the duration of a task. This is done by giving to codelets a
  855. performance model. There are several kinds of performance models.
  856. @itemize
  857. @item
  858. Providing an estimation from the application itself (@code{STARPU_COMMON} model type and @code{cost_model} field),
  859. see for instance
  860. @code{examples/common/blas_model.c} and @code{examples/common/blas_model.h}. It can also be provided for each architecture (@code{STARPU_PER_ARCH} model type and @code{per_arch} field)
  861. @item
  862. Measured at runtime (STARPU_HISTORY_BASED model type). This assumes that for a
  863. given set of data input/output sizes, the performance will always be about the
  864. same. This is very true for regular kernels on GPUs for instance (<0.1% error),
  865. and just a bit less true on CPUs (~=1% error). This also assumes that there are
  866. few different sets of data input/output sizes. StarPU will then keep record of
  867. the average time of previous executions on the various processing units, and use
  868. it as an estimation. It will also save it in @code{~/.starpu/sampling/codelets}
  869. for further executions. The following is a small code example.
  870. @cartouche
  871. @smallexample
  872. static struct starpu_perfmodel_t mult_perf_model = @{
  873. .type = STARPU_HISTORY_BASED,
  874. .symbol = "mult_perf_model"
  875. @};
  876. starpu_codelet cl = @{
  877. .where = STARPU_CPU,
  878. .cpu_func = cpu_mult,
  879. .nbuffers = 3,
  880. /* for the scheduling policy to be able to use performance models */
  881. .model = &mult_perf_model
  882. @};
  883. @end smallexample
  884. @end cartouche
  885. @item
  886. Measured at runtime and refined by regression (STARPU_REGRESSION_BASED model
  887. type). This still assumes performance regularity, but can work with various data
  888. input sizes, by applying a*n^b+c regression over observed execution times.
  889. @end itemize
  890. @node Theoretical lower bound on execution time
  891. @section Theoretical lower bound on execution time
  892. For kernels with history-based performance models, StarPU can very easily provide a theoretical lower
  893. bound for the execution time of a whole set of tasks. See for
  894. instance @code{examples/lu/lu_example.c}: before submitting tasks,
  895. call @code{starpu_bound_start}, and after complete execution, call
  896. @code{starpu_bound_stop}. @code{starpu_bound_print_lp} or
  897. @code{starpu_bound_print_mps} can then be used to output a Linear Programming
  898. problem corresponding to the schedule of your tasks. Run it through
  899. @code{lp_solve} or any other linear programming solver, and that will give you a
  900. lower bound for the total execution time of your tasks. If StarPU was compiled
  901. with the glpk library installed, @code{starpu_bound_compute} can be used to
  902. solve it immediately and get the optimized minimum. Its @code{integer}
  903. parameter allows to decide whether integer resolution should be computed
  904. and returned.
  905. The @code{deps} parameter tells StarPU whether to take tasks and implicit data
  906. dependencies into account. It must be understood that the linear programming
  907. problem size is quadratic with the number of tasks and thus the time to solve it
  908. will be very long, it could be minutes for just a few dozen tasks. You should
  909. probably use @code{lp_solve -timeout 1 test.pl -wmps test.mps} to convert the
  910. problem to MPS format and then use a better solver, @code{glpsol} might be
  911. better than @code{lp_solve} for instance (the @code{--pcost} option may be
  912. useful), but sometimes doesn't manage to converge. @code{cbc} might look
  913. slower, but it is parallel. Be sure to try at least all the @code{-B} options
  914. of @code{lp_solve}. For instance, we often just use
  915. @code{lp_solve -cc -B1 -Bb -Bg -Bp -Bf -Br -BG -Bd -Bs -BB -Bo -Bc -Bi} , and
  916. the @code{-gr} option can also be quite useful.
  917. Setting @code{deps} to 0 will only take into account the actual computations
  918. on processing units. It however still properly takes into account the varying
  919. performances of kernels and processing units, which is quite more accurate than
  920. just comparing StarPU performances with the fastest of the kernels being used.
  921. The @code{prio} parameter tells StarPU whether to simulate taking into account
  922. the priorities as the StarPU scheduler would, i.e. schedule prioritized
  923. tasks before less prioritized tasks, to check to which extend this results
  924. to a less optimal solution. This increases even more computation time.
  925. Note that all this however doesn't take into account data transfer, which is
  926. assumed to be completely overlapped.
  927. @node More examples
  928. @section More examples
  929. More examples are available in the StarPU sources in the @code{examples/}
  930. directory. Simple examples include:
  931. @table @asis
  932. @item @code{incrementer/}:
  933. Trivial incrementation test.
  934. @item @code{basic_examples/}:
  935. Simple documented Hello world (as shown in @ref{Hello World}), vector/scalar product (as shown
  936. in @ref{Vector Scaling on an Hybrid CPU/GPU Machine}), matrix
  937. product examples (as shown in @ref{Performance model example}), an example using the blocked matrix data
  938. interface, and an example using the variable data interface.
  939. @item @code{matvecmult/}:
  940. OpenCL example from NVidia, adapted to StarPU.
  941. @item @code{axpy/}:
  942. AXPY CUBLAS operation adapted to StarPU.
  943. @item @code{fortran/}:
  944. Example of Fortran bindings.
  945. @end table
  946. More advanced examples include:
  947. @table @asis
  948. @item @code{filters/}:
  949. Examples using filters, as shown in @ref{Partitioning Data}.
  950. @item @code{lu/}:
  951. LU matrix factorization.
  952. @end table
  953. @c ---------------------------------------------------------------------
  954. @c Performance feedback
  955. @c ---------------------------------------------------------------------
  956. @node Performance feedback
  957. @chapter Performance feedback
  958. @menu
  959. * On-line:: On-line performance feedback
  960. * Off-line:: Off-line performance feedback
  961. @end menu
  962. @node On-line
  963. @section On-line performance feedback
  964. @menu
  965. * Enabling monitoring:: Enabling on-line performance monitoring
  966. * Task feedback:: Per-task feedback
  967. * Codelet feedback:: Per-codelet feedback
  968. * Worker feedback:: Per-worker feedback
  969. * Bus feedback:: Bus-related feedback
  970. @end menu
  971. @node Enabling monitoring
  972. @subsection Enabling on-line performance monitoring
  973. In order to enable online performance monitoring, the application must call
  974. @code{starpu_profiling_status_set(STARPU_PROFILING_ENABLE)}. It is possible to
  975. detect whether monitoring is already enabled or not by calling
  976. @code{starpu_profiling_status_get()}. Enabling monitoring also reinitialize all
  977. previously collected feedback.
  978. Likewise, performance monitoring is stopped by calling
  979. @code{starpu_profiling_status_set(STARPU_PROFILING_DISABLE)}. Note that this
  980. does not reset the performance counters so that the application may consult
  981. them later on.
  982. More details about the performance monitoring API are available in section
  983. @ref{Profiling API}.
  984. @node Task feedback
  985. @subsection Per-task feedback
  986. If profiling is enabled, a pointer to a @code{starpu_task_profiling_info}
  987. structure is put in the @code{.profiling_info} field of the @code{starpu_task}
  988. structure when a task terminates.
  989. This structure is automatically destroyed when the task structure is destroyed,
  990. either automatically or by calling @code{starpu_task_destroy}.
  991. The @code{starpu_task_profiling_info} structure indicates the date when the
  992. task was submitted (@code{submit_time}), started (@code{start_time}), and
  993. terminated (@code{end_time}), relative to the initialization of
  994. StarPU with @code{starpu_init}. It also specifies the identifier of the worker
  995. that has executed the task (@code{workerid}).
  996. These date are stored as @code{timespec} structures which the user may convert
  997. into micro-seconds using the @code{starpu_timing_timespec_to_us} helper
  998. function.
  999. It it worth noting that the application may directly access this structure from
  1000. the callback executed at the end of the task. The @code{starpu_task} structure
  1001. associated to the callback currently being executed is indeed accessible with
  1002. the @code{starpu_get_current_task()} function.
  1003. @node Codelet feedback
  1004. @subsection Per-codelet feedback
  1005. The @code{per_worker_stats} field of the @code{starpu_codelet_t} structure is
  1006. an array of counters. The i-th entry of the array is incremented every time a
  1007. task implementing the codelet is executed on the i-th worker.
  1008. This array is not reinitialized when profiling is enabled or disabled.
  1009. @node Worker feedback
  1010. @subsection Per-worker feedback
  1011. The second argument returned by the @code{starpu_worker_get_profiling_info}
  1012. function is a @code{starpu_worker_profiling_info} structure that gives
  1013. statistics about the specified worker. This structure specifies when StarPU
  1014. started collecting profiling information for that worker (@code{start_time}),
  1015. the duration of the profiling measurement interval (@code{total_time}), the
  1016. time spent executing kernels (@code{executing_time}), the time spent sleeping
  1017. because there is no task to execute at all (@code{sleeping_time}), and the
  1018. number of tasks that were executed while profiling was enabled.
  1019. These values give an estimation of the proportion of time spent do real work,
  1020. and the time spent either sleeping because there are not enough executable
  1021. tasks or simply wasted in pure StarPU overhead.
  1022. Calling @code{starpu_worker_get_profiling_info} resets the profiling
  1023. information associated to a worker.
  1024. When an FxT trace is generated (see @ref{Generating traces}), it is also
  1025. possible to use the @code{starpu_top} script (described in @ref{starpu-top}) to
  1026. generate a graphic showing the evolution of these values during the time, for
  1027. the different workers.
  1028. @node Bus feedback
  1029. @subsection Bus-related feedback
  1030. TODO
  1031. @c how to enable/disable performance monitoring
  1032. @c what kind of information do we get ?
  1033. @node Off-line
  1034. @section Off-line performance feedback
  1035. @menu
  1036. * Generating traces:: Generating traces with FxT
  1037. * Gantt diagram:: Creating a Gantt Diagram
  1038. * DAG:: Creating a DAG with graphviz
  1039. * starpu-top:: Monitoring activity
  1040. @end menu
  1041. @node Generating traces
  1042. @subsection Generating traces with FxT
  1043. StarPU can use the FxT library (see
  1044. @indicateurl{https://savannah.nongnu.org/projects/fkt/}) to generate traces
  1045. with a limited runtime overhead.
  1046. You can either get the FxT library from CVS (autotools are required):
  1047. @example
  1048. % cvs -d :pserver:anonymous@@cvs.sv.gnu.org:/sources/fkt co FxT
  1049. % ./bootstrap
  1050. @end example
  1051. If autotools are not available on your machine, or if you prefer to do so,
  1052. FxT's code is also available as a tarball:
  1053. @example
  1054. % wget http://download.savannah.gnu.org/releases/fkt/fxt-0.2.tar.gz
  1055. @end example
  1056. Compiling and installing the FxT library in the @code{$FXTDIR} path is
  1057. done following the standard procedure:
  1058. @example
  1059. % ./configure --prefix=$FXTDIR
  1060. % make
  1061. % make install
  1062. @end example
  1063. In order to have StarPU to generate traces, StarPU should be configured with
  1064. the @code{--with-fxt} option:
  1065. @example
  1066. $ ./configure --with-fxt=$FXTDIR
  1067. @end example
  1068. When FxT is enabled, a trace is generated when StarPU is terminated by calling
  1069. @code{starpu_shutdown()}). The trace is a binary file whose name has the form
  1070. @code{prof_file_XXX_YYY} where @code{XXX} is the user name, and
  1071. @code{YYY} is the pid of the process that used StarPU. This file is saved in the
  1072. @code{/tmp/} directory by default, or by the directory specified by
  1073. the @code{STARPU_FXT_PREFIX} environment variable.
  1074. @node Gantt diagram
  1075. @subsection Creating a Gantt Diagram
  1076. When the FxT trace file @code{filename} has been generated, it is possible to
  1077. generate a trace in the Paje format by calling:
  1078. @example
  1079. % fxt_tool -i filename
  1080. @end example
  1081. This will create a @code{paje.trace} file in the current directory that can be
  1082. inspected with the Vite trace visualizing open-source tool. More information
  1083. about Vite is available at @indicateurl{http://vite.gforge.inria.fr/}. It is
  1084. possible to open the @code{paje.trace} file with Vite by using the following
  1085. command:
  1086. @example
  1087. % vite paje.trace
  1088. @end example
  1089. @node DAG
  1090. @subsection Creating a DAG with graphviz
  1091. When the FxT trace file @code{filename} has been generated, it is possible to
  1092. generate a task graph in the DOT format by calling:
  1093. @example
  1094. $ fxt_tool -i filename
  1095. @end example
  1096. This will create a @code{dag.dot} file in the current directory. This file is a
  1097. task graph described using the DOT language. It is possible to get a
  1098. graphical output of the graph by using the graphviz library:
  1099. @example
  1100. $ dot -Tpdf dag.dot -o output.pdf
  1101. @end example
  1102. @node starpu-top
  1103. @subsection Monitoring activity
  1104. When the FxT trace file @code{filename} has been generated, it is possible to
  1105. generate a activity trace by calling:
  1106. @example
  1107. $ fxt_tool -i filename
  1108. @end example
  1109. This will create an @code{activity.data} file in the current
  1110. directory. A profile of the application showing the activity of StarPU
  1111. during the execution of the program can be generated:
  1112. @example
  1113. $ starpu_top.sh activity.data
  1114. @end example
  1115. This will create a file named @code{activity.eps} in the current directory.
  1116. This picture is composed of two parts.
  1117. The first part shows the activity of the different workers. The green sections
  1118. indicate which proportion of the time was spent executed kernels on the
  1119. processing unit. The red sections indicate the proportion of time spent in
  1120. StartPU: an important overhead may indicate that the granularity may be too
  1121. low, and that bigger tasks may be appropriate to use the processing unit more
  1122. efficiently. The black sections indicate that the processing unit was blocked
  1123. because there was no task to process: this may indicate a lack of parallelism
  1124. which may be alleviated by creating more tasks when it is possible.
  1125. The second part of the @code{activity.eps} picture is a graph showing the
  1126. evolution of the number of tasks available in the system during the execution.
  1127. Ready tasks are shown in black, and tasks that are submitted but not
  1128. schedulable yet are shown in grey.
  1129. @c ---------------------------------------------------------------------
  1130. @c Configuration options
  1131. @c ---------------------------------------------------------------------
  1132. @node Configuring StarPU
  1133. @chapter Configuring StarPU
  1134. @menu
  1135. * Compilation configuration::
  1136. * Execution configuration through environment variables::
  1137. @end menu
  1138. @node Compilation configuration
  1139. @section Compilation configuration
  1140. The following arguments can be given to the @code{configure} script.
  1141. @menu
  1142. * Common configuration::
  1143. * Configuring workers::
  1144. * Advanced configuration::
  1145. @end menu
  1146. @node Common configuration
  1147. @subsection Common configuration
  1148. @menu
  1149. * --enable-debug::
  1150. * --enable-fast::
  1151. * --enable-verbose::
  1152. * --enable-coverage::
  1153. @end menu
  1154. @node --enable-debug
  1155. @subsubsection @code{--enable-debug}
  1156. @table @asis
  1157. @item @emph{Description}:
  1158. Enable debugging messages.
  1159. @end table
  1160. @node --enable-fast
  1161. @subsubsection @code{--enable-fast}
  1162. @table @asis
  1163. @item @emph{Description}:
  1164. Do not enforce assertions, saves a lot of time spent to compute them otherwise.
  1165. @end table
  1166. @node --enable-verbose
  1167. @subsubsection @code{--enable-verbose}
  1168. @table @asis
  1169. @item @emph{Description}:
  1170. Augment the verbosity of the debugging messages.
  1171. @end table
  1172. @node --enable-coverage
  1173. @subsubsection @code{--enable-coverage}
  1174. @table @asis
  1175. @item @emph{Description}:
  1176. Enable flags for the coverage tool.
  1177. @end table
  1178. @node Configuring workers
  1179. @subsection Configuring workers
  1180. @menu
  1181. * --enable-nmaxcpus::
  1182. * --disable-cpu::
  1183. * --enable-maxcudadev::
  1184. * --disable-cuda::
  1185. * --with-cuda-dir::
  1186. * --enable-maxopencldev::
  1187. * --disable-opencl::
  1188. * --with-opencl-dir::
  1189. * --enable-gordon::
  1190. * --with-gordon-dir::
  1191. @end menu
  1192. @node --enable-nmaxcpus
  1193. @subsubsection @code{--enable-nmaxcpus=<number>}
  1194. @table @asis
  1195. @item @emph{Description}:
  1196. Defines the maximum number of CPU cores that StarPU will support, then
  1197. available as the @code{STARPU_NMAXCPUS} macro.
  1198. @end table
  1199. @node --disable-cpu
  1200. @subsubsection @code{--disable-cpu}
  1201. @table @asis
  1202. @item @emph{Description}:
  1203. Disable the use of CPUs of the machine. Only GPUs etc. will be used.
  1204. @end table
  1205. @node --enable-maxcudadev
  1206. @subsubsection @code{--enable-maxcudadev=<number>}
  1207. @table @asis
  1208. @item @emph{Description}:
  1209. Defines the maximum number of CUDA devices that StarPU will support, then
  1210. available as the @code{STARPU_MAXCUDADEVS} macro.
  1211. @end table
  1212. @node --disable-cuda
  1213. @subsubsection @code{--disable-cuda}
  1214. @table @asis
  1215. @item @emph{Description}:
  1216. Disable the use of CUDA, even if a valid CUDA installation was detected.
  1217. @end table
  1218. @node --with-cuda-dir
  1219. @subsubsection @code{--with-cuda-dir=<path>}
  1220. @table @asis
  1221. @item @emph{Description}:
  1222. Specify the directory where CUDA is installed. This directory should notably contain
  1223. @code{include/cuda.h}.
  1224. @end table
  1225. @node --enable-maxopencldev
  1226. @subsubsection @code{--enable-maxopencldev=<number>}
  1227. @table @asis
  1228. @item @emph{Description}:
  1229. Defines the maximum number of OpenCL devices that StarPU will support, then
  1230. available as the @code{STARPU_MAXOPENCLDEVS} macro.
  1231. @end table
  1232. @node --disable-opencl
  1233. @subsubsection @code{--disable-opencl}
  1234. @table @asis
  1235. @item @emph{Description}:
  1236. Disable the use of OpenCL, even if the SDK is detected.
  1237. @end table
  1238. @node --with-opencl-dir
  1239. @subsubsection @code{--with-opencl-dir=<path>}
  1240. @table @asis
  1241. @item @emph{Description}:
  1242. Specify the location of the OpenCL SDK. This directory should notably contain
  1243. @code{include/CL/cl.h}.
  1244. @end table
  1245. @node --enable-gordon
  1246. @subsubsection @code{--enable-gordon}
  1247. @table @asis
  1248. @item @emph{Description}:
  1249. Enable the use of the Gordon runtime for Cell SPUs.
  1250. @c TODO: rather default to enabled when detected
  1251. @end table
  1252. @node --with-gordon-dir
  1253. @subsubsection @code{--with-gordon-dir=<path>}
  1254. @table @asis
  1255. @item @emph{Description}:
  1256. Specify the location of the Gordon SDK.
  1257. @end table
  1258. @node Advanced configuration
  1259. @subsection Advanced configuration
  1260. @menu
  1261. * --enable-perf-debug::
  1262. * --enable-model-debug::
  1263. * --enable-stats::
  1264. * --enable-maxbuffers::
  1265. * --enable-allocation-cache::
  1266. * --enable-opengl-render::
  1267. * --enable-blas-lib::
  1268. * --with-magma::
  1269. * --with-fxt::
  1270. * --with-perf-model-dir::
  1271. * --with-mpicc::
  1272. * --with-goto-dir::
  1273. * --with-atlas-dir::
  1274. @end menu
  1275. @node --enable-perf-debug
  1276. @subsubsection @code{--enable-perf-debug}
  1277. @table @asis
  1278. @item @emph{Description}:
  1279. Enable performance debugging.
  1280. @end table
  1281. @node --enable-model-debug
  1282. @subsubsection @code{--enable-model-debug}
  1283. @table @asis
  1284. @item @emph{Description}:
  1285. Enable performance model debugging.
  1286. @end table
  1287. @node --enable-stats
  1288. @subsubsection @code{--enable-stats}
  1289. @table @asis
  1290. @item @emph{Description}:
  1291. Enable statistics.
  1292. @end table
  1293. @node --enable-maxbuffers
  1294. @subsubsection @code{--enable-maxbuffers=<nbuffers>}
  1295. @table @asis
  1296. @item @emph{Description}:
  1297. Define the maximum number of buffers that tasks will be able to take
  1298. as parameters, then available as the @code{STARPU_NMAXBUFS} macro.
  1299. @end table
  1300. @node --enable-allocation-cache
  1301. @subsubsection @code{--enable-allocation-cache}
  1302. @table @asis
  1303. @item @emph{Description}:
  1304. Enable the use of a data allocation cache to avoid the cost of it with
  1305. CUDA. Still experimental.
  1306. @end table
  1307. @node --enable-opengl-render
  1308. @subsubsection @code{--enable-opengl-render}
  1309. @table @asis
  1310. @item @emph{Description}:
  1311. Enable the use of OpenGL for the rendering of some examples.
  1312. @c TODO: rather default to enabled when detected
  1313. @end table
  1314. @node --enable-blas-lib
  1315. @subsubsection @code{--enable-blas-lib=<name>}
  1316. @table @asis
  1317. @item @emph{Description}:
  1318. Specify the blas library to be used by some of the examples. The
  1319. library has to be 'atlas' or 'goto'.
  1320. @end table
  1321. @node --with-magma
  1322. @subsubsection @code{--with-magma=<path>}
  1323. @table @asis
  1324. @item @emph{Description}:
  1325. Specify where magma is installed.
  1326. @end table
  1327. @node --with-fxt
  1328. @subsubsection @code{--with-fxt=<path>}
  1329. @table @asis
  1330. @item @emph{Description}:
  1331. Specify the location of FxT (for generating traces and rendering them
  1332. using ViTE). This directory should notably contain
  1333. @code{include/fxt/fxt.h}.
  1334. @c TODO add ref to other section
  1335. @end table
  1336. @node --with-perf-model-dir
  1337. @subsubsection @code{--with-perf-model-dir=<dir>}
  1338. @table @asis
  1339. @item @emph{Description}:
  1340. Specify where performance models should be stored (instead of defaulting to the
  1341. current user's home).
  1342. @end table
  1343. @node --with-mpicc
  1344. @subsubsection @code{--with-mpicc=<path to mpicc>}
  1345. @table @asis
  1346. @item @emph{Description}:
  1347. Specify the location of the @code{mpicc} compiler to be used for starpumpi.
  1348. @end table
  1349. @node --with-goto-dir
  1350. @subsubsection @code{--with-goto-dir=<dir>}
  1351. @table @asis
  1352. @item @emph{Description}:
  1353. Specify the location of GotoBLAS.
  1354. @end table
  1355. @node --with-atlas-dir
  1356. @subsubsection @code{--with-atlas-dir=<dir>}
  1357. @table @asis
  1358. @item @emph{Description}:
  1359. Specify the location of ATLAS. This directory should notably contain
  1360. @code{include/cblas.h}.
  1361. @end table
  1362. @c ---------------------------------------------------------------------
  1363. @c Environment variables
  1364. @c ---------------------------------------------------------------------
  1365. @node Execution configuration through environment variables
  1366. @section Execution configuration through environment variables
  1367. @menu
  1368. * Workers:: Configuring workers
  1369. * Scheduling:: Configuring the Scheduling engine
  1370. * Misc:: Miscellaneous and debug
  1371. @end menu
  1372. Note: the values given in @code{starpu_conf} structure passed when
  1373. calling @code{starpu_init} will override the values of the environment
  1374. variables.
  1375. @node Workers
  1376. @subsection Configuring workers
  1377. @menu
  1378. * STARPU_NCPUS:: Number of CPU workers
  1379. * STARPU_NCUDA:: Number of CUDA workers
  1380. * STARPU_NOPENCL:: Number of OpenCL workers
  1381. * STARPU_NGORDON:: Number of SPU workers (Cell)
  1382. * STARPU_WORKERS_CPUID:: Bind workers to specific CPUs
  1383. * STARPU_WORKERS_CUDAID:: Select specific CUDA devices
  1384. * STARPU_WORKERS_OPENCLID:: Select specific OpenCL devices
  1385. @end menu
  1386. @node STARPU_NCPUS
  1387. @subsubsection @code{STARPU_NCPUS} -- Number of CPU workers
  1388. @table @asis
  1389. @item @emph{Description}:
  1390. Specify the maximum number of CPU workers. Note that StarPU will not allocate
  1391. more CPUs than there are physical CPUs, and that some CPUs are used to control
  1392. the accelerators.
  1393. @end table
  1394. @node STARPU_NCUDA
  1395. @subsubsection @code{STARPU_NCUDA} -- Number of CUDA workers
  1396. @table @asis
  1397. @item @emph{Description}:
  1398. Specify the maximum number of CUDA devices that StarPU can use. If
  1399. @code{STARPU_NCUDA} is lower than the number of physical devices, it is
  1400. possible to select which CUDA devices should be used by the means of the
  1401. @code{STARPU_WORKERS_CUDAID} environment variable.
  1402. @end table
  1403. @node STARPU_NOPENCL
  1404. @subsubsection @code{STARPU_NOPENCL} -- Number of OpenCL workers
  1405. @table @asis
  1406. @item @emph{Description}:
  1407. OpenCL equivalent of the @code{STARPU_NCUDA} environment variable.
  1408. @end table
  1409. @node STARPU_NGORDON
  1410. @subsubsection @code{STARPU_NGORDON} -- Number of SPU workers (Cell)
  1411. @table @asis
  1412. @item @emph{Description}:
  1413. Specify the maximum number of SPUs that StarPU can use.
  1414. @end table
  1415. @node STARPU_WORKERS_CPUID
  1416. @subsubsection @code{STARPU_WORKERS_CPUID} -- Bind workers to specific CPUs
  1417. @table @asis
  1418. @item @emph{Description}:
  1419. Passing an array of integers (starting from 0) in @code{STARPU_WORKERS_CPUID}
  1420. specifies on which logical CPU the different workers should be
  1421. bound. For instance, if @code{STARPU_WORKERS_CPUID = "1 3 0 2"}, the first
  1422. worker will be bound to logical CPU #1, the second CPU worker will be bound to
  1423. logical CPU #3 and so on. Note that the logical ordering of the CPUs is either
  1424. determined by the OS, or provided by the @code{hwloc} library in case it is
  1425. available.
  1426. Note that the first workers correspond to the CUDA workers, then come the
  1427. OpenCL and the SPU, and finally the CPU workers. For example if
  1428. we have @code{STARPU_NCUDA=1}, @code{STARPU_NOPENCL=1}, @code{STARPU_NCPUS=2}
  1429. and @code{STARPU_WORKERS_CPUID = "0 2 1 3"}, the CUDA device will be controlled
  1430. by logical CPU #0, the OpenCL device will be controlled by logical CPU #2, and
  1431. the logical CPUs #1 and #3 will be used by the CPU workers.
  1432. If the number of workers is larger than the array given in
  1433. @code{STARPU_WORKERS_CPUID}, the workers are bound to the logical CPUs in a
  1434. round-robin fashion: if @code{STARPU_WORKERS_CPUID = "0 1"}, the first and the
  1435. third (resp. second and fourth) workers will be put on CPU #0 (resp. CPU #1).
  1436. This variable is ignored if the @code{use_explicit_workers_bindid} flag of the
  1437. @code{starpu_conf} structure passed to @code{starpu_init} is set.
  1438. @end table
  1439. @node STARPU_WORKERS_CUDAID
  1440. @subsubsection @code{STARPU_WORKERS_CUDAID} -- Select specific CUDA devices
  1441. @table @asis
  1442. @item @emph{Description}:
  1443. Similarly to the @code{STARPU_WORKERS_CPUID} environment variable, it is
  1444. possible to select which CUDA devices should be used by StarPU. On a machine
  1445. equipped with 4 GPUs, setting @code{STARPU_WORKERS_CUDAID = "1 3"} and
  1446. @code{STARPU_NCUDA=2} specifies that 2 CUDA workers should be created, and that
  1447. they should use CUDA devices #1 and #3 (the logical ordering of the devices is
  1448. the one reported by CUDA).
  1449. This variable is ignored if the @code{use_explicit_workers_cuda_gpuid} flag of
  1450. the @code{starpu_conf} structure passed to @code{starpu_init} is set.
  1451. @end table
  1452. @node STARPU_WORKERS_OPENCLID
  1453. @subsubsection @code{STARPU_WORKERS_OPENCLID} -- Select specific OpenCL devices
  1454. @table @asis
  1455. @item @emph{Description}:
  1456. OpenCL equivalent of the @code{STARPU_WORKERS_CUDAID} environment variable.
  1457. This variable is ignored if the @code{use_explicit_workers_opencl_gpuid} flag of
  1458. the @code{starpu_conf} structure passed to @code{starpu_init} is set.
  1459. @end table
  1460. @node Scheduling
  1461. @subsection Configuring the Scheduling engine
  1462. @menu
  1463. * STARPU_SCHED:: Scheduling policy
  1464. * STARPU_CALIBRATE:: Calibrate performance models
  1465. * STARPU_PREFETCH:: Use data prefetch
  1466. * STARPU_SCHED_ALPHA:: Computation factor
  1467. * STARPU_SCHED_BETA:: Communication factor
  1468. @end menu
  1469. @node STARPU_SCHED
  1470. @subsubsection @code{STARPU_SCHED} -- Scheduling policy
  1471. @table @asis
  1472. @item @emph{Description}:
  1473. This chooses between the different scheduling policies proposed by StarPU: work
  1474. random, stealing, greedy, with performance models, etc.
  1475. Use @code{STARPU_SCHED=help} to get the list of available schedulers.
  1476. @end table
  1477. @node STARPU_CALIBRATE
  1478. @subsubsection @code{STARPU_CALIBRATE} -- Calibrate performance models
  1479. @table @asis
  1480. @item @emph{Description}:
  1481. If this variable is set to 1, the performance models are calibrated during
  1482. the execution. If it is set to 2, the previous values are dropped to restart
  1483. calibration from scratch.
  1484. Note: this currently only applies to dm and dmda scheduling policies.
  1485. @end table
  1486. @node STARPU_PREFETCH
  1487. @subsubsection @code{STARPU_PREFETCH} -- Use data prefetch
  1488. @table @asis
  1489. @item @emph{Description}:
  1490. This variable indicates whether data prefetching should be enabled (0 means
  1491. that it is disabled). If prefetching is enabled, when a task is scheduled to be
  1492. executed e.g. on a GPU, StarPU will request an asynchronous transfer in
  1493. advance, so that data is already present on the GPU when the task starts. As a
  1494. result, computation and data transfers are overlapped.
  1495. @end table
  1496. @node STARPU_SCHED_ALPHA
  1497. @subsubsection @code{STARPU_SCHED_ALPHA} -- Computation factor
  1498. @table @asis
  1499. @item @emph{Description}:
  1500. To estimate the cost of a task StarPU takes into account the estimated
  1501. computation time (obtained thanks to performance models). The alpha factor is
  1502. the coefficient to be applied to it before adding it to the communication part.
  1503. @end table
  1504. @node STARPU_SCHED_BETA
  1505. @subsubsection @code{STARPU_SCHED_BETA} -- Communication factor
  1506. @table @asis
  1507. @item @emph{Description}:
  1508. To estimate the cost of a task StarPU takes into account the estimated
  1509. data transfer time (obtained thanks to performance models). The beta factor is
  1510. the coefficient to be applied to it before adding it to the computation part.
  1511. @end table
  1512. @node Misc
  1513. @subsection Miscellaneous and debug
  1514. @menu
  1515. * STARPU_LOGFILENAME:: Select debug file name
  1516. * STARPU_FXT_PREFIX:: FxT trace location
  1517. @end menu
  1518. @node STARPU_LOGFILENAME
  1519. @subsubsection @code{STARPU_LOGFILENAME} -- Select debug file name
  1520. @table @asis
  1521. @item @emph{Description}:
  1522. This variable specifies in which file the debugging output should be saved to.
  1523. @end table
  1524. @node STARPU_FXT_PREFIX
  1525. @subsubsection @code{STARPU_FXT_PREFIX} -- FxT trace location
  1526. @table @asis
  1527. @item @emph{Description}
  1528. This variable specifies in which directory to save the trace generated if FxT is enabled.
  1529. @end table
  1530. @c ---------------------------------------------------------------------
  1531. @c StarPU API
  1532. @c ---------------------------------------------------------------------
  1533. @node StarPU API
  1534. @chapter StarPU API
  1535. @menu
  1536. * Initialization and Termination:: Initialization and Termination methods
  1537. * Workers' Properties:: Methods to enumerate workers' properties
  1538. * Data Library:: Methods to manipulate data
  1539. * Data Interfaces::
  1540. * Data Partition::
  1541. * Codelets and Tasks:: Methods to construct tasks
  1542. * Explicit Dependencies:: Explicit Dependencies
  1543. * Implicit Data Dependencies:: Implicit Data Dependencies
  1544. * Performance Model API::
  1545. * Profiling API:: Profiling API
  1546. * CUDA extensions:: CUDA extensions
  1547. * OpenCL extensions:: OpenCL extensions
  1548. * Cell extensions:: Cell extensions
  1549. * Miscellaneous helpers::
  1550. @end menu
  1551. @node Initialization and Termination
  1552. @section Initialization and Termination
  1553. @menu
  1554. * starpu_init:: Initialize StarPU
  1555. * struct starpu_conf:: StarPU runtime configuration
  1556. * starpu_shutdown:: Terminate StarPU
  1557. @end menu
  1558. @node starpu_init
  1559. @subsection @code{starpu_init} -- Initialize StarPU
  1560. @table @asis
  1561. @item @emph{Description}:
  1562. This is StarPU initialization method, which must be called prior to any other
  1563. StarPU call. It is possible to specify StarPU's configuration (e.g. scheduling
  1564. policy, number of cores, ...) by passing a non-null argument. Default
  1565. configuration is used if the passed argument is @code{NULL}.
  1566. @item @emph{Return value}:
  1567. Upon successful completion, this function returns 0. Otherwise, @code{-ENODEV}
  1568. indicates that no worker was available (so that StarPU was not initialized).
  1569. @item @emph{Prototype}:
  1570. @code{int starpu_init(struct starpu_conf *conf);}
  1571. @end table
  1572. @node struct starpu_conf
  1573. @subsection @code{struct starpu_conf} -- StarPU runtime configuration
  1574. @table @asis
  1575. @item @emph{Description}:
  1576. This structure is passed to the @code{starpu_init} function in order
  1577. to configure StarPU.
  1578. When the default value is used, StarPU automatically selects the number
  1579. of processing units and takes the default scheduling policy. This parameter
  1580. overwrites the equivalent environment variables.
  1581. @item @emph{Fields}:
  1582. @table @asis
  1583. @item @code{sched_policy_name} (default = NULL):
  1584. This is the name of the scheduling policy. This can also be specified with the
  1585. @code{STARPU_SCHED} environment variable.
  1586. @item @code{sched_policy} (default = NULL):
  1587. This is the definition of the scheduling policy. This field is ignored
  1588. if @code{sched_policy_name} is set.
  1589. @item @code{ncpus} (default = -1):
  1590. This is the maximum number of CPU cores that StarPU can use. This can also be
  1591. specified with the @code{STARPU_NCPUS} environment variable.
  1592. @item @code{ncuda} (default = -1):
  1593. This is the maximum number of CUDA devices that StarPU can use. This can also be
  1594. specified with the @code{STARPU_NCUDA} environment variable.
  1595. @item @code{nopencl} (default = -1):
  1596. This is the maximum number of OpenCL devices that StarPU can use. This can also be
  1597. specified with the @code{STARPU_NOPENCL} environment variable.
  1598. @item @code{nspus} (default = -1):
  1599. This is the maximum number of Cell SPUs that StarPU can use. This can also be
  1600. specified with the @code{STARPU_NGORDON} environment variable.
  1601. @item @code{use_explicit_workers_bindid} (default = 0)
  1602. If this flag is set, the @code{workers_bindid} array indicates where the
  1603. different workers are bound, otherwise StarPU automatically selects where to
  1604. bind the different workers unless the @code{STARPU_WORKERS_CPUID} environment
  1605. variable is set. The @code{STARPU_WORKERS_CPUID} environment variable is
  1606. ignored if the @code{use_explicit_workers_bindid} flag is set.
  1607. @item @code{workers_bindid[STARPU_NMAXWORKERS]}
  1608. If the @code{use_explicit_workers_bindid} flag is set, this array indicates
  1609. where to bind the different workers. The i-th entry of the
  1610. @code{workers_bindid} indicates the logical identifier of the processor which
  1611. should execute the i-th worker. Note that the logical ordering of the CPUs is
  1612. either determined by the OS, or provided by the @code{hwloc} library in case it
  1613. is available.
  1614. When this flag is set, the @ref{STARPU_WORKERS_CPUID} environment variable is
  1615. ignored.
  1616. @item @code{use_explicit_workers_cuda_gpuid} (default = 0)
  1617. If this flag is set, the CUDA workers will be attached to the CUDA devices
  1618. specified in the @code{workers_cuda_gpuid} array. Otherwise, StarPU affects the
  1619. CUDA devices in a round-robin fashion.
  1620. When this flag is set, the @ref{STARPU_WORKERS_CUDAID} environment variable is
  1621. ignored.
  1622. @item @code{workers_cuda_gpuid[STARPU_NMAXWORKERS]}
  1623. If the @code{use_explicit_workers_cuda_gpuid} flag is set, this array contains
  1624. the logical identifiers of the CUDA devices (as used by @code{cudaGetDevice}).
  1625. @item @code{use_explicit_workers_opencl_gpuid} (default = 0)
  1626. If this flag is set, the OpenCL workers will be attached to the OpenCL devices
  1627. specified in the @code{workers_opencl_gpuid} array. Otherwise, StarPU affects the
  1628. OpenCL devices in a round-robin fashion.
  1629. @item @code{workers_opencl_gpuid[STARPU_NMAXWORKERS]}:
  1630. @item @code{calibrate} (default = 0):
  1631. If this flag is set, StarPU will calibrate the performance models when
  1632. executing tasks. If this value is equal to -1, the default value is used. The
  1633. default value is overwritten by the @code{STARPU_CALIBRATE} environment
  1634. variable when it is set.
  1635. @end table
  1636. @end table
  1637. @node starpu_shutdown
  1638. @subsection @code{starpu_shutdown} -- Terminate StarPU
  1639. @table @asis
  1640. @item @emph{Description}:
  1641. This is StarPU termination method. It must be called at the end of the
  1642. application: statistics and other post-mortem debugging information are not
  1643. guaranteed to be available until this method has been called.
  1644. @item @emph{Prototype}:
  1645. @code{void starpu_shutdown(void);}
  1646. @end table
  1647. @node Workers' Properties
  1648. @section Workers' Properties
  1649. @menu
  1650. * starpu_worker_get_count:: Get the number of processing units
  1651. * starpu_cpu_worker_get_count:: Get the number of CPU controlled by StarPU
  1652. * starpu_cuda_worker_get_count:: Get the number of CUDA devices controlled by StarPU
  1653. * starpu_opencl_worker_get_count:: Get the number of OpenCL devices controlled by StarPU
  1654. * starpu_spu_worker_get_count:: Get the number of Cell SPUs controlled by StarPU
  1655. * starpu_worker_get_id:: Get the identifier of the current worker
  1656. * starpu_worker_get_devid:: Get the device identifier of a worker
  1657. * starpu_worker_get_type:: Get the type of processing unit associated to a worker
  1658. * starpu_worker_get_name:: Get the name of a worker
  1659. * starpu_worker_get_memory_node:: Get the memory node of a worker
  1660. @end menu
  1661. @node starpu_worker_get_count
  1662. @subsection @code{starpu_worker_get_count} -- Get the number of processing units
  1663. @table @asis
  1664. @item @emph{Description}:
  1665. This function returns the number of workers (i.e. processing units executing
  1666. StarPU tasks). The returned value should be at most @code{STARPU_NMAXWORKERS}.
  1667. @item @emph{Prototype}:
  1668. @code{unsigned starpu_worker_get_count(void);}
  1669. @end table
  1670. @node starpu_cpu_worker_get_count
  1671. @subsection @code{starpu_cpu_worker_get_count} -- Get the number of CPU controlled by StarPU
  1672. @table @asis
  1673. @item @emph{Description}:
  1674. This function returns the number of CPUs controlled by StarPU. The returned
  1675. value should be at most @code{STARPU_NMAXCPUS}.
  1676. @item @emph{Prototype}:
  1677. @code{unsigned starpu_cpu_worker_get_count(void);}
  1678. @end table
  1679. @node starpu_cuda_worker_get_count
  1680. @subsection @code{starpu_cuda_worker_get_count} -- Get the number of CUDA devices controlled by StarPU
  1681. @table @asis
  1682. @item @emph{Description}:
  1683. This function returns the number of CUDA devices controlled by StarPU. The returned
  1684. value should be at most @code{STARPU_MAXCUDADEVS}.
  1685. @item @emph{Prototype}:
  1686. @code{unsigned starpu_cuda_worker_get_count(void);}
  1687. @end table
  1688. @node starpu_opencl_worker_get_count
  1689. @subsection @code{starpu_opencl_worker_get_count} -- Get the number of OpenCL devices controlled by StarPU
  1690. @table @asis
  1691. @item @emph{Description}:
  1692. This function returns the number of OpenCL devices controlled by StarPU. The returned
  1693. value should be at most @code{STARPU_MAXOPENCLDEVS}.
  1694. @item @emph{Prototype}:
  1695. @code{unsigned starpu_opencl_worker_get_count(void);}
  1696. @end table
  1697. @node starpu_spu_worker_get_count
  1698. @subsection @code{starpu_spu_worker_get_count} -- Get the number of Cell SPUs controlled by StarPU
  1699. @table @asis
  1700. @item @emph{Description}:
  1701. This function returns the number of Cell SPUs controlled by StarPU.
  1702. @item @emph{Prototype}:
  1703. @code{unsigned starpu_opencl_worker_get_count(void);}
  1704. @end table
  1705. @node starpu_worker_get_id
  1706. @subsection @code{starpu_worker_get_id} -- Get the identifier of the current worker
  1707. @table @asis
  1708. @item @emph{Description}:
  1709. This function returns the identifier of the worker associated to the calling
  1710. thread. The returned value is either -1 if the current context is not a StarPU
  1711. worker (i.e. when called from the application outside a task or a callback), or
  1712. an integer between 0 and @code{starpu_worker_get_count() - 1}.
  1713. @item @emph{Prototype}:
  1714. @code{int starpu_worker_get_id(void);}
  1715. @end table
  1716. @node starpu_worker_get_devid
  1717. @subsection @code{starpu_worker_get_devid} -- Get the device identifier of a worker
  1718. @table @asis
  1719. @item @emph{Description}:
  1720. This functions returns the device id of the worker associated to an identifier
  1721. (as returned by the @code{starpu_worker_get_id} function). In the case of a
  1722. CUDA worker, this device identifier is the logical device identifier exposed by
  1723. CUDA (used by the @code{cudaGetDevice} function for instance). The device
  1724. identifier of a CPU worker is the logical identifier of the core on which the
  1725. worker was bound; this identifier is either provided by the OS or by the
  1726. @code{hwloc} library in case it is available.
  1727. @item @emph{Prototype}:
  1728. @code{int starpu_worker_get_devid(int id);}
  1729. @end table
  1730. @node starpu_worker_get_type
  1731. @subsection @code{starpu_worker_get_type} -- Get the type of processing unit associated to a worker
  1732. @table @asis
  1733. @item @emph{Description}:
  1734. This function returns the type of worker associated to an identifier (as
  1735. returned by the @code{starpu_worker_get_id} function). The returned value
  1736. indicates the architecture of the worker: @code{STARPU_CPU_WORKER} for a CPU
  1737. core, @code{STARPU_CUDA_WORKER} for a CUDA device,
  1738. @code{STARPU_OPENCL_WORKER} for a OpenCL device, and
  1739. @code{STARPU_GORDON_WORKER} for a Cell SPU. The value returned for an invalid
  1740. identifier is unspecified.
  1741. @item @emph{Prototype}:
  1742. @code{enum starpu_archtype starpu_worker_get_type(int id);}
  1743. @end table
  1744. @node starpu_worker_get_name
  1745. @subsection @code{starpu_worker_get_name} -- Get the name of a worker
  1746. @table @asis
  1747. @item @emph{Description}:
  1748. StarPU associates a unique human readable string to each processing unit. This
  1749. function copies at most the @code{maxlen} first bytes of the unique string
  1750. associated to a worker identified by its identifier @code{id} into the
  1751. @code{dst} buffer. The caller is responsible for ensuring that the @code{dst}
  1752. is a valid pointer to a buffer of @code{maxlen} bytes at least. Calling this
  1753. function on an invalid identifier results in an unspecified behaviour.
  1754. @item @emph{Prototype}:
  1755. @code{void starpu_worker_get_name(int id, char *dst, size_t maxlen);}
  1756. @end table
  1757. @node starpu_worker_get_memory_node
  1758. @subsection @code{starpu_worker_get_memory_node} -- Get the memory node of a worker
  1759. @table @asis
  1760. @item @emph{Description}:
  1761. This function returns the identifier of the memory node associated to the
  1762. worker identified by @code{workerid}.
  1763. @item @emph{Prototype}:
  1764. @code{unsigned starpu_worker_get_memory_node(unsigned workerid);}
  1765. @end table
  1766. @node Data Library
  1767. @section Data Library
  1768. This section describes the data management facilities provided by StarPU.
  1769. We show how to use existing data interfaces in @ref{Data Interfaces}, but developers can
  1770. design their own data interfaces if required.
  1771. @menu
  1772. * starpu_access_mode:: starpu_access_mode
  1773. * unsigned memory_node:: Memory node
  1774. * starpu_data_handle:: StarPU opaque data handle
  1775. * void *interface:: StarPU data interface
  1776. * starpu_data_register:: Register a piece of data to StarPU
  1777. * starpu_data_unregister:: Unregister a piece of data from StarPU
  1778. * starpu_data_invalidate:: Invalidate all data replicates
  1779. * starpu_data_acquire:: Access registered data from the application
  1780. * starpu_data_acquire_cb:: Access registered data from the application asynchronously
  1781. * starpu_data_release:: Release registered data from the application
  1782. @end menu
  1783. @node starpu_access_mode
  1784. @subsection @code{starpu_access_mode} -- Data access mode
  1785. This datatype describes a data access mode. The different available modes are:
  1786. @table @asis
  1787. @table @asis
  1788. @item @code{STARPU_R} read-only mode.
  1789. @item @code{STARPU_W} write-only mode.
  1790. @item @code{STARPU_RW} read-write mode. This is equivalent to @code{STARPU_R|STARPU_W}.
  1791. @item @code{STARPU_SCRATCH} scratch memory. A temporary buffer is allocated for the task, but StarPU does not enforce data consistency.
  1792. @end table
  1793. @end table
  1794. @node unsigned memory_node
  1795. @subsection @code{unsigned memory_node} -- Memory node
  1796. @table @asis
  1797. @item @emph{Description}:
  1798. Every worker is associated to a memory node which is a logical abstraction of
  1799. the address space from which the processing unit gets its data. For instance,
  1800. the memory node associated to the different CPU workers represents main memory
  1801. (RAM), the memory node associated to a GPU is DRAM embedded on the device.
  1802. Every memory node is identified by a logical index which is accessible from the
  1803. @code{starpu_worker_get_memory_node} function. When registering a piece of data
  1804. to StarPU, the specified memory node indicates where the piece of data
  1805. initially resides (we also call this memory node the home node of a piece of
  1806. data).
  1807. @end table
  1808. @node starpu_data_handle
  1809. @subsection @code{starpu_data_handle} -- StarPU opaque data handle
  1810. @table @asis
  1811. @item @emph{Description}:
  1812. StarPU uses @code{starpu_data_handle} as an opaque handle to manage a piece of
  1813. data. Once a piece of data has been registered to StarPU, it is associated to a
  1814. @code{starpu_data_handle} which keeps track of the state of the piece of data
  1815. over the entire machine, so that we can maintain data consistency and locate
  1816. data replicates for instance.
  1817. @end table
  1818. @node void *interface
  1819. @subsection @code{void *interface} -- StarPU data interface
  1820. @table @asis
  1821. @item @emph{Description}:
  1822. Data management is done at a high-level in StarPU: rather than accessing a mere
  1823. list of contiguous buffers, the tasks may manipulate data that are described by
  1824. a high-level construct which we call data interface.
  1825. An example of data interface is the "vector" interface which describes a
  1826. contiguous data array on a spefic memory node. This interface is a simple
  1827. structure containing the number of elements in the array, the size of the
  1828. elements, and the address of the array in the appropriate address space (this
  1829. address may be invalid if there is no valid copy of the array in the memory
  1830. node). More informations on the data interfaces provided by StarPU are
  1831. given in @ref{Data Interfaces}.
  1832. When a piece of data managed by StarPU is used by a task, the task
  1833. implementation is given a pointer to an interface describing a valid copy of
  1834. the data that is accessible from the current processing unit.
  1835. @end table
  1836. @node starpu_data_register
  1837. @subsection @code{starpu_data_register} -- Register a piece of data to StarPU
  1838. @table @asis
  1839. @item @emph{Description}:
  1840. Register a piece of data into the handle located at the @code{handleptr}
  1841. address. The @code{interface} buffer contains the initial description of the
  1842. data in the home node. The @code{ops} argument is a pointer to a structure
  1843. describing the different methods used to manipulate this type of interface. See
  1844. @ref{struct starpu_data_interface_ops_t} for more details on this structure.
  1845. If @code{home_node} is not a valid memory node, StarPU will automatically
  1846. allocate the memory described by the interface the data handle is used for the
  1847. first time in write-only mode. Once such data handle has been automatically
  1848. allocated, it is possible to access it using any access mode.
  1849. Note that StarPU supplies a set of predefined types of interface (e.g. vector or
  1850. matrix) which can be registered by the means of helper functions (e.g.
  1851. @code{starpu_vector_data_register} or @code{starpu_matrix_data_register}).
  1852. @item @emph{Prototype}:
  1853. @code{void starpu_data_register(starpu_data_handle *handleptr,
  1854. uint32_t home_node,
  1855. void *interface,
  1856. struct starpu_data_interface_ops_t *ops);}
  1857. @end table
  1858. @node starpu_data_unregister
  1859. @subsection @code{starpu_data_unregister} -- Unregister a piece of data from StarPU
  1860. @table @asis
  1861. @item @emph{Description}:
  1862. This function unregisters a data handle from StarPU. If the data was
  1863. automatically allocated by StarPU because the home node was not valid, all
  1864. automatically allocated buffers are freed. Otherwise, a valid copy of the data
  1865. is put back into the home node in the buffer that was initially registered.
  1866. Using a data handle that has been unregistered from StarPU results in an
  1867. undefined behaviour.
  1868. @item @emph{Prototype}:
  1869. @code{void starpu_data_unregister(starpu_data_handle handle);}
  1870. @end table
  1871. @node starpu_data_invalidate
  1872. @subsection @code{starpu_data_invalidate} -- Invalidate all data replicates
  1873. @table @asis
  1874. @item @emph{Description}:
  1875. Destroy all replicates of the data handle. After data invalidation, the first
  1876. access to the handle must be performed in write-only mode. Accessing an
  1877. invalidated data in read-mode results in undefined behaviour.
  1878. @item @emph{Prototype}:
  1879. @code{void starpu_data_invalidate(starpu_data_handle handle);}
  1880. @end table
  1881. @c TODO create a specific sections about user interaction with the DSM ?
  1882. @node starpu_data_acquire
  1883. @subsection @code{starpu_data_acquire} -- Access registered data from the application
  1884. @table @asis
  1885. @item @emph{Description}:
  1886. The application must call this function prior to accessing registered data from
  1887. main memory outside tasks. StarPU ensures that the application will get an
  1888. up-to-date copy of the data in main memory located where the data was
  1889. originally registered, and that all concurrent accesses (e.g. from tasks) will
  1890. be consistent with the access mode specified in the @code{mode} argument.
  1891. @code{starpu_data_release} must be called once the application does not need to
  1892. access the piece of data anymore.
  1893. Note that implicit data dependencies are also enforced by
  1894. @code{starpu_data_acquire} in case they are enabled.
  1895. @code{starpu_data_acquire} is a blocking call, so that it cannot be called from
  1896. tasks or from their callbacks (in that case, @code{starpu_data_acquire} returns
  1897. @code{-EDEADLK}). Upon successful completion, this function returns 0.
  1898. @item @emph{Prototype}:
  1899. @code{int starpu_data_acquire(starpu_data_handle handle, starpu_access_mode mode);}
  1900. @end table
  1901. @node starpu_data_acquire_cb
  1902. @subsection @code{starpu_data_acquire_cb} -- Access registered data from the application asynchronously
  1903. @table @asis
  1904. @item @emph{Description}:
  1905. @code{starpu_data_acquire_cb} is the asynchronous equivalent of
  1906. @code{starpu_data_release}. When the data specified in the first argument is
  1907. available in the appropriate access mode, the callback function is executed.
  1908. The application may access the requested data during the execution of this
  1909. callback. The callback function must call @code{starpu_data_release} once the
  1910. application does not need to access the piece of data anymore.
  1911. Note that implicit data dependencies are also enforced by
  1912. @code{starpu_data_acquire} in case they are enabled.
  1913. Contrary to @code{starpu_data_acquire}, this function is non-blocking and may
  1914. be called from task callbacks. Upon successful completion, this function
  1915. returns 0.
  1916. @item @emph{Prototype}:
  1917. @code{int starpu_data_acquire_cb(starpu_data_handle handle, starpu_access_mode mode, void (*callback)(void *), void *arg);}
  1918. @end table
  1919. @node starpu_data_release
  1920. @subsection @code{starpu_data_release} -- Release registered data from the application
  1921. @table @asis
  1922. @item @emph{Description}:
  1923. This function releases the piece of data acquired by the application either by
  1924. @code{starpu_data_acquire} or by @code{starpu_data_acquire_cb}.
  1925. @item @emph{Prototype}:
  1926. @code{void starpu_data_release(starpu_data_handle handle);}
  1927. @end table
  1928. @node Data Interfaces
  1929. @section Data Interfaces
  1930. @menu
  1931. * Variable Interface::
  1932. * Vector Interface::
  1933. * Matrix Interface::
  1934. * BCSR Interface for Sparse Matrices (Blocked Compressed Sparse Row Representation)::
  1935. * CSR Interface for Sparse Matrices (Compressed Sparse Row Representation)::
  1936. * Block Interface::
  1937. @end menu
  1938. @node Variable Interface
  1939. @subsection Variable Interface
  1940. @table @asis
  1941. @item @emph{Description}:
  1942. @item @emph{Prototype}:
  1943. @code{void starpu_variable_data_register(starpu_data_handle *handle,
  1944. uint32_t home_node,
  1945. uintptr_t ptr, size_t elemsize);}
  1946. @item @emph{Example}:
  1947. @cartouche
  1948. @smallexample
  1949. float var;
  1950. starpu_data_handle var_handle;
  1951. starpu_variable_data_register(&var_handle, 0, (uintptr_t)&var, sizeof(var));
  1952. @end smallexample
  1953. @end cartouche
  1954. @end table
  1955. @node Vector Interface
  1956. @subsection Vector Interface
  1957. @table @asis
  1958. @item @emph{Description}:
  1959. @item @emph{Prototype}:
  1960. @code{void starpu_vector_data_register(starpu_data_handle *handle, uint32_t home_node,
  1961. uintptr_t ptr, uint32_t nx, size_t elemsize);}
  1962. @item @emph{Example}:
  1963. @cartouche
  1964. @smallexample
  1965. float vector[NX];
  1966. starpu_data_handle vector_handle;
  1967. starpu_vector_data_register(&vector_handle, 0, (uintptr_t)vector, NX,
  1968. sizeof(vector[0]));
  1969. @end smallexample
  1970. @end cartouche
  1971. @end table
  1972. @node Matrix Interface
  1973. @subsection Matrix Interface
  1974. @table @asis
  1975. @item @emph{Description}:
  1976. @item @emph{Prototype}:
  1977. @code{void starpu_matrix_data_register(starpu_data_handle *handle, uint32_t home_node,
  1978. uintptr_t ptr, uint32_t ld, uint32_t nx,
  1979. uint32_t ny, size_t elemsize);}
  1980. @item @emph{Example}:
  1981. @cartouche
  1982. @smallexample
  1983. float *matrix;
  1984. starpu_data_handle matrix_handle;
  1985. matrix = (float*)malloc(width * height * sizeof(float));
  1986. starpu_matrix_data_register(&matrix_handle, 0, (uintptr_t)matrix,
  1987. width, width, height, sizeof(float));
  1988. @end smallexample
  1989. @end cartouche
  1990. @end table
  1991. @node BCSR Interface for Sparse Matrices (Blocked Compressed Sparse Row Representation)
  1992. @subsection BCSR Interface for Sparse Matrices (Blocked Compressed Sparse Row Representation)
  1993. @table @asis
  1994. @item @emph{Description}:
  1995. @item @emph{Prototype}:
  1996. @code{void starpu_bcsr_data_register(starpu_data_handle *handle, uint32_t home_node, uint32_t nnz, uint32_t nrow,
  1997. uintptr_t nzval, uint32_t *colind, uint32_t *rowptr, uint32_t firstentry, uint32_t r, uint32_t c, size_t elemsize);}
  1998. @item @emph{Example}:
  1999. @cartouche
  2000. @smallexample
  2001. @end smallexample
  2002. @end cartouche
  2003. @end table
  2004. @node CSR Interface for Sparse Matrices (Compressed Sparse Row Representation)
  2005. @subsection CSR Interface for Sparse Matrices (Compressed Sparse Row Representation)
  2006. @table @asis
  2007. @item @emph{Description}:
  2008. @item @emph{Prototype}:
  2009. @code{void starpu_csr_data_register(starpu_data_handle *handle, uint32_t home_node, uint32_t nnz, uint32_t nrow,
  2010. uintptr_t nzval, uint32_t *colind, uint32_t *rowptr, uint32_t firstentry, size_t elemsize);}
  2011. @item @emph{Example}:
  2012. @cartouche
  2013. @smallexample
  2014. @end smallexample
  2015. @end cartouche
  2016. @end table
  2017. @node Block Interface
  2018. @subsection Block Interface
  2019. @table @asis
  2020. @item @emph{Description}:
  2021. @item @emph{Prototype}:
  2022. @code{void starpu_block_data_register(starpu_data_handle *handle, uint32_t home_node,
  2023. uintptr_t ptr, uint32_t ldy, uint32_t ldz, uint32_t nx,
  2024. uint32_t ny, uint32_t nz, size_t elemsize);}
  2025. @item @emph{Example}:
  2026. @cartouche
  2027. @smallexample
  2028. float *block;
  2029. starpu_data_handle block_handle;
  2030. block = (float*)malloc(nx*ny*nz*sizeof(float));
  2031. starpu_block_data_register(&block_handle, 0, (uintptr_t)block,
  2032. nx, nx*ny, nx, ny, nz, sizeof(float));
  2033. @end smallexample
  2034. @end cartouche
  2035. @end table
  2036. @node Data Partition
  2037. @section Data Partition
  2038. @menu
  2039. * struct starpu_data_filter:: StarPU filter structure
  2040. * starpu_data_partition:: Partition Data
  2041. * starpu_data_unpartition:: Unpartition Data
  2042. * starpu_data_get_nb_children::
  2043. * starpu_data_get_sub_data::
  2044. * Predefined filter functions::
  2045. @end menu
  2046. @node struct starpu_data_filter
  2047. @subsection @code{struct starpu_data_filter} -- StarPU filter structure
  2048. @table @asis
  2049. @item @emph{Description}:
  2050. The filter structure describes a data partitioning function.
  2051. @item @emph{Fields}:
  2052. @table @asis
  2053. @item @code{filter_func}:
  2054. TODO
  2055. @code{void (*filter_func)(void *father_interface, void* child_interface, struct starpu_data_filter *, unsigned id, unsigned nparts);}
  2056. @item @code{get_nchildren}:
  2057. TODO
  2058. @code{unsigned (*get_nchildren)(struct starpu_data_filter *, starpu_data_handle initial_handle);}
  2059. @item @code{get_child_ops}:
  2060. TODO
  2061. @code{struct starpu_data_interface_ops_t *(*get_child_ops)(struct starpu_data_filter *, unsigned id);}
  2062. @item @code{filter_arg}:
  2063. TODO
  2064. @item @code{nchildren}:
  2065. TODO
  2066. @item @code{filter_arg_ptr}:
  2067. TODO
  2068. @end table
  2069. @end table
  2070. @node starpu_data_partition
  2071. @subsection starpu_data_partition -- Partition Data
  2072. @table @asis
  2073. @item @emph{Description}:
  2074. TODO
  2075. @item @emph{Prototype}:
  2076. @code{void starpu_data_partition(starpu_data_handle initial_handle, struct starpu_data_filter *f);}
  2077. @end table
  2078. @node starpu_data_unpartition
  2079. @subsection starpu_data_unpartition -- Unpartition data
  2080. @table @asis
  2081. @item @emph{Description}:
  2082. TODO
  2083. @item @emph{Prototype}:
  2084. @code{void starpu_data_unpartition(starpu_data_handle root_data, uint32_t gathering_node);}
  2085. @end table
  2086. @node starpu_data_get_nb_children
  2087. @subsection starpu_data_get_nb_children
  2088. @table @asis
  2089. @item @emph{Description}:
  2090. TODO
  2091. @item @emph{Return value}:
  2092. This function returns returns the number of children.
  2093. @item @emph{Prototype}:
  2094. @code{int starpu_data_get_nb_children(starpu_data_handle handle);}
  2095. @end table
  2096. @c starpu_data_handle starpu_data_get_child(starpu_data_handle handle, unsigned i);
  2097. @node starpu_data_get_sub_data
  2098. @subsection starpu_data_get_sub_data
  2099. @table @asis
  2100. @item @emph{Description}:
  2101. TODO
  2102. @item @emph{Return value}:
  2103. TODO
  2104. @item @emph{Prototype}:
  2105. @code{starpu_data_handle starpu_data_get_sub_data(starpu_data_handle root_data, unsigned depth, ... );}
  2106. @end table
  2107. @node Predefined filter functions
  2108. @subsection Predefined filter functions
  2109. @menu
  2110. * Partitioning BCSR Data::
  2111. * Partitioning BLAS interface::
  2112. * Partitioning Vector Data::
  2113. * Partitioning Block Data::
  2114. @end menu
  2115. This section gives a list of the predefined partitioning functions.
  2116. Examples on how to use them are shown in @ref{Partitioning Data}.
  2117. @node Partitioning BCSR Data
  2118. @subsubsection Partitioning BCSR Data
  2119. @itemize
  2120. @item
  2121. TODO
  2122. @code{void starpu_canonical_block_filter_bcsr(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts);}
  2123. @item
  2124. TODO
  2125. @code{void starpu_vertical_block_filter_func_csr(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts);}
  2126. @end itemize
  2127. @node Partitioning BLAS interface
  2128. @subsubsection Partitioning BLAS interface
  2129. @itemize
  2130. @item
  2131. TODO
  2132. @code{void starpu_block_filter_func(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts);}
  2133. @item
  2134. TODO
  2135. @code{void starpu_vertical_block_filter_func(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts);}
  2136. @end itemize
  2137. @node Partitioning Vector Data
  2138. @subsubsection Partitioning Vector Data
  2139. @itemize
  2140. @item
  2141. TODO
  2142. @code{void starpu_block_filter_func_vector(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts);}
  2143. @item
  2144. TODO
  2145. @code{void starpu_vector_list_filter_func(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts);}
  2146. @item
  2147. TODO
  2148. @code{void starpu_vector_divide_in_2_filter_func(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts);}
  2149. @end itemize
  2150. @node Partitioning Block Data
  2151. @subsubsection Partitioning Block Data
  2152. @itemize
  2153. @item
  2154. TODO
  2155. @code{void starpu_block_filter_func_block(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts);}
  2156. @end itemize
  2157. @node Codelets and Tasks
  2158. @section Codelets and Tasks
  2159. @menu
  2160. * struct starpu_codelet:: StarPU codelet structure
  2161. * struct starpu_task:: StarPU task structure
  2162. * starpu_task_init:: Initialize a Task
  2163. * starpu_task_create:: Allocate and Initialize a Task
  2164. * starpu_task_deinit:: Release all the resources used by a Task
  2165. * starpu_task_destroy:: Destroy a dynamically allocated Task
  2166. * starpu_task_wait:: Wait for the termination of a Task
  2167. * starpu_task_submit:: Submit a Task
  2168. * starpu_task_wait_for_all:: Wait for the termination of all Tasks
  2169. * starpu_get_current_task:: Return the task currently executed by the worker
  2170. * starpu_display_codelet_stats:: Display statistics
  2171. @end menu
  2172. @node struct starpu_codelet
  2173. @subsection @code{struct starpu_codelet} -- StarPU codelet structure
  2174. @table @asis
  2175. @item @emph{Description}:
  2176. The codelet structure describes a kernel that is possibly implemented on
  2177. various targets.
  2178. @item @emph{Fields}:
  2179. @table @asis
  2180. @item @code{where}:
  2181. Indicates which types of processing units are able to execute the codelet.
  2182. @code{STARPU_CPU|STARPU_CUDA} for instance indicates that the codelet is
  2183. implemented for both CPU cores and CUDA devices while @code{STARPU_GORDON}
  2184. indicates that it is only available on Cell SPUs.
  2185. @item @code{cpu_func} (optional):
  2186. Is a function pointer to the CPU implementation of the codelet. Its prototype
  2187. must be: @code{void cpu_func(void *buffers[], void *cl_arg)}. The first
  2188. argument being the array of data managed by the data management library, and
  2189. the second argument is a pointer to the argument passed from the @code{cl_arg}
  2190. field of the @code{starpu_task} structure.
  2191. The @code{cpu_func} field is ignored if @code{STARPU_CPU} does not appear in
  2192. the @code{where} field, it must be non-null otherwise.
  2193. @item @code{cuda_func} (optional):
  2194. Is a function pointer to the CUDA implementation of the codelet. @emph{This
  2195. must be a host-function written in the CUDA runtime API}. Its prototype must
  2196. be: @code{void cuda_func(void *buffers[], void *cl_arg);}. The @code{cuda_func}
  2197. field is ignored if @code{STARPU_CUDA} does not appear in the @code{where}
  2198. field, it must be non-null otherwise.
  2199. @item @code{opencl_func} (optional):
  2200. Is a function pointer to the OpenCL implementation of the codelet. Its
  2201. prototype must be:
  2202. @code{void opencl_func(starpu_data_interface_t *descr, void *arg);}.
  2203. This pointer is ignored if @code{STARPU_OPENCL} does not appear in the
  2204. @code{where} field, it must be non-null otherwise.
  2205. @item @code{gordon_func} (optional):
  2206. This is the index of the Cell SPU implementation within the Gordon library.
  2207. See Gordon documentation for more details on how to register a kernel and
  2208. retrieve its index.
  2209. @item @code{nbuffers}:
  2210. Specifies the number of arguments taken by the codelet. These arguments are
  2211. managed by the DSM and are accessed from the @code{void *buffers[]}
  2212. array. The constant argument passed with the @code{cl_arg} field of the
  2213. @code{starpu_task} structure is not counted in this number. This value should
  2214. not be above @code{STARPU_NMAXBUFS}.
  2215. @item @code{model} (optional):
  2216. This is a pointer to the performance model associated to this codelet. This
  2217. optional field is ignored when set to @code{NULL}. TODO
  2218. @end table
  2219. @end table
  2220. @node struct starpu_task
  2221. @subsection @code{struct starpu_task} -- StarPU task structure
  2222. @table @asis
  2223. @item @emph{Description}:
  2224. The @code{starpu_task} structure describes a task that can be offloaded on the various
  2225. processing units managed by StarPU. It instantiates a codelet. It can either be
  2226. allocated dynamically with the @code{starpu_task_create} method, or declared
  2227. statically. In the latter case, the programmer has to zero the
  2228. @code{starpu_task} structure and to fill the different fields properly. The
  2229. indicated default values correspond to the configuration of a task allocated
  2230. with @code{starpu_task_create}.
  2231. @item @emph{Fields}:
  2232. @table @asis
  2233. @item @code{cl}:
  2234. Is a pointer to the corresponding @code{starpu_codelet} data structure. This
  2235. describes where the kernel should be executed, and supplies the appropriate
  2236. implementations. When set to @code{NULL}, no code is executed during the tasks,
  2237. such empty tasks can be useful for synchronization purposes.
  2238. @item @code{buffers}:
  2239. Is an array of @code{starpu_buffer_descr_t} structures. It describes the
  2240. different pieces of data accessed by the task, and how they should be accessed.
  2241. The @code{starpu_buffer_descr_t} structure is composed of two fields, the
  2242. @code{handle} field specifies the handle of the piece of data, and the
  2243. @code{mode} field is the required access mode (eg @code{STARPU_RW}). The number
  2244. of entries in this array must be specified in the @code{nbuffers} field of the
  2245. @code{starpu_codelet} structure, and should not excede @code{STARPU_NMAXBUFS}.
  2246. If unsufficient, this value can be set with the @code{--enable-maxbuffers}
  2247. option when configuring StarPU.
  2248. @item @code{cl_arg} (optional) (default = NULL):
  2249. This pointer is passed to the codelet through the second argument
  2250. of the codelet implementation (e.g. @code{cpu_func} or @code{cuda_func}).
  2251. In the specific case of the Cell processor, see the @code{cl_arg_size}
  2252. argument.
  2253. @item @code{cl_arg_size} (optional, Cell specific):
  2254. In the case of the Cell processor, the @code{cl_arg} pointer is not directly
  2255. given to the SPU function. A buffer of size @code{cl_arg_size} is allocated on
  2256. the SPU. This buffer is then filled with the @code{cl_arg_size} bytes starting
  2257. at address @code{cl_arg}. In this case, the argument given to the SPU codelet
  2258. is therefore not the @code{cl_arg} pointer, but the address of the buffer in
  2259. local store (LS) instead. This field is ignored for CPU, CUDA and OpenCL
  2260. codelets.
  2261. @item @code{callback_func} (optional) (default = @code{NULL}):
  2262. This is a function pointer of prototype @code{void (*f)(void *)} which
  2263. specifies a possible callback. If this pointer is non-null, the callback
  2264. function is executed @emph{on the host} after the execution of the task. The
  2265. callback is passed the value contained in the @code{callback_arg} field. No
  2266. callback is executed if the field is set to @code{NULL}.
  2267. @item @code{callback_arg} (optional) (default = @code{NULL}):
  2268. This is the pointer passed to the callback function. This field is ignored if
  2269. the @code{callback_func} is set to @code{NULL}.
  2270. @item @code{use_tag} (optional) (default = 0):
  2271. If set, this flag indicates that the task should be associated with the tag
  2272. contained in the @code{tag_id} field. Tag allow the application to synchronize
  2273. with the task and to express task dependencies easily.
  2274. @item @code{tag_id}:
  2275. This fields contains the tag associated to the task if the @code{use_tag} field
  2276. was set, it is ignored otherwise.
  2277. @item @code{synchronous}:
  2278. If this flag is set, the @code{starpu_task_submit} function is blocking and
  2279. returns only when the task has been executed (or if no worker is able to
  2280. process the task). Otherwise, @code{starpu_task_submit} returns immediately.
  2281. @item @code{priority} (optional) (default = @code{STARPU_DEFAULT_PRIO}):
  2282. This field indicates a level of priority for the task. This is an integer value
  2283. that must be set between the return values of the
  2284. @code{starpu_sched_get_min_priority} function for the least important tasks,
  2285. and that of the @code{starpu_sched_get_max_priority} for the most important
  2286. tasks (included). The @code{STARPU_MIN_PRIO} and @code{STARPU_MAX_PRIO} macros
  2287. are provided for convenience and respectively returns value of
  2288. @code{starpu_sched_get_min_priority} and @code{starpu_sched_get_max_priority}.
  2289. Default priority is @code{STARPU_DEFAULT_PRIO}, which is always defined as 0 in
  2290. order to allow static task initialization. Scheduling strategies that take
  2291. priorities into account can use this parameter to take better scheduling
  2292. decisions, but the scheduling policy may also ignore it.
  2293. @item @code{execute_on_a_specific_worker} (default = 0):
  2294. If this flag is set, StarPU will bypass the scheduler and directly affect this
  2295. task to the worker specified by the @code{workerid} field.
  2296. @item @code{workerid} (optional):
  2297. If the @code{execute_on_a_specific_worker} field is set, this field indicates
  2298. which is the identifier of the worker that should process this task (as
  2299. returned by @code{starpu_worker_get_id}). This field is ignored if
  2300. @code{execute_on_a_specific_worker} field is set to 0.
  2301. @item @code{detach} (optional) (default = 1):
  2302. If this flag is set, it is not possible to synchronize with the task
  2303. by the means of @code{starpu_task_wait} later on. Internal data structures
  2304. are only guaranteed to be freed once @code{starpu_task_wait} is called if the
  2305. flag is not set.
  2306. @item @code{destroy} (optional) (default = 1):
  2307. If this flag is set, the task structure will automatically be freed, either
  2308. after the execution of the callback if the task is detached, or during
  2309. @code{starpu_task_wait} otherwise. If this flag is not set, dynamically
  2310. allocated data structures will not be freed until @code{starpu_task_destroy} is
  2311. called explicitly. Setting this flag for a statically allocated task structure
  2312. will result in undefined behaviour.
  2313. @item @code{predicted} (output field):
  2314. Predicted duration of the task. This field is only set if the scheduling
  2315. strategy used performance models.
  2316. @end table
  2317. @end table
  2318. @node starpu_task_init
  2319. @subsection @code{starpu_task_init} -- Initialize a Task
  2320. @table @asis
  2321. @item @emph{Description}:
  2322. Initialize a task structure with default values. This function is implicitly
  2323. called by @code{starpu_task_create}. By default, tasks initialized with
  2324. @code{starpu_task_init} must be deinitialized explicitly with
  2325. @code{starpu_task_deinit}. Tasks can also be initialized statically, using the
  2326. constant @code{STARPU_TASK_INITIALIZER}.
  2327. @item @emph{Prototype}:
  2328. @code{void starpu_task_init(struct starpu_task *task);}
  2329. @end table
  2330. @node starpu_task_create
  2331. @subsection @code{starpu_task_create} -- Allocate and Initialize a Task
  2332. @table @asis
  2333. @item @emph{Description}:
  2334. Allocate a task structure and initialize it with default values. Tasks
  2335. allocated dynamically with @code{starpu_task_create} are automatically freed when the
  2336. task is terminated. If the destroy flag is explicitly unset, the resources used
  2337. by the task are freed by calling
  2338. @code{starpu_task_destroy}.
  2339. @item @emph{Prototype}:
  2340. @code{struct starpu_task *starpu_task_create(void);}
  2341. @end table
  2342. @node starpu_task_deinit
  2343. @subsection @code{starpu_task_deinit} -- Release all the resources used by a Task
  2344. @table @asis
  2345. @item @emph{Description}:
  2346. Release all the structures automatically allocated to execute the task. This is
  2347. called automatically by @code{starpu_task_destroy}, but the task structure itself is not
  2348. freed. This should be used for statically allocated tasks for instance.
  2349. @item @emph{Prototype}:
  2350. @code{void starpu_task_deinit(struct starpu_task *task);}
  2351. @end table
  2352. @node starpu_task_destroy
  2353. @subsection @code{starpu_task_destroy} -- Destroy a dynamically allocated Task
  2354. @table @asis
  2355. @item @emph{Description}:
  2356. Free the resource allocated during @code{starpu_task_create}. This function can be
  2357. called automatically after the execution of a task by setting the
  2358. @code{destroy} flag of the @code{starpu_task} structure (default behaviour).
  2359. Calling this function on a statically allocated task results in an undefined
  2360. behaviour.
  2361. @item @emph{Prototype}:
  2362. @code{void starpu_task_destroy(struct starpu_task *task);}
  2363. @end table
  2364. @node starpu_task_wait
  2365. @subsection @code{starpu_task_wait} -- Wait for the termination of a Task
  2366. @table @asis
  2367. @item @emph{Description}:
  2368. This function blocks until the task has been executed. It is not possible to
  2369. synchronize with a task more than once. It is not possible to wait for
  2370. synchronous or detached tasks.
  2371. @item @emph{Return value}:
  2372. Upon successful completion, this function returns 0. Otherwise, @code{-EINVAL}
  2373. indicates that the specified task was either synchronous or detached.
  2374. @item @emph{Prototype}:
  2375. @code{int starpu_task_wait(struct starpu_task *task);}
  2376. @end table
  2377. @node starpu_task_submit
  2378. @subsection @code{starpu_task_submit} -- Submit a Task
  2379. @table @asis
  2380. @item @emph{Description}:
  2381. This function submits a task to StarPU. Calling this function does
  2382. not mean that the task will be executed immediately as there can be data or task
  2383. (tag) dependencies that are not fulfilled yet: StarPU will take care of
  2384. scheduling this task with respect to such dependencies.
  2385. This function returns immediately if the @code{synchronous} field of the
  2386. @code{starpu_task} structure was set to 0, and block until the termination of
  2387. the task otherwise. It is also possible to synchronize the application with
  2388. asynchronous tasks by the means of tags, using the @code{starpu_tag_wait}
  2389. function for instance.
  2390. @item @emph{Return value}:
  2391. In case of success, this function returns 0, a return value of @code{-ENODEV}
  2392. means that there is no worker able to process this task (e.g. there is no GPU
  2393. available and this task is only implemented for CUDA devices).
  2394. @item @emph{Prototype}:
  2395. @code{int starpu_task_submit(struct starpu_task *task);}
  2396. @end table
  2397. @node starpu_task_wait_for_all
  2398. @subsection @code{starpu_task_wait_for_all} -- Wait for the termination of all Tasks
  2399. @table @asis
  2400. @item @emph{Description}:
  2401. This function blocks until all the tasks that were submitted are terminated.
  2402. @item @emph{Prototype}:
  2403. @code{void starpu_task_wait_for_all(void);}
  2404. @end table
  2405. @node starpu_get_current_task
  2406. @subsection @code{starpu_get_current_task} -- Return the task currently executed by the worker
  2407. @table @asis
  2408. @item @emph{Description}:
  2409. This function returns the task currently executed by the worker, or
  2410. NULL if it is called either from a thread that is not a task or simply
  2411. because there is no task being executed at the moment.
  2412. @item @emph{Prototype}:
  2413. @code{struct starpu_task *starpu_get_current_task(void);}
  2414. @end table
  2415. @node starpu_display_codelet_stats
  2416. @subsection @code{starpu_display_codelet_stats} -- Display statistics
  2417. @table @asis
  2418. @item @emph{Description}:
  2419. TODO
  2420. @item @emph{Prototype}:
  2421. @code{void starpu_display_codelet_stats(struct starpu_codelet_t *cl);}
  2422. @end table
  2423. @c Callbacks : what can we put in callbacks ?
  2424. @node Explicit Dependencies
  2425. @section Explicit Dependencies
  2426. @menu
  2427. * starpu_task_declare_deps_array:: starpu_task_declare_deps_array
  2428. * starpu_tag_t:: Task logical identifier
  2429. * starpu_tag_declare_deps:: Declare the Dependencies of a Tag
  2430. * starpu_tag_declare_deps_array:: Declare the Dependencies of a Tag
  2431. * starpu_tag_wait:: Block until a Tag is terminated
  2432. * starpu_tag_wait_array:: Block until a set of Tags is terminated
  2433. * starpu_tag_remove:: Destroy a Tag
  2434. * starpu_tag_notify_from_apps:: Feed a tag explicitly
  2435. @end menu
  2436. @node starpu_task_declare_deps_array
  2437. @subsection @code{starpu_task_declare_deps_array} -- Declare task dependencies
  2438. @table @asis
  2439. @item @emph{Description}:
  2440. Declare task dependencies between a @code{task} and an array of tasks of length
  2441. @code{ndeps}. This function must be called prior to the submission of the task,
  2442. but it may called after the submission or the execution of the tasks in the
  2443. array provided the tasks are still valid (ie. they were not automatically
  2444. destroyed). Calling this function on a task that was already submitted or with
  2445. an entry of @code{task_array} that is not a valid task anymore results in an
  2446. undefined behaviour. If @code{ndeps} is null, no dependency is added. It is
  2447. possible to call @code{starpu_task_declare_deps_array} multiple times on the
  2448. same task, in this case, the dependencies are added. It is possible to have
  2449. redundancy in the task dependencies.
  2450. @item @emph{Prototype}:
  2451. @code{void starpu_task_declare_deps_array(struct starpu_task *task, unsigned ndeps, struct starpu_task *task_array[]);}
  2452. @end table
  2453. @node starpu_tag_t
  2454. @subsection @code{starpu_tag_t} -- Task logical identifier
  2455. @table @asis
  2456. @item @emph{Description}:
  2457. It is possible to associate a task with a unique ``tag'' and to express
  2458. dependencies between tasks by the means of those tags. To do so, fill the
  2459. @code{tag_id} field of the @code{starpu_task} structure with a tag number (can
  2460. be arbitrary) and set the @code{use_tag} field to 1.
  2461. If @code{starpu_tag_declare_deps} is called with this tag number, the task will
  2462. not be started until the tasks which holds the declared dependency tags are
  2463. completed.
  2464. @end table
  2465. @node starpu_tag_declare_deps
  2466. @subsection @code{starpu_tag_declare_deps} -- Declare the Dependencies of a Tag
  2467. @table @asis
  2468. @item @emph{Description}:
  2469. Specify the dependencies of the task identified by tag @code{id}. The first
  2470. argument specifies the tag which is configured, the second argument gives the
  2471. number of tag(s) on which @code{id} depends. The following arguments are the
  2472. tags which have to be terminated to unlock the task.
  2473. This function must be called before the associated task is submitted to StarPU
  2474. with @code{starpu_task_submit}.
  2475. @item @emph{Remark}
  2476. Because of the variable arity of @code{starpu_tag_declare_deps}, note that the
  2477. last arguments @emph{must} be of type @code{starpu_tag_t}: constant values
  2478. typically need to be explicitly casted. Using the
  2479. @code{starpu_tag_declare_deps_array} function avoids this hazard.
  2480. @item @emph{Prototype}:
  2481. @code{void starpu_tag_declare_deps(starpu_tag_t id, unsigned ndeps, ...);}
  2482. @item @emph{Example}:
  2483. @cartouche
  2484. @example
  2485. /* Tag 0x1 depends on tags 0x32 and 0x52 */
  2486. starpu_tag_declare_deps((starpu_tag_t)0x1,
  2487. 2, (starpu_tag_t)0x32, (starpu_tag_t)0x52);
  2488. @end example
  2489. @end cartouche
  2490. @end table
  2491. @node starpu_tag_declare_deps_array
  2492. @subsection @code{starpu_tag_declare_deps_array} -- Declare the Dependencies of a Tag
  2493. @table @asis
  2494. @item @emph{Description}:
  2495. This function is similar to @code{starpu_tag_declare_deps}, except that its
  2496. does not take a variable number of arguments but an array of tags of size
  2497. @code{ndeps}.
  2498. @item @emph{Prototype}:
  2499. @code{void starpu_tag_declare_deps_array(starpu_tag_t id, unsigned ndeps, starpu_tag_t *array);}
  2500. @item @emph{Example}:
  2501. @cartouche
  2502. @example
  2503. /* Tag 0x1 depends on tags 0x32 and 0x52 */
  2504. starpu_tag_t tag_array[2] = @{0x32, 0x52@};
  2505. starpu_tag_declare_deps_array((starpu_tag_t)0x1, 2, tag_array);
  2506. @end example
  2507. @end cartouche
  2508. @end table
  2509. @node starpu_tag_wait
  2510. @subsection @code{starpu_tag_wait} -- Block until a Tag is terminated
  2511. @table @asis
  2512. @item @emph{Description}:
  2513. This function blocks until the task associated to tag @code{id} has been
  2514. executed. This is a blocking call which must therefore not be called within
  2515. tasks or callbacks, but only from the application directly. It is possible to
  2516. synchronize with the same tag multiple times, as long as the
  2517. @code{starpu_tag_remove} function is not called. Note that it is still
  2518. possible to synchronize with a tag associated to a task which @code{starpu_task}
  2519. data structure was freed (e.g. if the @code{destroy} flag of the
  2520. @code{starpu_task} was enabled).
  2521. @item @emph{Prototype}:
  2522. @code{void starpu_tag_wait(starpu_tag_t id);}
  2523. @end table
  2524. @node starpu_tag_wait_array
  2525. @subsection @code{starpu_tag_wait_array} -- Block until a set of Tags is terminated
  2526. @table @asis
  2527. @item @emph{Description}:
  2528. This function is similar to @code{starpu_tag_wait} except that it blocks until
  2529. @emph{all} the @code{ntags} tags contained in the @code{id} array are
  2530. terminated.
  2531. @item @emph{Prototype}:
  2532. @code{void starpu_tag_wait_array(unsigned ntags, starpu_tag_t *id);}
  2533. @end table
  2534. @node starpu_tag_remove
  2535. @subsection @code{starpu_tag_remove} -- Destroy a Tag
  2536. @table @asis
  2537. @item @emph{Description}:
  2538. This function releases the resources associated to tag @code{id}. It can be
  2539. called once the corresponding task has been executed and when there is
  2540. no other tag that depend on this tag anymore.
  2541. @item @emph{Prototype}:
  2542. @code{void starpu_tag_remove(starpu_tag_t id);}
  2543. @end table
  2544. @node starpu_tag_notify_from_apps
  2545. @subsection @code{starpu_tag_notify_from_apps} -- Feed a Tag explicitly
  2546. @table @asis
  2547. @item @emph{Description}:
  2548. This function explicitly unlocks tag @code{id}. It may be useful in the
  2549. case of applications which execute part of their computation outside StarPU
  2550. tasks (e.g. third-party libraries). It is also provided as a
  2551. convenient tool for the programmer, for instance to entirely construct the task
  2552. DAG before actually giving StarPU the opportunity to execute the tasks.
  2553. @item @emph{Prototype}:
  2554. @code{void starpu_tag_notify_from_apps(starpu_tag_t id);}
  2555. @end table
  2556. @node Implicit Data Dependencies
  2557. @section Implicit Data Dependencies
  2558. @menu
  2559. * starpu_data_set_default_sequential_consistency_flag:: starpu_data_set_default_sequential_consistency_flag
  2560. * starpu_data_get_default_sequential_consistency_flag:: starpu_data_get_default_sequential_consistency_flag
  2561. * starpu_data_set_sequential_consistency_flag:: starpu_data_set_sequential_consistency_flag
  2562. @end menu
  2563. In this section, we describe how StarPU makes it possible to insert implicit
  2564. task dependencies in order to enforce sequential data consistency. When this
  2565. data consistency is enabled on a specific data handle, any data access will
  2566. appear as sequentially consistent from the application. For instance, if the
  2567. application submits two tasks that access the same piece of data in read-only
  2568. mode, and then a third task that access it in write mode, dependencies will be
  2569. added between the two first tasks and the third one. Implicit data dependencies
  2570. are also inserted in the case of data accesses from the application.
  2571. @node starpu_data_set_default_sequential_consistency_flag
  2572. @subsection @code{starpu_data_set_default_sequential_consistency_flag} -- Set default sequential consistency flag
  2573. @table @asis
  2574. @item @emph{Description}:
  2575. Set the default sequential consistency flag. If a non-zero value is passed, a
  2576. sequential data consistency will be enforced for all handles registered after
  2577. this function call, otherwise it is disabled. By default, StarPU enables
  2578. sequential data consistency. It is also possible to select the data consistency
  2579. mode of a specific data handle with the
  2580. @code{starpu_data_set_sequential_consistency_flag} function.
  2581. @item @emph{Prototype}:
  2582. @code{void starpu_data_set_default_sequential_consistency_flag(unsigned flag);}
  2583. @end table
  2584. @node starpu_data_get_default_sequential_consistency_flag
  2585. @subsection @code{starpu_data_get_default_sequential_consistency_flag} -- Get current default sequential consistency flag
  2586. @table @asis
  2587. @item @emph{Description}:
  2588. This function returns the current default sequential consistency flag.
  2589. @item @emph{Prototype}:
  2590. @code{unsigned starpu_data_set_default_sequential_consistency_flag(void);}
  2591. @end table
  2592. @node starpu_data_set_sequential_consistency_flag
  2593. @subsection @code{starpu_data_set_sequential_consistency_flag} -- Set data sequential consistency mode
  2594. @table @asis
  2595. @item @emph{Description}:
  2596. Select the data consistency mode associated to a data handle. The consistency
  2597. mode set using this function has the priority over the default mode which can
  2598. be set with @code{starpu_data_set_sequential_consistency_flag}.
  2599. @item @emph{Prototype}:
  2600. @code{void starpu_data_set_sequential_consistency_flag(starpu_data_handle handle, unsigned flag);}
  2601. @end table
  2602. @node Performance Model API
  2603. @section Performance Model API
  2604. @menu
  2605. * starpu_load_history_debug::
  2606. * starpu_perfmodel_debugfilepath::
  2607. * starpu_perfmodel_get_arch_name::
  2608. * starpu_force_bus_sampling::
  2609. @end menu
  2610. @node starpu_load_history_debug
  2611. @subsection @code{starpu_load_history_debug}
  2612. @table @asis
  2613. @item @emph{Description}:
  2614. TODO
  2615. @item @emph{Prototype}:
  2616. @code{int starpu_load_history_debug(const char *symbol, struct starpu_perfmodel_t *model);}
  2617. @end table
  2618. @node starpu_perfmodel_debugfilepath
  2619. @subsection @code{starpu_perfmodel_debugfilepath}
  2620. @table @asis
  2621. @item @emph{Description}:
  2622. TODO
  2623. @item @emph{Prototype}:
  2624. @code{void starpu_perfmodel_debugfilepath(struct starpu_perfmodel_t *model, enum starpu_perf_archtype arch, char *path, size_t maxlen);}
  2625. @end table
  2626. @node starpu_perfmodel_get_arch_name
  2627. @subsection @code{starpu_perfmodel_get_arch_name}
  2628. @table @asis
  2629. @item @emph{Description}:
  2630. TODO
  2631. @item @emph{Prototype}:
  2632. @code{void starpu_perfmodel_get_arch_name(enum starpu_perf_archtype arch, char *archname, size_t maxlen);}
  2633. @end table
  2634. @node starpu_force_bus_sampling
  2635. @subsection @code{starpu_force_bus_sampling}
  2636. @table @asis
  2637. @item @emph{Description}:
  2638. TODO
  2639. @item @emph{Prototype}:
  2640. @code{void starpu_force_bus_sampling(void);}
  2641. @end table
  2642. @node Profiling API
  2643. @section Profiling API
  2644. @menu
  2645. * starpu_profiling_status_set:: starpu_profiling_status_set
  2646. * starpu_profiling_status_get:: starpu_profiling_status_get
  2647. * struct starpu_task_profiling_info:: task profiling information
  2648. * struct starpu_worker_profiling_info:: worker profiling information
  2649. * starpu_worker_get_profiling_info:: starpu_worker_get_profiling_info
  2650. * struct starpu_bus_profiling_info:: bus profiling information
  2651. * starpu_bus_get_count::
  2652. * starpu_bus_get_id::
  2653. * starpu_bus_get_src::
  2654. * starpu_bus_get_dst::
  2655. * starpu_timing_timespec_delay_us::
  2656. * starpu_timing_timespec_to_us::
  2657. * starpu_bus_profiling_helper_display_summary::
  2658. @end menu
  2659. @node starpu_profiling_status_set
  2660. @subsection @code{starpu_profiling_status_set} -- Set current profiling status
  2661. @table @asis
  2662. @item @emph{Description}:
  2663. Thie function sets the profiling status. Profiling is activated by passing
  2664. @code{STARPU_PROFILING_ENABLE} in @code{status}. Passing
  2665. @code{STARPU_PROFILING_DISABLE} disables profiling. Calling this function
  2666. resets all profiling measurements. When profiling is enabled, the
  2667. @code{profiling_info} field of the @code{struct starpu_task} structure points
  2668. to a valid @code{struct starpu_task_profiling_info} structure containing
  2669. information about the execution of the task.
  2670. @item @emph{Return value}:
  2671. Negative return values indicate an error, otherwise the previous status is
  2672. returned.
  2673. @item @emph{Prototype}:
  2674. @code{int starpu_profiling_status_set(int status);}
  2675. @end table
  2676. @node starpu_profiling_status_get
  2677. @subsection @code{starpu_profiling_status_get} -- Get current profiling status
  2678. @table @asis
  2679. @item @emph{Description}:
  2680. Return the current profiling status or a negative value in case there was an error.
  2681. @item @emph{Prototype}:
  2682. @code{int starpu_profiling_status_get(void);}
  2683. @end table
  2684. @node struct starpu_task_profiling_info
  2685. @subsection @code{struct starpu_task_profiling_info} -- Task profiling information
  2686. @table @asis
  2687. @item @emph{Description}:
  2688. This structure contains information about the execution of a task. It is
  2689. accessible from the @code{.profiling_info} field of the @code{starpu_task}
  2690. structure if profiling was enabled.
  2691. @item @emph{Fields}:
  2692. @table @asis
  2693. @item @code{submit_time}:
  2694. Date of task submission (relative to the initialization of StarPU).
  2695. @item @code{start_time}:
  2696. Date of task execution beginning (relative to the initialization of StarPU).
  2697. @item @code{end_time}:
  2698. Date of task execution termination (relative to the initialization of StarPU).
  2699. @item @code{workerid}:
  2700. Identifier of the worker which has executed the task.
  2701. @end table
  2702. @end table
  2703. @node struct starpu_worker_profiling_info
  2704. @subsection @code{struct starpu_worker_profiling_info} -- Worker profiling information
  2705. @table @asis
  2706. @item @emph{Description}:
  2707. This structure contains the profiling information associated to a worker.
  2708. @item @emph{Fields}:
  2709. @table @asis
  2710. @item @code{start_time}:
  2711. Starting date for the reported profiling measurements.
  2712. @item @code{total_time}:
  2713. Duration of the profiling measurement interval.
  2714. @item @code{executing_time}:
  2715. Time spent by the worker to execute tasks during the profiling measurement interval.
  2716. @item @code{sleeping_time}:
  2717. Time spent idling by the worker during the profiling measurement interval.
  2718. @item @code{executed_tasks}:
  2719. Number of tasks executed by the worker during the profiling measurement interval.
  2720. @end table
  2721. @end table
  2722. @node starpu_worker_get_profiling_info
  2723. @subsection @code{starpu_worker_get_profiling_info} -- Get worker profiling info
  2724. @table @asis
  2725. @item @emph{Description}:
  2726. Get the profiling info associated to the worker identified by @code{workerid},
  2727. and reset the profiling measurements. If the @code{worker_info} argument is
  2728. NULL, only reset the counters associated to worker @code{workerid}.
  2729. @item @emph{Return value}:
  2730. Upon successful completion, this function returns 0. Otherwise, a negative
  2731. value is returned.
  2732. @item @emph{Prototype}:
  2733. @code{int starpu_worker_get_profiling_info(int workerid, struct starpu_worker_profiling_info *worker_info);}
  2734. @end table
  2735. @node struct starpu_bus_profiling_info
  2736. @subsection @code{struct starpu_bus_profiling_info} -- Bus profiling information
  2737. @table @asis
  2738. @item @emph{Description}:
  2739. TODO
  2740. @item @emph{Fields}:
  2741. @table @asis
  2742. @item @code{start_time}:
  2743. TODO
  2744. @item @code{total_time}:
  2745. TODO
  2746. @item @code{transferred_bytes}:
  2747. TODO
  2748. @item @code{transfer_count}:
  2749. TODO
  2750. @end table
  2751. @end table
  2752. @node starpu_bus_get_count
  2753. @subsection @code{starpu_bus_get_count}
  2754. @table @asis
  2755. @item @emph{Description}:
  2756. TODO
  2757. @item @emph{Prototype}:
  2758. @code{int starpu_bus_get_count(void);}
  2759. @end table
  2760. @node starpu_bus_get_id
  2761. @subsection @code{starpu_bus_get_id}
  2762. @table @asis
  2763. @item @emph{Description}:
  2764. TODO
  2765. @item @emph{Prototype}:
  2766. @code{int starpu_bus_get_id(int src, int dst);}
  2767. @end table
  2768. @node starpu_bus_get_src
  2769. @subsection @code{starpu_bus_get_src}
  2770. @table @asis
  2771. @item @emph{Description}:
  2772. TODO
  2773. @item @emph{Prototype}:
  2774. @code{int starpu_bus_get_src(int busid);}
  2775. @end table
  2776. @node starpu_bus_get_dst
  2777. @subsection @code{starpu_bus_get_dst}
  2778. @table @asis
  2779. @item @emph{Description}:
  2780. TODO
  2781. @item @emph{Prototype}:
  2782. @code{int starpu_bus_get_dst(int busid);}
  2783. @end table
  2784. @node starpu_timing_timespec_delay_us
  2785. @subsection @code{starpu_timing_timespec_delay_us}
  2786. @table @asis
  2787. @item @emph{Description}:
  2788. TODO
  2789. @item @emph{Prototype}:
  2790. @code{double starpu_timing_timespec_delay_us(struct timespec *start, struct timespec *end);}
  2791. @end table
  2792. @node starpu_timing_timespec_to_us
  2793. @subsection @code{starpu_timing_timespec_to_us}
  2794. @table @asis
  2795. @item @emph{Description}:
  2796. TODO
  2797. @item @emph{Prototype}:
  2798. @code{double starpu_timing_timespec_to_us(struct timespec *ts);}
  2799. @end table
  2800. @node starpu_bus_profiling_helper_display_summary
  2801. @subsection @code{starpu_bus_profiling_helper_display_summary}
  2802. @table @asis
  2803. @item @emph{Description}:
  2804. TODO
  2805. @item @emph{Prototype}:
  2806. @code{void starpu_bus_profiling_helper_display_summary(void);}
  2807. @end table
  2808. @node CUDA extensions
  2809. @section CUDA extensions
  2810. @c void starpu_data_malloc_pinned_if_possible(float **A, size_t dim);
  2811. @menu
  2812. * starpu_cuda_get_local_stream:: Get current worker's CUDA stream
  2813. * starpu_helper_cublas_init:: Initialize CUBLAS on every CUDA device
  2814. * starpu_helper_cublas_shutdown:: Deinitialize CUBLAS on every CUDA device
  2815. @end menu
  2816. @node starpu_cuda_get_local_stream
  2817. @subsection @code{starpu_cuda_get_local_stream} -- Get current worker's CUDA stream
  2818. @table @asis
  2819. @item @emph{Description}:
  2820. StarPU provides a stream for every CUDA device controlled by StarPU. This
  2821. function is only provided for convenience so that programmers can easily use
  2822. asynchronous operations within codelets without having to create a stream by
  2823. hand. Note that the application is not forced to use the stream provided by
  2824. @code{starpu_cuda_get_local_stream} and may also create its own streams.
  2825. Synchronizing with @code{cudaThreadSynchronize()} is allowed, but will reduce
  2826. the likelihood of having all transfers overlapped.
  2827. @item @emph{Prototype}:
  2828. @code{cudaStream_t *starpu_cuda_get_local_stream(void);}
  2829. @end table
  2830. @node starpu_helper_cublas_init
  2831. @subsection @code{starpu_helper_cublas_init} -- Initialize CUBLAS on every CUDA device
  2832. @table @asis
  2833. @item @emph{Description}:
  2834. The CUBLAS library must be initialized prior to any CUBLAS call. Calling
  2835. @code{starpu_helper_cublas_init} will initialize CUBLAS on every CUDA device
  2836. controlled by StarPU. This call blocks until CUBLAS has been properly
  2837. initialized on every device.
  2838. @item @emph{Prototype}:
  2839. @code{void starpu_helper_cublas_init(void);}
  2840. @end table
  2841. @node starpu_helper_cublas_shutdown
  2842. @subsection @code{starpu_helper_cublas_shutdown} -- Deinitialize CUBLAS on every CUDA device
  2843. @table @asis
  2844. @item @emph{Description}:
  2845. This function synchronously deinitializes the CUBLAS library on every CUDA device.
  2846. @item @emph{Prototype}:
  2847. @code{void starpu_helper_cublas_shutdown(void);}
  2848. @end table
  2849. @node OpenCL extensions
  2850. @section OpenCL extensions
  2851. @menu
  2852. * Enabling OpenCL:: Enabling OpenCL
  2853. * Compiling OpenCL codelets:: Compiling OpenCL codelets
  2854. * Loading OpenCL codelets:: Loading OpenCL codelets
  2855. @end menu
  2856. @node Enabling OpenCL
  2857. @subsection Enabling OpenCL
  2858. On GPU devices which can run both CUDA and OpenCL, CUDA will be
  2859. enabled by default. To enable OpenCL, you need either to disable CUDA
  2860. when configuring StarPU:
  2861. @example
  2862. % ./configure --disable-cuda
  2863. @end example
  2864. or when running applications:
  2865. @example
  2866. % STARPU_NCUDA=0 ./application
  2867. @end example
  2868. OpenCL will automatically be started on any device not yet used by
  2869. CUDA. So on a machine running 4 GPUS, it is therefore possible to
  2870. enable CUDA on 2 devices, and OpenCL on the 2 other devices by doing
  2871. so:
  2872. @example
  2873. % STARPU_NCUDA=2 ./application
  2874. @end example
  2875. @node Compiling OpenCL codelets
  2876. @subsection Compiling OpenCL codelets
  2877. Source codes for OpenCL codelets can be stored in a file or in a
  2878. string. StarPU provides functions to build the program executable for
  2879. each available OpenCL device as a @code{cl_program} object. This
  2880. program executable can then be loaded within a specific queue as
  2881. explained in the next section. These are only helpers, Applications
  2882. can also fill a @code{starpu_opencl_program} array by hand for more advanced
  2883. use (e.g. different programs on the different OpenCL devices, for
  2884. relocation purpose for instance).
  2885. @menu
  2886. * starpu_opencl_load_opencl_from_file:: Compiling OpenCL source code
  2887. * starpu_opencl_load_opencl_from_string:: Compiling OpenCL source code
  2888. * starpu_opencl_unload_opencl:: Releasing OpenCL code
  2889. @end menu
  2890. @node starpu_opencl_load_opencl_from_file
  2891. @subsubsection @code{starpu_opencl_load_opencl_from_file} -- Compiling OpenCL source code
  2892. @table @asis
  2893. @item @emph{Description}:
  2894. TODO
  2895. @item @emph{Prototype}:
  2896. @code{int starpu_opencl_load_opencl_from_file(char *source_file_name, struct starpu_opencl_program *opencl_programs);}
  2897. @end table
  2898. @node starpu_opencl_load_opencl_from_string
  2899. @subsubsection @code{starpu_opencl_load_opencl_from_string} -- Compiling OpenCL source code
  2900. @table @asis
  2901. @item @emph{Description}:
  2902. TODO
  2903. @item @emph{Prototype}:
  2904. @code{int starpu_opencl_load_opencl_from_string(char *opencl_program_source, struct starpu_opencl_program *opencl_programs);}
  2905. @end table
  2906. @node starpu_opencl_unload_opencl
  2907. @subsubsection @code{starpu_opencl_unload_opencl} -- Releasing OpenCL code
  2908. @table @asis
  2909. @item @emph{Description}:
  2910. TODO
  2911. @item @emph{Prototype}:
  2912. @code{int starpu_opencl_unload_opencl(struct starpu_opencl_program *opencl_programs);}
  2913. @end table
  2914. @node Loading OpenCL codelets
  2915. @subsection Loading OpenCL codelets
  2916. @menu
  2917. * starpu_opencl_load_kernel:: Loading a kernel
  2918. * starpu_opencl_relase_kernel:: Releasing a kernel
  2919. @end menu
  2920. @node starpu_opencl_load_kernel
  2921. @subsubsection @code{starpu_opencl_load_kernel} -- Loading a kernel
  2922. @table @asis
  2923. @item @emph{Description}:
  2924. TODO
  2925. @item @emph{Prototype}:
  2926. @code{int starpu_opencl_load_kernel(cl_kernel *kernel, cl_command_queue *queue, struct starpu_opencl_program *opencl_programs, char *kernel_name, int devid)
  2927. }
  2928. @end table
  2929. @node starpu_opencl_relase_kernel
  2930. @subsubsection @code{starpu_opencl_release_kernel} -- Releasing a kernel
  2931. @table @asis
  2932. @item @emph{Description}:
  2933. TODO
  2934. @item @emph{Prototype}:
  2935. @code{int starpu_opencl_release_kernel(cl_kernel kernel);}
  2936. @end table
  2937. @node Cell extensions
  2938. @section Cell extensions
  2939. nothing yet.
  2940. @node Miscellaneous helpers
  2941. @section Miscellaneous helpers
  2942. @menu
  2943. * starpu_execute_on_each_worker:: Execute a function on a subset of workers
  2944. @end menu
  2945. @node starpu_execute_on_each_worker
  2946. @subsection @code{starpu_execute_on_each_worker} -- Execute a function on a subset of workers
  2947. @table @asis
  2948. @item @emph{Description}:
  2949. When calling this method, the offloaded function specified by the first argument is
  2950. executed by every StarPU worker that may execute the function.
  2951. The second argument is passed to the offloaded function.
  2952. The last argument specifies on which types of processing units the function
  2953. should be executed. Similarly to the @code{where} field of the
  2954. @code{starpu_codelet} structure, it is possible to specify that the function
  2955. should be executed on every CUDA device and every CPU by passing
  2956. @code{STARPU_CPU|STARPU_CUDA}.
  2957. This function blocks until the function has been executed on every appropriate
  2958. processing units, so that it may not be called from a callback function for
  2959. instance.
  2960. @item @emph{Prototype}:
  2961. @code{void starpu_execute_on_each_worker(void (*func)(void *), void *arg, uint32_t where);}
  2962. @end table
  2963. @c ---------------------------------------------------------------------
  2964. @c Advanced Topics
  2965. @c ---------------------------------------------------------------------
  2966. @node Advanced Topics
  2967. @chapter Advanced Topics
  2968. @menu
  2969. * Defining a new data interface::
  2970. * Defining a new scheduling policy::
  2971. @end menu
  2972. @node Defining a new data interface
  2973. @section Defining a new data interface
  2974. @menu
  2975. * struct starpu_data_interface_ops_t:: Per-interface methods
  2976. * struct starpu_data_copy_methods:: Per-interface data transfer methods
  2977. * An example of data interface:: An example of data interface
  2978. @end menu
  2979. @c void *starpu_data_get_interface_on_node(starpu_data_handle handle, unsigned memory_node); TODO
  2980. @node struct starpu_data_interface_ops_t
  2981. @subsection @code{struct starpu_data_interface_ops_t} -- Per-interface methods
  2982. @table @asis
  2983. @item @emph{Description}:
  2984. TODO describe all the different fields
  2985. @end table
  2986. @node struct starpu_data_copy_methods
  2987. @subsection @code{struct starpu_data_copy_methods} -- Per-interface data transfer methods
  2988. @table @asis
  2989. @item @emph{Description}:
  2990. TODO describe all the different fields
  2991. @end table
  2992. @node An example of data interface
  2993. @subsection An example of data interface
  2994. @table @asis
  2995. TODO
  2996. @end table
  2997. @node Defining a new scheduling policy
  2998. @section Defining a new scheduling policy
  2999. TODO
  3000. A full example showing how to define a new scheduling policy is available in
  3001. the StarPU sources in the directory @code{examples/scheduler/}.
  3002. @menu
  3003. * struct starpu_sched_policy_s::
  3004. * starpu_worker_set_sched_condition::
  3005. * starpu_sched_set_min_priority:: Set the minimum priority level
  3006. * starpu_sched_set_max_priority:: Set the maximum priority level
  3007. * Source code::
  3008. @end menu
  3009. @node struct starpu_sched_policy_s
  3010. @subsection @code{struct starpu_sched_policy_s} -- Scheduler methods
  3011. @table @asis
  3012. @item @emph{Description}:
  3013. This structure contains all the methods that implement a scheduling policy. An
  3014. application may specify which scheduling strategy in the @code{sched_policy}
  3015. field of the @code{starpu_conf} structure passed to the @code{starpu_init}
  3016. function.
  3017. @item @emph{Fields}:
  3018. @table @asis
  3019. @item @code{init_sched}:
  3020. Initialize the scheduling policy.
  3021. @item @code{deinit_sched}:
  3022. Cleanup the scheduling policy.
  3023. @item @code{push_task}:
  3024. Insert a task into the scheduler.
  3025. @item @code{push_prio_task}:
  3026. Insert a priority task into the scheduler.
  3027. @item @code{pop_task}:
  3028. Get a task from the scheduler. The mutex associated to the worker is already
  3029. taken when this method is called.
  3030. @item @code{pop_every_task}:
  3031. Remove all available tasks from the scheduler (tasks are chained by the means
  3032. of the prev and next fields of the starpu_task structure). The mutex associated
  3033. to the worker is already taken when this method is called.
  3034. @item @code{post_exec_hook} (optionnal):
  3035. This method is called every time a task has been executed.
  3036. @item @code{policy_name}:
  3037. Name of the policy (optionnal).
  3038. @item @code{policy_description}:
  3039. Description of the policy (optionnal).
  3040. @end table
  3041. @end table
  3042. @node starpu_worker_set_sched_condition
  3043. @subsection @code{starpu_worker_set_sched_condition} -- Specify the condition variable associated to a worker
  3044. @table @asis
  3045. @item @emph{Description}:
  3046. When there is no available task for a worker, StarPU blocks this worker on a
  3047. condition variable. This function specifies which condition variable (and the
  3048. associated mutex) should be used to block (and to wake up) a worker. Note that
  3049. multiple workers may use the same condition variable. For instance, in the case
  3050. of a scheduling strategy with a single task queue, the same condition variable
  3051. would be used to block and wake up all workers.
  3052. The initialization method of a scheduling strategy (@code{init_sched}) must
  3053. call this function once per worker.
  3054. @item @emph{Prototype}:
  3055. @code{void starpu_worker_set_sched_condition(int workerid, pthread_cond_t *sched_cond, pthread_mutex_t *sched_mutex);}
  3056. @end table
  3057. @node starpu_sched_set_min_priority
  3058. @subsection @code{starpu_sched_set_min_priority}
  3059. @table @asis
  3060. @item @emph{Description}:
  3061. Defines the minimum priority level supported by the scheduling policy. The
  3062. default minimum priority level is the same as the default priority level which
  3063. is 0 by convention. The application may access that value by calling the
  3064. @code{starpu_sched_get_min_priority} function. This function should only be
  3065. called from the initialization method of the scheduling policy, and should not
  3066. be used directly from the application.
  3067. @item @emph{Prototype}:
  3068. @code{void starpu_sched_set_min_priority(int min_prio)}
  3069. @end table
  3070. @node starpu_sched_set_max_priority
  3071. @subsection @code{starpu_sched_set_max_priority}
  3072. @table @asis
  3073. @item @emph{Description}:
  3074. Defines the maximum priority level supported by the scheduling policy. The
  3075. default maximum priority level is 1. The application may access that value by
  3076. calling the @code{starpu_sched_get_max_priority} function. This function should
  3077. only be called from the initialization method of the scheduling policy, and
  3078. should not be used directly from the application.
  3079. @item @emph{Prototype}:
  3080. @code{void starpu_sched_set_min_priority(int max_prio)}
  3081. @end table
  3082. @node Source code
  3083. @subsection Source code
  3084. @cartouche
  3085. @smallexample
  3086. static struct starpu_sched_policy_s dummy_sched_policy = @{
  3087. .init_sched = init_dummy_sched,
  3088. .deinit_sched = deinit_dummy_sched,
  3089. .push_task = push_task_dummy,
  3090. .push_prio_task = NULL,
  3091. .pop_task = pop_task_dummy,
  3092. .post_exec_hook = NULL,
  3093. .pop_every_task = NULL,
  3094. .policy_name = "dummy",
  3095. .policy_description = "dummy scheduling strategy"
  3096. @};
  3097. @end smallexample
  3098. @end cartouche
  3099. @c ---------------------------------------------------------------------
  3100. @c Appendices
  3101. @c ---------------------------------------------------------------------
  3102. @c ---------------------------------------------------------------------
  3103. @c Full source code for the 'Scaling a Vector' example
  3104. @c ---------------------------------------------------------------------
  3105. @node Full source code for the 'Scaling a Vector' example
  3106. @appendix Full source code for the 'Scaling a Vector' example
  3107. @menu
  3108. * Main application::
  3109. * CPU Codelet::
  3110. * CUDA Codelet::
  3111. * OpenCL Codelet::
  3112. @end menu
  3113. @node Main application
  3114. @section Main application
  3115. @smallexample
  3116. @include vector_scal_c.texi
  3117. @end smallexample
  3118. @node CPU Codelet
  3119. @section CPU Codelet
  3120. @smallexample
  3121. @include vector_scal_cpu.texi
  3122. @end smallexample
  3123. @node CUDA Codelet
  3124. @section CUDA Codelet
  3125. @smallexample
  3126. @include vector_scal_cuda.texi
  3127. @end smallexample
  3128. @node OpenCL Codelet
  3129. @section OpenCL Codelet
  3130. @menu
  3131. * Invoking the kernel::
  3132. * Source of the kernel::
  3133. @end menu
  3134. @node Invoking the kernel
  3135. @subsection Invoking the kernel
  3136. @smallexample
  3137. @include vector_scal_opencl.texi
  3138. @end smallexample
  3139. @node Source of the kernel
  3140. @subsection Source of the kernel
  3141. @smallexample
  3142. @include vector_scal_opencl_codelet.texi
  3143. @end smallexample
  3144. @bye