starpu.texi 76 KB

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