starpu.texi 111 KB

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