starpu.texi 124 KB

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