starpu.texi 122 KB

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