starpu.texi 137 KB

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