starpu.texi 93 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717
  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. * Codelets and Tasks:: Methods to construct tasks
  609. * Explicit Dependencies:: Explicit Dependencies
  610. * Implicit Data Dependencies:: Implicit Data Dependencies
  611. * Profiling API:: Profiling API
  612. * CUDA extensions:: CUDA extensions
  613. * OpenCL extensions:: OpenCL extensions
  614. * Cell extensions:: Cell extensions
  615. * Miscellaneous helpers::
  616. @end menu
  617. @node Initialization and Termination
  618. @section Initialization and Termination
  619. @menu
  620. * starpu_init:: Initialize StarPU
  621. * struct starpu_conf:: StarPU runtime configuration
  622. * starpu_shutdown:: Terminate StarPU
  623. @end menu
  624. @node starpu_init
  625. @subsection @code{starpu_init} -- Initialize StarPU
  626. @table @asis
  627. @item @emph{Description}:
  628. This is StarPU initialization method, which must be called prior to any other
  629. StarPU call. It is possible to specify StarPU's configuration (e.g. scheduling
  630. policy, number of cores, ...) by passing a non-null argument. Default
  631. configuration is used if the passed argument is @code{NULL}.
  632. @item @emph{Return value}:
  633. Upon successful completion, this function returns 0. Otherwise, @code{-ENODEV}
  634. indicates that no worker was available (so that StarPU was not initialized).
  635. @item @emph{Prototype}:
  636. @code{int starpu_init(struct starpu_conf *conf);}
  637. @end table
  638. @node struct starpu_conf
  639. @subsection @code{struct starpu_conf} -- StarPU runtime configuration
  640. @table @asis
  641. @item @emph{Description}:
  642. This structure is passed to the @code{starpu_init} function in order
  643. to configure StarPU.
  644. When the default value is used, StarPU automatically selects the number
  645. of processing units and takes the default scheduling policy. This parameter
  646. overwrites the equivalent environment variables.
  647. @item @emph{Fields}:
  648. @table @asis
  649. @item @code{sched_policy_name} (default = NULL):
  650. This is the name of the scheduling policy. This can also be specified with the
  651. @code{STARPU_SCHED} environment variable.
  652. @item @code{sched_policy} (default = NULL):
  653. This is the definition of the scheduling policy. This field is ignored
  654. if @code{sched_policy_name} is set.
  655. @item @code{ncpus} (default = -1):
  656. This is the maximum number of CPU cores that StarPU can use. This can also be
  657. specified with the @code{STARPU_NCPUS} environment variable.
  658. @item @code{ncuda} (default = -1):
  659. This is the maximum number of CUDA devices that StarPU can use. This can also be
  660. specified with the @code{STARPU_NCUDA} environment variable.
  661. @item @code{nopencl} (default = -1):
  662. This is the maximum number of OpenCL devices that StarPU can use. This can also be
  663. specified with the @code{STARPU_NOPENCL} environment variable.
  664. @item @code{nspus} (default = -1):
  665. This is the maximum number of Cell SPUs that StarPU can use. This can also be
  666. specified with the @code{STARPU_NGORDON} environment variable.
  667. @item @code{use_explicit_workers_bindid} (default = 0)
  668. If this flag is set, the @code{workers_bindid} array indicates where the
  669. different workers are bound, otherwise StarPU automatically selects where to
  670. bind the different workers unless the @code{STARPU_WORKERS_CPUID} environment
  671. variable is set. The @code{STARPU_WORKERS_CPUID} environment variable is
  672. ignored if the @code{use_explicit_workers_bindid} flag is set.
  673. @item @code{workers_bindid[STARPU_NMAXWORKERS]}
  674. If the @code{use_explicit_workers_bindid} flag is set, this array indicates
  675. where to bind the different workers. The i-th entry of the
  676. @code{workers_bindid} indicates the logical identifier of the processor which
  677. should execute the i-th worker. Note that the logical ordering of the CPUs is
  678. either determined by the OS, or provided by the @code{hwloc} library in case it
  679. is available.
  680. When this flag is set, the @ref{STARPU_WORKERS_CPUID} environment variable is
  681. ignored.
  682. @item @code{use_explicit_workers_cuda_gpuid} (default = 0)
  683. If this flag is set, the CUDA workers will be attached to the CUDA devices
  684. specified in the @code{workers_cuda_gpuid} array. Otherwise, StarPU affects the
  685. CUDA devices in a round-robin fashion.
  686. When this flag is set, the @ref{STARPU_WORKERS_CUDAID} environment variable is
  687. ignored.
  688. @item @code{workers_cuda_gpuid[STARPU_NMAXWORKERS]}
  689. If the @code{use_explicit_workers_cuda_gpuid} flag is set, this array contains
  690. the logical identifiers of the CUDA devices (as used by @code{cudaGetDevice}).
  691. @item @code{use_explicit_workers_opencl_gpuid} (default = 0)
  692. If this flag is set, the OpenCL workers will be attached to the OpenCL devices
  693. specified in the @code{workers_opencl_gpuid} array. Otherwise, StarPU affects the
  694. OpenCL devices in a round-robin fashion.
  695. @item @code{workers_opencl_gpuid[STARPU_NMAXWORKERS]}:
  696. @item @code{calibrate} (default = 0):
  697. If this flag is set, StarPU will calibrate the performance models when
  698. executing tasks. This can also be specified with the @code{STARPU_CALIBRATE}
  699. environment variable.
  700. @end table
  701. @end table
  702. @node starpu_shutdown
  703. @subsection @code{starpu_shutdown} -- Terminate StarPU
  704. @table @asis
  705. @item @emph{Description}:
  706. This is StarPU termination method. It must be called at the end of the
  707. application: statistics and other post-mortem debugging information are not
  708. guaranteed to be available until this method has been called.
  709. @item @emph{Prototype}:
  710. @code{void starpu_shutdown(void);}
  711. @end table
  712. @node Workers' Properties
  713. @section Workers' Properties
  714. @menu
  715. * starpu_worker_get_count:: Get the number of processing units
  716. * starpu_cpu_worker_get_count:: Get the number of CPU controlled by StarPU
  717. * starpu_cuda_worker_get_count:: Get the number of CUDA devices controlled by StarPU
  718. * starpu_opencl_worker_get_count:: Get the number of OpenCL devices controlled by StarPU
  719. * starpu_spu_worker_get_count:: Get the number of Cell SPUs controlled by StarPU
  720. * starpu_worker_get_id:: Get the identifier of the current worker
  721. * starpu_worker_get_devid:: Get the device identifier of a worker
  722. * starpu_worker_get_type:: Get the type of processing unit associated to a worker
  723. * starpu_worker_get_name:: Get the name of a worker
  724. * starpu_worker_get_memory_node:: Get the memory node of a worker
  725. @end menu
  726. @node starpu_worker_get_count
  727. @subsection @code{starpu_worker_get_count} -- Get the number of processing units
  728. @table @asis
  729. @item @emph{Description}:
  730. This function returns the number of workers (i.e. processing units executing
  731. StarPU tasks). The returned value should be at most @code{STARPU_NMAXWORKERS}.
  732. @item @emph{Prototype}:
  733. @code{unsigned starpu_worker_get_count(void);}
  734. @end table
  735. @node starpu_cpu_worker_get_count
  736. @subsection @code{starpu_cpu_worker_get_count} -- Get the number of CPU controlled by StarPU
  737. @table @asis
  738. @item @emph{Description}:
  739. This function returns the number of CPUs controlled by StarPU. The returned
  740. value should be at most @code{STARPU_NMAXCPUS}.
  741. @item @emph{Prototype}:
  742. @code{unsigned starpu_cpu_worker_get_count(void);}
  743. @end table
  744. @node starpu_cuda_worker_get_count
  745. @subsection @code{starpu_cuda_worker_get_count} -- Get the number of CUDA devices controlled by StarPU
  746. @table @asis
  747. @item @emph{Description}:
  748. This function returns the number of CUDA devices controlled by StarPU. The returned
  749. value should be at most @code{STARPU_MAXCUDADEVS}.
  750. @item @emph{Prototype}:
  751. @code{unsigned starpu_cuda_worker_get_count(void);}
  752. @end table
  753. @node starpu_opencl_worker_get_count
  754. @subsection @code{starpu_opencl_worker_get_count} -- Get the number of OpenCL devices controlled by StarPU
  755. @table @asis
  756. @item @emph{Description}:
  757. This function returns the number of OpenCL devices controlled by StarPU. The returned
  758. value should be at most @code{STARPU_MAXOPENCLDEVS}.
  759. @item @emph{Prototype}:
  760. @code{unsigned starpu_opencl_worker_get_count(void);}
  761. @end table
  762. @node starpu_spu_worker_get_count
  763. @subsection @code{starpu_spu_worker_get_count} -- Get the number of Cell SPUs controlled by StarPU
  764. @table @asis
  765. @item @emph{Description}:
  766. This function returns the number of Cell SPUs controlled by StarPU.
  767. @item @emph{Prototype}:
  768. @code{unsigned starpu_opencl_worker_get_count(void);}
  769. @end table
  770. @node starpu_worker_get_id
  771. @subsection @code{starpu_worker_get_id} -- Get the identifier of the current worker
  772. @table @asis
  773. @item @emph{Description}:
  774. This function returns the identifier of the worker associated to the calling
  775. thread. The returned value is either -1 if the current context is not a StarPU
  776. worker (i.e. when called from the application outside a task or a callback), or
  777. an integer between 0 and @code{starpu_worker_get_count() - 1}.
  778. @item @emph{Prototype}:
  779. @code{int starpu_worker_get_id(void);}
  780. @end table
  781. @node starpu_worker_get_devid
  782. @subsection @code{starpu_worker_get_devid} -- Get the device identifier of a worker
  783. @table @asis
  784. @item @emph{Description}:
  785. This functions returns the device id of the worker associated to an identifier
  786. (as returned by the @code{starpu_worker_get_id} function). In the case of a
  787. CUDA worker, this device identifier is the logical device identifier exposed by
  788. CUDA (used by the @code{cudaGetDevice} function for instance). The device
  789. identifier of a CPU worker is the logical identifier of the core on which the
  790. worker was bound; this identifier is either provided by the OS or by the
  791. @code{hwloc} library in case it is available.
  792. @item @emph{Prototype}:
  793. @code{int starpu_worker_get_devid(int id);}
  794. @end table
  795. @node starpu_worker_get_type
  796. @subsection @code{starpu_worker_get_type} -- Get the type of processing unit associated to a worker
  797. @table @asis
  798. @item @emph{Description}:
  799. This function returns the type of worker associated to an identifier (as
  800. returned by the @code{starpu_worker_get_id} function). The returned value
  801. indicates the architecture of the worker: @code{STARPU_CPU_WORKER} for a CPU
  802. core, @code{STARPU_CUDA_WORKER} for a CUDA device,
  803. @code{STARPU_OPENCL_WORKER} for a OpenCL device, and
  804. @code{STARPU_GORDON_WORKER} for a Cell SPU. The value returned for an invalid
  805. identifier is unspecified.
  806. @item @emph{Prototype}:
  807. @code{enum starpu_archtype starpu_worker_get_type(int id);}
  808. @end table
  809. @node starpu_worker_get_name
  810. @subsection @code{starpu_worker_get_name} -- Get the name of a worker
  811. @table @asis
  812. @item @emph{Description}:
  813. StarPU associates a unique human readable string to each processing unit. This
  814. function copies at most the @code{maxlen} first bytes of the unique string
  815. associated to a worker identified by its identifier @code{id} into the
  816. @code{dst} buffer. The caller is responsible for ensuring that the @code{dst}
  817. is a valid pointer to a buffer of @code{maxlen} bytes at least. Calling this
  818. function on an invalid identifier results in an unspecified behaviour.
  819. @item @emph{Prototype}:
  820. @code{void starpu_worker_get_name(int id, char *dst, size_t maxlen);}
  821. @end table
  822. @node starpu_worker_get_memory_node
  823. @subsection @code{starpu_worker_get_memory_node} -- Get the memory node of a worker
  824. @table @asis
  825. @item @emph{Description}:
  826. This function returns the identifier of the memory node associated to the
  827. worker identified by @code{workerid}.
  828. @item @emph{Prototype}:
  829. @code{unsigned starpu_worker_get_memory_node(unsigned workerid);}
  830. @end table
  831. @node Data Library
  832. @section Data Library
  833. This section describes the data management facilities provided by StarPU.
  834. We show how to use existing data interfaces in @ref{Data Interfaces}, but developers can
  835. design their own data interfaces if required.
  836. @menu
  837. * starpu_access_mode:: starpu_access_mode
  838. * unsigned memory_node:: Memory node
  839. * starpu_data_handle:: StarPU opaque data handle
  840. * void *interface:: StarPU data interface
  841. * starpu_data_register:: Register a piece of data to StarPU
  842. * starpu_data_unregister:: Unregister a piece of data from StarPU
  843. @end menu
  844. @node starpu_access_mode
  845. @subsection @code{starpu_access_mode} -- Data access mode
  846. This datatype describes a data access mode. The different available modes are:
  847. @table @asis
  848. @table @asis
  849. @item @code{STARPU_R} read-only mode.
  850. @item @code{STARPU_W} write-only mode.
  851. @item @code{STARPU_RW} read-write mode. This is equivalent to @code{STARPU_R|STARPU_W}.
  852. @item @code{STARPU_SCRATCH} scratch memory. A temporary buffer is allocated for the task, but StarPU does not enforce data consistency.
  853. @end table
  854. @end table
  855. @node unsigned memory_node
  856. @subsection @code{unsigned memory_node} -- Memory node
  857. @table @asis
  858. @item @emph{Description}:
  859. Every worker is associated to a memory node which is a logical abstraction of
  860. the address space from which the processing unit gets its data. For instance,
  861. the memory node associated to the different CPU workers represents main memory
  862. (RAM), the memory node associated to a GPU is DRAM embedded on the device.
  863. Every memory node is identified by a logical index which is accessible from the
  864. @code{starpu_worker_get_memory_node} function. When registering a piece of data
  865. to StarPU, the specified memory node indicates where the piece of data
  866. initially resides (we also call this memory node the home node of a piece of
  867. data).
  868. @end table
  869. @node starpu_data_handle
  870. @subsection @code{starpu_data_handle} -- StarPU opaque data handle
  871. @table @asis
  872. @item @emph{Description}:
  873. StarPU uses @code{starpu_data_handle} as an opaque handle to manage a piece of
  874. data. Once a piece of data has been registered to StarPU, it is associated to a
  875. @code{starpu_data_handle} which keeps track of the state of the piece of data
  876. over the entire machine, so that we can maintain data consistency and locate
  877. data replicates for instance.
  878. @end table
  879. @node void *interface
  880. @subsection @code{void *interface} -- StarPU data interface
  881. @table @asis
  882. @item @emph{Description}:
  883. Data management is done at a high-level in StarPU: rather than accessing a mere
  884. list of contiguous buffers, the tasks may manipulate data that are described by
  885. a high-level construct which we call data interface.
  886. An example of data interface is the "vector" interface which describes a
  887. contiguous data array on a spefic memory node. This interface is a simple
  888. structure containing the number of elements in the array, the size of the
  889. elements, and the address of the array in the appropriate address space (this
  890. address may be invalid if there is no valid copy of the array in the memory
  891. node). More informations on the data interfaces provided by StarPU are
  892. given in @ref{Data Interfaces}.
  893. When a piece of data managed by StarPU is used by a task, the task
  894. implementation is given a pointer to an interface describing a valid copy of
  895. the data that is accessible from the current processing unit.
  896. @end table
  897. @node starpu_data_register
  898. @subsection @code{starpu_data_register} -- Register a piece of data to StarPU
  899. @table @asis
  900. @item @emph{Description}:
  901. Register a piece of data into the handle located at the @code{handleptr}
  902. address. The @code{interface} buffer contains the initial description of the
  903. data in the home node. The @code{ops} argument is a pointer to a structure
  904. describing the different methods used to manipulate this type of interface. See
  905. @ref{struct starpu_data_interface_ops_t} for more details on this structure.
  906. If @code{home_node} is not a valid memory node, StarPU will automatically
  907. allocate the memory described by the interface the data handle is used for the
  908. first time in write-only mode. Once such data handle has been automatically
  909. allocated, it is possible to access it using any access mode.
  910. Note that StarPU supplies a set of predefined types of interface (eg. vector or
  911. matrix) which can be registered by the means of helper functions (eg.
  912. @code{starpu_vector_data_register} or @code{starpu_matrix_data_register}).
  913. @item @emph{Prototype}:
  914. @code{void starpu_data_register(starpu_data_handle *handleptr,
  915. uint32_t home_node,
  916. void *interface,
  917. struct starpu_data_interface_ops_t *ops);}
  918. @end table
  919. @node starpu_data_unregister
  920. @subsection @code{starpu_data_unregister} -- Unregister a piece of data from StarPU
  921. @table @asis
  922. @item @emph{Description}:
  923. This function unregisters a data handle from StarPU. If the data was
  924. automatically allocated by StarPU because the home node was not valid, all
  925. automatically allocated buffers are freed. Otherwise, a valid copy of the data
  926. is put back into the home node in the buffer that was initially registered.
  927. Using a data handle that has been unregistered from StarPU results in an
  928. undefined behaviour.
  929. @item @emph{Prototype}:
  930. @code{void starpu_data_unregister(starpu_data_handle handle);}
  931. @end table
  932. @c user interaction with the DSM
  933. @c void starpu_data_sync_with_mem(struct starpu_data_state_t *state);
  934. @c void starpu_notify_data_modification(struct starpu_data_state_t *state, uint32_t modifying_node);
  935. @c struct starpu_data_interface_ops_t *ops
  936. @node Data Interfaces
  937. @section Data Interfaces
  938. @menu
  939. * Variable Interface::
  940. * Vector Interface::
  941. * Matrix Interface::
  942. * BCSR Interface for Sparse Matrices (Blocked Compressed Sparse Row Representation)::
  943. * CSR Interface for Sparse Matrices (Compressed Sparse Row Representation)::
  944. * Block Interface::
  945. @end menu
  946. @node Variable Interface
  947. @subsection Variable Interface
  948. @table @asis
  949. @item @emph{Description}:
  950. @item @emph{Prototype}:
  951. @code{void starpu_variable_data_register(starpu_data_handle *handle,
  952. uint32_t home_node,
  953. uintptr_t ptr, size_t elemsize);}
  954. @item @emph{Example}:
  955. @cartouche
  956. @smallexample
  957. float var;
  958. starpu_data_handle var_handle;
  959. starpu_variable_data_register(&var_handle, 0, (uintptr_t)&var, sizeof(var));
  960. @end smallexample
  961. @end cartouche
  962. @end table
  963. @node Vector Interface
  964. @subsection Vector Interface
  965. @table @asis
  966. @item @emph{Description}:
  967. @item @emph{Prototype}:
  968. @code{void starpu_vector_data_register(starpu_data_handle *handle, uint32_t home_node,
  969. uintptr_t ptr, uint32_t nx, size_t elemsize);}
  970. @item @emph{Example}:
  971. @cartouche
  972. @smallexample
  973. float vector[NX];
  974. starpu_data_handle vector_handle;
  975. starpu_vector_data_register(&vector_handle, 0, (uintptr_t)vector, NX,
  976. sizeof(vector[0]));
  977. @end smallexample
  978. @end cartouche
  979. @end table
  980. @node Matrix Interface
  981. @subsection Matrix Interface
  982. @table @asis
  983. @item @emph{Description}:
  984. @item @emph{Prototype}:
  985. @code{void starpu_matrix_data_register(starpu_data_handle *handle, uint32_t home_node,
  986. uintptr_t ptr, uint32_t ld, uint32_t nx,
  987. uint32_t ny, size_t elemsize);}
  988. @item @emph{Example}:
  989. @cartouche
  990. @smallexample
  991. float *matrix;
  992. starpu_data_handle matrix_handle;
  993. matrix = (float*)malloc(width * height * sizeof(float));
  994. starpu_matrix_data_register(&matrix_handle, 0, (uintptr_t)matrix,
  995. width, width, height, sizeof(float));
  996. @end smallexample
  997. @end cartouche
  998. @end table
  999. @node BCSR Interface for Sparse Matrices (Blocked Compressed Sparse Row Representation)
  1000. @subsection BCSR Interface for Sparse Matrices (Blocked Compressed Sparse Row Representation)
  1001. @table @asis
  1002. @item @emph{Description}:
  1003. @item @emph{Prototype}:
  1004. @code{void starpu_bcsr_data_register(starpu_data_handle *handle, uint32_t home_node, uint32_t nnz, uint32_t nrow,
  1005. uintptr_t nzval, uint32_t *colind, uint32_t *rowptr, uint32_t firstentry, uint32_t r, uint32_t c, size_t elemsize);}
  1006. @item @emph{Example}:
  1007. @cartouche
  1008. @smallexample
  1009. @end smallexample
  1010. @end cartouche
  1011. @end table
  1012. @node CSR Interface for Sparse Matrices (Compressed Sparse Row Representation)
  1013. @subsection CSR Interface for Sparse Matrices (Compressed Sparse Row Representation)
  1014. @table @asis
  1015. @item @emph{Description}:
  1016. @item @emph{Prototype}:
  1017. @code{void starpu_csr_data_register(starpu_data_handle *handle, uint32_t home_node, uint32_t nnz, uint32_t nrow,
  1018. uintptr_t nzval, uint32_t *colind, uint32_t *rowptr, uint32_t firstentry, size_t elemsize);}
  1019. @item @emph{Example}:
  1020. @cartouche
  1021. @smallexample
  1022. @end smallexample
  1023. @end cartouche
  1024. @end table
  1025. @node Block Interface
  1026. @subsection Block Interface
  1027. @table @asis
  1028. @item @emph{Description}:
  1029. @item @emph{Prototype}:
  1030. @code{void starpu_block_data_register(starpu_data_handle *handle, uint32_t home_node,
  1031. uintptr_t ptr, uint32_t ldy, uint32_t ldz, uint32_t nx,
  1032. uint32_t ny, uint32_t nz, size_t elemsize);}
  1033. @item @emph{Example}:
  1034. @cartouche
  1035. @smallexample
  1036. float *block;
  1037. starpu_data_handle block_handle;
  1038. block = (float*)malloc(nx*ny*nz*sizeof(float));
  1039. starpu_block_data_register(&block_handle, 0, (uintptr_t)block,
  1040. nx, nx*ny, nx, ny, nz, sizeof(float));
  1041. @end smallexample
  1042. @end cartouche
  1043. @end table
  1044. @node Codelets and Tasks
  1045. @section Codelets and Tasks
  1046. @menu
  1047. * struct starpu_codelet:: StarPU codelet structure
  1048. * struct starpu_task:: StarPU task structure
  1049. * starpu_task_init:: Initialize a Task
  1050. * starpu_task_create:: Allocate and Initialize a Task
  1051. * starpu_task_deinit:: Release all the resources used by a Task
  1052. * starpu_task_destroy:: Destroy a dynamically allocated Task
  1053. * starpu_task_wait:: Wait for the termination of a Task
  1054. * starpu_task_submit:: Submit a Task
  1055. * starpu_task_wait_for_all:: Wait for the termination of all Tasks
  1056. @end menu
  1057. @node struct starpu_codelet
  1058. @subsection @code{struct starpu_codelet} -- StarPU codelet structure
  1059. @table @asis
  1060. @item @emph{Description}:
  1061. The codelet structure describes a kernel that is possibly implemented on
  1062. various targets.
  1063. @item @emph{Fields}:
  1064. @table @asis
  1065. @item @code{where}:
  1066. Indicates which types of processing units are able to execute the codelet.
  1067. @code{STARPU_CPU|STARPU_CUDA} for instance indicates that the codelet is
  1068. implemented for both CPU cores and CUDA devices while @code{STARPU_GORDON}
  1069. indicates that it is only available on Cell SPUs.
  1070. @item @code{cpu_func} (optional):
  1071. Is a function pointer to the CPU implementation of the codelet. Its prototype
  1072. must be: @code{void cpu_func(void *buffers[], void *cl_arg)}. The first
  1073. argument being the array of data managed by the data management library, and
  1074. the second argument is a pointer to the argument passed from the @code{cl_arg}
  1075. field of the @code{starpu_task} structure.
  1076. The @code{cpu_func} field is ignored if @code{STARPU_CPU} does not appear in
  1077. the @code{where} field, it must be non-null otherwise.
  1078. @item @code{cuda_func} (optional):
  1079. Is a function pointer to the CUDA implementation of the codelet. @emph{This
  1080. must be a host-function written in the CUDA runtime API}. Its prototype must
  1081. be: @code{void cuda_func(void *buffers[], void *cl_arg);}. The @code{cuda_func}
  1082. field is ignored if @code{STARPU_CUDA} does not appear in the @code{where}
  1083. field, it must be non-null otherwise.
  1084. @item @code{opencl_func} (optional):
  1085. Is a function pointer to the OpenCL implementation of the codelet. Its
  1086. prototype must be:
  1087. @code{void opencl_func(starpu_data_interface_t *descr, void *arg);}.
  1088. This pointer is ignored if @code{STARPU_OPENCL} does not appear in the
  1089. @code{where} field, it must be non-null otherwise.
  1090. @item @code{gordon_func} (optional):
  1091. This is the index of the Cell SPU implementation within the Gordon library.
  1092. See Gordon documentation for more details on how to register a kernel and
  1093. retrieve its index.
  1094. @item @code{nbuffers}:
  1095. Specifies the number of arguments taken by the codelet. These arguments are
  1096. managed by the DSM and are accessed from the @code{void *buffers[]}
  1097. array. The constant argument passed with the @code{cl_arg} field of the
  1098. @code{starpu_task} structure is not counted in this number. This value should
  1099. not be above @code{STARPU_NMAXBUFS}.
  1100. @item @code{model} (optional):
  1101. This is a pointer to the performance model associated to this codelet. This
  1102. optional field is ignored when set to @code{NULL}. TODO
  1103. @end table
  1104. @end table
  1105. @node struct starpu_task
  1106. @subsection @code{struct starpu_task} -- StarPU task structure
  1107. @table @asis
  1108. @item @emph{Description}:
  1109. The @code{starpu_task} structure describes a task that can be offloaded on the various
  1110. processing units managed by StarPU. It instantiates a codelet. It can either be
  1111. allocated dynamically with the @code{starpu_task_create} method, or declared
  1112. statically. In the latter case, the programmer has to zero the
  1113. @code{starpu_task} structure and to fill the different fields properly. The
  1114. indicated default values correspond to the configuration of a task allocated
  1115. with @code{starpu_task_create}.
  1116. @item @emph{Fields}:
  1117. @table @asis
  1118. @item @code{cl}:
  1119. Is a pointer to the corresponding @code{starpu_codelet} data structure. This
  1120. describes where the kernel should be executed, and supplies the appropriate
  1121. implementations. When set to @code{NULL}, no code is executed during the tasks,
  1122. such empty tasks can be useful for synchronization purposes.
  1123. @item @code{buffers}:
  1124. Is an array of @code{starpu_buffer_descr_t} structures. It describes the
  1125. different pieces of data accessed by the task, and how they should be accessed.
  1126. The @code{starpu_buffer_descr_t} structure is composed of two fields, the
  1127. @code{handle} field specifies the handle of the piece of data, and the
  1128. @code{mode} field is the required access mode (eg @code{STARPU_RW}). The number
  1129. of entries in this array must be specified in the @code{nbuffers} field of the
  1130. @code{starpu_codelet} structure, and should not excede @code{STARPU_NMAXBUFS}.
  1131. If unsufficient, this value can be set with the @code{--enable-maxbuffers}
  1132. option when configuring StarPU.
  1133. @item @code{cl_arg} (optional) (default = NULL):
  1134. This pointer is passed to the codelet through the second argument
  1135. of the codelet implementation (e.g. @code{cpu_func} or @code{cuda_func}).
  1136. In the specific case of the Cell processor, see the @code{cl_arg_size}
  1137. argument.
  1138. @item @code{cl_arg_size} (optional, Cell specific):
  1139. In the case of the Cell processor, the @code{cl_arg} pointer is not directly
  1140. given to the SPU function. A buffer of size @code{cl_arg_size} is allocated on
  1141. the SPU. This buffer is then filled with the @code{cl_arg_size} bytes starting
  1142. at address @code{cl_arg}. In this case, the argument given to the SPU codelet
  1143. is therefore not the @code{cl_arg} pointer, but the address of the buffer in
  1144. local store (LS) instead. This field is ignored for CPU, CUDA and OpenCL
  1145. codelets.
  1146. @item @code{callback_func} (optional) (default = @code{NULL}):
  1147. This is a function pointer of prototype @code{void (*f)(void *)} which
  1148. specifies a possible callback. If this pointer is non-null, the callback
  1149. function is executed @emph{on the host} after the execution of the task. The
  1150. callback is passed the value contained in the @code{callback_arg} field. No
  1151. callback is executed if the field is set to @code{NULL}.
  1152. @item @code{callback_arg} (optional) (default = @code{NULL}):
  1153. This is the pointer passed to the callback function. This field is ignored if
  1154. the @code{callback_func} is set to @code{NULL}.
  1155. @item @code{use_tag} (optional) (default = 0):
  1156. If set, this flag indicates that the task should be associated with the tag
  1157. contained in the @code{tag_id} field. Tag allow the application to synchronize
  1158. with the task and to express task dependencies easily.
  1159. @item @code{tag_id}:
  1160. This fields contains the tag associated to the task if the @code{use_tag} field
  1161. was set, it is ignored otherwise.
  1162. @item @code{synchronous}:
  1163. If this flag is set, the @code{starpu_task_submit} function is blocking and
  1164. returns only when the task has been executed (or if no worker is able to
  1165. process the task). Otherwise, @code{starpu_task_submit} returns immediately.
  1166. @item @code{priority} (optional) (default = @code{STARPU_DEFAULT_PRIO}):
  1167. This field indicates a level of priority for the task. This is an integer value
  1168. that must be set between @code{STARPU_MIN_PRIO} (for the least important
  1169. tasks) and @code{STARPU_MAX_PRIO} (for the most important tasks) included.
  1170. Default priority is @code{STARPU_DEFAULT_PRIO}. Scheduling strategies that
  1171. take priorities into account can use this parameter to take better scheduling
  1172. decisions, but the scheduling policy may also ignore it.
  1173. @item @code{execute_on_a_specific_worker} (default = 0):
  1174. If this flag is set, StarPU will bypass the scheduler and directly affect this
  1175. task to the worker specified by the @code{workerid} field.
  1176. @item @code{workerid} (optional):
  1177. If the @code{execute_on_a_specific_worker} field is set, this field indicates
  1178. which is the identifier of the worker that should process this task (as
  1179. returned by @code{starpu_worker_get_id}). This field is ignored if
  1180. @code{execute_on_a_specific_worker} field is set to 0.
  1181. @item @code{detach} (optional) (default = 1):
  1182. If this flag is set, it is not possible to synchronize with the task
  1183. by the means of @code{starpu_task_wait} later on. Internal data structures
  1184. are only guaranteed to be freed once @code{starpu_task_wait} is called if the
  1185. flag is not set.
  1186. @item @code{destroy} (optional) (default = 1):
  1187. If this flag is set, the task structure will automatically be freed, either
  1188. after the execution of the callback if the task is detached, or during
  1189. @code{starpu_task_wait} otherwise. If this flag is not set, dynamically
  1190. allocated data structures will not be freed until @code{starpu_task_destroy} is
  1191. called explicitly. Setting this flag for a statically allocated task structure
  1192. will result in undefined behaviour.
  1193. @end table
  1194. @end table
  1195. @node starpu_task_init
  1196. @subsection @code{starpu_task_init} -- Initialize a Task
  1197. @table @asis
  1198. @item @emph{Description}:
  1199. Initialize a task structure with default values. This function is implicitly
  1200. called by @code{starpu_task_create}. By default, tasks initialized with
  1201. @code{starpu_task_init} must be deinitialized explicitly with
  1202. @code{starpu_task_deinit}. Tasks can also be initialized statically, using the
  1203. constant @code{STARPU_TASK_INITIALIZER}.
  1204. @item @emph{Prototype}:
  1205. @code{void starpu_task_init(struct starpu_task *task);}
  1206. @end table
  1207. @node starpu_task_create
  1208. @subsection @code{starpu_task_create} -- Allocate and Initialize a Task
  1209. @table @asis
  1210. @item @emph{Description}:
  1211. Allocate a task structure and initialize it with default values. Tasks
  1212. allocated dynamically with @code{starpu_task_create} are automatically freed when the
  1213. task is terminated. If the destroy flag is explicitly unset, the resources used
  1214. by the task are freed by calling
  1215. @code{starpu_task_destroy}.
  1216. @item @emph{Prototype}:
  1217. @code{struct starpu_task *starpu_task_create(void);}
  1218. @end table
  1219. @node starpu_task_deinit
  1220. @subsection @code{starpu_task_deinit} -- Release all the resources used by a Task
  1221. @table @asis
  1222. @item @emph{Description}:
  1223. Release all the structures automatically allocated to execute the task. This is
  1224. called automatically by @code{starpu_task_destroy}, but the task structure itself is not
  1225. freed. This should be used for statically allocated tasks for instance.
  1226. @item @emph{Prototype}:
  1227. @code{void starpu_task_deinit(struct starpu_task *task);}
  1228. @end table
  1229. @node starpu_task_destroy
  1230. @subsection @code{starpu_task_destroy} -- Destroy a dynamically allocated Task
  1231. @table @asis
  1232. @item @emph{Description}:
  1233. Free the resource allocated during @code{starpu_task_create}. This function can be
  1234. called automatically after the execution of a task by setting the
  1235. @code{destroy} flag of the @code{starpu_task} structure (default behaviour).
  1236. Calling this function on a statically allocated task results in an undefined
  1237. behaviour.
  1238. @item @emph{Prototype}:
  1239. @code{void starpu_task_destroy(struct starpu_task *task);}
  1240. @end table
  1241. @node starpu_task_wait
  1242. @subsection @code{starpu_task_wait} -- Wait for the termination of a Task
  1243. @table @asis
  1244. @item @emph{Description}:
  1245. This function blocks until the task has been executed. It is not possible to
  1246. synchronize with a task more than once. It is not possible to wait for
  1247. synchronous or detached tasks.
  1248. @item @emph{Return value}:
  1249. Upon successful completion, this function returns 0. Otherwise, @code{-EINVAL}
  1250. indicates that the specified task was either synchronous or detached.
  1251. @item @emph{Prototype}:
  1252. @code{int starpu_task_wait(struct starpu_task *task);}
  1253. @end table
  1254. @node starpu_task_submit
  1255. @subsection @code{starpu_task_submit} -- Submit a Task
  1256. @table @asis
  1257. @item @emph{Description}:
  1258. This function submits a task to StarPU. Calling this function does
  1259. not mean that the task will be executed immediately as there can be data or task
  1260. (tag) dependencies that are not fulfilled yet: StarPU will take care of
  1261. scheduling this task with respect to such dependencies.
  1262. This function returns immediately if the @code{synchronous} field of the
  1263. @code{starpu_task} structure was set to 0, and block until the termination of
  1264. the task otherwise. It is also possible to synchronize the application with
  1265. asynchronous tasks by the means of tags, using the @code{starpu_tag_wait}
  1266. function for instance.
  1267. @item @emph{Return value}:
  1268. In case of success, this function returns 0, a return value of @code{-ENODEV}
  1269. means that there is no worker able to process this task (e.g. there is no GPU
  1270. available and this task is only implemented for CUDA devices).
  1271. @item @emph{Prototype}:
  1272. @code{int starpu_task_submit(struct starpu_task *task);}
  1273. @end table
  1274. @node starpu_task_wait_for_all
  1275. @subsection @code{starpu_task_wait_for_all} -- Wait for the termination of all Tasks
  1276. @table @asis
  1277. @item @emph{Description}:
  1278. This function blocks until all the tasks that were submitted are terminated.
  1279. @item @emph{Prototype}:
  1280. @code{void starpu_task_wait_for_all(void);}
  1281. @end table
  1282. @c Callbacks : what can we put in callbacks ?
  1283. @node Explicit Dependencies
  1284. @section Explicit Dependencies
  1285. @menu
  1286. * starpu_task_declare_deps_array:: starpu_task_declare_deps_array
  1287. * starpu_tag_t:: Task logical identifier
  1288. * starpu_tag_declare_deps:: Declare the Dependencies of a Tag
  1289. * starpu_tag_declare_deps_array:: Declare the Dependencies of a Tag
  1290. * starpu_tag_wait:: Block until a Tag is terminated
  1291. * starpu_tag_wait_array:: Block until a set of Tags is terminated
  1292. * starpu_tag_remove:: Destroy a Tag
  1293. * starpu_tag_notify_from_apps:: Feed a tag explicitly
  1294. @end menu
  1295. @node starpu_task_declare_deps_array
  1296. @subsection @code{starpu_task_declare_deps_array} -- Declare task dependencies
  1297. @table @asis
  1298. @item @emph{Description}:
  1299. Declare task dependencies between a @code{task} and an array of tasks of length
  1300. @code{ndeps}. This function must be called prior to the submission of the task,
  1301. but it may called after the submission or the execution of the tasks in the
  1302. array provided the tasks are still valid (ie. they were not automatically
  1303. destroyed). Calling this function on a task that was already submitted or with
  1304. an entry of @code{task_array} that is not a valid task anymore results in an
  1305. undefined behaviour. If @code{ndeps} is null, no dependency is added. It is
  1306. possible to call @code{starpu_task_declare_deps_array} multiple times on the
  1307. same task, in this case, the dependencies are added. It is possible to have
  1308. redundancy in the task dependencies.
  1309. @item @emph{Prototype}:
  1310. @code{void starpu_task_declare_deps_array(struct starpu_task *task, unsigned ndeps, struct starpu_task *task_array[]);}
  1311. @end table
  1312. @node starpu_tag_t
  1313. @subsection @code{starpu_tag_t} -- Task logical identifier
  1314. @table @asis
  1315. @item @emph{Description}:
  1316. It is possible to associate a task with a unique ``tag'' and to express
  1317. dependencies between tasks by the means of those tags. To do so, fill the
  1318. @code{tag_id} field of the @code{starpu_task} structure with a tag number (can
  1319. be arbitrary) and set the @code{use_tag} field to 1.
  1320. If @code{starpu_tag_declare_deps} is called with this tag number, the task will
  1321. not be started until the tasks which holds the declared dependency tags are
  1322. completed.
  1323. @end table
  1324. @node starpu_tag_declare_deps
  1325. @subsection @code{starpu_tag_declare_deps} -- Declare the Dependencies of a Tag
  1326. @table @asis
  1327. @item @emph{Description}:
  1328. Specify the dependencies of the task identified by tag @code{id}. The first
  1329. argument specifies the tag which is configured, the second argument gives the
  1330. number of tag(s) on which @code{id} depends. The following arguments are the
  1331. tags which have to be terminated to unlock the task.
  1332. This function must be called before the associated task is submitted to StarPU
  1333. with @code{starpu_task_submit}.
  1334. @item @emph{Remark}
  1335. Because of the variable arity of @code{starpu_tag_declare_deps}, note that the
  1336. last arguments @emph{must} be of type @code{starpu_tag_t}: constant values
  1337. typically need to be explicitly casted. Using the
  1338. @code{starpu_tag_declare_deps_array} function avoids this hazard.
  1339. @item @emph{Prototype}:
  1340. @code{void starpu_tag_declare_deps(starpu_tag_t id, unsigned ndeps, ...);}
  1341. @item @emph{Example}:
  1342. @cartouche
  1343. @example
  1344. /* Tag 0x1 depends on tags 0x32 and 0x52 */
  1345. starpu_tag_declare_deps((starpu_tag_t)0x1,
  1346. 2, (starpu_tag_t)0x32, (starpu_tag_t)0x52);
  1347. @end example
  1348. @end cartouche
  1349. @end table
  1350. @node starpu_tag_declare_deps_array
  1351. @subsection @code{starpu_tag_declare_deps_array} -- Declare the Dependencies of a Tag
  1352. @table @asis
  1353. @item @emph{Description}:
  1354. This function is similar to @code{starpu_tag_declare_deps}, except that its
  1355. does not take a variable number of arguments but an array of tags of size
  1356. @code{ndeps}.
  1357. @item @emph{Prototype}:
  1358. @code{void starpu_tag_declare_deps_array(starpu_tag_t id, unsigned ndeps, starpu_tag_t *array);}
  1359. @item @emph{Example}:
  1360. @cartouche
  1361. @example
  1362. /* Tag 0x1 depends on tags 0x32 and 0x52 */
  1363. starpu_tag_t tag_array[2] = @{0x32, 0x52@};
  1364. starpu_tag_declare_deps_array((starpu_tag_t)0x1, 2, tag_array);
  1365. @end example
  1366. @end cartouche
  1367. @end table
  1368. @node starpu_tag_wait
  1369. @subsection @code{starpu_tag_wait} -- Block until a Tag is terminated
  1370. @table @asis
  1371. @item @emph{Description}:
  1372. This function blocks until the task associated to tag @code{id} has been
  1373. executed. This is a blocking call which must therefore not be called within
  1374. tasks or callbacks, but only from the application directly. It is possible to
  1375. synchronize with the same tag multiple times, as long as the
  1376. @code{starpu_tag_remove} function is not called. Note that it is still
  1377. possible to synchronize with a tag associated to a task which @code{starpu_task}
  1378. data structure was freed (e.g. if the @code{destroy} flag of the
  1379. @code{starpu_task} was enabled).
  1380. @item @emph{Prototype}:
  1381. @code{void starpu_tag_wait(starpu_tag_t id);}
  1382. @end table
  1383. @node starpu_tag_wait_array
  1384. @subsection @code{starpu_tag_wait_array} -- Block until a set of Tags is terminated
  1385. @table @asis
  1386. @item @emph{Description}:
  1387. This function is similar to @code{starpu_tag_wait} except that it blocks until
  1388. @emph{all} the @code{ntags} tags contained in the @code{id} array are
  1389. terminated.
  1390. @item @emph{Prototype}:
  1391. @code{void starpu_tag_wait_array(unsigned ntags, starpu_tag_t *id);}
  1392. @end table
  1393. @node starpu_tag_remove
  1394. @subsection @code{starpu_tag_remove} -- Destroy a Tag
  1395. @table @asis
  1396. @item @emph{Description}:
  1397. This function releases the resources associated to tag @code{id}. It can be
  1398. called once the corresponding task has been executed and when there is
  1399. no other tag that depend on this tag anymore.
  1400. @item @emph{Prototype}:
  1401. @code{void starpu_tag_remove(starpu_tag_t id);}
  1402. @end table
  1403. @node starpu_tag_notify_from_apps
  1404. @subsection @code{starpu_tag_notify_from_apps} -- Feed a Tag explicitly
  1405. @table @asis
  1406. @item @emph{Description}:
  1407. This function explicitly unlocks tag @code{id}. It may be useful in the
  1408. case of applications which execute part of their computation outside StarPU
  1409. tasks (e.g. third-party libraries). It is also provided as a
  1410. convenient tool for the programmer, for instance to entirely construct the task
  1411. DAG before actually giving StarPU the opportunity to execute the tasks.
  1412. @item @emph{Prototype}:
  1413. @code{void starpu_tag_notify_from_apps(starpu_tag_t id);}
  1414. @end table
  1415. @node Implicit Data Dependencies
  1416. @section Implicit Data Dependencies
  1417. @menu
  1418. * starpu_data_set_default_sequential_consistency_flag:: starpu_data_set_default_sequential_consistency_flag
  1419. * starpu_data_get_default_sequential_consistency_flag:: starpu_data_get_default_sequential_consistency_flag
  1420. * starpu_data_set_sequential_consistency_flag:: starpu_data_set_sequential_consistency_flag
  1421. @end menu
  1422. In this section, we describe how StarPU makes it possible to insert implicit
  1423. task dependencies in order to enforce sequential data consistency. When this
  1424. data consistency is enabled on a specific data handle, any data access will
  1425. appear as sequentially consistent from the application. For instance, if the
  1426. application submits two tasks that access the same piece of data in read-only
  1427. mode, and then a third task that access it in write mode, dependencies will be
  1428. added between the two first tasks and the third one. Implicit data dependencies
  1429. are also inserted in the case of data accesses from the application.
  1430. @node starpu_data_set_default_sequential_consistency_flag
  1431. @subsection @code{starpu_data_set_default_sequential_consistency_flag} -- Set default sequential consistency flag
  1432. @table @asis
  1433. @item @emph{Description}:
  1434. Set the default sequential consistency flag. If a non-null value is passed, a
  1435. sequential data consistency will be enforced for all handles registered after
  1436. this function call, otherwise it is disabled. By default, StarPU enables
  1437. sequential data consistency. It is also possible to select the data consistency
  1438. mode of a specific data handle with the
  1439. @code{starpu_data_set_sequential_consistency_flag} function.
  1440. @item @emph{Prototype}:
  1441. @code{void starpu_data_set_default_sequential_consistency_flag(unsigned flag);}
  1442. @end table
  1443. @node starpu_data_get_default_sequential_consistency_flag
  1444. @subsection @code{starpu_data_get_default_sequential_consistency_flag} -- Get current default sequential consistency flag
  1445. @table @asis
  1446. @item @emph{Description}:
  1447. This function returns the current default sequential consistency flag.
  1448. @item @emph{Prototype}:
  1449. @code{unsigned starpu_data_set_default_sequential_consistency_flag(void);}
  1450. @end table
  1451. @node starpu_data_set_sequential_consistency_flag
  1452. @subsection @code{starpu_data_set_sequential_consistency_flag} -- Set data sequential consistency mode
  1453. @table @asis
  1454. @item @emph{Description}:
  1455. Select the data consistency mode associated to a data handle. The consistency
  1456. mode set using this function has the priority over the default mode which can
  1457. be set with @code{starpu_data_set_sequential_consistency_flag}.
  1458. @item @emph{Prototype}:
  1459. @code{void starpu_data_set_sequential_consistency_flag(starpu_data_handle handle, unsigned flag);}
  1460. @end table
  1461. @node Profiling API
  1462. @section Profiling API
  1463. @menu
  1464. * starpu_profiling_status_set:: starpu_profiling_status_set
  1465. * starpu_profiling_status_get:: starpu_profiling_status_get
  1466. * struct starpu_task_profiling_info:: task profiling information
  1467. * struct starpu_worker_profiling_info:: worker profiling information
  1468. * starpu_worker_get_profiling_info:: starpu_worker_get_profiling_info
  1469. * struct starpu_bus_profiling_info:: bus profiling information
  1470. @end menu
  1471. @node starpu_profiling_status_set
  1472. @subsection @code{starpu_profiling_status_set} -- Set current profiling status
  1473. @table @asis
  1474. @item @emph{Description}:
  1475. Thie function sets the profiling status. Profiling is activated by passing
  1476. @code{STARPU_PROFILING_ENABLE} in @code{status}. Passing
  1477. @code{STARPU_PROFILING_DISABLE} disables profiling. Calling this function
  1478. resets all profiling measurements. When profiling is enabled, the
  1479. @code{profiling_info} field of the @code{struct starpu_task} structure points
  1480. to a valid @code{struct starpu_task_profiling_info} structure containing
  1481. information about the execution of the task.
  1482. @item @emph{Return value}:
  1483. Negative return values indicate an error, otherwise the previous status is
  1484. returned.
  1485. @item @emph{Prototype}:
  1486. @code{int starpu_profiling_status_set(int status);}
  1487. @end table
  1488. @node starpu_profiling_status_get
  1489. @subsection @code{starpu_profiling_status_get} -- Get current profiling status
  1490. @table @asis
  1491. @item @emph{Description}:
  1492. Return the current profiling status or a negative value in case there was an error.
  1493. @item @emph{Prototype}:
  1494. @code{int starpu_profiling_status_get(void);}
  1495. @end table
  1496. @node struct starpu_task_profiling_info
  1497. @subsection @code{struct starpu_task_profiling_info} -- Task profiling information
  1498. @table @asis
  1499. @item @emph{Description}:
  1500. This structure contains information about the execution of a task. It is
  1501. accessible from the @code{.profiling_info} field of the @code{starpu_task}
  1502. structure if profiling was enabled.
  1503. @item @emph{Fields}:
  1504. @table @asis
  1505. @item @code{submit_time}:
  1506. Date of task submission (relative to the initialization of StarPU).
  1507. @item @code{start_time}:
  1508. Date of task execution beginning (relative to the initialization of StarPU).
  1509. @item @code{end_time}:
  1510. Date of task execution termination (relative to the initialization of StarPU).
  1511. @item @code{workerid}:
  1512. Identifier of the worker which has executed the task.
  1513. @end table
  1514. @end table
  1515. @node struct starpu_worker_profiling_info
  1516. @subsection @code{struct starpu_worker_profiling_info} -- Worker profiling information
  1517. @table @asis
  1518. @item @emph{Description}:
  1519. This structure contains the profiling information associated to a worker.
  1520. @item @emph{Fields}:
  1521. @table @asis
  1522. @item @code{start_time}:
  1523. Starting date for the reported profiling measurements.
  1524. @item @code{total_time}:
  1525. Duration of the profiling measurement interval.
  1526. @item @code{executing_time}:
  1527. Time spent by the worker to execute tasks during the profiling measurement interval.
  1528. @item @code{sleeping_time}:
  1529. Time spent idling by the worker during the profiling measurement interval.
  1530. @item @code{executed_tasks}:
  1531. Number of tasks executed by the worker during the profiling measurement interval.
  1532. @end table
  1533. @end table
  1534. @node starpu_worker_get_profiling_info
  1535. @subsection @code{starpu_worker_get_profiling_info} -- Get worker profiling info
  1536. @table @asis
  1537. @item @emph{Description}:
  1538. Get the profiling info associated to the worker identified by @code{workerid},
  1539. and reset the profiling measurements. If the @code{worker_info} argument is
  1540. NULL, only reset the counters associated to worker @code{workerid}.
  1541. @item @emph{Return value}:
  1542. Upon successful completion, this function returns 0. Otherwise, a negative
  1543. value is returned.
  1544. @item @emph{Prototype}:
  1545. @code{int starpu_worker_get_profiling_info(int workerid, struct starpu_worker_profiling_info *worker_info);}
  1546. @end table
  1547. @node struct starpu_bus_profiling_info
  1548. @subsection @code{struct starpu_bus_profiling_info} -- Bus profiling information
  1549. @table @asis
  1550. @item @emph{Description}:
  1551. TODO
  1552. @item @emph{Fields}:
  1553. @table @asis
  1554. @item @code{start_time}:
  1555. TODO
  1556. @item @code{total_time}:
  1557. TODO
  1558. @item @code{transferred_bytes}:
  1559. TODO
  1560. @item @code{transfer_count}:
  1561. TODO
  1562. @end table
  1563. @end table
  1564. @node CUDA extensions
  1565. @section CUDA extensions
  1566. @c void starpu_data_malloc_pinned_if_possible(float **A, size_t dim);
  1567. @menu
  1568. * starpu_cuda_get_local_stream:: Get current worker's CUDA stream
  1569. * starpu_helper_cublas_init:: Initialize CUBLAS on every CUDA device
  1570. * starpu_helper_cublas_shutdown:: Deinitialize CUBLAS on every CUDA device
  1571. @end menu
  1572. @node starpu_cuda_get_local_stream
  1573. @subsection @code{starpu_cuda_get_local_stream} -- Get current worker's CUDA stream
  1574. @table @asis
  1575. @item @emph{Description}:
  1576. StarPU provides a stream for every CUDA device controlled by StarPU. This
  1577. function is only provided for convenience so that programmers can easily use
  1578. asynchronous operations within codelets without having to create a stream by
  1579. hand. Note that the application is not forced to use the stream provided by
  1580. @code{starpu_cuda_get_local_stream} and may also create its own streams.
  1581. @item @emph{Prototype}:
  1582. @code{cudaStream_t *starpu_cuda_get_local_stream(void);}
  1583. @end table
  1584. @node starpu_helper_cublas_init
  1585. @subsection @code{starpu_helper_cublas_init} -- Initialize CUBLAS on every CUDA device
  1586. @table @asis
  1587. @item @emph{Description}:
  1588. The CUBLAS library must be initialized prior to any CUBLAS call. Calling
  1589. @code{starpu_helper_cublas_init} will initialize CUBLAS on every CUDA device
  1590. controlled by StarPU. This call blocks until CUBLAS has been properly
  1591. initialized on every device.
  1592. @item @emph{Prototype}:
  1593. @code{void starpu_helper_cublas_init(void);}
  1594. @end table
  1595. @node starpu_helper_cublas_shutdown
  1596. @subsection @code{starpu_helper_cublas_shutdown} -- Deinitialize CUBLAS on every CUDA device
  1597. @table @asis
  1598. @item @emph{Description}:
  1599. This function synchronously deinitializes the CUBLAS library on every CUDA device.
  1600. @item @emph{Prototype}:
  1601. @code{void starpu_helper_cublas_shutdown(void);}
  1602. @end table
  1603. @node OpenCL extensions
  1604. @section OpenCL extensions
  1605. @menu
  1606. * Enabling OpenCL:: Enabling OpenCL
  1607. * Compiling OpenCL codelets:: Compiling OpenCL codelets
  1608. @end menu
  1609. @node Enabling OpenCL
  1610. @subsection Enabling OpenCL
  1611. On GPU devices which can run both CUDA and OpenCL, CUDA will be
  1612. enabled by default. To enable OpenCL, you need either to disable CUDA
  1613. when configuring StarPU:
  1614. @example
  1615. % ./configure --disable-cuda
  1616. @end example
  1617. or when running applications:
  1618. @example
  1619. % STARPU_NCUDA=0 ./application
  1620. @end example
  1621. OpenCL will automatically be started on any device not yet used by
  1622. CUDA. So on a machine running 4 GPUS, it is therefore possible to
  1623. enable CUDA on 2 devices, and OpenCL on the 2 other devices by doing
  1624. so:
  1625. @example
  1626. % STARPU_NCUDA=2 ./application
  1627. @end example
  1628. @node Compiling OpenCL codelets
  1629. @subsection Compiling OpenCL codelets
  1630. TODO
  1631. @node Cell extensions
  1632. @section Cell extensions
  1633. nothing yet.
  1634. @node Miscellaneous helpers
  1635. @section Miscellaneous helpers
  1636. @menu
  1637. * starpu_execute_on_each_worker:: Execute a function on a subset of workers
  1638. @end menu
  1639. @node starpu_execute_on_each_worker
  1640. @subsection @code{starpu_execute_on_each_worker} -- Execute a function on a subset of workers
  1641. @table @asis
  1642. @item @emph{Description}:
  1643. When calling this method, the offloaded function specified by the first argument is
  1644. executed by every StarPU worker that may execute the function.
  1645. The second argument is passed to the offloaded function.
  1646. The last argument specifies on which types of processing units the function
  1647. should be executed. Similarly to the @code{where} field of the
  1648. @code{starpu_codelet} structure, it is possible to specify that the function
  1649. should be executed on every CUDA device and every CPU by passing
  1650. @code{STARPU_CPU|STARPU_CUDA}.
  1651. This function blocks until the function has been executed on every appropriate
  1652. processing units, so that it may not be called from a callback function for
  1653. instance.
  1654. @item @emph{Prototype}:
  1655. @code{void starpu_execute_on_each_worker(void (*func)(void *), void *arg, uint32_t where);}
  1656. @end table
  1657. @c ---------------------------------------------------------------------
  1658. @c Basic Examples
  1659. @c ---------------------------------------------------------------------
  1660. @node Basic Examples
  1661. @chapter Basic Examples
  1662. @menu
  1663. * Compiling and linking options::
  1664. * Hello World:: Submitting Tasks
  1665. * Scaling a Vector:: Manipulating Data
  1666. * Vector Scaling on an Hybrid CPU/GPU Machine:: Handling Heterogeneous Architectures
  1667. @end menu
  1668. @node Compiling and linking options
  1669. @section Compiling and linking options
  1670. Let's suppose StarPU has been installed in the directory
  1671. @code{$STARPU_DIR}. As explained in @ref{Setting flags for compiling and linking applications},
  1672. the variable @code{PKG_CONFIG_PATH} needs to be set. It is also
  1673. necessary to set the variable @code{LD_LIBRARY_PATH} to locate dynamic
  1674. libraries at runtime.
  1675. @example
  1676. % PKG_CONFIG_PATH=$STARPU_DIR/lib/pkgconfig:$PKG_CONFIG_PATH
  1677. % LD_LIBRARY_PATH=$STARPU_DIR/lib:$LD_LIBRARY_PATH
  1678. @end example
  1679. The Makefile could for instance contain the following lines to define which
  1680. options must be given to the compiler and to the linker:
  1681. @cartouche
  1682. @example
  1683. CFLAGS += $$(pkg-config --cflags libstarpu)
  1684. LDFLAGS += $$(pkg-config --libs libstarpu)
  1685. @end example
  1686. @end cartouche
  1687. @node Hello World
  1688. @section Hello World
  1689. @menu
  1690. * Required Headers::
  1691. * Defining a Codelet::
  1692. * Submitting a Task::
  1693. * Execution of Hello World::
  1694. @end menu
  1695. In this section, we show how to implement a simple program that submits a task to StarPU.
  1696. @node Required Headers
  1697. @subsection Required Headers
  1698. The @code{starpu.h} header should be included in any code using StarPU.
  1699. @cartouche
  1700. @smallexample
  1701. #include <starpu.h>
  1702. @end smallexample
  1703. @end cartouche
  1704. @node Defining a Codelet
  1705. @subsection Defining a Codelet
  1706. @cartouche
  1707. @smallexample
  1708. void cpu_func(void *buffers[], void *cl_arg)
  1709. @{
  1710. float *array = cl_arg;
  1711. printf("Hello world (array = @{%f, %f@} )\n", array[0], array[1]);
  1712. @}
  1713. starpu_codelet cl =
  1714. @{
  1715. .where = STARPU_CPU,
  1716. .cpu_func = cpu_func,
  1717. .nbuffers = 0
  1718. @};
  1719. @end smallexample
  1720. @end cartouche
  1721. A codelet is a structure that represents a computational kernel. Such a codelet
  1722. may contain an implementation of the same kernel on different architectures
  1723. (e.g. CUDA, Cell's SPU, x86, ...).
  1724. The @code{nbuffers} field specifies the number of data buffers that are
  1725. manipulated by the codelet: here the codelet does not access or modify any data
  1726. that is controlled by our data management library. Note that the argument
  1727. passed to the codelet (the @code{cl_arg} field of the @code{starpu_task}
  1728. structure) does not count as a buffer since it is not managed by our data
  1729. management library.
  1730. @c TODO need a crossref to the proper description of "where" see bla for more ...
  1731. We create a codelet which may only be executed on the CPUs. The @code{where}
  1732. field is a bitmask that defines where the codelet may be executed. Here, the
  1733. @code{STARPU_CPU} value means that only CPUs can execute this codelet
  1734. (@pxref{Codelets and Tasks} for more details on this field).
  1735. When a CPU core executes a codelet, it calls the @code{cpu_func} function,
  1736. which @emph{must} have the following prototype:
  1737. @code{void (*cpu_func)(void *buffers[], void *cl_arg);}
  1738. In this example, we can ignore the first argument of this function which gives a
  1739. description of the input and output buffers (e.g. the size and the location of
  1740. the matrices). The second argument is a pointer to a buffer passed as an
  1741. argument to the codelet by the means of the @code{cl_arg} field of the
  1742. @code{starpu_task} structure.
  1743. @c TODO rewrite so that it is a little clearer ?
  1744. Be aware that this may be a pointer to a
  1745. @emph{copy} of the actual buffer, and not the pointer given by the programmer:
  1746. if the codelet modifies this buffer, there is no guarantee that the initial
  1747. buffer will be modified as well: this for instance implies that the buffer
  1748. cannot be used as a synchronization medium.
  1749. @node Submitting a Task
  1750. @subsection Submitting a Task
  1751. @cartouche
  1752. @smallexample
  1753. void callback_func(void *callback_arg)
  1754. @{
  1755. printf("Callback function (arg %x)\n", callback_arg);
  1756. @}
  1757. int main(int argc, char **argv)
  1758. @{
  1759. /* @b{initialize StarPU} */
  1760. starpu_init(NULL);
  1761. struct starpu_task *task = starpu_task_create();
  1762. task->cl = &cl; /* @b{Pointer to the codelet defined above} */
  1763. float array[2] = @{1.0f, -1.0f@};
  1764. task->cl_arg = &array;
  1765. task->cl_arg_size = sizeof(array);
  1766. task->callback_func = callback_func;
  1767. task->callback_arg = 0x42;
  1768. /* @b{starpu_task_submit will be a blocking call} */
  1769. task->synchronous = 1;
  1770. /* @b{submit the task to StarPU} */
  1771. starpu_task_submit(task);
  1772. /* @b{terminate StarPU} */
  1773. starpu_shutdown();
  1774. return 0;
  1775. @}
  1776. @end smallexample
  1777. @end cartouche
  1778. Before submitting any tasks to StarPU, @code{starpu_init} must be called. The
  1779. @code{NULL} argument specifies that we use default configuration. Tasks cannot
  1780. be submitted after the termination of StarPU by a call to
  1781. @code{starpu_shutdown}.
  1782. In the example above, a task structure is allocated by a call to
  1783. @code{starpu_task_create}. This function only allocates and fills the
  1784. corresponding structure with the default settings (@pxref{starpu_task_create}),
  1785. but it does not submit the task to StarPU.
  1786. @c not really clear ;)
  1787. The @code{cl} field is a pointer to the codelet which the task will
  1788. execute: in other words, the codelet structure describes which computational
  1789. kernel should be offloaded on the different architectures, and the task
  1790. structure is a wrapper containing a codelet and the piece of data on which the
  1791. codelet should operate.
  1792. The optional @code{cl_arg} field is a pointer to a buffer (of size
  1793. @code{cl_arg_size}) with some parameters for the kernel
  1794. described by the codelet. For instance, if a codelet implements a computational
  1795. kernel that multiplies its input vector by a constant, the constant could be
  1796. specified by the means of this buffer, instead of registering it.
  1797. Once a task has been executed, an optional callback function can be called.
  1798. While the computational kernel could be offloaded on various architectures, the
  1799. callback function is always executed on a CPU. The @code{callback_arg}
  1800. pointer is passed as an argument of the callback. The prototype of a callback
  1801. function must be:
  1802. @code{void (*callback_function)(void *);}
  1803. If the @code{synchronous} field is non-null, task submission will be
  1804. synchronous: the @code{starpu_task_submit} function will not return until the
  1805. task was executed. Note that the @code{starpu_shutdown} method does not
  1806. guarantee that asynchronous tasks have been executed before it returns.
  1807. @node Execution of Hello World
  1808. @subsection Execution of Hello World
  1809. @smallexample
  1810. % make helloWorld
  1811. cc $(pkg-config --cflags libstarpu) $(pkg-config --libs libstarpu) helloWorld.c -o helloWorld
  1812. % ./helloWorld
  1813. Hello world (array = @{1.000000, -1.000000@} )
  1814. Callback function (arg 42)
  1815. @end smallexample
  1816. @node Scaling a Vector
  1817. @section Manipulating Data: Scaling a Vector
  1818. The previous example has shown how to submit tasks. In this section,
  1819. we show how StarPU tasks can manipulate data. The full source code for
  1820. this example is given in @ref{Full source code for the 'Scaling a Vector' example}.
  1821. @menu
  1822. * Source code of Vector Scaling::
  1823. * Execution of Vector Scaling::
  1824. @end menu
  1825. @node Source code of Vector Scaling
  1826. @subsection Source code of Vector Scaling
  1827. Programmers can describe the data layout of their application so that StarPU is
  1828. responsible for enforcing data coherency and availability across the machine.
  1829. Instead of handling complex (and non-portable) mechanisms to perform data
  1830. movements, programmers only declare which piece of data is accessed and/or
  1831. modified by a task, and StarPU makes sure that when a computational kernel
  1832. starts somewhere (e.g. on a GPU), its data are available locally.
  1833. Before submitting those tasks, the programmer first needs to declare the
  1834. different pieces of data to StarPU using the @code{starpu_*_data_register}
  1835. functions. To ease the development of applications for StarPU, it is possible
  1836. to describe multiple types of data layout. A type of data layout is called an
  1837. @b{interface}. By default, there are different interfaces available in StarPU:
  1838. here we will consider the @b{vector interface}.
  1839. The following lines show how to declare an array of @code{NX} elements of type
  1840. @code{float} using the vector interface:
  1841. @cartouche
  1842. @smallexample
  1843. float vector[NX];
  1844. starpu_data_handle vector_handle;
  1845. starpu_vector_data_register(&vector_handle, 0, (uintptr_t)vector, NX,
  1846. sizeof(vector[0]));
  1847. @end smallexample
  1848. @end cartouche
  1849. The first argument, called the @b{data handle}, is an opaque pointer which
  1850. designates the array in StarPU. This is also the structure which is used to
  1851. describe which data is used by a task. The second argument is the node number
  1852. where the data currently resides. Here it is 0 since the @code{vector} array is in
  1853. the main memory. Then comes the pointer @code{vector} where the data can be found,
  1854. the number of elements in the vector and the size of each element.
  1855. It is possible to construct a StarPU task that will manipulate the
  1856. vector and a constant factor.
  1857. @cartouche
  1858. @smallexample
  1859. float factor = 3.14;
  1860. struct starpu_task *task = starpu_task_create();
  1861. task->cl = &cl; /* @b{Pointer to the codelet defined below} */
  1862. task->buffers[0].handle = vector_handle; /* @b{First parameter of the codelet} */
  1863. task->buffers[0].mode = STARPU_RW;
  1864. task->cl_arg = &factor;
  1865. task->cl_arg_size = sizeof(factor);
  1866. task->synchronous = 1;
  1867. starpu_task_submit(task);
  1868. @end smallexample
  1869. @end cartouche
  1870. Since the factor is a mere float value parameter, it does not need a preliminary registration, and
  1871. can just be passed through the @code{cl_arg} pointer like in the previous
  1872. example. The vector parameter is described by its handle.
  1873. There are two fields in each element of the @code{buffers} array.
  1874. @code{handle} is the handle of the data, and @code{mode} specifies how the
  1875. kernel will access the data (@code{STARPU_R} for read-only, @code{STARPU_W} for
  1876. write-only and @code{STARPU_RW} for read and write access).
  1877. The definition of the codelet can be written as follows:
  1878. @cartouche
  1879. @smallexample
  1880. void scal_cpu_func(void *buffers[], void *cl_arg)
  1881. @{
  1882. unsigned i;
  1883. float *factor = cl_arg;
  1884. /* length of the vector */
  1885. unsigned n = STARPU_GET_VECTOR_NX(buffers[0]);
  1886. /* local copy of the vector pointer */
  1887. float *val = (float *)STARPU_GET_VECTOR_PTR(buffers[0]);
  1888. for (i = 0; i < n; i++)
  1889. val[i] *= *factor;
  1890. @}
  1891. starpu_codelet cl = @{
  1892. .where = STARPU_CPU,
  1893. .cpu_func = scal_cpu_func,
  1894. .nbuffers = 1
  1895. @};
  1896. @end smallexample
  1897. @end cartouche
  1898. The second argument of the @code{scal_cpu_func} function contains a pointer to the
  1899. parameters of the codelet (given in @code{task->cl_arg}), so that we read the
  1900. constant factor from this pointer. The first argument is an array that gives
  1901. a description of all the buffers passed in the @code{task->buffers}@ array. The
  1902. size of this array is given by the @code{nbuffers} field of the codelet
  1903. structure. For the sake of generality, this array contains pointers to the
  1904. different interfaces describing each buffer. In the case of the @b{vector
  1905. interface}, the location of the vector (resp. its length) is accessible in the
  1906. @code{ptr} (resp. @code{nx}) of this array. Since the vector is accessed in a
  1907. read-write fashion, any modification will automatically affect future accesses
  1908. to this vector made by other tasks.
  1909. @node Execution of Vector Scaling
  1910. @subsection Execution of Vector Scaling
  1911. @smallexample
  1912. % make vector
  1913. cc $(pkg-config --cflags libstarpu) $(pkg-config --libs libstarpu) vector.c -o vector
  1914. % ./vector
  1915. 0.000000 3.000000 6.000000 9.000000 12.000000
  1916. @end smallexample
  1917. @node Vector Scaling on an Hybrid CPU/GPU Machine
  1918. @section Vector Scaling on an Hybrid CPU/GPU Machine
  1919. Contrary to the previous examples, the task submitted in this example may not
  1920. only be executed by the CPUs, but also by a CUDA device.
  1921. @menu
  1922. * Definition of the CUDA Codelet::
  1923. * Definition of the OpenCL Codelet::
  1924. * Definition of the Main Code::
  1925. * Compilation and execution of Hybrid Vector Scaling::
  1926. @end menu
  1927. @node Definition of the CUDA Codelet
  1928. @subsection Definition of the CUDA Codelet
  1929. The CUDA implementation can be written as follows. It needs to be
  1930. compiled with a CUDA compiler such as nvcc, the NVIDIA CUDA compiler
  1931. driver.
  1932. @cartouche
  1933. @smallexample
  1934. #include <starpu.h>
  1935. static __global__ void vector_mult_cuda(float *val, unsigned n,
  1936. float factor)
  1937. @{
  1938. unsigned i;
  1939. for(i = 0 ; i < n ; i++)
  1940. val[i] *= factor;
  1941. @}
  1942. extern "C" void scal_cuda_func(void *buffers[], void *_args)
  1943. @{
  1944. float *factor = (float *)_args;
  1945. /* length of the vector */
  1946. unsigned n = STARPU_GET_VECTOR_NX(buffers[0]);
  1947. /* local copy of the vector pointer */
  1948. float *val = (float *)STARPU_GET_VECTOR_PTR(buffers[0]);
  1949. @i{ vector_mult_cuda<<<1,1>>>(val, n, *factor);}
  1950. @i{ cudaThreadSynchronize();}
  1951. @}
  1952. @end smallexample
  1953. @end cartouche
  1954. @node Definition of the OpenCL Codelet
  1955. @subsection Definition of the OpenCL Codelet
  1956. The OpenCL implementation can be written as follows. StarPU provides
  1957. tools to compile a OpenCL codelet stored in a file.
  1958. @cartouche
  1959. @smallexample
  1960. __kernel void vector_mult_opencl(__global float* val, int nx, float factor)
  1961. @{
  1962. const int i = get_global_id(0);
  1963. if (i < nx) @{
  1964. val[i] *= factor;
  1965. @}
  1966. @}
  1967. @end smallexample
  1968. @end cartouche
  1969. @cartouche
  1970. @smallexample
  1971. #include <starpu.h>
  1972. @i{#include <starpu_opencl.h>}
  1973. @i{extern struct starpu_opencl_program programs;}
  1974. void scal_opencl_func(void *buffers[], void *_args)
  1975. @{
  1976. float *factor = _args;
  1977. @i{ int id, devid, err;}
  1978. @i{ cl_kernel kernel;}
  1979. @i{ cl_command_queue queue;}
  1980. /* length of the vector */
  1981. unsigned n = STARPU_GET_VECTOR_NX(buffers[0]);
  1982. /* local copy of the vector pointer */
  1983. float *val = (float *)STARPU_GET_VECTOR_PTR(buffers[0]);
  1984. @i{ id = starpu_worker_get_id();}
  1985. @i{ devid = starpu_worker_get_devid(id);}
  1986. @i{ err = starpu_opencl_load_kernel(&kernel, &queue, &programs,}
  1987. @i{ "vector_mult_opencl", devid); /* @b{Name of the codelet defined above} */}
  1988. @i{ if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);}
  1989. @i{ err = 0;}
  1990. @i{ err = clSetKernelArg(kernel, 0, sizeof(cl_mem), &val);}
  1991. @i{ err = clSetKernelArg(kernel, 1, sizeof(n), &n);}
  1992. @i{ err |= clSetKernelArg(kernel, 2, sizeof(*factor), factor);}
  1993. @i{ if (err) STARPU_OPENCL_REPORT_ERROR(err);}
  1994. @i{ @{}
  1995. @i{ size_t global=1;}
  1996. @i{ size_t local=1;}
  1997. @i{ err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &global, &local, 0, NULL, NULL);}
  1998. @i{ if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);}
  1999. @i{ @}}
  2000. @i{ clFinish(queue);}
  2001. @i{ starpu_opencl_release_kernel(kernel);}
  2002. @}
  2003. @end smallexample
  2004. @end cartouche
  2005. @node Definition of the Main Code
  2006. @subsection Definition of the Main Code
  2007. The CPU implementation is the same as in the previous section.
  2008. Here is the source of the main application. You can notice the value of the
  2009. field @code{where} for the codelet. We specify
  2010. @code{STARPU_CPU|STARPU_CUDA|STARPU_OPENCL} to indicate to StarPU that the codelet
  2011. can be executed either on a CPU or on a CUDA or an OpenCL device.
  2012. @cartouche
  2013. @smallexample
  2014. #include <starpu.h>
  2015. #define NX 2048
  2016. extern void scal_cuda_func(void *buffers[], void *_args);
  2017. extern void scal_cpu_func(void *buffers[], void *_args);
  2018. extern void scal_opencl_func(void *buffers[], void *_args);
  2019. /* @b{Definition of the codelet} */
  2020. static starpu_codelet cl = @{
  2021. .where = STARPU_CPU|STARPU_CUDA|STARPU_OPENCL; /* @b{It can be executed on a CPU,} */
  2022. /* @b{on a CUDA device, or on an OpenCL device} */
  2023. .cuda_func = scal_cuda_func;
  2024. .cpu_func = scal_cpu_func;
  2025. .opencl_func = scal_opencl_func;
  2026. .nbuffers = 1;
  2027. @}
  2028. #ifdef STARPU_USE_OPENCL
  2029. /* @b{The compiled version of the OpenCL program} */
  2030. struct starpu_opencl_program programs;
  2031. #endif
  2032. int main(int argc, char **argv)
  2033. @{
  2034. float *vector;
  2035. int i, ret;
  2036. float factor=3.0;
  2037. struct starpu_task *task;
  2038. starpu_data_handle vector_handle;
  2039. starpu_init(NULL); /* @b{Initialising StarPU} */
  2040. #ifdef STARPU_USE_OPENCL
  2041. starpu_opencl_load_opencl_from_file("examples/basic_examples/vector_scal_opencl_codelet.cl",
  2042. &programs);
  2043. #endif
  2044. vector = malloc(NX*sizeof(vector[0]));
  2045. assert(vector);
  2046. for(i=0 ; i<NX ; i++) vector[i] = i;
  2047. @end smallexample
  2048. @end cartouche
  2049. @cartouche
  2050. @smallexample
  2051. /* @b{Registering data within StarPU} */
  2052. starpu_vector_data_register(&vector_handle, 0, (uintptr_t)vector,
  2053. NX, sizeof(vector[0]));
  2054. /* @b{Definition of the task} */
  2055. task = starpu_task_create();
  2056. task->cl = &cl;
  2057. task->buffers[0].handle = vector_handle;
  2058. task->buffers[0].mode = STARPU_RW;
  2059. task->cl_arg = &factor;
  2060. task->cl_arg_size = sizeof(factor);
  2061. @end smallexample
  2062. @end cartouche
  2063. @cartouche
  2064. @smallexample
  2065. /* @b{Submitting the task} */
  2066. ret = starpu_task_submit(task);
  2067. if (ret == -ENODEV) @{
  2068. fprintf(stderr, "No worker may execute this task\n");
  2069. return 1;
  2070. @}
  2071. /* @b{Waiting for its termination} */
  2072. starpu_task_wait_for_all();
  2073. /* @b{Update the vector in RAM} */
  2074. starpu_data_sync_with_mem(vector_handle, STARPU_R);
  2075. @end smallexample
  2076. @end cartouche
  2077. @cartouche
  2078. @smallexample
  2079. /* @b{Access the data} */
  2080. for(i=0 ; i<NX; i++) @{
  2081. fprintf(stderr, "%f ", vector[i]);
  2082. @}
  2083. fprintf(stderr, "\n");
  2084. /* @b{Release the data and shutdown StarPU} */
  2085. starpu_data_release_from_mem(vector_handle);
  2086. starpu_shutdown();
  2087. return 0;
  2088. @}
  2089. @end smallexample
  2090. @end cartouche
  2091. @node Compilation and execution of Hybrid Vector Scaling
  2092. @subsection Compilation and execution of Hybrid Vector Scaling
  2093. The Makefile given at the beginning of the section must be extended to
  2094. give the rules to compile the CUDA source code.
  2095. @cartouche
  2096. @smallexample
  2097. CFLAGS += $(shell pkg-config --cflags libstarpu)
  2098. LDFLAGS += $(shell pkg-config --libs libstarpu)
  2099. CC = gcc
  2100. vector: vector.o vector_cpu.o vector_cuda.o
  2101. %.o: %.cu
  2102. nvcc $(CFLAGS) $< -c $@
  2103. clean:
  2104. rm -f vector *.o
  2105. @end smallexample
  2106. @end cartouche
  2107. @smallexample
  2108. % make
  2109. @end smallexample
  2110. and to execute it, with the default configuration:
  2111. @smallexample
  2112. % ./vector
  2113. 0.000000 3.000000 6.000000 9.000000 12.000000
  2114. @end smallexample
  2115. or for example, by disabling CPU devices:
  2116. @smallexample
  2117. % STARPU_NCPUS=0 ./vector
  2118. 0.000000 3.000000 6.000000 9.000000 12.000000
  2119. @end smallexample
  2120. or by disabling CUDA devices:
  2121. @smallexample
  2122. % STARPU_NCUDA=0 ./vector
  2123. 0.000000 3.000000 6.000000 9.000000 12.000000
  2124. @end smallexample
  2125. @c TODO: Add performance model example (and update basic_examples)
  2126. @c ---------------------------------------------------------------------
  2127. @c Advanced Topics
  2128. @c ---------------------------------------------------------------------
  2129. @node Advanced Topics
  2130. @chapter Advanced Topics
  2131. @menu
  2132. * Defining a new data interface::
  2133. * Defining a new scheduling policy::
  2134. @end menu
  2135. @node Defining a new data interface
  2136. @section Defining a new data interface
  2137. @menu
  2138. * struct starpu_data_interface_ops_t:: Per-interface methods
  2139. * struct starpu_data_copy_methods:: Per-interface data transfer methods
  2140. * An example of data interface:: An example of data interface
  2141. @end menu
  2142. @c void *starpu_data_get_interface_on_node(starpu_data_handle handle, unsigned memory_node); TODO
  2143. @node struct starpu_data_interface_ops_t
  2144. @subsection @code{struct starpu_data_interface_ops_t} -- Per-interface methods
  2145. @table @asis
  2146. @item @emph{Description}:
  2147. TODO describe all the different fields
  2148. @end table
  2149. @node struct starpu_data_copy_methods
  2150. @subsection @code{struct starpu_data_copy_methods} -- Per-interface data transfer methods
  2151. @table @asis
  2152. @item @emph{Description}:
  2153. TODO describe all the different fields
  2154. @end table
  2155. @node An example of data interface
  2156. @subsection An example of data interface
  2157. @table @asis
  2158. TODO
  2159. @end table
  2160. @node Defining a new scheduling policy
  2161. @section Defining a new scheduling policy
  2162. TODO
  2163. @c ---------------------------------------------------------------------
  2164. @c Appendices
  2165. @c ---------------------------------------------------------------------
  2166. @c ---------------------------------------------------------------------
  2167. @c Full source code for the 'Scaling a Vector' example
  2168. @c ---------------------------------------------------------------------
  2169. @node Full source code for the 'Scaling a Vector' example
  2170. @appendix Full source code for the 'Scaling a Vector' example
  2171. @menu
  2172. * Main application::
  2173. * CPU Codelet::
  2174. * CUDA Codelet::
  2175. * OpenCL Codelet::
  2176. @end menu
  2177. @node Main application
  2178. @section Main application
  2179. @smallexample
  2180. @include vector_scal_c.texi
  2181. @end smallexample
  2182. @node CPU Codelet
  2183. @section CPU Codelet
  2184. @smallexample
  2185. @include vector_scal_cpu.texi
  2186. @end smallexample
  2187. @node CUDA Codelet
  2188. @section CUDA Codelet
  2189. @smallexample
  2190. @include vector_scal_cuda.texi
  2191. @end smallexample
  2192. @node OpenCL Codelet
  2193. @section OpenCL Codelet
  2194. @menu
  2195. * Invoking the kernel::
  2196. * Source of the kernel::
  2197. @end menu
  2198. @node Invoking the kernel
  2199. @subsection Invoking the kernel
  2200. @smallexample
  2201. @include vector_scal_opencl.texi
  2202. @end smallexample
  2203. @node Source of the kernel
  2204. @subsection Source of the kernel
  2205. @smallexample
  2206. @include vector_scal_opencl_codelet.texi
  2207. @end smallexample
  2208. @bye