starpu.texi 115 KB

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