starpu.texi 111 KB

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