starpu.texi 114 KB

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