starpu.texi 96 KB

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