starpu.texi 115 KB

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