starpu.texi 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886
  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. * Configuration options:: Configurations options
  30. * Environment variables:: Environment variables used by StarPU
  31. * StarPU API:: The API to use StarPU
  32. * Basic Examples:: Basic examples of the use of StarPU
  33. * Advanced Topics:: Advanced use of StarPU
  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. * Configuring StarPU::
  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 Configuring StarPU
  135. @subsection Configuring StarPU
  136. @example
  137. % ./configure
  138. @end example
  139. Details about options that are useful to give to @code{./configure} are given in
  140. @ref{Configuration options}.
  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. @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 Configuration options
  209. @chapter Configuration options
  210. @table @asis
  211. @item @code{--disable-cpu}
  212. Disable the use of CPUs of the machine. Only GPUs etc. will be used.
  213. @item @code{--enable-maxcudadev=<number>}
  214. Defines the maximum number of CUDA devices that StarPU will support, then
  215. available as the STARPU_MAXCUDADEVS macro.
  216. @item @code{--disable-cuda}
  217. Disable the use of CUDA, even if the SDK is detected.
  218. @item @code{--enable-maxopencldev=<number>}
  219. Defines the maximum number of OpenCL devices that StarPU will support, then
  220. available as the STARPU_MAXOPENCLDEVS macro.
  221. @item @code{--disable-opencl}
  222. Disable the use of OpenCL, even if the SDK is detected.
  223. @item @code{--enable-gordon}
  224. Enable the use of the Gordon runtime for Cell SPUs.
  225. @c TODO: rather default to enabled when detected
  226. @item @code{--enable-debug}
  227. Enable debugging messages.
  228. @item @code{--enable-fast}
  229. Do not enforce assertions, saves a lot of time spent to compute them otherwise.
  230. @item @code{--enable-verbose}
  231. Augment the verbosity of the debugging messages.
  232. @item @code{--enable-coverage}
  233. Enable flags for the coverage tool.
  234. @item @code{--enable-perf-debug}
  235. Enable performance debugging.
  236. @item @code{--enable-model-debug}
  237. Enable performance model debugging.
  238. @item @code{--enable-stats}
  239. Enable statistics.
  240. @item @code{--enable-maxbuffers=<nbuffers>}
  241. Define the maximum number of buffers that tasks will be able to take as parameters, then available as the STARPU_NMAXBUFS macro.
  242. @item @code{--enable-allocation-cache}
  243. Enable the use of a data allocation cache to avoid the cost of it with
  244. CUDA. Still experimental.
  245. @item @code{--enable-opengl-render}
  246. Enable the use of OpenGL for the rendering of some examples.
  247. @c TODO: rather default to enabled when detected
  248. @item @code{--enable-blas-lib=<name>}
  249. Specify the blas library to be used by some of the examples. The
  250. library has to be 'atlas' or 'goto'.
  251. @item @code{--with-cuda-dir=<path>}
  252. Specify the location of the CUDA SDK resides. This directory should notably contain
  253. @code{include/cuda.h}.
  254. @item @code{--with-magma=<path>}
  255. Specify where magma is installed.
  256. @item @code{--with-opencl-dir=<path>}
  257. Specify the location of the OpenCL SDK. This directory should notably contain
  258. @code{include/CL/cl.h}.
  259. @item @code{--with-gordon-dir=<path>}
  260. Specify the location of the Gordon SDK.
  261. @item @code{--with-fxt=<path>}
  262. Specify the location of FxT (for generating traces and rendering them
  263. using ViTE). This directory should notably contain
  264. @code{include/fxt/fxt.h}.
  265. @item @code{--with-perf-model-dir=<dir>}
  266. Specify where performance models should be stored (instead of defaulting to the
  267. current user's home).
  268. @item @code{--with-mpicc=<path to mpicc>}
  269. Specify the location of the @code{mpicc} compiler to be used for starpumpi.
  270. @c TODO: also just use AC_PROG
  271. @item @code{--with-mpi}
  272. Enable building libstarpumpi.
  273. @c TODO: rather just use the availability of mpicc instead of a second option
  274. @item @code{--with-goto-dir=<dir>}
  275. Specify the location of GotoBLAS.
  276. @item @code{--with-atlas-dir=<dir>}
  277. Specify the location of ATLAS. This directory should notably contain
  278. @code{include/cblas.h}.
  279. @end table
  280. @c ---------------------------------------------------------------------
  281. @c Environment variables
  282. @c ---------------------------------------------------------------------
  283. @node Environment variables
  284. @chapter Environment variables
  285. @menu
  286. * Workers:: Configuring workers
  287. * Scheduling:: Configuring the Scheduling engine
  288. * Misc:: Miscellaneous and debug
  289. @end menu
  290. Note: the values given in @code{starpu_conf} structure passed when
  291. calling @code{starpu_init} will override the values of the environment
  292. variables.
  293. @node Workers
  294. @section Configuring workers
  295. @menu
  296. * STARPU_NCPUS:: Number of CPU workers
  297. * STARPU_NCUDA:: Number of CUDA workers
  298. * STARPU_NOPENCL:: Number of OpenCL workers
  299. * STARPU_NGORDON:: Number of SPU workers (Cell)
  300. * STARPU_WORKERS_CPUID:: Bind workers to specific CPUs
  301. * STARPU_WORKERS_CUDAID:: Select specific CUDA devices
  302. * STARPU_WORKERS_OPENCLID:: Select specific OpenCL devices
  303. @end menu
  304. @node STARPU_NCPUS
  305. @subsection @code{STARPU_NCPUS} -- Number of CPU workers
  306. @table @asis
  307. @item @emph{Description}:
  308. Specify the maximum number of CPU workers. Note that StarPU will not allocate
  309. more CPUs than there are physical CPUs, and that some CPUs are used to control
  310. the accelerators.
  311. @end table
  312. @node STARPU_NCUDA
  313. @subsection @code{STARPU_NCUDA} -- Number of CUDA workers
  314. @table @asis
  315. @item @emph{Description}:
  316. Specify the maximum number of CUDA devices that StarPU can use. If
  317. @code{STARPU_NCUDA} is lower than the number of physical devices, it is
  318. possible to select which CUDA devices should be used by the means of the
  319. @code{STARPU_WORKERS_CUDAID} environment variable.
  320. @end table
  321. @node STARPU_NOPENCL
  322. @subsection @code{STARPU_NOPENCL} -- Number of OpenCL workers
  323. @table @asis
  324. @item @emph{Description}:
  325. OpenCL equivalent of the @code{STARPU_NCUDA} environment variable.
  326. @end table
  327. @node STARPU_NGORDON
  328. @subsection @code{STARPU_NGORDON} -- Number of SPU workers (Cell)
  329. @table @asis
  330. @item @emph{Description}:
  331. Specify the maximum number of SPUs that StarPU can use.
  332. @end table
  333. @node STARPU_WORKERS_CPUID
  334. @subsection @code{STARPU_WORKERS_CPUID} -- Bind workers to specific CPUs
  335. @table @asis
  336. @item @emph{Description}:
  337. Passing an array of integers (starting from 0) in @code{STARPU_WORKERS_CPUID}
  338. specifies on which logical CPU the different workers should be
  339. bound. For instance, if @code{STARPU_WORKERS_CPUID = "1 3 0 2"}, the first
  340. worker will be bound to logical CPU #1, the second CPU worker will be bound to
  341. logical CPU #3 and so on. Note that the logical ordering of the CPUs is either
  342. determined by the OS, or provided by the @code{hwloc} library in case it is
  343. available.
  344. Note that the first workers correspond to the CUDA workers, then come the
  345. OpenCL and the SPU, and finally the CPU workers. For example if
  346. we have @code{STARPU_NCUDA=1}, @code{STARPU_NOPENCL=1}, @code{STARPU_NCPUS=2}
  347. and @code{STARPU_WORKERS_CPUID = "0 2 1 3"}, the CUDA device will be controlled
  348. by logical CPU #0, the OpenCL device will be controlled by logical CPU #2, and
  349. the logical CPUs #1 and #3 will be used by the CPU workers.
  350. If the number of workers is larger than the array given in
  351. @code{STARPU_WORKERS_CPUID}, the workers are bound to the logical CPUs in a
  352. round-robin fashion: if @code{STARPU_WORKERS_CPUID = "0 1"}, the first and the
  353. third (resp. second and fourth) workers will be put on CPU #0 (resp. CPU #1).
  354. @end table
  355. @node STARPU_WORKERS_CUDAID
  356. @subsection @code{STARPU_WORKERS_CUDAID} -- Select specific CUDA devices
  357. @table @asis
  358. @item @emph{Description}:
  359. Similarly to the @code{STARPU_WORKERS_CPUID} environment variable, it is
  360. possible to select which CUDA devices should be used by StarPU. On a machine
  361. equipped with 4 GPUs, setting @code{STARPU_WORKERS_CUDAID = "1 3"} and
  362. @code{STARPU_NCUDA=2} specifies that 2 CUDA workers should be created, and that
  363. they should use CUDA devices #1 and #3 (the logical ordering of the devices is
  364. the one reported by CUDA).
  365. @end table
  366. @node STARPU_WORKERS_OPENCLID
  367. @subsection @code{STARPU_WORKERS_OPENCLID} -- Select specific OpenCL devices
  368. @table @asis
  369. @item @emph{Description}:
  370. OpenCL equivalent of the @code{STARPU_WORKERS_CUDAID} environment variable.
  371. @end table
  372. @node Scheduling
  373. @section Configuring the Scheduling engine
  374. @menu
  375. * STARPU_SCHED:: Scheduling policy
  376. * STARPU_CALIBRATE:: Calibrate performance models
  377. * STARPU_PREFETCH:: Use data prefetch
  378. * STARPU_SCHED_ALPHA:: Computation factor
  379. * STARPU_SCHED_BETA:: Communication factor
  380. @end menu
  381. @node STARPU_SCHED
  382. @subsection @code{STARPU_SCHED} -- Scheduling policy
  383. @table @asis
  384. @item @emph{Description}:
  385. This chooses between the different scheduling policies proposed by StarPU: work
  386. random, stealing, greedy, with performance models, etc.
  387. Use @code{STARPU_SCHED=help} to get the list of available schedulers.
  388. @end table
  389. @node STARPU_CALIBRATE
  390. @subsection @code{STARPU_CALIBRATE} -- Calibrate performance models
  391. @table @asis
  392. @item @emph{Description}:
  393. If this variable is set to 1, the performance models are calibrated during
  394. the execution. If it is set to 2, the previous values are dropped to restart
  395. calibration from scratch.
  396. Note: this currently only applies to dm and dmda scheduling policies.
  397. @end table
  398. @node STARPU_PREFETCH
  399. @subsection @code{STARPU_PREFETCH} -- Use data prefetch
  400. @table @asis
  401. @item @emph{Description}:
  402. If this variable is set, data prefetching will be enabled, that is when a task is
  403. scheduled to be executed e.g. on a GPU, StarPU will request an asynchronous
  404. transfer in advance, so that data is already present on the GPU when the task
  405. starts. As a result, computation and data transfers are overlapped.
  406. @end table
  407. @node STARPU_SCHED_ALPHA
  408. @subsection @code{STARPU_SCHED_ALPHA} -- Computation factor
  409. @table @asis
  410. @item @emph{Description}:
  411. To estimate the cost of a task StarPU takes into account the estimated
  412. computation time (obtained thanks to performance models). The alpha factor is
  413. the coefficient to be applied to it before adding it to the communication part.
  414. @end table
  415. @node STARPU_SCHED_BETA
  416. @subsection @code{STARPU_SCHED_BETA} -- Communication factor
  417. @table @asis
  418. @item @emph{Description}:
  419. To estimate the cost of a task StarPU takes into account the estimated
  420. data transfer time (obtained thanks to performance models). The beta factor is
  421. the coefficient to be applied to it before adding it to the computation part.
  422. @end table
  423. @node Misc
  424. @section Miscellaneous and debug
  425. @menu
  426. * STARPU_LOGFILENAME:: Select debug file name
  427. @end menu
  428. @node STARPU_LOGFILENAME
  429. @subsection @code{STARPU_LOGFILENAME} -- Select debug file name
  430. @table @asis
  431. @item @emph{Description}:
  432. This variable specify in which file the debugging output should be saved to.
  433. @end table
  434. @c ---------------------------------------------------------------------
  435. @c StarPU API
  436. @c ---------------------------------------------------------------------
  437. @node StarPU API
  438. @chapter StarPU API
  439. @menu
  440. * Initialization and Termination:: Initialization and Termination methods
  441. * Workers' Properties:: Methods to enumerate workers' properties
  442. * Data Library:: Methods to manipulate data
  443. * Codelets and Tasks:: Methods to construct tasks
  444. * Tags:: Task dependencies
  445. * CUDA extensions:: CUDA extensions
  446. * OpenCL extensions:: OpenCL extensions
  447. * Cell extensions:: Cell extensions
  448. * Miscellaneous:: Miscellaneous helpers
  449. @end menu
  450. @node Initialization and Termination
  451. @section Initialization and Termination
  452. @menu
  453. * starpu_init:: Initialize StarPU
  454. * struct starpu_conf:: StarPU runtime configuration
  455. * starpu_shutdown:: Terminate StarPU
  456. @end menu
  457. @node starpu_init
  458. @subsection @code{starpu_init} -- Initialize StarPU
  459. @table @asis
  460. @item @emph{Description}:
  461. This is StarPU initialization method, which must be called prior to any other
  462. StarPU call. It is possible to specify StarPU's configuration (e.g. scheduling
  463. policy, number of cores, ...) by passing a non-null argument. Default
  464. configuration is used if the passed argument is @code{NULL}.
  465. @item @emph{Return value}:
  466. Upon successful completion, this function returns 0. Otherwise, @code{-ENODEV}
  467. indicates that no worker was available (so that StarPU was not initialized).
  468. @item @emph{Prototype}:
  469. @code{int starpu_init(struct starpu_conf *conf);}
  470. @end table
  471. @node struct starpu_conf
  472. @subsection @code{struct starpu_conf} -- StarPU runtime configuration
  473. @table @asis
  474. @item @emph{Description}:
  475. This structure is passed to the @code{starpu_init} function in order
  476. to configure StarPU.
  477. When the default value is used, StarPU automatically selects the number
  478. of processing units and takes the default scheduling policy. This parameter
  479. overwrites the equivalent environment variables.
  480. @item @emph{Fields}:
  481. @table @asis
  482. @item @code{sched_policy} (default = NULL):
  483. This is the name of the scheduling policy. This can also be specified with the
  484. @code{STARPU_SCHED} environment variable.
  485. @item @code{ncpus} (default = -1):
  486. This is the maximum number of CPU cores that StarPU can use. This can also be
  487. specified with the @code{STARPU_NCPUS} environment variable.
  488. @item @code{ncuda} (default = -1):
  489. This is the maximum number of CUDA devices that StarPU can use. This can also be
  490. specified with the @code{STARPU_NCUDA} environment variable.
  491. @item @code{nopencl} (default = -1):
  492. This is the maximum number of OpenCL devices that StarPU can use. This can also be
  493. specified with the @code{STARPU_NOPENCL} environment variable.
  494. @item @code{nspus} (default = -1):
  495. This is the maximum number of Cell SPUs that StarPU can use. This can also be
  496. specified with the @code{STARPU_NGORDON} environment variable.
  497. @item @code{calibrate} (default = 0):
  498. If this flag is set, StarPU will calibrate the performance models when
  499. executing tasks. This can also be specified with the @code{STARPU_CALIBRATE}
  500. environment variable.
  501. @end table
  502. @end table
  503. @node starpu_shutdown
  504. @subsection @code{starpu_shutdown} -- Terminate StarPU
  505. @table @asis
  506. @item @emph{Description}:
  507. This is StarPU termination method. It must be called at the end of the
  508. application: statistics and other post-mortem debugging information are not
  509. guaranteed to be available until this method has been called.
  510. @item @emph{Prototype}:
  511. @code{void starpu_shutdown(void);}
  512. @end table
  513. @node Workers' Properties
  514. @section Workers' Properties
  515. @menu
  516. * starpu_worker_get_count:: Get the number of processing units
  517. * starpu_cpu_worker_get_count:: Get the number of CPU controlled by StarPU
  518. * starpu_cuda_worker_get_count:: Get the number of CUDA devices controlled by StarPU
  519. * starpu_opencl_worker_get_count:: Get the number of OpenCL devices controlled by StarPU
  520. * starpu_spu_worker_get_count:: Get the number of Cell SPUs controlled by StarPU
  521. * starpu_worker_get_id:: Get the identifier of the current worker
  522. * starpu_worker_get_type:: Get the type of processing unit associated to a worker
  523. * starpu_worker_get_name:: Get the name of a worker
  524. @end menu
  525. @node starpu_worker_get_count
  526. @subsection @code{starpu_worker_get_count} -- Get the number of processing units
  527. @table @asis
  528. @item @emph{Description}:
  529. This function returns the number of workers (i.e. processing units executing
  530. StarPU tasks). The returned value should be at most @code{STARPU_NMAXWORKERS}.
  531. @item @emph{Prototype}:
  532. @code{unsigned starpu_worker_get_count(void);}
  533. @end table
  534. @node starpu_cpu_worker_get_count
  535. @subsection @code{starpu_cpu_worker_get_count} -- Get the number of CPU controlled by StarPU
  536. @table @asis
  537. @item @emph{Description}:
  538. This function returns the number of CPUs controlled by StarPU. The returned
  539. value should be at most @code{STARPU_NMAXCPUS}.
  540. @item @emph{Prototype}:
  541. @code{unsigned starpu_cpu_worker_get_count(void);}
  542. @end table
  543. @node starpu_cuda_worker_get_count
  544. @subsection @code{starpu_cuda_worker_get_count} -- Get the number of CUDA devices controlled by StarPU
  545. @table @asis
  546. @item @emph{Description}:
  547. This function returns the number of CUDA devices controlled by StarPU. The returned
  548. value should be at most @code{STARPU_MAXCUDADEVS}.
  549. @item @emph{Prototype}:
  550. @code{unsigned starpu_cuda_worker_get_count(void);}
  551. @end table
  552. @node starpu_opencl_worker_get_count
  553. @subsection @code{starpu_opencl_worker_get_count} -- Get the number of OpenCL devices controlled by StarPU
  554. @table @asis
  555. @item @emph{Description}:
  556. This function returns the number of OpenCL devices controlled by StarPU. The returned
  557. value should be at most @code{STARPU_MAXOPENCLDEVS}.
  558. @item @emph{Prototype}:
  559. @code{unsigned starpu_opencl_worker_get_count(void);}
  560. @end table
  561. @node starpu_spu_worker_get_count
  562. @subsection @code{starpu_spu_worker_get_count} -- Get the number of Cell SPUs controlled by StarPU
  563. @table @asis
  564. @item @emph{Description}:
  565. This function returns the number of Cell SPUs controlled by StarPU.
  566. @item @emph{Prototype}:
  567. @code{unsigned starpu_opencl_worker_get_count(void);}
  568. @end table
  569. @node starpu_worker_get_id
  570. @subsection @code{starpu_worker_get_id} -- Get the identifier of the current worker
  571. @table @asis
  572. @item @emph{Description}:
  573. This function returns the identifier of the worker associated to the calling
  574. thread. The returned value is either -1 if the current context is not a StarPU
  575. worker (i.e. when called from the application outside a task or a callback), or
  576. an integer between 0 and @code{starpu_worker_get_count() - 1}.
  577. @item @emph{Prototype}:
  578. @code{int starpu_worker_get_id(void);}
  579. @end table
  580. @node starpu_worker_get_type
  581. @subsection @code{starpu_worker_get_type} -- Get the type of processing unit associated to a worker
  582. @table @asis
  583. @item @emph{Description}:
  584. This function returns the type of worker associated to an identifier (as
  585. returned by the @code{starpu_worker_get_id} function). The returned value
  586. indicates the architecture of the worker: @code{STARPU_CPU_WORKER} for a CPU
  587. core, @code{STARPU_CUDA_WORKER} for a CUDA device,
  588. @code{STARPU_OPENCL_WORKER} for a OpenCL device, and
  589. @code{STARPU_GORDON_WORKER} for a Cell SPU. The value returned for an invalid
  590. identifier is unspecified.
  591. @item @emph{Prototype}:
  592. @code{enum starpu_archtype starpu_worker_get_type(int id);}
  593. @end table
  594. @node starpu_worker_get_name
  595. @subsection @code{starpu_worker_get_name} -- Get the name of a worker
  596. @table @asis
  597. @item @emph{Description}:
  598. StarPU associates a unique human readable string to each processing unit. This
  599. function copies at most the @code{maxlen} first bytes of the unique string
  600. associated to a worker identified by its identifier @code{id} into the
  601. @code{dst} buffer. The caller is responsible for ensuring that the @code{dst}
  602. is a valid pointer to a buffer of @code{maxlen} bytes at least. Calling this
  603. function on an invalid identifier results in an unspecified behaviour.
  604. @item @emph{Prototype}:
  605. @code{void starpu_worker_get_name(int id, char *dst, size_t maxlen);}
  606. @end table
  607. @node Data Library
  608. @section Data Library
  609. This section describes the data management facilities provided by StarPU.
  610. TODO: We show how to use existing data interfaces in [ref], but developers can
  611. design their own data interfaces if required.
  612. @menu
  613. * starpu_data_handle:: StarPU opaque data handle
  614. * void *interface:: StarPU data interface
  615. @end menu
  616. @node starpu_data_handle
  617. @subsection @code{starpu_data_handle} -- StarPU opaque data handle
  618. @table @asis
  619. @item @emph{Description}:
  620. StarPU uses @code{starpu_data_handle} as an opaque handle to manage a piece of
  621. data. Once a piece of data has been registered to StarPU, it is associated to a
  622. @code{starpu_data_handle} which keeps track of the state of the piece of data
  623. over the entire machine, so that we can maintain data consistency and locate
  624. data replicates for instance.
  625. @end table
  626. @node void *interface
  627. @subsection @code{void *interface} -- StarPU data interface
  628. @table @asis
  629. @item @emph{Description}:
  630. Data management is done at a high-level in StarPU: rather than accessing a mere
  631. list of contiguous buffers, the tasks may manipulate data that are described by
  632. a high-level construct which we call data interface.
  633. TODO
  634. @end table
  635. @c void starpu_data_unregister(struct starpu_data_state_t *state);
  636. @c starpu_worker_get_memory_node TODO
  637. @c
  638. @c user interaction with the DSM
  639. @c void starpu_data_sync_with_mem(struct starpu_data_state_t *state);
  640. @c void starpu_notify_data_modification(struct starpu_data_state_t *state, uint32_t modifying_node);
  641. @node Codelets and Tasks
  642. @section Codelets and Tasks
  643. @menu
  644. * struct starpu_codelet:: StarPU codelet structure
  645. * struct starpu_task:: StarPU task structure
  646. * starpu_task_init:: Initialize a Task
  647. * starpu_task_create:: Allocate and Initialize a Task
  648. * starpu_task_deinit:: Release all the resources used by a Task
  649. * starpu_task_destroy:: Destroy a dynamically allocated Task
  650. * starpu_task_wait:: Wait for the termination of a Task
  651. * starpu_task_submit:: Submit a Task
  652. * starpu_task_wait_for_all:: Wait for the termination of all Tasks
  653. @end menu
  654. @node struct starpu_codelet
  655. @subsection @code{struct starpu_codelet} -- StarPU codelet structure
  656. @table @asis
  657. @item @emph{Description}:
  658. The codelet structure describes a kernel that is possibly implemented on
  659. various targets.
  660. @item @emph{Fields}:
  661. @table @asis
  662. @item @code{where}:
  663. Indicates which types of processing units are able to execute the codelet.
  664. @code{STARPU_CPU|STARPU_CUDA} for instance indicates that the codelet is
  665. implemented for both CPU cores and CUDA devices while @code{STARPU_GORDON}
  666. indicates that it is only available on Cell SPUs.
  667. @item @code{cpu_func} (optional):
  668. Is a function pointer to the CPU implementation of the codelet. Its prototype
  669. must be: @code{void cpu_func(void *buffers[], void *cl_arg)}. The first
  670. argument being the array of data managed by the data management library, and
  671. the second argument is a pointer to the argument passed from the @code{cl_arg}
  672. field of the @code{starpu_task} structure.
  673. The @code{cpu_func} field is ignored if @code{STARPU_CPU} does not appear in
  674. the @code{where} field, it must be non-null otherwise.
  675. @item @code{cuda_func} (optional):
  676. Is a function pointer to the CUDA implementation of the codelet. @emph{This
  677. must be a host-function written in the CUDA runtime API}. Its prototype must
  678. be: @code{void cuda_func(void *buffers[], void *cl_arg);}. The @code{cuda_func}
  679. field is ignored if @code{STARPU_CUDA} does not appear in the @code{where}
  680. field, it must be non-null otherwise.
  681. @item @code{opencl_func} (optional):
  682. Is a function pointer to the OpenCL implementation of the codelet. Its
  683. prototype must be:
  684. @code{void opencl_func(starpu_data_interface_t *descr, void *arg);}.
  685. This pointer is ignored if @code{OPENCL} does not appear in the
  686. @code{where} field, it must be non-null otherwise.
  687. @item @code{gordon_func} (optional):
  688. This is the index of the Cell SPU implementation within the Gordon library.
  689. TODO
  690. @item @code{nbuffers}:
  691. Specifies the number of arguments taken by the codelet. These arguments are
  692. managed by the DSM and are accessed from the @code{void *buffers[]}
  693. array. The constant argument passed with the @code{cl_arg} field of the
  694. @code{starpu_task} structure is not counted in this number. This value should
  695. not be above @code{STARPU_NMAXBUFS}.
  696. @item @code{model} (optional):
  697. This is a pointer to the performance model associated to this codelet. This
  698. optional field is ignored when null. TODO
  699. @end table
  700. @end table
  701. @node struct starpu_task
  702. @subsection @code{struct starpu_task} -- StarPU task structure
  703. @table @asis
  704. @item @emph{Description}:
  705. The @code{starpu_task} structure describes a task that can be offloaded on the various
  706. processing units managed by StarPU. It instantiates a codelet. It can either be
  707. allocated dynamically with the @code{starpu_task_create} method, or declared
  708. statically. In the latter case, the programmer has to zero the
  709. @code{starpu_task} structure and to fill the different fields properly. The
  710. indicated default values correspond to the configuration of a task allocated
  711. with @code{starpu_task_create}.
  712. @item @emph{Fields}:
  713. @table @asis
  714. @item @code{cl}:
  715. Is a pointer to the corresponding @code{starpu_codelet} data structure. This
  716. describes where the kernel should be executed, and supplies the appropriate
  717. implementations. When set to @code{NULL}, no code is executed during the tasks,
  718. such empty tasks can be useful for synchronization purposes.
  719. @item @code{buffers}:
  720. TODO
  721. @item @code{cl_arg} (optional) (default = NULL):
  722. This pointer is passed to the codelet through the second argument
  723. of the codelet implementation (e.g. @code{cpu_func} or @code{cuda_func}).
  724. In the specific case of the Cell processor, see the @code{cl_arg_size}
  725. argument.
  726. @item @code{cl_arg_size} (optional, Cell specific):
  727. In the case of the Cell processor, the @code{cl_arg} pointer is not directly
  728. given to the SPU function. A buffer of size @code{cl_arg_size} is allocated on
  729. the SPU. This buffer is then filled with the @code{cl_arg_size} bytes starting
  730. at address @code{cl_arg}. In this case, the argument given to the SPU codelet
  731. is therefore not the @code{cl_arg} pointer, but the address of the buffer in
  732. local store (LS) instead. This field is ignored for CPU, CUDA and OpenCL
  733. codelets.
  734. @item @code{callback_func} (optional) (default = @code{NULL}):
  735. This is a function pointer of prototype @code{void (*f)(void *)} which
  736. specifies a possible callback. If this pointer is non-null, the callback
  737. function is executed @emph{on the host} after the execution of the task. The
  738. callback is passed the value contained in the @code{callback_arg} field. No
  739. callback is executed if the field is null.
  740. @item @code{callback_arg} (optional) (default = @code{NULL}):
  741. This is the pointer passed to the callback function. This field is ignored if
  742. the @code{callback_func} is null.
  743. @item @code{use_tag} (optional) (default = 0):
  744. If set, this flag indicates that the task should be associated with the tag
  745. contained in the @code{tag_id} field. Tag allow the application to synchronize
  746. with the task and to express task dependencies easily.
  747. @item @code{tag_id}:
  748. This fields contains the tag associated to the task if the @code{use_tag} field
  749. was set, it is ignored otherwise.
  750. @item @code{synchronous}:
  751. If this flag is set, the @code{starpu_task_submit} function is blocking and
  752. returns only when the task has been executed (or if no worker is able to
  753. process the task). Otherwise, @code{starpu_task_submit} returns immediately.
  754. @item @code{priority} (optional) (default = @code{STARPU_DEFAULT_PRIO}):
  755. This field indicates a level of priority for the task. This is an integer value
  756. that must be set between @code{STARPU_MIN_PRIO} (for the least important
  757. tasks) and @code{STARPU_MAX_PRIO} (for the most important tasks) included.
  758. Default priority is @code{STARPU_DEFAULT_PRIO}. Scheduling strategies that
  759. take priorities into account can use this parameter to take better scheduling
  760. decisions, but the scheduling policy may also ignore it.
  761. @item @code{execute_on_a_specific_worker} (default = 0):
  762. If this flag is set, StarPU will bypass the scheduler and directly affect this
  763. task to the worker specified by the @code{workerid} field.
  764. @item @code{workerid} (optional):
  765. If the @code{execute_on_a_specific_worker} field is set, this field indicates
  766. which is the identifier of the worker that should process this task (as
  767. returned by @code{starpu_worker_get_id}). This field is ignored if
  768. @code{execute_on_a_specific_worker} field is set to 0.
  769. @item @code{detach} (optional) (default = 1):
  770. If this flag is set, it is not possible to synchronize with the task
  771. by the means of @code{starpu_task_wait} later on. Internal data structures
  772. are only guaranteed to be freed once @code{starpu_task_wait} is called if the
  773. flag is not set.
  774. @item @code{destroy} (optional) (default = 1):
  775. If this flag is set, the task structure will automatically be freed, either
  776. after the execution of the callback if the task is detached, or during
  777. @code{starpu_task_wait} otherwise. If this flag is not set, dynamically
  778. allocated data structures will not be freed until @code{starpu_task_destroy} is
  779. called explicitly. Setting this flag for a statically allocated task structure
  780. will result in undefined behaviour.
  781. @end table
  782. @end table
  783. @node starpu_task_init
  784. @subsection @code{starpu_task_init} -- Initialize a Task
  785. @table @asis
  786. @item @emph{Description}:
  787. Initialize a task structure with default values. This function is implicitly
  788. called by @code{starpu_task_create}. By default, tasks initialized with
  789. @code{starpu_task_init} must be deinitialized explicitly with
  790. @code{starpu_task_deinit}. Tasks can also be initialized statically, using the
  791. constant @code{STARPU_TASK_INITIALIZER}.
  792. @item @emph{Prototype}:
  793. @code{void starpu_task_init(struct starpu_task *task);}
  794. @end table
  795. @node starpu_task_create
  796. @subsection @code{starpu_task_create} -- Allocate and Initialize a Task
  797. @table @asis
  798. @item @emph{Description}:
  799. Allocate a task structure and initialize it with default values. Tasks
  800. allocated dynamically with @code{starpu_task_create} are automatically freed when the
  801. task is terminated. If the destroy flag is explicitly unset, the resources used
  802. by the task are freed by calling
  803. @code{starpu_task_destroy}.
  804. @item @emph{Prototype}:
  805. @code{struct starpu_task *starpu_task_create(void);}
  806. @end table
  807. @node starpu_task_deinit
  808. @subsection @code{starpu_task_deinit} -- Release all the resources used by a Task
  809. @table @asis
  810. @item @emph{Description}:
  811. Release all the structures automatically allocated to execute the task. This is
  812. called automatically by @code{starpu_task_destroy}, but the task structure itself is not
  813. freed. This should be used for statically allocated tasks for instance.
  814. @item @emph{Prototype}:
  815. @code{void starpu_task_deinit(struct starpu_task *task);}
  816. @end table
  817. @node starpu_task_destroy
  818. @subsection @code{starpu_task_destroy} -- Destroy a dynamically allocated Task
  819. @table @asis
  820. @item @emph{Description}:
  821. Free the resource allocated during @code{starpu_task_create}. This function can be
  822. called automatically after the execution of a task by setting the
  823. @code{destroy} flag of the @code{starpu_task} structure (default behaviour).
  824. Calling this function on a statically allocated task results in an undefined
  825. behaviour.
  826. @item @emph{Prototype}:
  827. @code{void starpu_task_destroy(struct starpu_task *task);}
  828. @end table
  829. @node starpu_task_wait
  830. @subsection @code{starpu_task_wait} -- Wait for the termination of a Task
  831. @table @asis
  832. @item @emph{Description}:
  833. This function blocks until the task has been executed. It is not possible to
  834. synchronize with a task more than once. It is not possible to wait for
  835. synchronous or detached tasks.
  836. @item @emph{Return value}:
  837. Upon successful completion, this function returns 0. Otherwise, @code{-EINVAL}
  838. indicates that the specified task was either synchronous or detached.
  839. @item @emph{Prototype}:
  840. @code{int starpu_task_wait(struct starpu_task *task);}
  841. @end table
  842. @node starpu_task_submit
  843. @subsection @code{starpu_task_submit} -- Submit a Task
  844. @table @asis
  845. @item @emph{Description}:
  846. This function submits a task to StarPU. Calling this function does
  847. not mean that the task will be executed immediately as there can be data or task
  848. (tag) dependencies that are not fulfilled yet: StarPU will take care of
  849. scheduling this task with respect to such dependencies.
  850. This function returns immediately if the @code{synchronous} field of the
  851. @code{starpu_task} structure was set to 0, and block until the termination of
  852. the task otherwise. It is also possible to synchronize the application with
  853. asynchronous tasks by the means of tags, using the @code{starpu_tag_wait}
  854. function for instance.
  855. @item @emph{Return value}:
  856. In case of success, this function returns 0, a return value of @code{-ENODEV}
  857. means that there is no worker able to process this task (e.g. there is no GPU
  858. available and this task is only implemented for CUDA devices).
  859. @item @emph{Prototype}:
  860. @code{int starpu_task_submit(struct starpu_task *task);}
  861. @end table
  862. @node starpu_task_wait_for_all
  863. @subsection @code{starpu_task_wait_for_all} -- Wait for the termination of all Tasks
  864. @table @asis
  865. @item @emph{Description}:
  866. This function blocks until all the tasks that were submitted are terminated.
  867. @item @emph{Prototype}:
  868. @code{void starpu_task_wait_for_all(void);}
  869. @end table
  870. @c Callbacks : what can we put in callbacks ?
  871. @node Tags
  872. @section Tags
  873. @menu
  874. * starpu_tag_t:: Task identifier
  875. * starpu_tag_declare_deps:: Declare the Dependencies of a Tag
  876. * starpu_tag_declare_deps_array:: Declare the Dependencies of a Tag
  877. * starpu_tag_wait:: Block until a Tag is terminated
  878. * starpu_tag_wait_array:: Block until a set of Tags is terminated
  879. * starpu_tag_remove:: Destroy a Tag
  880. * starpu_tag_notify_from_apps:: Feed a tag explicitly
  881. @end menu
  882. @node starpu_tag_t
  883. @subsection @code{starpu_tag_t} -- Task identifier
  884. @table @asis
  885. @item @emph{Description}:
  886. It is possible to associate a task with a unique ``tag'' and to express
  887. dependencies between tasks by the means of those tags. To do so, fill the
  888. @code{tag_id} field of the @code{starpu_task} structure with a tag number (can
  889. be arbitrary) and set the @code{use_tag} field to 1.
  890. If @code{starpu_tag_declare_deps} is called with this tag number, the task will
  891. not be started until the tasks which holds the declared dependency tags are
  892. completed.
  893. @end table
  894. @node starpu_tag_declare_deps
  895. @subsection @code{starpu_tag_declare_deps} -- Declare the Dependencies of a Tag
  896. @table @asis
  897. @item @emph{Description}:
  898. Specify the dependencies of the task identified by tag @code{id}. The first
  899. argument specifies the tag which is configured, the second argument gives the
  900. number of tag(s) on which @code{id} depends. The following arguments are the
  901. tags which have to be terminated to unlock the task.
  902. This function must be called before the associated task is submitted to StarPU
  903. with @code{starpu_task_submit}.
  904. @item @emph{Remark}
  905. Because of the variable arity of @code{starpu_tag_declare_deps}, note that the
  906. last arguments @emph{must} be of type @code{starpu_tag_t}: constant values
  907. typically need to be explicitly casted. Using the
  908. @code{starpu_tag_declare_deps_array} function avoids this hazard.
  909. @item @emph{Prototype}:
  910. @code{void starpu_tag_declare_deps(starpu_tag_t id, unsigned ndeps, ...);}
  911. @item @emph{Example}:
  912. @cartouche
  913. @example
  914. /* Tag 0x1 depends on tags 0x32 and 0x52 */
  915. starpu_tag_declare_deps((starpu_tag_t)0x1,
  916. 2, (starpu_tag_t)0x32, (starpu_tag_t)0x52);
  917. @end example
  918. @end cartouche
  919. @end table
  920. @node starpu_tag_declare_deps_array
  921. @subsection @code{starpu_tag_declare_deps_array} -- Declare the Dependencies of a Tag
  922. @table @asis
  923. @item @emph{Description}:
  924. This function is similar to @code{starpu_tag_declare_deps}, except that its
  925. does not take a variable number of arguments but an array of tags of size
  926. @code{ndeps}.
  927. @item @emph{Prototype}:
  928. @code{void starpu_tag_declare_deps_array(starpu_tag_t id, unsigned ndeps, starpu_tag_t *array);}
  929. @item @emph{Example}:
  930. @cartouche
  931. @example
  932. /* Tag 0x1 depends on tags 0x32 and 0x52 */
  933. starpu_tag_t tag_array[2] = @{0x32, 0x52@};
  934. starpu_tag_declare_deps_array((starpu_tag_t)0x1, 2, tag_array);
  935. @end example
  936. @end cartouche
  937. @end table
  938. @node starpu_tag_wait
  939. @subsection @code{starpu_tag_wait} -- Block until a Tag is terminated
  940. @table @asis
  941. @item @emph{Description}:
  942. This function blocks until the task associated to tag @code{id} has been
  943. executed. This is a blocking call which must therefore not be called within
  944. tasks or callbacks, but only from the application directly. It is possible to
  945. synchronize with the same tag multiple times, as long as the
  946. @code{starpu_tag_remove} function is not called. Note that it is still
  947. possible to synchronize with a tag associated to a task which @code{starpu_task}
  948. data structure was freed (e.g. if the @code{destroy} flag of the
  949. @code{starpu_task} was enabled).
  950. @item @emph{Prototype}:
  951. @code{void starpu_tag_wait(starpu_tag_t id);}
  952. @end table
  953. @node starpu_tag_wait_array
  954. @subsection @code{starpu_tag_wait_array} -- Block until a set of Tags is terminated
  955. @table @asis
  956. @item @emph{Description}:
  957. This function is similar to @code{starpu_tag_wait} except that it blocks until
  958. @emph{all} the @code{ntags} tags contained in the @code{id} array are
  959. terminated.
  960. @item @emph{Prototype}:
  961. @code{void starpu_tag_wait_array(unsigned ntags, starpu_tag_t *id);}
  962. @end table
  963. @node starpu_tag_remove
  964. @subsection @code{starpu_tag_remove} -- Destroy a Tag
  965. @table @asis
  966. @item @emph{Description}:
  967. This function releases the resources associated to tag @code{id}. It can be
  968. called once the corresponding task has been executed and when there is
  969. no other tag that depend on this tag anymore.
  970. @item @emph{Prototype}:
  971. @code{void starpu_tag_remove(starpu_tag_t id);}
  972. @end table
  973. @node starpu_tag_notify_from_apps
  974. @subsection @code{starpu_tag_notify_from_apps} -- Feed a Tag explicitly
  975. @table @asis
  976. @item @emph{Description}:
  977. This function explicitly unlocks tag @code{id}. It may be useful in the
  978. case of applications which execute part of their computation outside StarPU
  979. tasks (e.g. third-party libraries). It is also provided as a
  980. convenient tool for the programmer, for instance to entirely construct the task
  981. DAG before actually giving StarPU the opportunity to execute the tasks.
  982. @item @emph{Prototype}:
  983. @code{void starpu_tag_notify_from_apps(starpu_tag_t id);}
  984. @end table
  985. @node CUDA extensions
  986. @section CUDA extensions
  987. @c void starpu_data_malloc_pinned_if_possible(float **A, size_t dim);
  988. @c starpu_helper_cublas_init TODO
  989. @c starpu_helper_cublas_shutdown TODO
  990. @menu
  991. * starpu_cuda_get_local_stream:: Get current worker's CUDA stream
  992. * starpu_helper_cublas_init:: Initialize CUBLAS on every CUDA device
  993. * starpu_helper_cublas_shutdown:: Deinitialize CUBLAS on every CUDA device
  994. @end menu
  995. @node starpu_cuda_get_local_stream
  996. @subsection @code{starpu_cuda_get_local_stream} -- Get current worker's CUDA stream
  997. @table @asis
  998. @item @emph{Description}:
  999. StarPU provides a stream for every CUDA device controlled by StarPU. This
  1000. function is only provided for convenience so that programmers can easily use
  1001. asynchronous operations within codelets without having to create a stream by
  1002. hand. Note that the application is not forced to use the stream provided by
  1003. @code{starpu_cuda_get_local_stream} and may also create its own streams.
  1004. @item @emph{Prototype}:
  1005. @code{cudaStream_t *starpu_cuda_get_local_stream(void);}
  1006. @end table
  1007. @node starpu_helper_cublas_init
  1008. @subsection @code{starpu_helper_cublas_init} -- Initialize CUBLAS on every CUDA device
  1009. @table @asis
  1010. @item @emph{Description}:
  1011. The CUBLAS library must be initialized prior to any CUBLAS call. Calling
  1012. @code{starpu_helper_cublas_init} will initialize CUBLAS on every CUDA device
  1013. controlled by StarPU. This call blocks until CUBLAS has been properly
  1014. initialized on every device.
  1015. @item @emph{Prototype}:
  1016. @code{void starpu_helper_cublas_init(void);}
  1017. @end table
  1018. @node starpu_helper_cublas_shutdown
  1019. @subsection @code{starpu_helper_cublas_shutdown} -- Deinitialize CUBLAS on every CUDA device
  1020. @table @asis
  1021. @item @emph{Description}:
  1022. This function synchronously deinitializes the CUBLAS library on every CUDA device.
  1023. @item @emph{Prototype}:
  1024. @code{void starpu_helper_cublas_shutdown(void);}
  1025. @end table
  1026. @node OpenCL extensions
  1027. @section OpenCL extensions
  1028. @menu
  1029. * Enabling OpenCL:: Enabling OpenCL
  1030. * Compiling OpenCL codelets:: Compiling OpenCL codelets
  1031. @end menu
  1032. @node Enabling OpenCL
  1033. @subsection Enabling OpenCL
  1034. On GPU devices which can run both CUDA and OpenCL, CUDA will be
  1035. enabled by default. To enable OpenCL, you need either to disable CUDA
  1036. when configuring StarPU:
  1037. @example
  1038. % ./configure --disable-cuda
  1039. @end example
  1040. or when running applications:
  1041. @example
  1042. % STARPU_NCUDA=0 ./application
  1043. @end example
  1044. OpenCL will automatically be started on any device not yet used by
  1045. CUDA. So on a machine running 4 GPUS, it is therefore possible to
  1046. enable CUDA on 2 devices, and OpenCL on the 2 other devices by doing
  1047. so:
  1048. @example
  1049. % STARPU_NCUDA=2 ./application
  1050. @end example
  1051. @node Compiling OpenCL codelets
  1052. @subsection Compiling OpenCL codelets
  1053. TODO
  1054. @node Cell extensions
  1055. @section Cell extensions
  1056. nothing yet.
  1057. @node Miscellaneous helpers
  1058. @section Miscellaneous helpers
  1059. @menu
  1060. * starpu_execute_on_each_worker:: Execute a function on a subset of workers
  1061. @end menu
  1062. @node starpu_execute_on_each_worker
  1063. @subsection @code{starpu_execute_on_each_worker} -- Execute a function on a subset of workers
  1064. @table @asis
  1065. @item @emph{Description}:
  1066. When calling this method, the offloaded function specified by the first argument is
  1067. executed by every StarPU worker that may execute the function.
  1068. The second argument is passed to the offloaded function.
  1069. The last argument specifies on which types of processing units the function
  1070. should be executed. Similarly to the @code{where} field of the
  1071. @code{starpu_codelet} structure, it is possible to specify that the function
  1072. should be executed on every CUDA device and every CPU by passing
  1073. @code{STARPU_CPU|STARPU_CUDA}.
  1074. This function blocks until the function has been executed on every appropriate
  1075. processing units, so that it may not be called from a callback function for
  1076. instance.
  1077. @item @emph{Prototype}:
  1078. @code{void starpu_execute_on_each_worker(void (*func)(void *), void *arg, uint32_t where);}
  1079. @end table
  1080. @c ---------------------------------------------------------------------
  1081. @c Basic Examples
  1082. @c ---------------------------------------------------------------------
  1083. @node Basic Examples
  1084. @chapter Basic Examples
  1085. @menu
  1086. * Compiling and linking options::
  1087. * Hello World:: Submitting Tasks
  1088. * Manipulating Data: Scaling a Vector::
  1089. * Vector Scaling on an Hybrid CPU/GPU Machine:: Handling Heterogeneous Architectures
  1090. @end menu
  1091. @node Compiling and linking options
  1092. @section Compiling and linking options
  1093. The Makefile could for instance contain the following lines to define which
  1094. options must be given to the compiler and to the linker:
  1095. @cartouche
  1096. @example
  1097. CFLAGS+=$$(pkg-config --cflags libstarpu)
  1098. LIBS+=$$(pkg-config --libs libstarpu)
  1099. @end example
  1100. @end cartouche
  1101. @node Hello World
  1102. @section Hello World
  1103. @menu
  1104. * Required Headers::
  1105. * Defining a Codelet::
  1106. * Submitting a Task::
  1107. @end menu
  1108. In this section, we show how to implement a simple program that submits a task to StarPU.
  1109. @node Required Headers
  1110. @subsection Required Headers
  1111. The @code{starpu.h} header should be included in any code using StarPU.
  1112. @cartouche
  1113. @example
  1114. #include <starpu.h>
  1115. @end example
  1116. @end cartouche
  1117. @node Defining a Codelet
  1118. @subsection Defining a Codelet
  1119. @cartouche
  1120. @example
  1121. void cpu_func(void *buffers[], void *cl_arg)
  1122. @{
  1123. float *array = cl_arg;
  1124. printf("Hello world (array = @{%f, %f@} )\n", array[0], array[1]);
  1125. @}
  1126. starpu_codelet cl =
  1127. @{
  1128. .where = STARPU_CPU,
  1129. .cpu_func = cpu_func,
  1130. .nbuffers = 0
  1131. @};
  1132. @end example
  1133. @end cartouche
  1134. A codelet is a structure that represents a computational kernel. Such a codelet
  1135. may contain an implementation of the same kernel on different architectures
  1136. (e.g. CUDA, Cell's SPU, x86, ...).
  1137. The @code{nbuffers} field specifies the number of data buffers that are
  1138. manipulated by the codelet: here the codelet does not access or modify any data
  1139. that is controlled by our data management library. Note that the argument
  1140. passed to the codelet (the @code{cl_arg} field of the @code{starpu_task}
  1141. structure) does not count as a buffer since it is not managed by our data
  1142. management library.
  1143. @c TODO need a crossref to the proper description of "where" see bla for more ...
  1144. We create a codelet which may only be executed on the CPUs. The @code{where}
  1145. field is a bitmask that defines where the codelet may be executed. Here, the
  1146. @code{STARPU_CPU} value means that only CPUs can execute this codelet
  1147. (@pxref{Codelets and Tasks} for more details on this field).
  1148. When a CPU core executes a codelet, it calls the @code{cpu_func} function,
  1149. which @emph{must} have the following prototype:
  1150. @cartouche
  1151. @example
  1152. void (*cpu_func)(void *buffers[], void *cl_arg);
  1153. @end example
  1154. @end cartouche
  1155. In this example, we can ignore the first argument of this function which gives a
  1156. description of the input and output buffers (e.g. the size and the location of
  1157. the matrices). The second argument is a pointer to a buffer passed as an
  1158. argument to the codelet by the means of the @code{cl_arg} field of the
  1159. @code{starpu_task} structure.
  1160. @c TODO rewrite so that it is a little clearer ?
  1161. Be aware that this may be a pointer to a
  1162. @emph{copy} of the actual buffer, and not the pointer given by the programmer:
  1163. if the codelet modifies this buffer, there is no guarantee that the initial
  1164. buffer will be modified as well: this for instance implies that the buffer
  1165. cannot be used as a synchronization medium.
  1166. @node Submitting a Task
  1167. @subsection Submitting a Task
  1168. @cartouche
  1169. @example
  1170. void callback_func(void *callback_arg)
  1171. @{
  1172. printf("Callback function (arg %x)\n", callback_arg);
  1173. @}
  1174. int main(int argc, char **argv)
  1175. @{
  1176. /* initialize StarPU */
  1177. starpu_init(NULL);
  1178. struct starpu_task *task = starpu_task_create();
  1179. task->cl = &cl;
  1180. float *array[2] = @{1.0f, -1.0f@};
  1181. task->cl_arg = &array;
  1182. task->cl_arg_size = 2*sizeof(float);
  1183. task->callback_func = callback_func;
  1184. task->callback_arg = 0x42;
  1185. /* starpu_task_submit will be a blocking call */
  1186. task->synchronous = 1;
  1187. /* submit the task to StarPU */
  1188. starpu_task_submit(task);
  1189. /* terminate StarPU */
  1190. starpu_shutdown();
  1191. return 0;
  1192. @}
  1193. @end example
  1194. @end cartouche
  1195. Before submitting any tasks to StarPU, @code{starpu_init} must be called. The
  1196. @code{NULL} argument specifies that we use default configuration. Tasks cannot
  1197. be submitted after the termination of StarPU by a call to
  1198. @code{starpu_shutdown}.
  1199. In the example above, a task structure is allocated by a call to
  1200. @code{starpu_task_create}. This function only allocates and fills the
  1201. corresponding structure with the default settings (@pxref{starpu_task_create}),
  1202. but it does not submit the task to StarPU.
  1203. @c not really clear ;)
  1204. The @code{cl} field is a pointer to the codelet which the task will
  1205. execute: in other words, the codelet structure describes which computational
  1206. kernel should be offloaded on the different architectures, and the task
  1207. structure is a wrapper containing a codelet and the piece of data on which the
  1208. codelet should operate.
  1209. The optional @code{cl_arg} field is a pointer to a buffer (of size
  1210. @code{cl_arg_size}) with some parameters for the kernel
  1211. described by the codelet. For instance, if a codelet implements a computational
  1212. kernel that multiplies its input vector by a constant, the constant could be
  1213. specified by the means of this buffer.
  1214. Once a task has been executed, an optional callback function can be called.
  1215. While the computational kernel could be offloaded on various architectures, the
  1216. callback function is always executed on a CPU. The @code{callback_arg}
  1217. pointer is passed as an argument of the callback. The prototype of a callback
  1218. function must be:
  1219. @cartouche
  1220. @example
  1221. void (*callback_function)(void *);
  1222. @end example
  1223. @end cartouche
  1224. If the @code{synchronous} field is non-null, task submission will be
  1225. synchronous: the @code{starpu_task_submit} function will not return until the
  1226. task was executed. Note that the @code{starpu_shutdown} method does not
  1227. guarantee that asynchronous tasks have been executed before it returns.
  1228. @node Manipulating Data: Scaling a Vector
  1229. @section Manipulating Data: Scaling a Vector
  1230. The previous example has shown how to submit tasks. In this section we show how
  1231. StarPU tasks can manipulate data.
  1232. Programmers can describe the data layout of their application so that StarPU is
  1233. responsible for enforcing data coherency and availability across the machine.
  1234. Instead of handling complex (and non-portable) mechanisms to perform data
  1235. movements, programmers only declare which piece of data is accessed and/or
  1236. modified by a task, and StarPU makes sure that when a computational kernel
  1237. starts somewhere (e.g. on a GPU), its data are available locally.
  1238. Before submitting those tasks, the programmer first needs to declare the
  1239. different pieces of data to StarPU using the @code{starpu_*_data_register}
  1240. functions. To ease the development of applications for StarPU, it is possible
  1241. to describe multiple types of data layout. A type of data layout is called an
  1242. @b{interface}. By default, there are different interfaces available in StarPU:
  1243. here we will consider the @b{vector interface}.
  1244. The following lines show how to declare an array of @code{n} elements of type
  1245. @code{float} using the vector interface:
  1246. @cartouche
  1247. @example
  1248. float tab[n];
  1249. starpu_data_handle tab_handle;
  1250. starpu_vector_data_register(&tab_handle, 0, tab, n, sizeof(float));
  1251. @end example
  1252. @end cartouche
  1253. The first argument, called the @b{data handle}, is an opaque pointer which
  1254. designates the array in StarPU. This is also the structure which is used to
  1255. describe which data is used by a task. The second argument is the node number
  1256. where the data currently resides. Here it is 0 since the @code{tab} array is in
  1257. the main memory. Then comes the pointer @code{tab} where the data can be found,
  1258. the number of elements in the vector and the size of each element.
  1259. It is possible to construct a StarPU
  1260. task that multiplies this vector by a constant factor:
  1261. @cartouche
  1262. @example
  1263. float factor = 3.0;
  1264. struct starpu_task *task = starpu_task_create();
  1265. task->cl = &cl;
  1266. task->buffers[0].handle = tab_handle;
  1267. task->buffers[0].mode = STARPU_RW;
  1268. task->cl_arg = &factor;
  1269. task->cl_arg_size = sizeof(float);
  1270. task->synchronous = 1;
  1271. starpu_task_submit(task);
  1272. @end example
  1273. @end cartouche
  1274. Since the factor is constant, it does not need a preliminary declaration, and
  1275. can just be passed through the @code{cl_arg} pointer like in the previous
  1276. example. The vector parameter is described by its handle.
  1277. There are two fields in each element of the @code{buffers} array.
  1278. @code{handle} is the handle of the data, and @code{mode} specifies how the
  1279. kernel will access the data (@code{STARPU_R} for read-only, @code{STARPU_W} for
  1280. write-only and @code{STARPU_RW} for read and write access).
  1281. The definition of the codelet can be written as follows:
  1282. @cartouche
  1283. @example
  1284. void scal_func(void *buffers[], void *cl_arg)
  1285. @{
  1286. unsigned i;
  1287. float *factor = cl_arg;
  1288. struct starpu_vector_interface_s *vector = buffers[0];
  1289. /* length of the vector */
  1290. unsigned n = STARPU_GET_VECTOR_NX(vector);
  1291. /* local copy of the vector pointer */
  1292. float *val = (float *)STARPU_GET_VECTOR_PTR(vector);
  1293. for (i = 0; i < n; i++)
  1294. val[i] *= *factor;
  1295. @}
  1296. starpu_codelet cl = @{
  1297. .where = STARPU_CPU,
  1298. .cpu_func = scal_func,
  1299. .nbuffers = 1
  1300. @};
  1301. @end example
  1302. @end cartouche
  1303. The second argument of the @code{scal_func} function contains a pointer to the
  1304. parameters of the codelet (given in @code{task->cl_arg}), so that we read the
  1305. constant factor from this pointer. The first argument is an array that gives
  1306. a description of every buffers passed in the @code{task->buffers}@ array. The
  1307. size of this array is given by the @code{nbuffers} field of the codelet
  1308. structure. For the sake of generality, this array contains pointers to the
  1309. different interfaces describing each buffer. In the case of the @b{vector
  1310. interface}, the location of the vector (resp. its length) is accessible in the
  1311. @code{ptr} (resp. @code{nx}) of this array. Since the vector is accessed in a
  1312. read-write fashion, any modification will automatically affect future accesses
  1313. to this vector made by other tasks.
  1314. @node Vector Scaling on an Hybrid CPU/GPU Machine
  1315. @section Vector Scaling on an Hybrid CPU/GPU Machine
  1316. Contrary to the previous examples, the task submitted in this example may not
  1317. only be executed by the CPUs, but also by a CUDA device.
  1318. @menu
  1319. * Source code:: Source of the StarPU application
  1320. * Compilation and execution:: Executing the StarPU application
  1321. @end menu
  1322. @node Source code
  1323. @subsection Source code
  1324. The CUDA implementation can be written as follows. It needs to be
  1325. compiled with a CUDA compiler such as nvcc, the NVIDIA CUDA compiler
  1326. driver.
  1327. @cartouche
  1328. @example
  1329. #include <starpu.h>
  1330. static __global__ void vector_mult_cuda(float *val, unsigned n,
  1331. float factor)
  1332. @{
  1333. unsigned i;
  1334. for(i = 0 ; i < n ; i++)
  1335. val[i] *= factor;
  1336. @}
  1337. extern "C" void scal_cuda_func(void *buffers[], void *_args)
  1338. @{
  1339. float *factor = (float *)_args;
  1340. struct starpu_vector_interface_s *vector = (struct starpu_vector_interface_s *) buffers[0];
  1341. /* length of the vector */
  1342. unsigned n = STARPU_GET_VECTOR_NX(vector);
  1343. /* local copy of the vector pointer */
  1344. float *val = (float *)STARPU_GET_VECTOR_PTR(vector);
  1345. /* TODO: use more blocks and threads in blocks */
  1346. vector_mult_cuda<<<1,1>>>(val, n, *factor);
  1347. cudaThreadSynchronize();
  1348. @}
  1349. @end example
  1350. @end cartouche
  1351. The CPU implementation is the same as in the previous section.
  1352. Here is the source of the main application. You can notice the value of the
  1353. field @code{where} for the codelet. We specify
  1354. @code{STARPU_CPU|STARPU_CUDA} to indicate to StarPU that the codelet
  1355. can be executed either on a CPU or on a CUDA device.
  1356. @cartouche
  1357. @example
  1358. #include <starpu.h>
  1359. #define NX 5
  1360. extern void scal_cuda_func(void *buffers[], void *_args);
  1361. extern void scal_func(void *buffers[], void *_args);
  1362. /* @b{Definition of the codelet} */
  1363. static starpu_codelet cl = @{
  1364. .where = STARPU_CPU|STARPU_CUDA; /* @b{It can be executed on a CPU} */
  1365. /* @b{or on a CUDA device} */
  1366. .cuda_func = scal_cuda_func;
  1367. .cpu_func = scal_func;
  1368. .nbuffers = 1;
  1369. @}
  1370. int main(int argc, char **argv)
  1371. @{
  1372. float *vector;
  1373. int i, ret;
  1374. float factor=3.0;
  1375. struct starpu_task *task;
  1376. starpu_data_handle tab_handle;
  1377. starpu_init(NULL); /* @b{Initialising StarPU} */
  1378. vector = (float*)malloc(NX*sizeof(float));
  1379. assert(vector);
  1380. for(i=0 ; i<NX ; i++) vector[i] = i;
  1381. @end example
  1382. @end cartouche
  1383. @cartouche
  1384. @example
  1385. /* @b{Registering data within StarPU} */
  1386. starpu_vector_data_register(&tab_handle, 0, (uintptr_t)vector,
  1387. NX, sizeof(float));
  1388. /* @b{Definition of the task} */
  1389. task = starpu_task_create();
  1390. task->cl = &cl;
  1391. task->callback_func = NULL;
  1392. task->buffers[0].handle = tab_handle;
  1393. task->buffers[0].mode = STARPU_RW;
  1394. task->cl_arg = &factor;
  1395. @end example
  1396. @end cartouche
  1397. @cartouche
  1398. @example
  1399. /* @b{Submitting the task} */
  1400. ret = starpu_task_submit(task);
  1401. if (ret == -ENODEV) @{
  1402. fprintf(stderr, "No worker may execute this task\n");
  1403. return 1;
  1404. @}
  1405. /* @b{Waiting for its termination} */
  1406. starpu_task_wait_for_all();
  1407. /* @b{Update the vector in RAM} */
  1408. starpu_data_sync_with_mem(tab_handle, STARPU_R);
  1409. @end example
  1410. @end cartouche
  1411. @cartouche
  1412. @example
  1413. /* @b{Access the data} */
  1414. for(i=0 ; i<NX; i++) @{
  1415. fprintf(stderr, "%f ", vector[i]);
  1416. @}
  1417. fprintf(stderr, "\n");
  1418. /* @b{Release the data and shutdown StarPU} */
  1419. starpu_data_release_from_mem(tab_handle);
  1420. starpu_shutdown();
  1421. return 0;
  1422. @}
  1423. @end example
  1424. @end cartouche
  1425. @node Compilation and execution
  1426. @subsection Compilation and execution
  1427. Let's suppose StarPU has been installed in the directory
  1428. @code{$STARPU_DIR}. As explained in @ref{pkg-config configuration},
  1429. the variable @code{PKG_CONFIG_PATH} needs to be set. It is also
  1430. necessary to set the variable @code{LD_LIBRARY_PATH} to locate dynamic
  1431. libraries at runtime.
  1432. @example
  1433. % PKG_CONFIG_PATH=$STARPU_DIR/lib/pkgconfig:$PKG_CONFIG_PATH
  1434. % LD_LIBRARY_PATH=$STARPU_DIR/lib:$LD_LIBRARY_PATH
  1435. @end example
  1436. It is then possible to compile the application using the following
  1437. makefile:
  1438. @cartouche
  1439. @example
  1440. CFLAGS += $(shell pkg-config --cflags libstarpu)
  1441. LDFLAGS += $(shell pkg-config --libs libstarpu)
  1442. CC = gcc
  1443. vector: vector.o vector_cpu.o vector_cuda.o
  1444. %.o: %.cu
  1445. nvcc $(CFLAGS) $< -c $@
  1446. clean:
  1447. rm -f vector *.o
  1448. @end example
  1449. @end cartouche
  1450. @example
  1451. % make
  1452. @end example
  1453. and to execute it, with the default configuration:
  1454. @example
  1455. % ./vector
  1456. 0.000000 3.000000 6.000000 9.000000 12.000000
  1457. @end example
  1458. or for example, by disabling CPU devices:
  1459. @example
  1460. % STARPU_NCPUS=0 ./vector
  1461. 0.000000 3.000000 6.000000 9.000000 12.000000
  1462. @end example
  1463. or by disabling CUDA devices:
  1464. @example
  1465. % STARPU_NCUDA=0 ./vector
  1466. 0.000000 3.000000 6.000000 9.000000 12.000000
  1467. @end example
  1468. @c TODO: Add performance model example (and update basic_examples)
  1469. @c ---------------------------------------------------------------------
  1470. @c Advanced Topics
  1471. @c ---------------------------------------------------------------------
  1472. @node Advanced Topics
  1473. @chapter Advanced Topics
  1474. @bye