starpu.texi 89 KB

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