starpu.texi 59 KB

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