starpu.texi 68 KB

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