starpu.texi 68 KB

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