starpu.texi 118 KB

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