starpu.texi 93 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723
  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. TODO
  1048. @node Codelets and Tasks
  1049. @section Codelets and Tasks
  1050. @menu
  1051. * struct starpu_codelet:: StarPU codelet structure
  1052. * struct starpu_task:: StarPU task structure
  1053. * starpu_task_init:: Initialize a Task
  1054. * starpu_task_create:: Allocate and Initialize a Task
  1055. * starpu_task_deinit:: Release all the resources used by a Task
  1056. * starpu_task_destroy:: Destroy a dynamically allocated Task
  1057. * starpu_task_wait:: Wait for the termination of a Task
  1058. * starpu_task_submit:: Submit a Task
  1059. * starpu_task_wait_for_all:: Wait for the termination of all Tasks
  1060. @end menu
  1061. @node struct starpu_codelet
  1062. @subsection @code{struct starpu_codelet} -- StarPU codelet structure
  1063. @table @asis
  1064. @item @emph{Description}:
  1065. The codelet structure describes a kernel that is possibly implemented on
  1066. various targets.
  1067. @item @emph{Fields}:
  1068. @table @asis
  1069. @item @code{where}:
  1070. Indicates which types of processing units are able to execute the codelet.
  1071. @code{STARPU_CPU|STARPU_CUDA} for instance indicates that the codelet is
  1072. implemented for both CPU cores and CUDA devices while @code{STARPU_GORDON}
  1073. indicates that it is only available on Cell SPUs.
  1074. @item @code{cpu_func} (optional):
  1075. Is a function pointer to the CPU implementation of the codelet. Its prototype
  1076. must be: @code{void cpu_func(void *buffers[], void *cl_arg)}. The first
  1077. argument being the array of data managed by the data management library, and
  1078. the second argument is a pointer to the argument passed from the @code{cl_arg}
  1079. field of the @code{starpu_task} structure.
  1080. The @code{cpu_func} field is ignored if @code{STARPU_CPU} does not appear in
  1081. the @code{where} field, it must be non-null otherwise.
  1082. @item @code{cuda_func} (optional):
  1083. Is a function pointer to the CUDA implementation of the codelet. @emph{This
  1084. must be a host-function written in the CUDA runtime API}. Its prototype must
  1085. be: @code{void cuda_func(void *buffers[], void *cl_arg);}. The @code{cuda_func}
  1086. field is ignored if @code{STARPU_CUDA} does not appear in the @code{where}
  1087. field, it must be non-null otherwise.
  1088. @item @code{opencl_func} (optional):
  1089. Is a function pointer to the OpenCL implementation of the codelet. Its
  1090. prototype must be:
  1091. @code{void opencl_func(starpu_data_interface_t *descr, void *arg);}.
  1092. This pointer is ignored if @code{STARPU_OPENCL} does not appear in the
  1093. @code{where} field, it must be non-null otherwise.
  1094. @item @code{gordon_func} (optional):
  1095. This is the index of the Cell SPU implementation within the Gordon library.
  1096. See Gordon documentation for more details on how to register a kernel and
  1097. retrieve its index.
  1098. @item @code{nbuffers}:
  1099. Specifies the number of arguments taken by the codelet. These arguments are
  1100. managed by the DSM and are accessed from the @code{void *buffers[]}
  1101. array. The constant argument passed with the @code{cl_arg} field of the
  1102. @code{starpu_task} structure is not counted in this number. This value should
  1103. not be above @code{STARPU_NMAXBUFS}.
  1104. @item @code{model} (optional):
  1105. This is a pointer to the performance model associated to this codelet. This
  1106. optional field is ignored when set to @code{NULL}. TODO
  1107. @end table
  1108. @end table
  1109. @node struct starpu_task
  1110. @subsection @code{struct starpu_task} -- StarPU task structure
  1111. @table @asis
  1112. @item @emph{Description}:
  1113. The @code{starpu_task} structure describes a task that can be offloaded on the various
  1114. processing units managed by StarPU. It instantiates a codelet. It can either be
  1115. allocated dynamically with the @code{starpu_task_create} method, or declared
  1116. statically. In the latter case, the programmer has to zero the
  1117. @code{starpu_task} structure and to fill the different fields properly. The
  1118. indicated default values correspond to the configuration of a task allocated
  1119. with @code{starpu_task_create}.
  1120. @item @emph{Fields}:
  1121. @table @asis
  1122. @item @code{cl}:
  1123. Is a pointer to the corresponding @code{starpu_codelet} data structure. This
  1124. describes where the kernel should be executed, and supplies the appropriate
  1125. implementations. When set to @code{NULL}, no code is executed during the tasks,
  1126. such empty tasks can be useful for synchronization purposes.
  1127. @item @code{buffers}:
  1128. Is an array of @code{starpu_buffer_descr_t} structures. It describes the
  1129. different pieces of data accessed by the task, and how they should be accessed.
  1130. The @code{starpu_buffer_descr_t} structure is composed of two fields, the
  1131. @code{handle} field specifies the handle of the piece of data, and the
  1132. @code{mode} field is the required access mode (eg @code{STARPU_RW}). The number
  1133. of entries in this array must be specified in the @code{nbuffers} field of the
  1134. @code{starpu_codelet} structure, and should not excede @code{STARPU_NMAXBUFS}.
  1135. If unsufficient, this value can be set with the @code{--enable-maxbuffers}
  1136. option when configuring StarPU.
  1137. @item @code{cl_arg} (optional) (default = NULL):
  1138. This pointer is passed to the codelet through the second argument
  1139. of the codelet implementation (e.g. @code{cpu_func} or @code{cuda_func}).
  1140. In the specific case of the Cell processor, see the @code{cl_arg_size}
  1141. argument.
  1142. @item @code{cl_arg_size} (optional, Cell specific):
  1143. In the case of the Cell processor, the @code{cl_arg} pointer is not directly
  1144. given to the SPU function. A buffer of size @code{cl_arg_size} is allocated on
  1145. the SPU. This buffer is then filled with the @code{cl_arg_size} bytes starting
  1146. at address @code{cl_arg}. In this case, the argument given to the SPU codelet
  1147. is therefore not the @code{cl_arg} pointer, but the address of the buffer in
  1148. local store (LS) instead. This field is ignored for CPU, CUDA and OpenCL
  1149. codelets.
  1150. @item @code{callback_func} (optional) (default = @code{NULL}):
  1151. This is a function pointer of prototype @code{void (*f)(void *)} which
  1152. specifies a possible callback. If this pointer is non-null, the callback
  1153. function is executed @emph{on the host} after the execution of the task. The
  1154. callback is passed the value contained in the @code{callback_arg} field. No
  1155. callback is executed if the field is set to @code{NULL}.
  1156. @item @code{callback_arg} (optional) (default = @code{NULL}):
  1157. This is the pointer passed to the callback function. This field is ignored if
  1158. the @code{callback_func} is set to @code{NULL}.
  1159. @item @code{use_tag} (optional) (default = 0):
  1160. If set, this flag indicates that the task should be associated with the tag
  1161. contained in the @code{tag_id} field. Tag allow the application to synchronize
  1162. with the task and to express task dependencies easily.
  1163. @item @code{tag_id}:
  1164. This fields contains the tag associated to the task if the @code{use_tag} field
  1165. was set, it is ignored otherwise.
  1166. @item @code{synchronous}:
  1167. If this flag is set, the @code{starpu_task_submit} function is blocking and
  1168. returns only when the task has been executed (or if no worker is able to
  1169. process the task). Otherwise, @code{starpu_task_submit} returns immediately.
  1170. @item @code{priority} (optional) (default = @code{STARPU_DEFAULT_PRIO}):
  1171. This field indicates a level of priority for the task. This is an integer value
  1172. that must be set between @code{STARPU_MIN_PRIO} (for the least important
  1173. tasks) and @code{STARPU_MAX_PRIO} (for the most important tasks) included.
  1174. Default priority is @code{STARPU_DEFAULT_PRIO}. Scheduling strategies that
  1175. take priorities into account can use this parameter to take better scheduling
  1176. decisions, but the scheduling policy may also ignore it.
  1177. @item @code{execute_on_a_specific_worker} (default = 0):
  1178. If this flag is set, StarPU will bypass the scheduler and directly affect this
  1179. task to the worker specified by the @code{workerid} field.
  1180. @item @code{workerid} (optional):
  1181. If the @code{execute_on_a_specific_worker} field is set, this field indicates
  1182. which is the identifier of the worker that should process this task (as
  1183. returned by @code{starpu_worker_get_id}). This field is ignored if
  1184. @code{execute_on_a_specific_worker} field is set to 0.
  1185. @item @code{detach} (optional) (default = 1):
  1186. If this flag is set, it is not possible to synchronize with the task
  1187. by the means of @code{starpu_task_wait} later on. Internal data structures
  1188. are only guaranteed to be freed once @code{starpu_task_wait} is called if the
  1189. flag is not set.
  1190. @item @code{destroy} (optional) (default = 1):
  1191. If this flag is set, the task structure will automatically be freed, either
  1192. after the execution of the callback if the task is detached, or during
  1193. @code{starpu_task_wait} otherwise. If this flag is not set, dynamically
  1194. allocated data structures will not be freed until @code{starpu_task_destroy} is
  1195. called explicitly. Setting this flag for a statically allocated task structure
  1196. will result in undefined behaviour.
  1197. @end table
  1198. @end table
  1199. @node starpu_task_init
  1200. @subsection @code{starpu_task_init} -- Initialize a Task
  1201. @table @asis
  1202. @item @emph{Description}:
  1203. Initialize a task structure with default values. This function is implicitly
  1204. called by @code{starpu_task_create}. By default, tasks initialized with
  1205. @code{starpu_task_init} must be deinitialized explicitly with
  1206. @code{starpu_task_deinit}. Tasks can also be initialized statically, using the
  1207. constant @code{STARPU_TASK_INITIALIZER}.
  1208. @item @emph{Prototype}:
  1209. @code{void starpu_task_init(struct starpu_task *task);}
  1210. @end table
  1211. @node starpu_task_create
  1212. @subsection @code{starpu_task_create} -- Allocate and Initialize a Task
  1213. @table @asis
  1214. @item @emph{Description}:
  1215. Allocate a task structure and initialize it with default values. Tasks
  1216. allocated dynamically with @code{starpu_task_create} are automatically freed when the
  1217. task is terminated. If the destroy flag is explicitly unset, the resources used
  1218. by the task are freed by calling
  1219. @code{starpu_task_destroy}.
  1220. @item @emph{Prototype}:
  1221. @code{struct starpu_task *starpu_task_create(void);}
  1222. @end table
  1223. @node starpu_task_deinit
  1224. @subsection @code{starpu_task_deinit} -- Release all the resources used by a Task
  1225. @table @asis
  1226. @item @emph{Description}:
  1227. Release all the structures automatically allocated to execute the task. This is
  1228. called automatically by @code{starpu_task_destroy}, but the task structure itself is not
  1229. freed. This should be used for statically allocated tasks for instance.
  1230. @item @emph{Prototype}:
  1231. @code{void starpu_task_deinit(struct starpu_task *task);}
  1232. @end table
  1233. @node starpu_task_destroy
  1234. @subsection @code{starpu_task_destroy} -- Destroy a dynamically allocated Task
  1235. @table @asis
  1236. @item @emph{Description}:
  1237. Free the resource allocated during @code{starpu_task_create}. This function can be
  1238. called automatically after the execution of a task by setting the
  1239. @code{destroy} flag of the @code{starpu_task} structure (default behaviour).
  1240. Calling this function on a statically allocated task results in an undefined
  1241. behaviour.
  1242. @item @emph{Prototype}:
  1243. @code{void starpu_task_destroy(struct starpu_task *task);}
  1244. @end table
  1245. @node starpu_task_wait
  1246. @subsection @code{starpu_task_wait} -- Wait for the termination of a Task
  1247. @table @asis
  1248. @item @emph{Description}:
  1249. This function blocks until the task has been executed. It is not possible to
  1250. synchronize with a task more than once. It is not possible to wait for
  1251. synchronous or detached tasks.
  1252. @item @emph{Return value}:
  1253. Upon successful completion, this function returns 0. Otherwise, @code{-EINVAL}
  1254. indicates that the specified task was either synchronous or detached.
  1255. @item @emph{Prototype}:
  1256. @code{int starpu_task_wait(struct starpu_task *task);}
  1257. @end table
  1258. @node starpu_task_submit
  1259. @subsection @code{starpu_task_submit} -- Submit a Task
  1260. @table @asis
  1261. @item @emph{Description}:
  1262. This function submits a task to StarPU. Calling this function does
  1263. not mean that the task will be executed immediately as there can be data or task
  1264. (tag) dependencies that are not fulfilled yet: StarPU will take care of
  1265. scheduling this task with respect to such dependencies.
  1266. This function returns immediately if the @code{synchronous} field of the
  1267. @code{starpu_task} structure was set to 0, and block until the termination of
  1268. the task otherwise. It is also possible to synchronize the application with
  1269. asynchronous tasks by the means of tags, using the @code{starpu_tag_wait}
  1270. function for instance.
  1271. @item @emph{Return value}:
  1272. In case of success, this function returns 0, a return value of @code{-ENODEV}
  1273. means that there is no worker able to process this task (e.g. there is no GPU
  1274. available and this task is only implemented for CUDA devices).
  1275. @item @emph{Prototype}:
  1276. @code{int starpu_task_submit(struct starpu_task *task);}
  1277. @end table
  1278. @node starpu_task_wait_for_all
  1279. @subsection @code{starpu_task_wait_for_all} -- Wait for the termination of all Tasks
  1280. @table @asis
  1281. @item @emph{Description}:
  1282. This function blocks until all the tasks that were submitted are terminated.
  1283. @item @emph{Prototype}:
  1284. @code{void starpu_task_wait_for_all(void);}
  1285. @end table
  1286. @c Callbacks : what can we put in callbacks ?
  1287. @node Explicit Dependencies
  1288. @section Explicit Dependencies
  1289. @menu
  1290. * starpu_task_declare_deps_array:: starpu_task_declare_deps_array
  1291. * starpu_tag_t:: Task logical identifier
  1292. * starpu_tag_declare_deps:: Declare the Dependencies of a Tag
  1293. * starpu_tag_declare_deps_array:: Declare the Dependencies of a Tag
  1294. * starpu_tag_wait:: Block until a Tag is terminated
  1295. * starpu_tag_wait_array:: Block until a set of Tags is terminated
  1296. * starpu_tag_remove:: Destroy a Tag
  1297. * starpu_tag_notify_from_apps:: Feed a tag explicitly
  1298. @end menu
  1299. @node starpu_task_declare_deps_array
  1300. @subsection @code{starpu_task_declare_deps_array} -- Declare task dependencies
  1301. @table @asis
  1302. @item @emph{Description}:
  1303. Declare task dependencies between a @code{task} and an array of tasks of length
  1304. @code{ndeps}. This function must be called prior to the submission of the task,
  1305. but it may called after the submission or the execution of the tasks in the
  1306. array provided the tasks are still valid (ie. they were not automatically
  1307. destroyed). Calling this function on a task that was already submitted or with
  1308. an entry of @code{task_array} that is not a valid task anymore results in an
  1309. undefined behaviour. If @code{ndeps} is null, no dependency is added. It is
  1310. possible to call @code{starpu_task_declare_deps_array} multiple times on the
  1311. same task, in this case, the dependencies are added. It is possible to have
  1312. redundancy in the task dependencies.
  1313. @item @emph{Prototype}:
  1314. @code{void starpu_task_declare_deps_array(struct starpu_task *task, unsigned ndeps, struct starpu_task *task_array[]);}
  1315. @end table
  1316. @node starpu_tag_t
  1317. @subsection @code{starpu_tag_t} -- Task logical identifier
  1318. @table @asis
  1319. @item @emph{Description}:
  1320. It is possible to associate a task with a unique ``tag'' and to express
  1321. dependencies between tasks by the means of those tags. To do so, fill the
  1322. @code{tag_id} field of the @code{starpu_task} structure with a tag number (can
  1323. be arbitrary) and set the @code{use_tag} field to 1.
  1324. If @code{starpu_tag_declare_deps} is called with this tag number, the task will
  1325. not be started until the tasks which holds the declared dependency tags are
  1326. completed.
  1327. @end table
  1328. @node starpu_tag_declare_deps
  1329. @subsection @code{starpu_tag_declare_deps} -- Declare the Dependencies of a Tag
  1330. @table @asis
  1331. @item @emph{Description}:
  1332. Specify the dependencies of the task identified by tag @code{id}. The first
  1333. argument specifies the tag which is configured, the second argument gives the
  1334. number of tag(s) on which @code{id} depends. The following arguments are the
  1335. tags which have to be terminated to unlock the task.
  1336. This function must be called before the associated task is submitted to StarPU
  1337. with @code{starpu_task_submit}.
  1338. @item @emph{Remark}
  1339. Because of the variable arity of @code{starpu_tag_declare_deps}, note that the
  1340. last arguments @emph{must} be of type @code{starpu_tag_t}: constant values
  1341. typically need to be explicitly casted. Using the
  1342. @code{starpu_tag_declare_deps_array} function avoids this hazard.
  1343. @item @emph{Prototype}:
  1344. @code{void starpu_tag_declare_deps(starpu_tag_t id, unsigned ndeps, ...);}
  1345. @item @emph{Example}:
  1346. @cartouche
  1347. @example
  1348. /* Tag 0x1 depends on tags 0x32 and 0x52 */
  1349. starpu_tag_declare_deps((starpu_tag_t)0x1,
  1350. 2, (starpu_tag_t)0x32, (starpu_tag_t)0x52);
  1351. @end example
  1352. @end cartouche
  1353. @end table
  1354. @node starpu_tag_declare_deps_array
  1355. @subsection @code{starpu_tag_declare_deps_array} -- Declare the Dependencies of a Tag
  1356. @table @asis
  1357. @item @emph{Description}:
  1358. This function is similar to @code{starpu_tag_declare_deps}, except that its
  1359. does not take a variable number of arguments but an array of tags of size
  1360. @code{ndeps}.
  1361. @item @emph{Prototype}:
  1362. @code{void starpu_tag_declare_deps_array(starpu_tag_t id, unsigned ndeps, starpu_tag_t *array);}
  1363. @item @emph{Example}:
  1364. @cartouche
  1365. @example
  1366. /* Tag 0x1 depends on tags 0x32 and 0x52 */
  1367. starpu_tag_t tag_array[2] = @{0x32, 0x52@};
  1368. starpu_tag_declare_deps_array((starpu_tag_t)0x1, 2, tag_array);
  1369. @end example
  1370. @end cartouche
  1371. @end table
  1372. @node starpu_tag_wait
  1373. @subsection @code{starpu_tag_wait} -- Block until a Tag is terminated
  1374. @table @asis
  1375. @item @emph{Description}:
  1376. This function blocks until the task associated to tag @code{id} has been
  1377. executed. This is a blocking call which must therefore not be called within
  1378. tasks or callbacks, but only from the application directly. It is possible to
  1379. synchronize with the same tag multiple times, as long as the
  1380. @code{starpu_tag_remove} function is not called. Note that it is still
  1381. possible to synchronize with a tag associated to a task which @code{starpu_task}
  1382. data structure was freed (e.g. if the @code{destroy} flag of the
  1383. @code{starpu_task} was enabled).
  1384. @item @emph{Prototype}:
  1385. @code{void starpu_tag_wait(starpu_tag_t id);}
  1386. @end table
  1387. @node starpu_tag_wait_array
  1388. @subsection @code{starpu_tag_wait_array} -- Block until a set of Tags is terminated
  1389. @table @asis
  1390. @item @emph{Description}:
  1391. This function is similar to @code{starpu_tag_wait} except that it blocks until
  1392. @emph{all} the @code{ntags} tags contained in the @code{id} array are
  1393. terminated.
  1394. @item @emph{Prototype}:
  1395. @code{void starpu_tag_wait_array(unsigned ntags, starpu_tag_t *id);}
  1396. @end table
  1397. @node starpu_tag_remove
  1398. @subsection @code{starpu_tag_remove} -- Destroy a Tag
  1399. @table @asis
  1400. @item @emph{Description}:
  1401. This function releases the resources associated to tag @code{id}. It can be
  1402. called once the corresponding task has been executed and when there is
  1403. no other tag that depend on this tag anymore.
  1404. @item @emph{Prototype}:
  1405. @code{void starpu_tag_remove(starpu_tag_t id);}
  1406. @end table
  1407. @node starpu_tag_notify_from_apps
  1408. @subsection @code{starpu_tag_notify_from_apps} -- Feed a Tag explicitly
  1409. @table @asis
  1410. @item @emph{Description}:
  1411. This function explicitly unlocks tag @code{id}. It may be useful in the
  1412. case of applications which execute part of their computation outside StarPU
  1413. tasks (e.g. third-party libraries). It is also provided as a
  1414. convenient tool for the programmer, for instance to entirely construct the task
  1415. DAG before actually giving StarPU the opportunity to execute the tasks.
  1416. @item @emph{Prototype}:
  1417. @code{void starpu_tag_notify_from_apps(starpu_tag_t id);}
  1418. @end table
  1419. @node Implicit Data Dependencies
  1420. @section Implicit Data Dependencies
  1421. @menu
  1422. * starpu_data_set_default_sequential_consistency_flag:: starpu_data_set_default_sequential_consistency_flag
  1423. * starpu_data_get_default_sequential_consistency_flag:: starpu_data_get_default_sequential_consistency_flag
  1424. * starpu_data_set_sequential_consistency_flag:: starpu_data_set_sequential_consistency_flag
  1425. @end menu
  1426. In this section, we describe how StarPU makes it possible to insert implicit
  1427. task dependencies in order to enforce sequential data consistency. When this
  1428. data consistency is enabled on a specific data handle, any data access will
  1429. appear as sequentially consistent from the application. For instance, if the
  1430. application submits two tasks that access the same piece of data in read-only
  1431. mode, and then a third task that access it in write mode, dependencies will be
  1432. added between the two first tasks and the third one. Implicit data dependencies
  1433. are also inserted in the case of data accesses from the application.
  1434. @node starpu_data_set_default_sequential_consistency_flag
  1435. @subsection @code{starpu_data_set_default_sequential_consistency_flag} -- Set default sequential consistency flag
  1436. @table @asis
  1437. @item @emph{Description}:
  1438. Set the default sequential consistency flag. If a non-null value is passed, a
  1439. sequential data consistency will be enforced for all handles registered after
  1440. this function call, otherwise it is disabled. By default, StarPU enables
  1441. sequential data consistency. It is also possible to select the data consistency
  1442. mode of a specific data handle with the
  1443. @code{starpu_data_set_sequential_consistency_flag} function.
  1444. @item @emph{Prototype}:
  1445. @code{void starpu_data_set_default_sequential_consistency_flag(unsigned flag);}
  1446. @end table
  1447. @node starpu_data_get_default_sequential_consistency_flag
  1448. @subsection @code{starpu_data_get_default_sequential_consistency_flag} -- Get current default sequential consistency flag
  1449. @table @asis
  1450. @item @emph{Description}:
  1451. This function returns the current default sequential consistency flag.
  1452. @item @emph{Prototype}:
  1453. @code{unsigned starpu_data_set_default_sequential_consistency_flag(void);}
  1454. @end table
  1455. @node starpu_data_set_sequential_consistency_flag
  1456. @subsection @code{starpu_data_set_sequential_consistency_flag} -- Set data sequential consistency mode
  1457. @table @asis
  1458. @item @emph{Description}:
  1459. Select the data consistency mode associated to a data handle. The consistency
  1460. mode set using this function has the priority over the default mode which can
  1461. be set with @code{starpu_data_set_sequential_consistency_flag}.
  1462. @item @emph{Prototype}:
  1463. @code{void starpu_data_set_sequential_consistency_flag(starpu_data_handle handle, unsigned flag);}
  1464. @end table
  1465. @node Profiling API
  1466. @section Profiling API
  1467. @menu
  1468. * starpu_profiling_status_set:: starpu_profiling_status_set
  1469. * starpu_profiling_status_get:: starpu_profiling_status_get
  1470. * struct starpu_task_profiling_info:: task profiling information
  1471. * struct starpu_worker_profiling_info:: worker profiling information
  1472. * starpu_worker_get_profiling_info:: starpu_worker_get_profiling_info
  1473. * struct starpu_bus_profiling_info:: bus profiling information
  1474. @end menu
  1475. @node starpu_profiling_status_set
  1476. @subsection @code{starpu_profiling_status_set} -- Set current profiling status
  1477. @table @asis
  1478. @item @emph{Description}:
  1479. Thie function sets the profiling status. Profiling is activated by passing
  1480. @code{STARPU_PROFILING_ENABLE} in @code{status}. Passing
  1481. @code{STARPU_PROFILING_DISABLE} disables profiling. Calling this function
  1482. resets all profiling measurements. When profiling is enabled, the
  1483. @code{profiling_info} field of the @code{struct starpu_task} structure points
  1484. to a valid @code{struct starpu_task_profiling_info} structure containing
  1485. information about the execution of the task.
  1486. @item @emph{Return value}:
  1487. Negative return values indicate an error, otherwise the previous status is
  1488. returned.
  1489. @item @emph{Prototype}:
  1490. @code{int starpu_profiling_status_set(int status);}
  1491. @end table
  1492. @node starpu_profiling_status_get
  1493. @subsection @code{starpu_profiling_status_get} -- Get current profiling status
  1494. @table @asis
  1495. @item @emph{Description}:
  1496. Return the current profiling status or a negative value in case there was an error.
  1497. @item @emph{Prototype}:
  1498. @code{int starpu_profiling_status_get(void);}
  1499. @end table
  1500. @node struct starpu_task_profiling_info
  1501. @subsection @code{struct starpu_task_profiling_info} -- Task profiling information
  1502. @table @asis
  1503. @item @emph{Description}:
  1504. This structure contains information about the execution of a task. It is
  1505. accessible from the @code{.profiling_info} field of the @code{starpu_task}
  1506. structure if profiling was enabled.
  1507. @item @emph{Fields}:
  1508. @table @asis
  1509. @item @code{submit_time}:
  1510. Date of task submission (relative to the initialization of StarPU).
  1511. @item @code{start_time}:
  1512. Date of task execution beginning (relative to the initialization of StarPU).
  1513. @item @code{end_time}:
  1514. Date of task execution termination (relative to the initialization of StarPU).
  1515. @item @code{workerid}:
  1516. Identifier of the worker which has executed the task.
  1517. @end table
  1518. @end table
  1519. @node struct starpu_worker_profiling_info
  1520. @subsection @code{struct starpu_worker_profiling_info} -- Worker profiling information
  1521. @table @asis
  1522. @item @emph{Description}:
  1523. This structure contains the profiling information associated to a worker.
  1524. @item @emph{Fields}:
  1525. @table @asis
  1526. @item @code{start_time}:
  1527. Starting date for the reported profiling measurements.
  1528. @item @code{total_time}:
  1529. Duration of the profiling measurement interval.
  1530. @item @code{executing_time}:
  1531. Time spent by the worker to execute tasks during the profiling measurement interval.
  1532. @item @code{sleeping_time}:
  1533. Time spent idling by the worker during the profiling measurement interval.
  1534. @item @code{executed_tasks}:
  1535. Number of tasks executed by the worker during the profiling measurement interval.
  1536. @end table
  1537. @end table
  1538. @node starpu_worker_get_profiling_info
  1539. @subsection @code{starpu_worker_get_profiling_info} -- Get worker profiling info
  1540. @table @asis
  1541. @item @emph{Description}:
  1542. Get the profiling info associated to the worker identified by @code{workerid},
  1543. and reset the profiling measurements. If the @code{worker_info} argument is
  1544. NULL, only reset the counters associated to worker @code{workerid}.
  1545. @item @emph{Return value}:
  1546. Upon successful completion, this function returns 0. Otherwise, a negative
  1547. value is returned.
  1548. @item @emph{Prototype}:
  1549. @code{int starpu_worker_get_profiling_info(int workerid, struct starpu_worker_profiling_info *worker_info);}
  1550. @end table
  1551. @node struct starpu_bus_profiling_info
  1552. @subsection @code{struct starpu_bus_profiling_info} -- Bus profiling information
  1553. @table @asis
  1554. @item @emph{Description}:
  1555. TODO
  1556. @item @emph{Fields}:
  1557. @table @asis
  1558. @item @code{start_time}:
  1559. TODO
  1560. @item @code{total_time}:
  1561. TODO
  1562. @item @code{transferred_bytes}:
  1563. TODO
  1564. @item @code{transfer_count}:
  1565. TODO
  1566. @end table
  1567. @end table
  1568. @node CUDA extensions
  1569. @section CUDA extensions
  1570. @c void starpu_data_malloc_pinned_if_possible(float **A, size_t dim);
  1571. @menu
  1572. * starpu_cuda_get_local_stream:: Get current worker's CUDA stream
  1573. * starpu_helper_cublas_init:: Initialize CUBLAS on every CUDA device
  1574. * starpu_helper_cublas_shutdown:: Deinitialize CUBLAS on every CUDA device
  1575. @end menu
  1576. @node starpu_cuda_get_local_stream
  1577. @subsection @code{starpu_cuda_get_local_stream} -- Get current worker's CUDA stream
  1578. @table @asis
  1579. @item @emph{Description}:
  1580. StarPU provides a stream for every CUDA device controlled by StarPU. This
  1581. function is only provided for convenience so that programmers can easily use
  1582. asynchronous operations within codelets without having to create a stream by
  1583. hand. Note that the application is not forced to use the stream provided by
  1584. @code{starpu_cuda_get_local_stream} and may also create its own streams.
  1585. @item @emph{Prototype}:
  1586. @code{cudaStream_t *starpu_cuda_get_local_stream(void);}
  1587. @end table
  1588. @node starpu_helper_cublas_init
  1589. @subsection @code{starpu_helper_cublas_init} -- Initialize CUBLAS on every CUDA device
  1590. @table @asis
  1591. @item @emph{Description}:
  1592. The CUBLAS library must be initialized prior to any CUBLAS call. Calling
  1593. @code{starpu_helper_cublas_init} will initialize CUBLAS on every CUDA device
  1594. controlled by StarPU. This call blocks until CUBLAS has been properly
  1595. initialized on every device.
  1596. @item @emph{Prototype}:
  1597. @code{void starpu_helper_cublas_init(void);}
  1598. @end table
  1599. @node starpu_helper_cublas_shutdown
  1600. @subsection @code{starpu_helper_cublas_shutdown} -- Deinitialize CUBLAS on every CUDA device
  1601. @table @asis
  1602. @item @emph{Description}:
  1603. This function synchronously deinitializes the CUBLAS library on every CUDA device.
  1604. @item @emph{Prototype}:
  1605. @code{void starpu_helper_cublas_shutdown(void);}
  1606. @end table
  1607. @node OpenCL extensions
  1608. @section OpenCL extensions
  1609. @menu
  1610. * Enabling OpenCL:: Enabling OpenCL
  1611. * Compiling OpenCL codelets:: Compiling OpenCL codelets
  1612. @end menu
  1613. @node Enabling OpenCL
  1614. @subsection Enabling OpenCL
  1615. On GPU devices which can run both CUDA and OpenCL, CUDA will be
  1616. enabled by default. To enable OpenCL, you need either to disable CUDA
  1617. when configuring StarPU:
  1618. @example
  1619. % ./configure --disable-cuda
  1620. @end example
  1621. or when running applications:
  1622. @example
  1623. % STARPU_NCUDA=0 ./application
  1624. @end example
  1625. OpenCL will automatically be started on any device not yet used by
  1626. CUDA. So on a machine running 4 GPUS, it is therefore possible to
  1627. enable CUDA on 2 devices, and OpenCL on the 2 other devices by doing
  1628. so:
  1629. @example
  1630. % STARPU_NCUDA=2 ./application
  1631. @end example
  1632. @node Compiling OpenCL codelets
  1633. @subsection Compiling OpenCL codelets
  1634. TODO
  1635. @node Cell extensions
  1636. @section Cell extensions
  1637. nothing yet.
  1638. @node Miscellaneous helpers
  1639. @section Miscellaneous helpers
  1640. @menu
  1641. * starpu_execute_on_each_worker:: Execute a function on a subset of workers
  1642. @end menu
  1643. @node starpu_execute_on_each_worker
  1644. @subsection @code{starpu_execute_on_each_worker} -- Execute a function on a subset of workers
  1645. @table @asis
  1646. @item @emph{Description}:
  1647. When calling this method, the offloaded function specified by the first argument is
  1648. executed by every StarPU worker that may execute the function.
  1649. The second argument is passed to the offloaded function.
  1650. The last argument specifies on which types of processing units the function
  1651. should be executed. Similarly to the @code{where} field of the
  1652. @code{starpu_codelet} structure, it is possible to specify that the function
  1653. should be executed on every CUDA device and every CPU by passing
  1654. @code{STARPU_CPU|STARPU_CUDA}.
  1655. This function blocks until the function has been executed on every appropriate
  1656. processing units, so that it may not be called from a callback function for
  1657. instance.
  1658. @item @emph{Prototype}:
  1659. @code{void starpu_execute_on_each_worker(void (*func)(void *), void *arg, uint32_t where);}
  1660. @end table
  1661. @c ---------------------------------------------------------------------
  1662. @c Basic Examples
  1663. @c ---------------------------------------------------------------------
  1664. @node Basic Examples
  1665. @chapter Basic Examples
  1666. @menu
  1667. * Compiling and linking options::
  1668. * Hello World:: Submitting Tasks
  1669. * Scaling a Vector:: Manipulating Data
  1670. * Vector Scaling on an Hybrid CPU/GPU Machine:: Handling Heterogeneous Architectures
  1671. @end menu
  1672. @node Compiling and linking options
  1673. @section Compiling and linking options
  1674. Let's suppose StarPU has been installed in the directory
  1675. @code{$STARPU_DIR}. As explained in @ref{Setting flags for compiling and linking applications},
  1676. the variable @code{PKG_CONFIG_PATH} needs to be set. It is also
  1677. necessary to set the variable @code{LD_LIBRARY_PATH} to locate dynamic
  1678. libraries at runtime.
  1679. @example
  1680. % PKG_CONFIG_PATH=$STARPU_DIR/lib/pkgconfig:$PKG_CONFIG_PATH
  1681. % LD_LIBRARY_PATH=$STARPU_DIR/lib:$LD_LIBRARY_PATH
  1682. @end example
  1683. The Makefile could for instance contain the following lines to define which
  1684. options must be given to the compiler and to the linker:
  1685. @cartouche
  1686. @example
  1687. CFLAGS += $$(pkg-config --cflags libstarpu)
  1688. LDFLAGS += $$(pkg-config --libs libstarpu)
  1689. @end example
  1690. @end cartouche
  1691. @node Hello World
  1692. @section Hello World
  1693. @menu
  1694. * Required Headers::
  1695. * Defining a Codelet::
  1696. * Submitting a Task::
  1697. * Execution of Hello World::
  1698. @end menu
  1699. In this section, we show how to implement a simple program that submits a task to StarPU.
  1700. @node Required Headers
  1701. @subsection Required Headers
  1702. The @code{starpu.h} header should be included in any code using StarPU.
  1703. @cartouche
  1704. @smallexample
  1705. #include <starpu.h>
  1706. @end smallexample
  1707. @end cartouche
  1708. @node Defining a Codelet
  1709. @subsection Defining a Codelet
  1710. @cartouche
  1711. @smallexample
  1712. void cpu_func(void *buffers[], void *cl_arg)
  1713. @{
  1714. float *array = cl_arg;
  1715. printf("Hello world (array = @{%f, %f@} )\n", array[0], array[1]);
  1716. @}
  1717. starpu_codelet cl =
  1718. @{
  1719. .where = STARPU_CPU,
  1720. .cpu_func = cpu_func,
  1721. .nbuffers = 0
  1722. @};
  1723. @end smallexample
  1724. @end cartouche
  1725. A codelet is a structure that represents a computational kernel. Such a codelet
  1726. may contain an implementation of the same kernel on different architectures
  1727. (e.g. CUDA, Cell's SPU, x86, ...).
  1728. The @code{nbuffers} field specifies the number of data buffers that are
  1729. manipulated by the codelet: here the codelet does not access or modify any data
  1730. that is controlled by our data management library. Note that the argument
  1731. passed to the codelet (the @code{cl_arg} field of the @code{starpu_task}
  1732. structure) does not count as a buffer since it is not managed by our data
  1733. management library.
  1734. @c TODO need a crossref to the proper description of "where" see bla for more ...
  1735. We create a codelet which may only be executed on the CPUs. The @code{where}
  1736. field is a bitmask that defines where the codelet may be executed. Here, the
  1737. @code{STARPU_CPU} value means that only CPUs can execute this codelet
  1738. (@pxref{Codelets and Tasks} for more details on this field).
  1739. When a CPU core executes a codelet, it calls the @code{cpu_func} function,
  1740. which @emph{must} have the following prototype:
  1741. @code{void (*cpu_func)(void *buffers[], void *cl_arg);}
  1742. In this example, we can ignore the first argument of this function which gives a
  1743. description of the input and output buffers (e.g. the size and the location of
  1744. the matrices). The second argument is a pointer to a buffer passed as an
  1745. argument to the codelet by the means of the @code{cl_arg} field of the
  1746. @code{starpu_task} structure.
  1747. @c TODO rewrite so that it is a little clearer ?
  1748. Be aware that this may be a pointer to a
  1749. @emph{copy} of the actual buffer, and not the pointer given by the programmer:
  1750. if the codelet modifies this buffer, there is no guarantee that the initial
  1751. buffer will be modified as well: this for instance implies that the buffer
  1752. cannot be used as a synchronization medium.
  1753. @node Submitting a Task
  1754. @subsection Submitting a Task
  1755. @cartouche
  1756. @smallexample
  1757. void callback_func(void *callback_arg)
  1758. @{
  1759. printf("Callback function (arg %x)\n", callback_arg);
  1760. @}
  1761. int main(int argc, char **argv)
  1762. @{
  1763. /* @b{initialize StarPU} */
  1764. starpu_init(NULL);
  1765. struct starpu_task *task = starpu_task_create();
  1766. task->cl = &cl; /* @b{Pointer to the codelet defined above} */
  1767. float array[2] = @{1.0f, -1.0f@};
  1768. task->cl_arg = &array;
  1769. task->cl_arg_size = sizeof(array);
  1770. task->callback_func = callback_func;
  1771. task->callback_arg = 0x42;
  1772. /* @b{starpu_task_submit will be a blocking call} */
  1773. task->synchronous = 1;
  1774. /* @b{submit the task to StarPU} */
  1775. starpu_task_submit(task);
  1776. /* @b{terminate StarPU} */
  1777. starpu_shutdown();
  1778. return 0;
  1779. @}
  1780. @end smallexample
  1781. @end cartouche
  1782. Before submitting any tasks to StarPU, @code{starpu_init} must be called. The
  1783. @code{NULL} argument specifies that we use default configuration. Tasks cannot
  1784. be submitted after the termination of StarPU by a call to
  1785. @code{starpu_shutdown}.
  1786. In the example above, a task structure is allocated by a call to
  1787. @code{starpu_task_create}. This function only allocates and fills the
  1788. corresponding structure with the default settings (@pxref{starpu_task_create}),
  1789. but it does not submit the task to StarPU.
  1790. @c not really clear ;)
  1791. The @code{cl} field is a pointer to the codelet which the task will
  1792. execute: in other words, the codelet structure describes which computational
  1793. kernel should be offloaded on the different architectures, and the task
  1794. structure is a wrapper containing a codelet and the piece of data on which the
  1795. codelet should operate.
  1796. The optional @code{cl_arg} field is a pointer to a buffer (of size
  1797. @code{cl_arg_size}) with some parameters for the kernel
  1798. described by the codelet. For instance, if a codelet implements a computational
  1799. kernel that multiplies its input vector by a constant, the constant could be
  1800. specified by the means of this buffer, instead of registering it.
  1801. Once a task has been executed, an optional callback function can be called.
  1802. While the computational kernel could be offloaded on various architectures, the
  1803. callback function is always executed on a CPU. The @code{callback_arg}
  1804. pointer is passed as an argument of the callback. The prototype of a callback
  1805. function must be:
  1806. @code{void (*callback_function)(void *);}
  1807. If the @code{synchronous} field is non-null, task submission will be
  1808. synchronous: the @code{starpu_task_submit} function will not return until the
  1809. task was executed. Note that the @code{starpu_shutdown} method does not
  1810. guarantee that asynchronous tasks have been executed before it returns.
  1811. @node Execution of Hello World
  1812. @subsection Execution of Hello World
  1813. @smallexample
  1814. % make helloWorld
  1815. cc $(pkg-config --cflags libstarpu) $(pkg-config --libs libstarpu) helloWorld.c -o helloWorld
  1816. % ./helloWorld
  1817. Hello world (array = @{1.000000, -1.000000@} )
  1818. Callback function (arg 42)
  1819. @end smallexample
  1820. @node Scaling a Vector
  1821. @section Manipulating Data: Scaling a Vector
  1822. The previous example has shown how to submit tasks. In this section,
  1823. we show how StarPU tasks can manipulate data. The full source code for
  1824. this example is given in @ref{Full source code for the 'Scaling a Vector' example}.
  1825. @menu
  1826. * Source code of Vector Scaling::
  1827. * Execution of Vector Scaling::
  1828. @end menu
  1829. @node Source code of Vector Scaling
  1830. @subsection Source code of Vector Scaling
  1831. Programmers can describe the data layout of their application so that StarPU is
  1832. responsible for enforcing data coherency and availability across the machine.
  1833. Instead of handling complex (and non-portable) mechanisms to perform data
  1834. movements, programmers only declare which piece of data is accessed and/or
  1835. modified by a task, and StarPU makes sure that when a computational kernel
  1836. starts somewhere (e.g. on a GPU), its data are available locally.
  1837. Before submitting those tasks, the programmer first needs to declare the
  1838. different pieces of data to StarPU using the @code{starpu_*_data_register}
  1839. functions. To ease the development of applications for StarPU, it is possible
  1840. to describe multiple types of data layout. A type of data layout is called an
  1841. @b{interface}. By default, there are different interfaces available in StarPU:
  1842. here we will consider the @b{vector interface}.
  1843. The following lines show how to declare an array of @code{NX} elements of type
  1844. @code{float} using the vector interface:
  1845. @cartouche
  1846. @smallexample
  1847. float vector[NX];
  1848. starpu_data_handle vector_handle;
  1849. starpu_vector_data_register(&vector_handle, 0, (uintptr_t)vector, NX,
  1850. sizeof(vector[0]));
  1851. @end smallexample
  1852. @end cartouche
  1853. The first argument, called the @b{data handle}, is an opaque pointer which
  1854. designates the array in StarPU. This is also the structure which is used to
  1855. describe which data is used by a task. The second argument is the node number
  1856. where the data currently resides. Here it is 0 since the @code{vector} array is in
  1857. the main memory. Then comes the pointer @code{vector} where the data can be found,
  1858. the number of elements in the vector and the size of each element.
  1859. It is possible to construct a StarPU task that will manipulate the
  1860. vector and a constant factor.
  1861. @cartouche
  1862. @smallexample
  1863. float factor = 3.14;
  1864. struct starpu_task *task = starpu_task_create();
  1865. task->cl = &cl; /* @b{Pointer to the codelet defined below} */
  1866. task->buffers[0].handle = vector_handle; /* @b{First parameter of the codelet} */
  1867. task->buffers[0].mode = STARPU_RW;
  1868. task->cl_arg = &factor;
  1869. task->cl_arg_size = sizeof(factor);
  1870. task->synchronous = 1;
  1871. starpu_task_submit(task);
  1872. @end smallexample
  1873. @end cartouche
  1874. Since the factor is a mere float value parameter, it does not need a preliminary registration, and
  1875. can just be passed through the @code{cl_arg} pointer like in the previous
  1876. example. The vector parameter is described by its handle.
  1877. There are two fields in each element of the @code{buffers} array.
  1878. @code{handle} is the handle of the data, and @code{mode} specifies how the
  1879. kernel will access the data (@code{STARPU_R} for read-only, @code{STARPU_W} for
  1880. write-only and @code{STARPU_RW} for read and write access).
  1881. The definition of the codelet can be written as follows:
  1882. @cartouche
  1883. @smallexample
  1884. void scal_cpu_func(void *buffers[], void *cl_arg)
  1885. @{
  1886. unsigned i;
  1887. float *factor = cl_arg;
  1888. /* length of the vector */
  1889. unsigned n = STARPU_GET_VECTOR_NX(buffers[0]);
  1890. /* local copy of the vector pointer */
  1891. float *val = (float *)STARPU_GET_VECTOR_PTR(buffers[0]);
  1892. for (i = 0; i < n; i++)
  1893. val[i] *= *factor;
  1894. @}
  1895. starpu_codelet cl = @{
  1896. .where = STARPU_CPU,
  1897. .cpu_func = scal_cpu_func,
  1898. .nbuffers = 1
  1899. @};
  1900. @end smallexample
  1901. @end cartouche
  1902. The second argument of the @code{scal_cpu_func} function contains a pointer to the
  1903. parameters of the codelet (given in @code{task->cl_arg}), so that we read the
  1904. constant factor from this pointer. The first argument is an array that gives
  1905. a description of all the buffers passed in the @code{task->buffers}@ array. The
  1906. size of this array is given by the @code{nbuffers} field of the codelet
  1907. structure. For the sake of generality, this array contains pointers to the
  1908. different interfaces describing each buffer. In the case of the @b{vector
  1909. interface}, the location of the vector (resp. its length) is accessible in the
  1910. @code{ptr} (resp. @code{nx}) of this array. Since the vector is accessed in a
  1911. read-write fashion, any modification will automatically affect future accesses
  1912. to this vector made by other tasks.
  1913. @node Execution of Vector Scaling
  1914. @subsection Execution of Vector Scaling
  1915. @smallexample
  1916. % make vector
  1917. cc $(pkg-config --cflags libstarpu) $(pkg-config --libs libstarpu) vector.c -o vector
  1918. % ./vector
  1919. 0.000000 3.000000 6.000000 9.000000 12.000000
  1920. @end smallexample
  1921. @node Vector Scaling on an Hybrid CPU/GPU Machine
  1922. @section Vector Scaling on an Hybrid CPU/GPU Machine
  1923. Contrary to the previous examples, the task submitted in this example may not
  1924. only be executed by the CPUs, but also by a CUDA device.
  1925. @menu
  1926. * Definition of the CUDA Codelet::
  1927. * Definition of the OpenCL Codelet::
  1928. * Definition of the Main Code::
  1929. * Compilation and execution of Hybrid Vector Scaling::
  1930. @end menu
  1931. @node Definition of the CUDA Codelet
  1932. @subsection Definition of the CUDA Codelet
  1933. The CUDA implementation can be written as follows. It needs to be
  1934. compiled with a CUDA compiler such as nvcc, the NVIDIA CUDA compiler
  1935. driver.
  1936. @cartouche
  1937. @smallexample
  1938. #include <starpu.h>
  1939. static __global__ void vector_mult_cuda(float *val, unsigned n,
  1940. float factor)
  1941. @{
  1942. unsigned i;
  1943. for(i = 0 ; i < n ; i++)
  1944. val[i] *= factor;
  1945. @}
  1946. extern "C" void scal_cuda_func(void *buffers[], void *_args)
  1947. @{
  1948. float *factor = (float *)_args;
  1949. /* length of the vector */
  1950. unsigned n = STARPU_GET_VECTOR_NX(buffers[0]);
  1951. /* local copy of the vector pointer */
  1952. float *val = (float *)STARPU_GET_VECTOR_PTR(buffers[0]);
  1953. @i{ vector_mult_cuda<<<1,1>>>(val, n, *factor);}
  1954. @i{ cudaThreadSynchronize();}
  1955. @}
  1956. @end smallexample
  1957. @end cartouche
  1958. @node Definition of the OpenCL Codelet
  1959. @subsection Definition of the OpenCL Codelet
  1960. The OpenCL implementation can be written as follows. StarPU provides
  1961. tools to compile a OpenCL codelet stored in a file.
  1962. @cartouche
  1963. @smallexample
  1964. __kernel void vector_mult_opencl(__global float* val, int nx, float factor)
  1965. @{
  1966. const int i = get_global_id(0);
  1967. if (i < nx) @{
  1968. val[i] *= factor;
  1969. @}
  1970. @}
  1971. @end smallexample
  1972. @end cartouche
  1973. @cartouche
  1974. @smallexample
  1975. #include <starpu.h>
  1976. @i{#include <starpu_opencl.h>}
  1977. @i{extern struct starpu_opencl_program programs;}
  1978. void scal_opencl_func(void *buffers[], void *_args)
  1979. @{
  1980. float *factor = _args;
  1981. @i{ int id, devid, err;}
  1982. @i{ cl_kernel kernel;}
  1983. @i{ cl_command_queue queue;}
  1984. /* length of the vector */
  1985. unsigned n = STARPU_GET_VECTOR_NX(buffers[0]);
  1986. /* local copy of the vector pointer */
  1987. float *val = (float *)STARPU_GET_VECTOR_PTR(buffers[0]);
  1988. @i{ id = starpu_worker_get_id();}
  1989. @i{ devid = starpu_worker_get_devid(id);}
  1990. @i{ err = starpu_opencl_load_kernel(&kernel, &queue, &programs,}
  1991. @i{ "vector_mult_opencl", devid); /* @b{Name of the codelet defined above} */}
  1992. @i{ if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);}
  1993. @i{ err = 0;}
  1994. @i{ err = clSetKernelArg(kernel, 0, sizeof(cl_mem), &val);}
  1995. @i{ err = clSetKernelArg(kernel, 1, sizeof(n), &n);}
  1996. @i{ err |= clSetKernelArg(kernel, 2, sizeof(*factor), factor);}
  1997. @i{ if (err) STARPU_OPENCL_REPORT_ERROR(err);}
  1998. @i{ @{}
  1999. @i{ size_t global=1;}
  2000. @i{ size_t local=1;}
  2001. @i{ err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &global, &local, 0, NULL, NULL);}
  2002. @i{ if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);}
  2003. @i{ @}}
  2004. @i{ clFinish(queue);}
  2005. @i{ starpu_opencl_release_kernel(kernel);}
  2006. @}
  2007. @end smallexample
  2008. @end cartouche
  2009. @node Definition of the Main Code
  2010. @subsection Definition of the Main Code
  2011. The CPU implementation is the same as in the previous section.
  2012. Here is the source of the main application. You can notice the value of the
  2013. field @code{where} for the codelet. We specify
  2014. @code{STARPU_CPU|STARPU_CUDA|STARPU_OPENCL} to indicate to StarPU that the codelet
  2015. can be executed either on a CPU or on a CUDA or an OpenCL device.
  2016. @cartouche
  2017. @smallexample
  2018. #include <starpu.h>
  2019. #define NX 2048
  2020. extern void scal_cuda_func(void *buffers[], void *_args);
  2021. extern void scal_cpu_func(void *buffers[], void *_args);
  2022. extern void scal_opencl_func(void *buffers[], void *_args);
  2023. /* @b{Definition of the codelet} */
  2024. static starpu_codelet cl = @{
  2025. .where = STARPU_CPU|STARPU_CUDA|STARPU_OPENCL; /* @b{It can be executed on a CPU,} */
  2026. /* @b{on a CUDA device, or on an OpenCL device} */
  2027. .cuda_func = scal_cuda_func;
  2028. .cpu_func = scal_cpu_func;
  2029. .opencl_func = scal_opencl_func;
  2030. .nbuffers = 1;
  2031. @}
  2032. #ifdef STARPU_USE_OPENCL
  2033. /* @b{The compiled version of the OpenCL program} */
  2034. struct starpu_opencl_program programs;
  2035. #endif
  2036. int main(int argc, char **argv)
  2037. @{
  2038. float *vector;
  2039. int i, ret;
  2040. float factor=3.0;
  2041. struct starpu_task *task;
  2042. starpu_data_handle vector_handle;
  2043. starpu_init(NULL); /* @b{Initialising StarPU} */
  2044. #ifdef STARPU_USE_OPENCL
  2045. starpu_opencl_load_opencl_from_file("examples/basic_examples/vector_scal_opencl_codelet.cl",
  2046. &programs);
  2047. #endif
  2048. vector = malloc(NX*sizeof(vector[0]));
  2049. assert(vector);
  2050. for(i=0 ; i<NX ; i++) vector[i] = i;
  2051. @end smallexample
  2052. @end cartouche
  2053. @cartouche
  2054. @smallexample
  2055. /* @b{Registering data within StarPU} */
  2056. starpu_vector_data_register(&vector_handle, 0, (uintptr_t)vector,
  2057. NX, sizeof(vector[0]));
  2058. /* @b{Definition of the task} */
  2059. task = starpu_task_create();
  2060. task->cl = &cl;
  2061. task->buffers[0].handle = vector_handle;
  2062. task->buffers[0].mode = STARPU_RW;
  2063. task->cl_arg = &factor;
  2064. task->cl_arg_size = sizeof(factor);
  2065. @end smallexample
  2066. @end cartouche
  2067. @cartouche
  2068. @smallexample
  2069. /* @b{Submitting the task} */
  2070. ret = starpu_task_submit(task);
  2071. if (ret == -ENODEV) @{
  2072. fprintf(stderr, "No worker may execute this task\n");
  2073. return 1;
  2074. @}
  2075. /* @b{Waiting for its termination} */
  2076. starpu_task_wait_for_all();
  2077. /* @b{Update the vector in RAM} */
  2078. starpu_data_sync_with_mem(vector_handle, STARPU_R);
  2079. @end smallexample
  2080. @end cartouche
  2081. @cartouche
  2082. @smallexample
  2083. /* @b{Access the data} */
  2084. for(i=0 ; i<NX; i++) @{
  2085. fprintf(stderr, "%f ", vector[i]);
  2086. @}
  2087. fprintf(stderr, "\n");
  2088. /* @b{Release the data and shutdown StarPU} */
  2089. starpu_data_release_from_mem(vector_handle);
  2090. starpu_shutdown();
  2091. return 0;
  2092. @}
  2093. @end smallexample
  2094. @end cartouche
  2095. @node Compilation and execution of Hybrid Vector Scaling
  2096. @subsection Compilation and execution of Hybrid Vector Scaling
  2097. The Makefile given at the beginning of the section must be extended to
  2098. give the rules to compile the CUDA source code.
  2099. @cartouche
  2100. @smallexample
  2101. CFLAGS += $(shell pkg-config --cflags libstarpu)
  2102. LDFLAGS += $(shell pkg-config --libs libstarpu)
  2103. CC = gcc
  2104. vector: vector.o vector_cpu.o vector_cuda.o
  2105. %.o: %.cu
  2106. nvcc $(CFLAGS) $< -c $@
  2107. clean:
  2108. rm -f vector *.o
  2109. @end smallexample
  2110. @end cartouche
  2111. @smallexample
  2112. % make
  2113. @end smallexample
  2114. and to execute it, with the default configuration:
  2115. @smallexample
  2116. % ./vector
  2117. 0.000000 3.000000 6.000000 9.000000 12.000000
  2118. @end smallexample
  2119. or for example, by disabling CPU devices:
  2120. @smallexample
  2121. % STARPU_NCPUS=0 ./vector
  2122. 0.000000 3.000000 6.000000 9.000000 12.000000
  2123. @end smallexample
  2124. or by disabling CUDA devices:
  2125. @smallexample
  2126. % STARPU_NCUDA=0 ./vector
  2127. 0.000000 3.000000 6.000000 9.000000 12.000000
  2128. @end smallexample
  2129. @c TODO: Add performance model example (and update basic_examples)
  2130. @c ---------------------------------------------------------------------
  2131. @c Advanced Topics
  2132. @c ---------------------------------------------------------------------
  2133. @node Advanced Topics
  2134. @chapter Advanced Topics
  2135. @menu
  2136. * Defining a new data interface::
  2137. * Defining a new scheduling policy::
  2138. @end menu
  2139. @node Defining a new data interface
  2140. @section Defining a new data interface
  2141. @menu
  2142. * struct starpu_data_interface_ops_t:: Per-interface methods
  2143. * struct starpu_data_copy_methods:: Per-interface data transfer methods
  2144. * An example of data interface:: An example of data interface
  2145. @end menu
  2146. @c void *starpu_data_get_interface_on_node(starpu_data_handle handle, unsigned memory_node); TODO
  2147. @node struct starpu_data_interface_ops_t
  2148. @subsection @code{struct starpu_data_interface_ops_t} -- Per-interface methods
  2149. @table @asis
  2150. @item @emph{Description}:
  2151. TODO describe all the different fields
  2152. @end table
  2153. @node struct starpu_data_copy_methods
  2154. @subsection @code{struct starpu_data_copy_methods} -- Per-interface data transfer methods
  2155. @table @asis
  2156. @item @emph{Description}:
  2157. TODO describe all the different fields
  2158. @end table
  2159. @node An example of data interface
  2160. @subsection An example of data interface
  2161. @table @asis
  2162. TODO
  2163. @end table
  2164. @node Defining a new scheduling policy
  2165. @section Defining a new scheduling policy
  2166. TODO
  2167. @c ---------------------------------------------------------------------
  2168. @c Appendices
  2169. @c ---------------------------------------------------------------------
  2170. @c ---------------------------------------------------------------------
  2171. @c Full source code for the 'Scaling a Vector' example
  2172. @c ---------------------------------------------------------------------
  2173. @node Full source code for the 'Scaling a Vector' example
  2174. @appendix Full source code for the 'Scaling a Vector' example
  2175. @menu
  2176. * Main application::
  2177. * CPU Codelet::
  2178. * CUDA Codelet::
  2179. * OpenCL Codelet::
  2180. @end menu
  2181. @node Main application
  2182. @section Main application
  2183. @smallexample
  2184. @include vector_scal_c.texi
  2185. @end smallexample
  2186. @node CPU Codelet
  2187. @section CPU Codelet
  2188. @smallexample
  2189. @include vector_scal_cpu.texi
  2190. @end smallexample
  2191. @node CUDA Codelet
  2192. @section CUDA Codelet
  2193. @smallexample
  2194. @include vector_scal_cuda.texi
  2195. @end smallexample
  2196. @node OpenCL Codelet
  2197. @section OpenCL Codelet
  2198. @menu
  2199. * Invoking the kernel::
  2200. * Source of the kernel::
  2201. @end menu
  2202. @node Invoking the kernel
  2203. @subsection Invoking the kernel
  2204. @smallexample
  2205. @include vector_scal_opencl.texi
  2206. @end smallexample
  2207. @node Source of the kernel
  2208. @subsection Source of the kernel
  2209. @smallexample
  2210. @include vector_scal_opencl_codelet.texi
  2211. @end smallexample
  2212. @bye