starpu.texi 87 KB

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