starpu.texi 123 KB

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