starpu.texi 115 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394
  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. * Downloading StarPU::
  115. * Configuration of StarPU::
  116. * Building and Installing StarPU::
  117. @end menu
  118. StarPU can be built and installed by the standard means of the GNU
  119. autotools. The following chapter is intended to briefly remind how these tools
  120. can be used to install StarPU.
  121. @node Downloading StarPU
  122. @section Downloading StarPU
  123. @menu
  124. * Getting Sources::
  125. * Optional dependencies::
  126. @end menu
  127. @node Getting Sources
  128. @subsection Getting Sources
  129. The source code is managed by a Subversion server hosted by the
  130. InriaGforge. To get the source code, you need:
  131. @itemize
  132. @item
  133. To install the client side of the software Subversion if it is
  134. not already available on your system. The software can be obtained from
  135. @indicateurl{http://subversion.tigris.org}.
  136. @item
  137. You can check out the project's SVN repository through anonymous
  138. access. This will provide you with a read access to the
  139. repository.
  140. You can also choose to become a member of the project @code{starpu}.
  141. For this, you first need to get an account to the gForge server. You
  142. can then send a request to join the project
  143. (@indicateurl{https://gforge.inria.fr/project/request.php?group_id=1570}).
  144. @item
  145. More information on how to get a gForge account, to become a member of
  146. a project, or on any other related task can be obtained from the
  147. InriaGforge at @indicateurl{https://gforge.inria.fr/}. The most important
  148. thing is to upload your public SSH key on the gForge server (see the
  149. FAQ at @indicateurl{http://siteadmin.gforge.inria.fr/FAQ.html#Q6} for
  150. instructions).
  151. @end itemize
  152. You can now check out the latest version from the Subversion server:
  153. @itemize
  154. @item
  155. using the anonymous access via svn:
  156. @example
  157. % svn checkout svn://scm.gforge.inria.fr/svn/starpu/trunk
  158. @end example
  159. @item
  160. using the anonymous access via https:
  161. @example
  162. % svn checkout --username anonsvn https://scm.gforge.inria.fr/svn/starpu/trunk
  163. @end example
  164. The password is @code{anonsvn}.
  165. @item
  166. using your gForge account
  167. @example
  168. % svn checkout svn+ssh://<login>@@scm.gforge.inria.fr/svn/starpu/trunk
  169. @end example
  170. @end itemize
  171. These steps require to run autoconf and automake to generate the
  172. @code{./configure} script. This can be done by calling
  173. @code{./autogen.sh}. The required version for autoconf is 2.60 or
  174. higher.
  175. @example
  176. % ./autogen.sh
  177. @end example
  178. If the autotools are not available on your machine or not recent
  179. enough, you can choose to download the latest nightly tarball, which
  180. is provided with a @code{configure} script.
  181. @example
  182. % wget http://starpu.gforge.inria.fr/testing/starpu-nightly-latest.tar.gz
  183. @end example
  184. @node Optional dependencies
  185. @subsection Optional dependencies
  186. The topology discovery library, hwloc, is not mandatory to use StarPU
  187. but strongly recommended. It allows to increase performance, and to
  188. perform some topology aware scheduling.
  189. hwloc is available in major distributions and for most OSes and can be
  190. downloaded from @indicateurl{http://www.open-mpi.org/software/hwloc}.
  191. @node Configuration of StarPU
  192. @section Configuration of StarPU
  193. @menu
  194. * Generating Makefiles and configuration scripts::
  195. * Running the configuration::
  196. @end menu
  197. @node Generating Makefiles and configuration scripts
  198. @subsection Generating Makefiles and configuration scripts
  199. This step is not necessary when using the tarball releases of StarPU. If you
  200. are using the source code from the svn repository, you first need to generate
  201. the configure scripts and the Makefiles.
  202. @example
  203. % ./autogen.sh
  204. @end example
  205. @node Running the configuration
  206. @subsection Running the configuration
  207. @example
  208. % ./configure
  209. @end example
  210. Details about options that are useful to give to @code{./configure} are given in
  211. @ref{Compilation configuration}.
  212. @node Building and Installing StarPU
  213. @section Building and Installing StarPU
  214. @menu
  215. * Building::
  216. * Sanity Checks::
  217. * Installing::
  218. @end menu
  219. @node Building
  220. @subsection Building
  221. @example
  222. % make
  223. @end example
  224. @node Sanity Checks
  225. @subsection Sanity Checks
  226. In order to make sure that StarPU is working properly on the system, it is also
  227. possible to run a test suite.
  228. @example
  229. % make check
  230. @end example
  231. @node Installing
  232. @subsection Installing
  233. In order to install StarPU at the location that was specified during
  234. configuration:
  235. @example
  236. % make install
  237. @end example
  238. @c ---------------------------------------------------------------------
  239. @c Using StarPU
  240. @c ---------------------------------------------------------------------
  241. @node Using StarPU
  242. @chapter Using StarPU
  243. @menu
  244. * Setting flags for compiling and linking applications::
  245. * Running a basic StarPU application::
  246. @end menu
  247. @node Setting flags for compiling and linking applications
  248. @section Setting flags for compiling and linking applications
  249. Compiling and linking an application against StarPU may require to use
  250. specific flags or libraries (for instance @code{CUDA} or @code{libspe2}).
  251. To this end, it is possible to use the @code{pkg-config} tool.
  252. If StarPU was not installed at some standard location, the path of StarPU's
  253. library must be specified in the @code{PKG_CONFIG_PATH} environment variable so
  254. that @code{pkg-config} can find it. For example if StarPU was installed in
  255. @code{$prefix_dir}:
  256. @example
  257. % PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$prefix_dir/lib/pkgconfig
  258. @end example
  259. The flags required to compile or link against StarPU are then
  260. accessible with the following commands:
  261. @example
  262. % pkg-config --cflags libstarpu # options for the compiler
  263. % pkg-config --libs libstarpu # options for the linker
  264. @end example
  265. @node Running a basic StarPU application
  266. @section Running a basic StarPU application
  267. Basic examples using StarPU have been built in the directory
  268. @code{$prefix_dir/lib/starpu/examples/}. You can for example run the
  269. example @code{vector_scal}.
  270. @example
  271. % $prefix_dir/lib/starpu/examples/vector_scal
  272. BEFORE : First element was 1.000000
  273. AFTER First element is 3.140000
  274. %
  275. @end example
  276. When StarPU is used for the first time, the directory
  277. @code{$HOME/.starpu/} is created, performance models will be stored in
  278. that directory.
  279. Please note that buses are benchmarked when StarPU is launched for the
  280. first time. This may take a few minutes, or less if @code{hwloc} is
  281. installed. This step is done only once per user and per machine.
  282. @c ---------------------------------------------------------------------
  283. @c Configuration options
  284. @c ---------------------------------------------------------------------
  285. @node Configuring StarPU
  286. @chapter Configuring StarPU
  287. @menu
  288. * Compilation configuration::
  289. * Execution configuration through environment variables::
  290. @end menu
  291. @node Compilation configuration
  292. @section Compilation configuration
  293. The following arguments can be given to the @code{configure} script.
  294. @menu
  295. * Common configuration::
  296. * Configuring workers::
  297. * Advanced configuration::
  298. @end menu
  299. @node Common configuration
  300. @subsection Common configuration
  301. @menu
  302. * --enable-debug::
  303. * --enable-fast::
  304. * --enable-verbose::
  305. * --enable-coverage::
  306. @end menu
  307. @node --enable-debug
  308. @subsubsection @code{--enable-debug}
  309. @table @asis
  310. @item @emph{Description}:
  311. Enable debugging messages.
  312. @end table
  313. @node --enable-fast
  314. @subsubsection @code{--enable-fast}
  315. @table @asis
  316. @item @emph{Description}:
  317. Do not enforce assertions, saves a lot of time spent to compute them otherwise.
  318. @end table
  319. @node --enable-verbose
  320. @subsubsection @code{--enable-verbose}
  321. @table @asis
  322. @item @emph{Description}:
  323. Augment the verbosity of the debugging messages.
  324. @end table
  325. @node --enable-coverage
  326. @subsubsection @code{--enable-coverage}
  327. @table @asis
  328. @item @emph{Description}:
  329. Enable flags for the coverage tool.
  330. @end table
  331. @node Configuring workers
  332. @subsection Configuring workers
  333. @menu
  334. * --enable-nmaxcpus::
  335. * --disable-cpu::
  336. * --enable-maxcudadev::
  337. * --disable-cuda::
  338. * --with-cuda-dir::
  339. * --enable-maxopencldev::
  340. * --disable-opencl::
  341. * --with-opencl-dir::
  342. * --enable-gordon::
  343. * --with-gordon-dir::
  344. @end menu
  345. @node --enable-nmaxcpus
  346. @subsubsection @code{--enable-nmaxcpus=<number>}
  347. @table @asis
  348. @item @emph{Description}:
  349. Defines the maximum number of CPU cores that StarPU will support, then
  350. available as the @code{STARPU_NMAXCPUS} macro.
  351. @end table
  352. @node --disable-cpu
  353. @subsubsection @code{--disable-cpu}
  354. @table @asis
  355. @item @emph{Description}:
  356. Disable the use of CPUs of the machine. Only GPUs etc. will be used.
  357. @end table
  358. @node --enable-maxcudadev
  359. @subsubsection @code{--enable-maxcudadev=<number>}
  360. @table @asis
  361. @item @emph{Description}:
  362. Defines the maximum number of CUDA devices that StarPU will support, then
  363. available as the @code{STARPU_MAXCUDADEVS} macro.
  364. @end table
  365. @node --disable-cuda
  366. @subsubsection @code{--disable-cuda}
  367. @table @asis
  368. @item @emph{Description}:
  369. Disable the use of CUDA, even if a valid CUDA installation was detected.
  370. @end table
  371. @node --with-cuda-dir
  372. @subsubsection @code{--with-cuda-dir=<path>}
  373. @table @asis
  374. @item @emph{Description}:
  375. Specify the directory where CUDA is installed. This directory should notably contain
  376. @code{include/cuda.h}.
  377. @end table
  378. @node --enable-maxopencldev
  379. @subsubsection @code{--enable-maxopencldev=<number>}
  380. @table @asis
  381. @item @emph{Description}:
  382. Defines the maximum number of OpenCL devices that StarPU will support, then
  383. available as the @code{STARPU_MAXOPENCLDEVS} macro.
  384. @end table
  385. @node --disable-opencl
  386. @subsubsection @code{--disable-opencl}
  387. @table @asis
  388. @item @emph{Description}:
  389. Disable the use of OpenCL, even if the SDK is detected.
  390. @end table
  391. @node --with-opencl-dir
  392. @subsubsection @code{--with-opencl-dir=<path>}
  393. @table @asis
  394. @item @emph{Description}:
  395. Specify the location of the OpenCL SDK. This directory should notably contain
  396. @code{include/CL/cl.h}.
  397. @end table
  398. @node --enable-gordon
  399. @subsubsection @code{--enable-gordon}
  400. @table @asis
  401. @item @emph{Description}:
  402. Enable the use of the Gordon runtime for Cell SPUs.
  403. @c TODO: rather default to enabled when detected
  404. @end table
  405. @node --with-gordon-dir
  406. @subsubsection @code{--with-gordon-dir=<path>}
  407. @table @asis
  408. @item @emph{Description}:
  409. Specify the location of the Gordon SDK.
  410. @end table
  411. @node Advanced configuration
  412. @subsection Advanced configuration
  413. @menu
  414. * --enable-perf-debug::
  415. * --enable-model-debug::
  416. * --enable-stats::
  417. * --enable-maxbuffers::
  418. * --enable-allocation-cache::
  419. * --enable-opengl-render::
  420. * --enable-blas-lib::
  421. * --with-magma::
  422. * --with-fxt::
  423. * --with-perf-model-dir::
  424. * --with-mpicc::
  425. * --with-mpi::
  426. * --with-goto-dir::
  427. * --with-atlas-dir::
  428. @end menu
  429. @node --enable-perf-debug
  430. @subsubsection @code{--enable-perf-debug}
  431. @table @asis
  432. @item @emph{Description}:
  433. Enable performance debugging.
  434. @end table
  435. @node --enable-model-debug
  436. @subsubsection @code{--enable-model-debug}
  437. @table @asis
  438. @item @emph{Description}:
  439. Enable performance model debugging.
  440. @end table
  441. @node --enable-stats
  442. @subsubsection @code{--enable-stats}
  443. @table @asis
  444. @item @emph{Description}:
  445. Enable statistics.
  446. @end table
  447. @node --enable-maxbuffers
  448. @subsubsection @code{--enable-maxbuffers=<nbuffers>}
  449. @table @asis
  450. @item @emph{Description}:
  451. Define the maximum number of buffers that tasks will be able to take
  452. as parameters, then available as the @code{STARPU_NMAXBUFS} macro.
  453. @end table
  454. @node --enable-allocation-cache
  455. @subsubsection @code{--enable-allocation-cache}
  456. @table @asis
  457. @item @emph{Description}:
  458. Enable the use of a data allocation cache to avoid the cost of it with
  459. CUDA. Still experimental.
  460. @end table
  461. @node --enable-opengl-render
  462. @subsubsection @code{--enable-opengl-render}
  463. @table @asis
  464. @item @emph{Description}:
  465. Enable the use of OpenGL for the rendering of some examples.
  466. @c TODO: rather default to enabled when detected
  467. @end table
  468. @node --enable-blas-lib
  469. @subsubsection @code{--enable-blas-lib=<name>}
  470. @table @asis
  471. @item @emph{Description}:
  472. Specify the blas library to be used by some of the examples. The
  473. library has to be 'atlas' or 'goto'.
  474. @end table
  475. @node --with-magma
  476. @subsubsection @code{--with-magma=<path>}
  477. @table @asis
  478. @item @emph{Description}:
  479. Specify where magma is installed.
  480. @end table
  481. @node --with-fxt
  482. @subsubsection @code{--with-fxt=<path>}
  483. @table @asis
  484. @item @emph{Description}:
  485. Specify the location of FxT (for generating traces and rendering them
  486. using ViTE). This directory should notably contain
  487. @code{include/fxt/fxt.h}.
  488. @end table
  489. @node --with-perf-model-dir
  490. @subsubsection @code{--with-perf-model-dir=<dir>}
  491. @table @asis
  492. @item @emph{Description}:
  493. Specify where performance models should be stored (instead of defaulting to the
  494. current user's home).
  495. @end table
  496. @node --with-mpicc
  497. @subsubsection @code{--with-mpicc=<path to mpicc>}
  498. @table @asis
  499. @item @emph{Description}:
  500. Specify the location of the @code{mpicc} compiler to be used for starpumpi.
  501. @c TODO: also just use AC_PROG
  502. @end table
  503. @node --with-mpi
  504. @subsubsection @code{--with-mpi}
  505. @table @asis
  506. @item @emph{Description}:
  507. Enable building libstarpumpi.
  508. @c TODO: rather just use the availability of mpicc instead of a second option
  509. @end table
  510. @node --with-goto-dir
  511. @subsubsection @code{--with-goto-dir=<dir>}
  512. @table @asis
  513. @item @emph{Description}:
  514. Specify the location of GotoBLAS.
  515. @end table
  516. @node --with-atlas-dir
  517. @subsubsection @code{--with-atlas-dir=<dir>}
  518. @table @asis
  519. @item @emph{Description}:
  520. Specify the location of ATLAS. This directory should notably contain
  521. @code{include/cblas.h}.
  522. @end table
  523. @c ---------------------------------------------------------------------
  524. @c Environment variables
  525. @c ---------------------------------------------------------------------
  526. @node Execution configuration through environment variables
  527. @section Execution configuration through environment variables
  528. @menu
  529. * Workers:: Configuring workers
  530. * Scheduling:: Configuring the Scheduling engine
  531. * Misc:: Miscellaneous and debug
  532. @end menu
  533. Note: the values given in @code{starpu_conf} structure passed when
  534. calling @code{starpu_init} will override the values of the environment
  535. variables.
  536. @node Workers
  537. @subsection Configuring workers
  538. @menu
  539. * STARPU_NCPUS:: Number of CPU workers
  540. * STARPU_NCUDA:: Number of CUDA workers
  541. * STARPU_NOPENCL:: Number of OpenCL workers
  542. * STARPU_NGORDON:: Number of SPU workers (Cell)
  543. * STARPU_WORKERS_CPUID:: Bind workers to specific CPUs
  544. * STARPU_WORKERS_CUDAID:: Select specific CUDA devices
  545. * STARPU_WORKERS_OPENCLID:: Select specific OpenCL devices
  546. @end menu
  547. @node STARPU_NCPUS
  548. @subsubsection @code{STARPU_NCPUS} -- Number of CPU workers
  549. @table @asis
  550. @item @emph{Description}:
  551. Specify the maximum number of CPU workers. Note that StarPU will not allocate
  552. more CPUs than there are physical CPUs, and that some CPUs are used to control
  553. the accelerators.
  554. @end table
  555. @node STARPU_NCUDA
  556. @subsubsection @code{STARPU_NCUDA} -- Number of CUDA workers
  557. @table @asis
  558. @item @emph{Description}:
  559. Specify the maximum number of CUDA devices that StarPU can use. If
  560. @code{STARPU_NCUDA} is lower than the number of physical devices, it is
  561. possible to select which CUDA devices should be used by the means of the
  562. @code{STARPU_WORKERS_CUDAID} environment variable.
  563. @end table
  564. @node STARPU_NOPENCL
  565. @subsubsection @code{STARPU_NOPENCL} -- Number of OpenCL workers
  566. @table @asis
  567. @item @emph{Description}:
  568. OpenCL equivalent of the @code{STARPU_NCUDA} environment variable.
  569. @end table
  570. @node STARPU_NGORDON
  571. @subsubsection @code{STARPU_NGORDON} -- Number of SPU workers (Cell)
  572. @table @asis
  573. @item @emph{Description}:
  574. Specify the maximum number of SPUs that StarPU can use.
  575. @end table
  576. @node STARPU_WORKERS_CPUID
  577. @subsubsection @code{STARPU_WORKERS_CPUID} -- Bind workers to specific CPUs
  578. @table @asis
  579. @item @emph{Description}:
  580. Passing an array of integers (starting from 0) in @code{STARPU_WORKERS_CPUID}
  581. specifies on which logical CPU the different workers should be
  582. bound. For instance, if @code{STARPU_WORKERS_CPUID = "1 3 0 2"}, the first
  583. worker will be bound to logical CPU #1, the second CPU worker will be bound to
  584. logical CPU #3 and so on. Note that the logical ordering of the CPUs is either
  585. determined by the OS, or provided by the @code{hwloc} library in case it is
  586. available.
  587. Note that the first workers correspond to the CUDA workers, then come the
  588. OpenCL and the SPU, and finally the CPU workers. For example if
  589. we have @code{STARPU_NCUDA=1}, @code{STARPU_NOPENCL=1}, @code{STARPU_NCPUS=2}
  590. and @code{STARPU_WORKERS_CPUID = "0 2 1 3"}, the CUDA device will be controlled
  591. by logical CPU #0, the OpenCL device will be controlled by logical CPU #2, and
  592. the logical CPUs #1 and #3 will be used by the CPU workers.
  593. If the number of workers is larger than the array given in
  594. @code{STARPU_WORKERS_CPUID}, the workers are bound to the logical CPUs in a
  595. round-robin fashion: if @code{STARPU_WORKERS_CPUID = "0 1"}, the first and the
  596. third (resp. second and fourth) workers will be put on CPU #0 (resp. CPU #1).
  597. This variable is ignored if the @code{use_explicit_workers_bindid} flag of the
  598. @code{starpu_conf} structure passed to @code{starpu_init} is set.
  599. @end table
  600. @node STARPU_WORKERS_CUDAID
  601. @subsubsection @code{STARPU_WORKERS_CUDAID} -- Select specific CUDA devices
  602. @table @asis
  603. @item @emph{Description}:
  604. Similarly to the @code{STARPU_WORKERS_CPUID} environment variable, it is
  605. possible to select which CUDA devices should be used by StarPU. On a machine
  606. equipped with 4 GPUs, setting @code{STARPU_WORKERS_CUDAID = "1 3"} and
  607. @code{STARPU_NCUDA=2} specifies that 2 CUDA workers should be created, and that
  608. they should use CUDA devices #1 and #3 (the logical ordering of the devices is
  609. the one reported by CUDA).
  610. This variable is ignored if the @code{use_explicit_workers_cuda_gpuid} flag of
  611. the @code{starpu_conf} structure passed to @code{starpu_init} is set.
  612. @end table
  613. @node STARPU_WORKERS_OPENCLID
  614. @subsubsection @code{STARPU_WORKERS_OPENCLID} -- Select specific OpenCL devices
  615. @table @asis
  616. @item @emph{Description}:
  617. OpenCL equivalent of the @code{STARPU_WORKERS_CUDAID} environment variable.
  618. This variable is ignored if the @code{use_explicit_workers_opencl_gpuid} flag of
  619. the @code{starpu_conf} structure passed to @code{starpu_init} is set.
  620. @end table
  621. @node Scheduling
  622. @subsection Configuring the Scheduling engine
  623. @menu
  624. * STARPU_SCHED:: Scheduling policy
  625. * STARPU_CALIBRATE:: Calibrate performance models
  626. * STARPU_PREFETCH:: Use data prefetch
  627. * STARPU_SCHED_ALPHA:: Computation factor
  628. * STARPU_SCHED_BETA:: Communication factor
  629. @end menu
  630. @node STARPU_SCHED
  631. @subsubsection @code{STARPU_SCHED} -- Scheduling policy
  632. @table @asis
  633. @item @emph{Description}:
  634. This chooses between the different scheduling policies proposed by StarPU: work
  635. random, stealing, greedy, with performance models, etc.
  636. Use @code{STARPU_SCHED=help} to get the list of available schedulers.
  637. @end table
  638. @node STARPU_CALIBRATE
  639. @subsubsection @code{STARPU_CALIBRATE} -- Calibrate performance models
  640. @table @asis
  641. @item @emph{Description}:
  642. If this variable is set to 1, the performance models are calibrated during
  643. the execution. If it is set to 2, the previous values are dropped to restart
  644. calibration from scratch.
  645. Note: this currently only applies to dm and dmda scheduling policies.
  646. @end table
  647. @node STARPU_PREFETCH
  648. @subsubsection @code{STARPU_PREFETCH} -- Use data prefetch
  649. @table @asis
  650. @item @emph{Description}:
  651. This variable indicates whether data prefetching should be enabled (0 means
  652. that it is disabled). If prefetching is enabled, when a task is scheduled to be
  653. executed e.g. on a GPU, StarPU will request an asynchronous transfer in
  654. advance, so that data is already present on the GPU when the task starts. As a
  655. result, computation and data transfers are overlapped.
  656. @end table
  657. @node STARPU_SCHED_ALPHA
  658. @subsubsection @code{STARPU_SCHED_ALPHA} -- Computation factor
  659. @table @asis
  660. @item @emph{Description}:
  661. To estimate the cost of a task StarPU takes into account the estimated
  662. computation time (obtained thanks to performance models). The alpha factor is
  663. the coefficient to be applied to it before adding it to the communication part.
  664. @end table
  665. @node STARPU_SCHED_BETA
  666. @subsubsection @code{STARPU_SCHED_BETA} -- Communication factor
  667. @table @asis
  668. @item @emph{Description}:
  669. To estimate the cost of a task StarPU takes into account the estimated
  670. data transfer time (obtained thanks to performance models). The beta factor is
  671. the coefficient to be applied to it before adding it to the computation part.
  672. @end table
  673. @node Misc
  674. @subsection Miscellaneous and debug
  675. @menu
  676. * STARPU_LOGFILENAME:: Select debug file name
  677. @end menu
  678. @node STARPU_LOGFILENAME
  679. @subsubsection @code{STARPU_LOGFILENAME} -- Select debug file name
  680. @table @asis
  681. @item @emph{Description}:
  682. This variable specify in which file the debugging output should be saved to.
  683. @end table
  684. @c ---------------------------------------------------------------------
  685. @c StarPU API
  686. @c ---------------------------------------------------------------------
  687. @node StarPU API
  688. @chapter StarPU API
  689. @menu
  690. * Initialization and Termination:: Initialization and Termination methods
  691. * Workers' Properties:: Methods to enumerate workers' properties
  692. * Data Library:: Methods to manipulate data
  693. * Data Interfaces::
  694. * Data Partition::
  695. * Codelets and Tasks:: Methods to construct tasks
  696. * Explicit Dependencies:: Explicit Dependencies
  697. * Implicit Data Dependencies:: Implicit Data Dependencies
  698. * Performance Model API::
  699. * Profiling API:: Profiling API
  700. * CUDA extensions:: CUDA extensions
  701. * OpenCL extensions:: OpenCL extensions
  702. * Cell extensions:: Cell extensions
  703. * Miscellaneous helpers::
  704. @end menu
  705. @node Initialization and Termination
  706. @section Initialization and Termination
  707. @menu
  708. * starpu_init:: Initialize StarPU
  709. * struct starpu_conf:: StarPU runtime configuration
  710. * starpu_shutdown:: Terminate StarPU
  711. @end menu
  712. @node starpu_init
  713. @subsection @code{starpu_init} -- Initialize StarPU
  714. @table @asis
  715. @item @emph{Description}:
  716. This is StarPU initialization method, which must be called prior to any other
  717. StarPU call. It is possible to specify StarPU's configuration (e.g. scheduling
  718. policy, number of cores, ...) by passing a non-null argument. Default
  719. configuration is used if the passed argument is @code{NULL}.
  720. @item @emph{Return value}:
  721. Upon successful completion, this function returns 0. Otherwise, @code{-ENODEV}
  722. indicates that no worker was available (so that StarPU was not initialized).
  723. @item @emph{Prototype}:
  724. @code{int starpu_init(struct starpu_conf *conf);}
  725. @end table
  726. @node struct starpu_conf
  727. @subsection @code{struct starpu_conf} -- StarPU runtime configuration
  728. @table @asis
  729. @item @emph{Description}:
  730. This structure is passed to the @code{starpu_init} function in order
  731. to configure StarPU.
  732. When the default value is used, StarPU automatically selects the number
  733. of processing units and takes the default scheduling policy. This parameter
  734. overwrites the equivalent environment variables.
  735. @item @emph{Fields}:
  736. @table @asis
  737. @item @code{sched_policy_name} (default = NULL):
  738. This is the name of the scheduling policy. This can also be specified with the
  739. @code{STARPU_SCHED} environment variable.
  740. @item @code{sched_policy} (default = NULL):
  741. This is the definition of the scheduling policy. This field is ignored
  742. if @code{sched_policy_name} is set.
  743. @item @code{ncpus} (default = -1):
  744. This is the maximum number of CPU cores that StarPU can use. This can also be
  745. specified with the @code{STARPU_NCPUS} environment variable.
  746. @item @code{ncuda} (default = -1):
  747. This is the maximum number of CUDA devices that StarPU can use. This can also be
  748. specified with the @code{STARPU_NCUDA} environment variable.
  749. @item @code{nopencl} (default = -1):
  750. This is the maximum number of OpenCL devices that StarPU can use. This can also be
  751. specified with the @code{STARPU_NOPENCL} environment variable.
  752. @item @code{nspus} (default = -1):
  753. This is the maximum number of Cell SPUs that StarPU can use. This can also be
  754. specified with the @code{STARPU_NGORDON} environment variable.
  755. @item @code{use_explicit_workers_bindid} (default = 0)
  756. If this flag is set, the @code{workers_bindid} array indicates where the
  757. different workers are bound, otherwise StarPU automatically selects where to
  758. bind the different workers unless the @code{STARPU_WORKERS_CPUID} environment
  759. variable is set. The @code{STARPU_WORKERS_CPUID} environment variable is
  760. ignored if the @code{use_explicit_workers_bindid} flag is set.
  761. @item @code{workers_bindid[STARPU_NMAXWORKERS]}
  762. If the @code{use_explicit_workers_bindid} flag is set, this array indicates
  763. where to bind the different workers. The i-th entry of the
  764. @code{workers_bindid} indicates the logical identifier of the processor which
  765. should execute the i-th worker. Note that the logical ordering of the CPUs is
  766. either determined by the OS, or provided by the @code{hwloc} library in case it
  767. is available.
  768. When this flag is set, the @ref{STARPU_WORKERS_CPUID} environment variable is
  769. ignored.
  770. @item @code{use_explicit_workers_cuda_gpuid} (default = 0)
  771. If this flag is set, the CUDA workers will be attached to the CUDA devices
  772. specified in the @code{workers_cuda_gpuid} array. Otherwise, StarPU affects the
  773. CUDA devices in a round-robin fashion.
  774. When this flag is set, the @ref{STARPU_WORKERS_CUDAID} environment variable is
  775. ignored.
  776. @item @code{workers_cuda_gpuid[STARPU_NMAXWORKERS]}
  777. If the @code{use_explicit_workers_cuda_gpuid} flag is set, this array contains
  778. the logical identifiers of the CUDA devices (as used by @code{cudaGetDevice}).
  779. @item @code{use_explicit_workers_opencl_gpuid} (default = 0)
  780. If this flag is set, the OpenCL workers will be attached to the OpenCL devices
  781. specified in the @code{workers_opencl_gpuid} array. Otherwise, StarPU affects the
  782. OpenCL devices in a round-robin fashion.
  783. @item @code{workers_opencl_gpuid[STARPU_NMAXWORKERS]}:
  784. @item @code{calibrate} (default = 0):
  785. If this flag is set, StarPU will calibrate the performance models when
  786. executing tasks. If this value is equal to -1, the default value is used. The
  787. default value is overwritten by the @code{STARPU_CALIBRATE} environment
  788. variable when it is set.
  789. @end table
  790. @end table
  791. @node starpu_shutdown
  792. @subsection @code{starpu_shutdown} -- Terminate StarPU
  793. @table @asis
  794. @item @emph{Description}:
  795. This is StarPU termination method. It must be called at the end of the
  796. application: statistics and other post-mortem debugging information are not
  797. guaranteed to be available until this method has been called.
  798. @item @emph{Prototype}:
  799. @code{void starpu_shutdown(void);}
  800. @end table
  801. @node Workers' Properties
  802. @section Workers' Properties
  803. @menu
  804. * starpu_worker_get_count:: Get the number of processing units
  805. * starpu_cpu_worker_get_count:: Get the number of CPU controlled by StarPU
  806. * starpu_cuda_worker_get_count:: Get the number of CUDA devices controlled by StarPU
  807. * starpu_opencl_worker_get_count:: Get the number of OpenCL devices controlled by StarPU
  808. * starpu_spu_worker_get_count:: Get the number of Cell SPUs controlled by StarPU
  809. * starpu_worker_get_id:: Get the identifier of the current worker
  810. * starpu_worker_get_devid:: Get the device identifier of a worker
  811. * starpu_worker_get_type:: Get the type of processing unit associated to a worker
  812. * starpu_worker_get_name:: Get the name of a worker
  813. * starpu_worker_get_memory_node:: Get the memory node of a worker
  814. @end menu
  815. @node starpu_worker_get_count
  816. @subsection @code{starpu_worker_get_count} -- Get the number of processing units
  817. @table @asis
  818. @item @emph{Description}:
  819. This function returns the number of workers (i.e. processing units executing
  820. StarPU tasks). The returned value should be at most @code{STARPU_NMAXWORKERS}.
  821. @item @emph{Prototype}:
  822. @code{unsigned starpu_worker_get_count(void);}
  823. @end table
  824. @node starpu_cpu_worker_get_count
  825. @subsection @code{starpu_cpu_worker_get_count} -- Get the number of CPU controlled by StarPU
  826. @table @asis
  827. @item @emph{Description}:
  828. This function returns the number of CPUs controlled by StarPU. The returned
  829. value should be at most @code{STARPU_NMAXCPUS}.
  830. @item @emph{Prototype}:
  831. @code{unsigned starpu_cpu_worker_get_count(void);}
  832. @end table
  833. @node starpu_cuda_worker_get_count
  834. @subsection @code{starpu_cuda_worker_get_count} -- Get the number of CUDA devices controlled by StarPU
  835. @table @asis
  836. @item @emph{Description}:
  837. This function returns the number of CUDA devices controlled by StarPU. The returned
  838. value should be at most @code{STARPU_MAXCUDADEVS}.
  839. @item @emph{Prototype}:
  840. @code{unsigned starpu_cuda_worker_get_count(void);}
  841. @end table
  842. @node starpu_opencl_worker_get_count
  843. @subsection @code{starpu_opencl_worker_get_count} -- Get the number of OpenCL devices controlled by StarPU
  844. @table @asis
  845. @item @emph{Description}:
  846. This function returns the number of OpenCL devices controlled by StarPU. The returned
  847. value should be at most @code{STARPU_MAXOPENCLDEVS}.
  848. @item @emph{Prototype}:
  849. @code{unsigned starpu_opencl_worker_get_count(void);}
  850. @end table
  851. @node starpu_spu_worker_get_count
  852. @subsection @code{starpu_spu_worker_get_count} -- Get the number of Cell SPUs controlled by StarPU
  853. @table @asis
  854. @item @emph{Description}:
  855. This function returns the number of Cell SPUs controlled by StarPU.
  856. @item @emph{Prototype}:
  857. @code{unsigned starpu_opencl_worker_get_count(void);}
  858. @end table
  859. @node starpu_worker_get_id
  860. @subsection @code{starpu_worker_get_id} -- Get the identifier of the current worker
  861. @table @asis
  862. @item @emph{Description}:
  863. This function returns the identifier of the worker associated to the calling
  864. thread. The returned value is either -1 if the current context is not a StarPU
  865. worker (i.e. when called from the application outside a task or a callback), or
  866. an integer between 0 and @code{starpu_worker_get_count() - 1}.
  867. @item @emph{Prototype}:
  868. @code{int starpu_worker_get_id(void);}
  869. @end table
  870. @node starpu_worker_get_devid
  871. @subsection @code{starpu_worker_get_devid} -- Get the device identifier of a worker
  872. @table @asis
  873. @item @emph{Description}:
  874. This functions returns the device id of the worker associated to an identifier
  875. (as returned by the @code{starpu_worker_get_id} function). In the case of a
  876. CUDA worker, this device identifier is the logical device identifier exposed by
  877. CUDA (used by the @code{cudaGetDevice} function for instance). The device
  878. identifier of a CPU worker is the logical identifier of the core on which the
  879. worker was bound; this identifier is either provided by the OS or by the
  880. @code{hwloc} library in case it is available.
  881. @item @emph{Prototype}:
  882. @code{int starpu_worker_get_devid(int id);}
  883. @end table
  884. @node starpu_worker_get_type
  885. @subsection @code{starpu_worker_get_type} -- Get the type of processing unit associated to a worker
  886. @table @asis
  887. @item @emph{Description}:
  888. This function returns the type of worker associated to an identifier (as
  889. returned by the @code{starpu_worker_get_id} function). The returned value
  890. indicates the architecture of the worker: @code{STARPU_CPU_WORKER} for a CPU
  891. core, @code{STARPU_CUDA_WORKER} for a CUDA device,
  892. @code{STARPU_OPENCL_WORKER} for a OpenCL device, and
  893. @code{STARPU_GORDON_WORKER} for a Cell SPU. The value returned for an invalid
  894. identifier is unspecified.
  895. @item @emph{Prototype}:
  896. @code{enum starpu_archtype starpu_worker_get_type(int id);}
  897. @end table
  898. @node starpu_worker_get_name
  899. @subsection @code{starpu_worker_get_name} -- Get the name of a worker
  900. @table @asis
  901. @item @emph{Description}:
  902. StarPU associates a unique human readable string to each processing unit. This
  903. function copies at most the @code{maxlen} first bytes of the unique string
  904. associated to a worker identified by its identifier @code{id} into the
  905. @code{dst} buffer. The caller is responsible for ensuring that the @code{dst}
  906. is a valid pointer to a buffer of @code{maxlen} bytes at least. Calling this
  907. function on an invalid identifier results in an unspecified behaviour.
  908. @item @emph{Prototype}:
  909. @code{void starpu_worker_get_name(int id, char *dst, size_t maxlen);}
  910. @end table
  911. @node starpu_worker_get_memory_node
  912. @subsection @code{starpu_worker_get_memory_node} -- Get the memory node of a worker
  913. @table @asis
  914. @item @emph{Description}:
  915. This function returns the identifier of the memory node associated to the
  916. worker identified by @code{workerid}.
  917. @item @emph{Prototype}:
  918. @code{unsigned starpu_worker_get_memory_node(unsigned workerid);}
  919. @end table
  920. @node Data Library
  921. @section Data Library
  922. This section describes the data management facilities provided by StarPU.
  923. We show how to use existing data interfaces in @ref{Data Interfaces}, but developers can
  924. design their own data interfaces if required.
  925. @menu
  926. * starpu_access_mode:: starpu_access_mode
  927. * unsigned memory_node:: Memory node
  928. * starpu_data_handle:: StarPU opaque data handle
  929. * void *interface:: StarPU data interface
  930. * starpu_data_register:: Register a piece of data to StarPU
  931. * starpu_data_unregister:: Unregister a piece of data from StarPU
  932. * starpu_data_invalidate:: Invalidate all data replicates
  933. * starpu_data_acquire:: Access registered data from the application
  934. * starpu_data_acquire_cb:: Access registered data from the application asynchronously
  935. * starpu_data_release:: Release registered data from the application
  936. @end menu
  937. @node starpu_access_mode
  938. @subsection @code{starpu_access_mode} -- Data access mode
  939. This datatype describes a data access mode. The different available modes are:
  940. @table @asis
  941. @table @asis
  942. @item @code{STARPU_R} read-only mode.
  943. @item @code{STARPU_W} write-only mode.
  944. @item @code{STARPU_RW} read-write mode. This is equivalent to @code{STARPU_R|STARPU_W}.
  945. @item @code{STARPU_SCRATCH} scratch memory. A temporary buffer is allocated for the task, but StarPU does not enforce data consistency.
  946. @end table
  947. @end table
  948. @node unsigned memory_node
  949. @subsection @code{unsigned memory_node} -- Memory node
  950. @table @asis
  951. @item @emph{Description}:
  952. Every worker is associated to a memory node which is a logical abstraction of
  953. the address space from which the processing unit gets its data. For instance,
  954. the memory node associated to the different CPU workers represents main memory
  955. (RAM), the memory node associated to a GPU is DRAM embedded on the device.
  956. Every memory node is identified by a logical index which is accessible from the
  957. @code{starpu_worker_get_memory_node} function. When registering a piece of data
  958. to StarPU, the specified memory node indicates where the piece of data
  959. initially resides (we also call this memory node the home node of a piece of
  960. data).
  961. @end table
  962. @node starpu_data_handle
  963. @subsection @code{starpu_data_handle} -- StarPU opaque data handle
  964. @table @asis
  965. @item @emph{Description}:
  966. StarPU uses @code{starpu_data_handle} as an opaque handle to manage a piece of
  967. data. Once a piece of data has been registered to StarPU, it is associated to a
  968. @code{starpu_data_handle} which keeps track of the state of the piece of data
  969. over the entire machine, so that we can maintain data consistency and locate
  970. data replicates for instance.
  971. @end table
  972. @node void *interface
  973. @subsection @code{void *interface} -- StarPU data interface
  974. @table @asis
  975. @item @emph{Description}:
  976. Data management is done at a high-level in StarPU: rather than accessing a mere
  977. list of contiguous buffers, the tasks may manipulate data that are described by
  978. a high-level construct which we call data interface.
  979. An example of data interface is the "vector" interface which describes a
  980. contiguous data array on a spefic memory node. This interface is a simple
  981. structure containing the number of elements in the array, the size of the
  982. elements, and the address of the array in the appropriate address space (this
  983. address may be invalid if there is no valid copy of the array in the memory
  984. node). More informations on the data interfaces provided by StarPU are
  985. given in @ref{Data Interfaces}.
  986. When a piece of data managed by StarPU is used by a task, the task
  987. implementation is given a pointer to an interface describing a valid copy of
  988. the data that is accessible from the current processing unit.
  989. @end table
  990. @node starpu_data_register
  991. @subsection @code{starpu_data_register} -- Register a piece of data to StarPU
  992. @table @asis
  993. @item @emph{Description}:
  994. Register a piece of data into the handle located at the @code{handleptr}
  995. address. The @code{interface} buffer contains the initial description of the
  996. data in the home node. The @code{ops} argument is a pointer to a structure
  997. describing the different methods used to manipulate this type of interface. See
  998. @ref{struct starpu_data_interface_ops_t} for more details on this structure.
  999. If @code{home_node} is not a valid memory node, StarPU will automatically
  1000. allocate the memory described by the interface the data handle is used for the
  1001. first time in write-only mode. Once such data handle has been automatically
  1002. allocated, it is possible to access it using any access mode.
  1003. Note that StarPU supplies a set of predefined types of interface (e.g. vector or
  1004. matrix) which can be registered by the means of helper functions (e.g.
  1005. @code{starpu_vector_data_register} or @code{starpu_matrix_data_register}).
  1006. @item @emph{Prototype}:
  1007. @code{void starpu_data_register(starpu_data_handle *handleptr,
  1008. uint32_t home_node,
  1009. void *interface,
  1010. struct starpu_data_interface_ops_t *ops);}
  1011. @end table
  1012. @node starpu_data_unregister
  1013. @subsection @code{starpu_data_unregister} -- Unregister a piece of data from StarPU
  1014. @table @asis
  1015. @item @emph{Description}:
  1016. This function unregisters a data handle from StarPU. If the data was
  1017. automatically allocated by StarPU because the home node was not valid, all
  1018. automatically allocated buffers are freed. Otherwise, a valid copy of the data
  1019. is put back into the home node in the buffer that was initially registered.
  1020. Using a data handle that has been unregistered from StarPU results in an
  1021. undefined behaviour.
  1022. @item @emph{Prototype}:
  1023. @code{void starpu_data_unregister(starpu_data_handle handle);}
  1024. @end table
  1025. @node starpu_data_invalidate
  1026. @subsection @code{starpu_data_invalidate} -- Invalidate all data replicates
  1027. @table @asis
  1028. @item @emph{Description}:
  1029. Destroy all replicates of the data handle. After data invalidation, the first
  1030. access to the handle must be performed in write-only mode. Accessing an
  1031. invalidated data in read-mode results in undefined behaviour.
  1032. @item @emph{Prototype}:
  1033. @code{void starpu_data_invalidate(starpu_data_handle handle);}
  1034. @end table
  1035. @c TODO create a specific sections about user interaction with the DSM ?
  1036. @node starpu_data_acquire
  1037. @subsection @code{starpu_data_acquire} -- Access registered data from the application
  1038. @table @asis
  1039. @item @emph{Description}:
  1040. The application must call this function prior to accessing registered data from
  1041. main memory outside tasks. StarPU ensures that the application will get an
  1042. up-to-date copy of the data in main memory located where the data was
  1043. originally registered, and that all concurrent accesses (e.g. from tasks) will
  1044. be consistent with the access mode specified in the @code{mode} argument.
  1045. @code{starpu_data_release} must be called once the application does not need to
  1046. access the piece of data anymore.
  1047. Note that implicit data dependencies are also enforced by
  1048. @code{starpu_data_acquire} in case they are enabled.
  1049. @code{starpu_data_acquire} is a blocking call, so that it cannot be called from
  1050. tasks or from their callbacks (in that case, @code{starpu_data_acquire} returns
  1051. @code{-EDEADLK}). Upon successful completion, this function returns 0.
  1052. @item @emph{Prototype}:
  1053. @code{int starpu_data_acquire(starpu_data_handle handle, starpu_access_mode mode);}
  1054. @end table
  1055. @node starpu_data_acquire_cb
  1056. @subsection @code{starpu_data_acquire_cb} -- Access registered data from the application asynchronously
  1057. @table @asis
  1058. @item @emph{Description}:
  1059. @code{starpu_data_acquire_cb} is the asynchronous equivalent of
  1060. @code{starpu_data_release}. When the data specified in the first argument is
  1061. available in the appropriate access mode, the callback function is executed.
  1062. The application may access the requested data during the execution of this
  1063. callback. The callback function must call @code{starpu_data_release} once the
  1064. application does not need to access the piece of data anymore.
  1065. Note that implicit data dependencies are also enforced by
  1066. @code{starpu_data_acquire} in case they are enabled.
  1067. Contrary to @code{starpu_data_acquire}, this function is non-blocking and may
  1068. be called from task callbacks. Upon successful completion, this function
  1069. returns 0.
  1070. @item @emph{Prototype}:
  1071. @code{int starpu_data_acquire_cb(starpu_data_handle handle, starpu_access_mode mode, void (*callback)(void *), void *arg);}
  1072. @end table
  1073. @node starpu_data_release
  1074. @subsection @code{starpu_data_release} -- Release registered data from the application
  1075. @table @asis
  1076. @item @emph{Description}:
  1077. This function releases the piece of data acquired by the application either by
  1078. @code{starpu_data_acquire} or by @code{starpu_data_acquire_cb}.
  1079. @item @emph{Prototype}:
  1080. @code{void starpu_data_release(starpu_data_handle handle);}
  1081. @end table
  1082. @node Data Interfaces
  1083. @section Data Interfaces
  1084. @menu
  1085. * Variable Interface::
  1086. * Vector Interface::
  1087. * Matrix Interface::
  1088. * BCSR Interface for Sparse Matrices (Blocked Compressed Sparse Row Representation)::
  1089. * CSR Interface for Sparse Matrices (Compressed Sparse Row Representation)::
  1090. * Block Interface::
  1091. @end menu
  1092. @node Variable Interface
  1093. @subsection Variable Interface
  1094. @table @asis
  1095. @item @emph{Description}:
  1096. @item @emph{Prototype}:
  1097. @code{void starpu_variable_data_register(starpu_data_handle *handle,
  1098. uint32_t home_node,
  1099. uintptr_t ptr, size_t elemsize);}
  1100. @item @emph{Example}:
  1101. @cartouche
  1102. @smallexample
  1103. float var;
  1104. starpu_data_handle var_handle;
  1105. starpu_variable_data_register(&var_handle, 0, (uintptr_t)&var, sizeof(var));
  1106. @end smallexample
  1107. @end cartouche
  1108. @end table
  1109. @node Vector Interface
  1110. @subsection Vector Interface
  1111. @table @asis
  1112. @item @emph{Description}:
  1113. @item @emph{Prototype}:
  1114. @code{void starpu_vector_data_register(starpu_data_handle *handle, uint32_t home_node,
  1115. uintptr_t ptr, uint32_t nx, size_t elemsize);}
  1116. @item @emph{Example}:
  1117. @cartouche
  1118. @smallexample
  1119. float vector[NX];
  1120. starpu_data_handle vector_handle;
  1121. starpu_vector_data_register(&vector_handle, 0, (uintptr_t)vector, NX,
  1122. sizeof(vector[0]));
  1123. @end smallexample
  1124. @end cartouche
  1125. @end table
  1126. @node Matrix Interface
  1127. @subsection Matrix Interface
  1128. @table @asis
  1129. @item @emph{Description}:
  1130. @item @emph{Prototype}:
  1131. @code{void starpu_matrix_data_register(starpu_data_handle *handle, uint32_t home_node,
  1132. uintptr_t ptr, uint32_t ld, uint32_t nx,
  1133. uint32_t ny, size_t elemsize);}
  1134. @item @emph{Example}:
  1135. @cartouche
  1136. @smallexample
  1137. float *matrix;
  1138. starpu_data_handle matrix_handle;
  1139. matrix = (float*)malloc(width * height * sizeof(float));
  1140. starpu_matrix_data_register(&matrix_handle, 0, (uintptr_t)matrix,
  1141. width, width, height, sizeof(float));
  1142. @end smallexample
  1143. @end cartouche
  1144. @end table
  1145. @node BCSR Interface for Sparse Matrices (Blocked Compressed Sparse Row Representation)
  1146. @subsection BCSR Interface for Sparse Matrices (Blocked Compressed Sparse Row Representation)
  1147. @table @asis
  1148. @item @emph{Description}:
  1149. @item @emph{Prototype}:
  1150. @code{void starpu_bcsr_data_register(starpu_data_handle *handle, uint32_t home_node, uint32_t nnz, uint32_t nrow,
  1151. uintptr_t nzval, uint32_t *colind, uint32_t *rowptr, uint32_t firstentry, uint32_t r, uint32_t c, size_t elemsize);}
  1152. @item @emph{Example}:
  1153. @cartouche
  1154. @smallexample
  1155. @end smallexample
  1156. @end cartouche
  1157. @end table
  1158. @node CSR Interface for Sparse Matrices (Compressed Sparse Row Representation)
  1159. @subsection CSR Interface for Sparse Matrices (Compressed Sparse Row Representation)
  1160. @table @asis
  1161. @item @emph{Description}:
  1162. @item @emph{Prototype}:
  1163. @code{void starpu_csr_data_register(starpu_data_handle *handle, uint32_t home_node, uint32_t nnz, uint32_t nrow,
  1164. uintptr_t nzval, uint32_t *colind, uint32_t *rowptr, uint32_t firstentry, size_t elemsize);}
  1165. @item @emph{Example}:
  1166. @cartouche
  1167. @smallexample
  1168. @end smallexample
  1169. @end cartouche
  1170. @end table
  1171. @node Block Interface
  1172. @subsection Block Interface
  1173. @table @asis
  1174. @item @emph{Description}:
  1175. @item @emph{Prototype}:
  1176. @code{void starpu_block_data_register(starpu_data_handle *handle, uint32_t home_node,
  1177. uintptr_t ptr, uint32_t ldy, uint32_t ldz, uint32_t nx,
  1178. uint32_t ny, uint32_t nz, size_t elemsize);}
  1179. @item @emph{Example}:
  1180. @cartouche
  1181. @smallexample
  1182. float *block;
  1183. starpu_data_handle block_handle;
  1184. block = (float*)malloc(nx*ny*nz*sizeof(float));
  1185. starpu_block_data_register(&block_handle, 0, (uintptr_t)block,
  1186. nx, nx*ny, nx, ny, nz, sizeof(float));
  1187. @end smallexample
  1188. @end cartouche
  1189. @end table
  1190. @node Data Partition
  1191. @section Data Partition
  1192. @menu
  1193. * struct starpu_data_filter:: StarPU filter structure
  1194. * starpu_data_partition:: Partition Data
  1195. * starpu_data_unpartition:: Unpartition Data
  1196. * starpu_data_get_nb_children::
  1197. * starpu_data_get_sub_data::
  1198. * Predefined filter functions::
  1199. @end menu
  1200. @node struct starpu_data_filter
  1201. @subsection @code{struct starpu_data_filter} -- StarPU filter structure
  1202. @table @asis
  1203. @item @emph{Description}:
  1204. The filter structure describes a data partitioning function.
  1205. @item @emph{Fields}:
  1206. @table @asis
  1207. @item @code{filter_func}:
  1208. TODO
  1209. @code{void (*filter_func)(void *father_interface, void* child_interface, struct starpu_data_filter *, unsigned id, unsigned nparts);}
  1210. @item @code{get_nchildren}:
  1211. TODO
  1212. @code{unsigned (*get_nchildren)(struct starpu_data_filter *, starpu_data_handle initial_handle);}
  1213. @item @code{get_child_ops}:
  1214. TODO
  1215. @code{struct starpu_data_interface_ops_t *(*get_child_ops)(struct starpu_data_filter *, unsigned id);}
  1216. @item @code{filter_arg}:
  1217. TODO
  1218. @item @code{nchildren}:
  1219. TODO
  1220. @item @code{filter_arg_ptr}:
  1221. TODO
  1222. @end table
  1223. @end table
  1224. @node starpu_data_partition
  1225. @subsection starpu_data_partition -- Partition Data
  1226. @table @asis
  1227. @item @emph{Description}:
  1228. TODO
  1229. @item @emph{Prototype}:
  1230. @code{void starpu_data_partition(starpu_data_handle initial_handle, struct starpu_data_filter *f);}
  1231. @end table
  1232. @node starpu_data_unpartition
  1233. @subsection starpu_data_unpartition -- Unpartition data
  1234. @table @asis
  1235. @item @emph{Description}:
  1236. TODO
  1237. @item @emph{Prototype}:
  1238. @code{void starpu_data_unpartition(starpu_data_handle root_data, uint32_t gathering_node);}
  1239. @end table
  1240. @node starpu_data_get_nb_children
  1241. @subsection starpu_data_get_nb_children
  1242. @table @asis
  1243. @item @emph{Description}:
  1244. TODO
  1245. @item @emph{Return value}:
  1246. This function returns returns the number of children.
  1247. @item @emph{Prototype}:
  1248. @code{int starpu_data_get_nb_children(starpu_data_handle handle);}
  1249. @end table
  1250. @c starpu_data_handle starpu_data_get_child(starpu_data_handle handle, unsigned i);
  1251. @node starpu_data_get_sub_data
  1252. @subsection starpu_data_get_sub_data
  1253. @table @asis
  1254. @item @emph{Description}:
  1255. TODO
  1256. @item @emph{Return value}:
  1257. TODO
  1258. @item @emph{Prototype}:
  1259. @code{starpu_data_handle starpu_data_get_sub_data(starpu_data_handle root_data, unsigned depth, ... );}
  1260. @end table
  1261. @node Predefined filter functions
  1262. @subsection Predefined filter functions
  1263. @menu
  1264. * Partitioning BCSR Data::
  1265. * Partitioning BLAS interface::
  1266. * Partitioning Vector Data::
  1267. * Partitioning Block Data::
  1268. @end menu
  1269. This section gives a list of the predefined partitioning functions.
  1270. Examples on how to use them are shown in @ref{Partitioning Data}.
  1271. @node Partitioning BCSR Data
  1272. @subsubsection Partitioning BCSR Data
  1273. @itemize
  1274. @item
  1275. TODO
  1276. @code{void starpu_canonical_block_filter_bcsr(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts);}
  1277. @item
  1278. TODO
  1279. @code{void starpu_vertical_block_filter_func_csr(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts);}
  1280. @end itemize
  1281. @node Partitioning BLAS interface
  1282. @subsubsection Partitioning BLAS interface
  1283. @itemize
  1284. @item
  1285. TODO
  1286. @code{void starpu_block_filter_func(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts);}
  1287. @item
  1288. TODO
  1289. @code{void starpu_vertical_block_filter_func(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts);}
  1290. @end itemize
  1291. @node Partitioning Vector Data
  1292. @subsubsection Partitioning Vector Data
  1293. @itemize
  1294. @item
  1295. TODO
  1296. @code{void starpu_block_filter_func_vector(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts);}
  1297. @item
  1298. TODO
  1299. @code{void starpu_vector_list_filter_func(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts);}
  1300. @item
  1301. TODO
  1302. @code{void starpu_vector_divide_in_2_filter_func(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts);}
  1303. @end itemize
  1304. @node Partitioning Block Data
  1305. @subsubsection Partitioning Block Data
  1306. @itemize
  1307. @item
  1308. TODO
  1309. @code{void starpu_block_filter_func_block(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts);}
  1310. @end itemize
  1311. @node Codelets and Tasks
  1312. @section Codelets and Tasks
  1313. @menu
  1314. * struct starpu_codelet:: StarPU codelet structure
  1315. * struct starpu_task:: StarPU task structure
  1316. * starpu_task_init:: Initialize a Task
  1317. * starpu_task_create:: Allocate and Initialize a Task
  1318. * starpu_task_deinit:: Release all the resources used by a Task
  1319. * starpu_task_destroy:: Destroy a dynamically allocated Task
  1320. * starpu_task_wait:: Wait for the termination of a Task
  1321. * starpu_task_submit:: Submit a Task
  1322. * starpu_task_wait_for_all:: Wait for the termination of all Tasks
  1323. * starpu_get_current_task:: Return the task currently executed by the worker
  1324. * starpu_display_codelet_stats:: Display statistics
  1325. @end menu
  1326. @node struct starpu_codelet
  1327. @subsection @code{struct starpu_codelet} -- StarPU codelet structure
  1328. @table @asis
  1329. @item @emph{Description}:
  1330. The codelet structure describes a kernel that is possibly implemented on
  1331. various targets.
  1332. @item @emph{Fields}:
  1333. @table @asis
  1334. @item @code{where}:
  1335. Indicates which types of processing units are able to execute the codelet.
  1336. @code{STARPU_CPU|STARPU_CUDA} for instance indicates that the codelet is
  1337. implemented for both CPU cores and CUDA devices while @code{STARPU_GORDON}
  1338. indicates that it is only available on Cell SPUs.
  1339. @item @code{cpu_func} (optional):
  1340. Is a function pointer to the CPU implementation of the codelet. Its prototype
  1341. must be: @code{void cpu_func(void *buffers[], void *cl_arg)}. The first
  1342. argument being the array of data managed by the data management library, and
  1343. the second argument is a pointer to the argument passed from the @code{cl_arg}
  1344. field of the @code{starpu_task} structure.
  1345. The @code{cpu_func} field is ignored if @code{STARPU_CPU} does not appear in
  1346. the @code{where} field, it must be non-null otherwise.
  1347. @item @code{cuda_func} (optional):
  1348. Is a function pointer to the CUDA implementation of the codelet. @emph{This
  1349. must be a host-function written in the CUDA runtime API}. Its prototype must
  1350. be: @code{void cuda_func(void *buffers[], void *cl_arg);}. The @code{cuda_func}
  1351. field is ignored if @code{STARPU_CUDA} does not appear in the @code{where}
  1352. field, it must be non-null otherwise.
  1353. @item @code{opencl_func} (optional):
  1354. Is a function pointer to the OpenCL implementation of the codelet. Its
  1355. prototype must be:
  1356. @code{void opencl_func(starpu_data_interface_t *descr, void *arg);}.
  1357. This pointer is ignored if @code{STARPU_OPENCL} does not appear in the
  1358. @code{where} field, it must be non-null otherwise.
  1359. @item @code{gordon_func} (optional):
  1360. This is the index of the Cell SPU implementation within the Gordon library.
  1361. See Gordon documentation for more details on how to register a kernel and
  1362. retrieve its index.
  1363. @item @code{nbuffers}:
  1364. Specifies the number of arguments taken by the codelet. These arguments are
  1365. managed by the DSM and are accessed from the @code{void *buffers[]}
  1366. array. The constant argument passed with the @code{cl_arg} field of the
  1367. @code{starpu_task} structure is not counted in this number. This value should
  1368. not be above @code{STARPU_NMAXBUFS}.
  1369. @item @code{model} (optional):
  1370. This is a pointer to the performance model associated to this codelet. This
  1371. optional field is ignored when set to @code{NULL}. TODO
  1372. @end table
  1373. @end table
  1374. @node struct starpu_task
  1375. @subsection @code{struct starpu_task} -- StarPU task structure
  1376. @table @asis
  1377. @item @emph{Description}:
  1378. The @code{starpu_task} structure describes a task that can be offloaded on the various
  1379. processing units managed by StarPU. It instantiates a codelet. It can either be
  1380. allocated dynamically with the @code{starpu_task_create} method, or declared
  1381. statically. In the latter case, the programmer has to zero the
  1382. @code{starpu_task} structure and to fill the different fields properly. The
  1383. indicated default values correspond to the configuration of a task allocated
  1384. with @code{starpu_task_create}.
  1385. @item @emph{Fields}:
  1386. @table @asis
  1387. @item @code{cl}:
  1388. Is a pointer to the corresponding @code{starpu_codelet} data structure. This
  1389. describes where the kernel should be executed, and supplies the appropriate
  1390. implementations. When set to @code{NULL}, no code is executed during the tasks,
  1391. such empty tasks can be useful for synchronization purposes.
  1392. @item @code{buffers}:
  1393. Is an array of @code{starpu_buffer_descr_t} structures. It describes the
  1394. different pieces of data accessed by the task, and how they should be accessed.
  1395. The @code{starpu_buffer_descr_t} structure is composed of two fields, the
  1396. @code{handle} field specifies the handle of the piece of data, and the
  1397. @code{mode} field is the required access mode (eg @code{STARPU_RW}). The number
  1398. of entries in this array must be specified in the @code{nbuffers} field of the
  1399. @code{starpu_codelet} structure, and should not excede @code{STARPU_NMAXBUFS}.
  1400. If unsufficient, this value can be set with the @code{--enable-maxbuffers}
  1401. option when configuring StarPU.
  1402. @item @code{cl_arg} (optional) (default = NULL):
  1403. This pointer is passed to the codelet through the second argument
  1404. of the codelet implementation (e.g. @code{cpu_func} or @code{cuda_func}).
  1405. In the specific case of the Cell processor, see the @code{cl_arg_size}
  1406. argument.
  1407. @item @code{cl_arg_size} (optional, Cell specific):
  1408. In the case of the Cell processor, the @code{cl_arg} pointer is not directly
  1409. given to the SPU function. A buffer of size @code{cl_arg_size} is allocated on
  1410. the SPU. This buffer is then filled with the @code{cl_arg_size} bytes starting
  1411. at address @code{cl_arg}. In this case, the argument given to the SPU codelet
  1412. is therefore not the @code{cl_arg} pointer, but the address of the buffer in
  1413. local store (LS) instead. This field is ignored for CPU, CUDA and OpenCL
  1414. codelets.
  1415. @item @code{callback_func} (optional) (default = @code{NULL}):
  1416. This is a function pointer of prototype @code{void (*f)(void *)} which
  1417. specifies a possible callback. If this pointer is non-null, the callback
  1418. function is executed @emph{on the host} after the execution of the task. The
  1419. callback is passed the value contained in the @code{callback_arg} field. No
  1420. callback is executed if the field is set to @code{NULL}.
  1421. @item @code{callback_arg} (optional) (default = @code{NULL}):
  1422. This is the pointer passed to the callback function. This field is ignored if
  1423. the @code{callback_func} is set to @code{NULL}.
  1424. @item @code{use_tag} (optional) (default = 0):
  1425. If set, this flag indicates that the task should be associated with the tag
  1426. contained in the @code{tag_id} field. Tag allow the application to synchronize
  1427. with the task and to express task dependencies easily.
  1428. @item @code{tag_id}:
  1429. This fields contains the tag associated to the task if the @code{use_tag} field
  1430. was set, it is ignored otherwise.
  1431. @item @code{synchronous}:
  1432. If this flag is set, the @code{starpu_task_submit} function is blocking and
  1433. returns only when the task has been executed (or if no worker is able to
  1434. process the task). Otherwise, @code{starpu_task_submit} returns immediately.
  1435. @item @code{priority} (optional) (default = @code{STARPU_DEFAULT_PRIO}):
  1436. This field indicates a level of priority for the task. This is an integer value
  1437. that must be set between @code{STARPU_MIN_PRIO} (for the least important
  1438. tasks) and @code{STARPU_MAX_PRIO} (for the most important tasks) included.
  1439. Default priority is @code{STARPU_DEFAULT_PRIO}. Scheduling strategies that
  1440. take priorities into account can use this parameter to take better scheduling
  1441. decisions, but the scheduling policy may also ignore it.
  1442. @item @code{execute_on_a_specific_worker} (default = 0):
  1443. If this flag is set, StarPU will bypass the scheduler and directly affect this
  1444. task to the worker specified by the @code{workerid} field.
  1445. @item @code{workerid} (optional):
  1446. If the @code{execute_on_a_specific_worker} field is set, this field indicates
  1447. which is the identifier of the worker that should process this task (as
  1448. returned by @code{starpu_worker_get_id}). This field is ignored if
  1449. @code{execute_on_a_specific_worker} field is set to 0.
  1450. @item @code{detach} (optional) (default = 1):
  1451. If this flag is set, it is not possible to synchronize with the task
  1452. by the means of @code{starpu_task_wait} later on. Internal data structures
  1453. are only guaranteed to be freed once @code{starpu_task_wait} is called if the
  1454. flag is not set.
  1455. @item @code{destroy} (optional) (default = 1):
  1456. If this flag is set, the task structure will automatically be freed, either
  1457. after the execution of the callback if the task is detached, or during
  1458. @code{starpu_task_wait} otherwise. If this flag is not set, dynamically
  1459. allocated data structures will not be freed until @code{starpu_task_destroy} is
  1460. called explicitly. Setting this flag for a statically allocated task structure
  1461. will result in undefined behaviour.
  1462. @item @code{predicted} (output field):
  1463. Predicted duration of the task. This field is only set if the scheduling
  1464. strategy used performance models.
  1465. @end table
  1466. @end table
  1467. @node starpu_task_init
  1468. @subsection @code{starpu_task_init} -- Initialize a Task
  1469. @table @asis
  1470. @item @emph{Description}:
  1471. Initialize a task structure with default values. This function is implicitly
  1472. called by @code{starpu_task_create}. By default, tasks initialized with
  1473. @code{starpu_task_init} must be deinitialized explicitly with
  1474. @code{starpu_task_deinit}. Tasks can also be initialized statically, using the
  1475. constant @code{STARPU_TASK_INITIALIZER}.
  1476. @item @emph{Prototype}:
  1477. @code{void starpu_task_init(struct starpu_task *task);}
  1478. @end table
  1479. @node starpu_task_create
  1480. @subsection @code{starpu_task_create} -- Allocate and Initialize a Task
  1481. @table @asis
  1482. @item @emph{Description}:
  1483. Allocate a task structure and initialize it with default values. Tasks
  1484. allocated dynamically with @code{starpu_task_create} are automatically freed when the
  1485. task is terminated. If the destroy flag is explicitly unset, the resources used
  1486. by the task are freed by calling
  1487. @code{starpu_task_destroy}.
  1488. @item @emph{Prototype}:
  1489. @code{struct starpu_task *starpu_task_create(void);}
  1490. @end table
  1491. @node starpu_task_deinit
  1492. @subsection @code{starpu_task_deinit} -- Release all the resources used by a Task
  1493. @table @asis
  1494. @item @emph{Description}:
  1495. Release all the structures automatically allocated to execute the task. This is
  1496. called automatically by @code{starpu_task_destroy}, but the task structure itself is not
  1497. freed. This should be used for statically allocated tasks for instance.
  1498. @item @emph{Prototype}:
  1499. @code{void starpu_task_deinit(struct starpu_task *task);}
  1500. @end table
  1501. @node starpu_task_destroy
  1502. @subsection @code{starpu_task_destroy} -- Destroy a dynamically allocated Task
  1503. @table @asis
  1504. @item @emph{Description}:
  1505. Free the resource allocated during @code{starpu_task_create}. This function can be
  1506. called automatically after the execution of a task by setting the
  1507. @code{destroy} flag of the @code{starpu_task} structure (default behaviour).
  1508. Calling this function on a statically allocated task results in an undefined
  1509. behaviour.
  1510. @item @emph{Prototype}:
  1511. @code{void starpu_task_destroy(struct starpu_task *task);}
  1512. @end table
  1513. @node starpu_task_wait
  1514. @subsection @code{starpu_task_wait} -- Wait for the termination of a Task
  1515. @table @asis
  1516. @item @emph{Description}:
  1517. This function blocks until the task has been executed. It is not possible to
  1518. synchronize with a task more than once. It is not possible to wait for
  1519. synchronous or detached tasks.
  1520. @item @emph{Return value}:
  1521. Upon successful completion, this function returns 0. Otherwise, @code{-EINVAL}
  1522. indicates that the specified task was either synchronous or detached.
  1523. @item @emph{Prototype}:
  1524. @code{int starpu_task_wait(struct starpu_task *task);}
  1525. @end table
  1526. @node starpu_task_submit
  1527. @subsection @code{starpu_task_submit} -- Submit a Task
  1528. @table @asis
  1529. @item @emph{Description}:
  1530. This function submits a task to StarPU. Calling this function does
  1531. not mean that the task will be executed immediately as there can be data or task
  1532. (tag) dependencies that are not fulfilled yet: StarPU will take care of
  1533. scheduling this task with respect to such dependencies.
  1534. This function returns immediately if the @code{synchronous} field of the
  1535. @code{starpu_task} structure was set to 0, and block until the termination of
  1536. the task otherwise. It is also possible to synchronize the application with
  1537. asynchronous tasks by the means of tags, using the @code{starpu_tag_wait}
  1538. function for instance.
  1539. @item @emph{Return value}:
  1540. In case of success, this function returns 0, a return value of @code{-ENODEV}
  1541. means that there is no worker able to process this task (e.g. there is no GPU
  1542. available and this task is only implemented for CUDA devices).
  1543. @item @emph{Prototype}:
  1544. @code{int starpu_task_submit(struct starpu_task *task);}
  1545. @end table
  1546. @node starpu_task_wait_for_all
  1547. @subsection @code{starpu_task_wait_for_all} -- Wait for the termination of all Tasks
  1548. @table @asis
  1549. @item @emph{Description}:
  1550. This function blocks until all the tasks that were submitted are terminated.
  1551. @item @emph{Prototype}:
  1552. @code{void starpu_task_wait_for_all(void);}
  1553. @end table
  1554. @node starpu_get_current_task
  1555. @subsection @code{starpu_get_current_task} -- Return the task currently executed by the worker
  1556. @table @asis
  1557. @item @emph{Description}:
  1558. This function returns the task currently executed by the worker, or
  1559. NULL if it is called either from a thread that is not a task or simply
  1560. because there is no task being executed at the moment.
  1561. @item @emph{Prototype}:
  1562. @code{struct starpu_task *starpu_get_current_task(void);}
  1563. @end table
  1564. @node starpu_display_codelet_stats
  1565. @subsection @code{starpu_display_codelet_stats} -- Display statistics
  1566. @table @asis
  1567. @item @emph{Description}:
  1568. TODO
  1569. @item @emph{Prototype}:
  1570. @code{void starpu_display_codelet_stats(struct starpu_codelet_t *cl);}
  1571. @end table
  1572. @c Callbacks : what can we put in callbacks ?
  1573. @node Explicit Dependencies
  1574. @section Explicit Dependencies
  1575. @menu
  1576. * starpu_task_declare_deps_array:: starpu_task_declare_deps_array
  1577. * starpu_tag_t:: Task logical identifier
  1578. * starpu_tag_declare_deps:: Declare the Dependencies of a Tag
  1579. * starpu_tag_declare_deps_array:: Declare the Dependencies of a Tag
  1580. * starpu_tag_wait:: Block until a Tag is terminated
  1581. * starpu_tag_wait_array:: Block until a set of Tags is terminated
  1582. * starpu_tag_remove:: Destroy a Tag
  1583. * starpu_tag_notify_from_apps:: Feed a tag explicitly
  1584. @end menu
  1585. @node starpu_task_declare_deps_array
  1586. @subsection @code{starpu_task_declare_deps_array} -- Declare task dependencies
  1587. @table @asis
  1588. @item @emph{Description}:
  1589. Declare task dependencies between a @code{task} and an array of tasks of length
  1590. @code{ndeps}. This function must be called prior to the submission of the task,
  1591. but it may called after the submission or the execution of the tasks in the
  1592. array provided the tasks are still valid (ie. they were not automatically
  1593. destroyed). Calling this function on a task that was already submitted or with
  1594. an entry of @code{task_array} that is not a valid task anymore results in an
  1595. undefined behaviour. If @code{ndeps} is null, no dependency is added. It is
  1596. possible to call @code{starpu_task_declare_deps_array} multiple times on the
  1597. same task, in this case, the dependencies are added. It is possible to have
  1598. redundancy in the task dependencies.
  1599. @item @emph{Prototype}:
  1600. @code{void starpu_task_declare_deps_array(struct starpu_task *task, unsigned ndeps, struct starpu_task *task_array[]);}
  1601. @end table
  1602. @node starpu_tag_t
  1603. @subsection @code{starpu_tag_t} -- Task logical identifier
  1604. @table @asis
  1605. @item @emph{Description}:
  1606. It is possible to associate a task with a unique ``tag'' and to express
  1607. dependencies between tasks by the means of those tags. To do so, fill the
  1608. @code{tag_id} field of the @code{starpu_task} structure with a tag number (can
  1609. be arbitrary) and set the @code{use_tag} field to 1.
  1610. If @code{starpu_tag_declare_deps} is called with this tag number, the task will
  1611. not be started until the tasks which holds the declared dependency tags are
  1612. completed.
  1613. @end table
  1614. @node starpu_tag_declare_deps
  1615. @subsection @code{starpu_tag_declare_deps} -- Declare the Dependencies of a Tag
  1616. @table @asis
  1617. @item @emph{Description}:
  1618. Specify the dependencies of the task identified by tag @code{id}. The first
  1619. argument specifies the tag which is configured, the second argument gives the
  1620. number of tag(s) on which @code{id} depends. The following arguments are the
  1621. tags which have to be terminated to unlock the task.
  1622. This function must be called before the associated task is submitted to StarPU
  1623. with @code{starpu_task_submit}.
  1624. @item @emph{Remark}
  1625. Because of the variable arity of @code{starpu_tag_declare_deps}, note that the
  1626. last arguments @emph{must} be of type @code{starpu_tag_t}: constant values
  1627. typically need to be explicitly casted. Using the
  1628. @code{starpu_tag_declare_deps_array} function avoids this hazard.
  1629. @item @emph{Prototype}:
  1630. @code{void starpu_tag_declare_deps(starpu_tag_t id, unsigned ndeps, ...);}
  1631. @item @emph{Example}:
  1632. @cartouche
  1633. @example
  1634. /* Tag 0x1 depends on tags 0x32 and 0x52 */
  1635. starpu_tag_declare_deps((starpu_tag_t)0x1,
  1636. 2, (starpu_tag_t)0x32, (starpu_tag_t)0x52);
  1637. @end example
  1638. @end cartouche
  1639. @end table
  1640. @node starpu_tag_declare_deps_array
  1641. @subsection @code{starpu_tag_declare_deps_array} -- Declare the Dependencies of a Tag
  1642. @table @asis
  1643. @item @emph{Description}:
  1644. This function is similar to @code{starpu_tag_declare_deps}, except that its
  1645. does not take a variable number of arguments but an array of tags of size
  1646. @code{ndeps}.
  1647. @item @emph{Prototype}:
  1648. @code{void starpu_tag_declare_deps_array(starpu_tag_t id, unsigned ndeps, starpu_tag_t *array);}
  1649. @item @emph{Example}:
  1650. @cartouche
  1651. @example
  1652. /* Tag 0x1 depends on tags 0x32 and 0x52 */
  1653. starpu_tag_t tag_array[2] = @{0x32, 0x52@};
  1654. starpu_tag_declare_deps_array((starpu_tag_t)0x1, 2, tag_array);
  1655. @end example
  1656. @end cartouche
  1657. @end table
  1658. @node starpu_tag_wait
  1659. @subsection @code{starpu_tag_wait} -- Block until a Tag is terminated
  1660. @table @asis
  1661. @item @emph{Description}:
  1662. This function blocks until the task associated to tag @code{id} has been
  1663. executed. This is a blocking call which must therefore not be called within
  1664. tasks or callbacks, but only from the application directly. It is possible to
  1665. synchronize with the same tag multiple times, as long as the
  1666. @code{starpu_tag_remove} function is not called. Note that it is still
  1667. possible to synchronize with a tag associated to a task which @code{starpu_task}
  1668. data structure was freed (e.g. if the @code{destroy} flag of the
  1669. @code{starpu_task} was enabled).
  1670. @item @emph{Prototype}:
  1671. @code{void starpu_tag_wait(starpu_tag_t id);}
  1672. @end table
  1673. @node starpu_tag_wait_array
  1674. @subsection @code{starpu_tag_wait_array} -- Block until a set of Tags is terminated
  1675. @table @asis
  1676. @item @emph{Description}:
  1677. This function is similar to @code{starpu_tag_wait} except that it blocks until
  1678. @emph{all} the @code{ntags} tags contained in the @code{id} array are
  1679. terminated.
  1680. @item @emph{Prototype}:
  1681. @code{void starpu_tag_wait_array(unsigned ntags, starpu_tag_t *id);}
  1682. @end table
  1683. @node starpu_tag_remove
  1684. @subsection @code{starpu_tag_remove} -- Destroy a Tag
  1685. @table @asis
  1686. @item @emph{Description}:
  1687. This function releases the resources associated to tag @code{id}. It can be
  1688. called once the corresponding task has been executed and when there is
  1689. no other tag that depend on this tag anymore.
  1690. @item @emph{Prototype}:
  1691. @code{void starpu_tag_remove(starpu_tag_t id);}
  1692. @end table
  1693. @node starpu_tag_notify_from_apps
  1694. @subsection @code{starpu_tag_notify_from_apps} -- Feed a Tag explicitly
  1695. @table @asis
  1696. @item @emph{Description}:
  1697. This function explicitly unlocks tag @code{id}. It may be useful in the
  1698. case of applications which execute part of their computation outside StarPU
  1699. tasks (e.g. third-party libraries). It is also provided as a
  1700. convenient tool for the programmer, for instance to entirely construct the task
  1701. DAG before actually giving StarPU the opportunity to execute the tasks.
  1702. @item @emph{Prototype}:
  1703. @code{void starpu_tag_notify_from_apps(starpu_tag_t id);}
  1704. @end table
  1705. @node Implicit Data Dependencies
  1706. @section Implicit Data Dependencies
  1707. @menu
  1708. * starpu_data_set_default_sequential_consistency_flag:: starpu_data_set_default_sequential_consistency_flag
  1709. * starpu_data_get_default_sequential_consistency_flag:: starpu_data_get_default_sequential_consistency_flag
  1710. * starpu_data_set_sequential_consistency_flag:: starpu_data_set_sequential_consistency_flag
  1711. @end menu
  1712. In this section, we describe how StarPU makes it possible to insert implicit
  1713. task dependencies in order to enforce sequential data consistency. When this
  1714. data consistency is enabled on a specific data handle, any data access will
  1715. appear as sequentially consistent from the application. For instance, if the
  1716. application submits two tasks that access the same piece of data in read-only
  1717. mode, and then a third task that access it in write mode, dependencies will be
  1718. added between the two first tasks and the third one. Implicit data dependencies
  1719. are also inserted in the case of data accesses from the application.
  1720. @node starpu_data_set_default_sequential_consistency_flag
  1721. @subsection @code{starpu_data_set_default_sequential_consistency_flag} -- Set default sequential consistency flag
  1722. @table @asis
  1723. @item @emph{Description}:
  1724. Set the default sequential consistency flag. If a non-null value is passed, a
  1725. sequential data consistency will be enforced for all handles registered after
  1726. this function call, otherwise it is disabled. By default, StarPU enables
  1727. sequential data consistency. It is also possible to select the data consistency
  1728. mode of a specific data handle with the
  1729. @code{starpu_data_set_sequential_consistency_flag} function.
  1730. @item @emph{Prototype}:
  1731. @code{void starpu_data_set_default_sequential_consistency_flag(unsigned flag);}
  1732. @end table
  1733. @node starpu_data_get_default_sequential_consistency_flag
  1734. @subsection @code{starpu_data_get_default_sequential_consistency_flag} -- Get current default sequential consistency flag
  1735. @table @asis
  1736. @item @emph{Description}:
  1737. This function returns the current default sequential consistency flag.
  1738. @item @emph{Prototype}:
  1739. @code{unsigned starpu_data_set_default_sequential_consistency_flag(void);}
  1740. @end table
  1741. @node starpu_data_set_sequential_consistency_flag
  1742. @subsection @code{starpu_data_set_sequential_consistency_flag} -- Set data sequential consistency mode
  1743. @table @asis
  1744. @item @emph{Description}:
  1745. Select the data consistency mode associated to a data handle. The consistency
  1746. mode set using this function has the priority over the default mode which can
  1747. be set with @code{starpu_data_set_sequential_consistency_flag}.
  1748. @item @emph{Prototype}:
  1749. @code{void starpu_data_set_sequential_consistency_flag(starpu_data_handle handle, unsigned flag);}
  1750. @end table
  1751. @node Performance Model API
  1752. @section Performance Model API
  1753. @menu
  1754. * starpu_load_history_debug::
  1755. * starpu_perfmodel_debugfilepath::
  1756. * starpu_perfmodel_get_arch_name::
  1757. * starpu_force_bus_sampling::
  1758. @end menu
  1759. @node starpu_load_history_debug
  1760. @subsection @code{starpu_load_history_debug}
  1761. @table @asis
  1762. @item @emph{Description}:
  1763. TODO
  1764. @item @emph{Prototype}:
  1765. @code{int starpu_load_history_debug(const char *symbol, struct starpu_perfmodel_t *model);}
  1766. @end table
  1767. @node starpu_perfmodel_debugfilepath
  1768. @subsection @code{starpu_perfmodel_debugfilepath}
  1769. @table @asis
  1770. @item @emph{Description}:
  1771. TODO
  1772. @item @emph{Prototype}:
  1773. @code{void starpu_perfmodel_debugfilepath(struct starpu_perfmodel_t *model, enum starpu_perf_archtype arch, char *path, size_t maxlen);}
  1774. @end table
  1775. @node starpu_perfmodel_get_arch_name
  1776. @subsection @code{starpu_perfmodel_get_arch_name}
  1777. @table @asis
  1778. @item @emph{Description}:
  1779. TODO
  1780. @item @emph{Prototype}:
  1781. @code{void starpu_perfmodel_get_arch_name(enum starpu_perf_archtype arch, char *archname, size_t maxlen);}
  1782. @end table
  1783. @node starpu_force_bus_sampling
  1784. @subsection @code{starpu_force_bus_sampling}
  1785. @table @asis
  1786. @item @emph{Description}:
  1787. TODO
  1788. @item @emph{Prototype}:
  1789. @code{void starpu_force_bus_sampling(void);}
  1790. @end table
  1791. @node Profiling API
  1792. @section Profiling API
  1793. @menu
  1794. * starpu_profiling_status_set:: starpu_profiling_status_set
  1795. * starpu_profiling_status_get:: starpu_profiling_status_get
  1796. * struct starpu_task_profiling_info:: task profiling information
  1797. * struct starpu_worker_profiling_info:: worker profiling information
  1798. * starpu_worker_get_profiling_info:: starpu_worker_get_profiling_info
  1799. * struct starpu_bus_profiling_info:: bus profiling information
  1800. * starpu_bus_get_count::
  1801. * starpu_bus_get_id::
  1802. * starpu_bus_get_src::
  1803. * starpu_bus_get_dst::
  1804. * starpu_timing_timespec_delay_us::
  1805. * starpu_timing_timespec_to_us::
  1806. * starpu_bus_profiling_helper_display_summary::
  1807. @end menu
  1808. @node starpu_profiling_status_set
  1809. @subsection @code{starpu_profiling_status_set} -- Set current profiling status
  1810. @table @asis
  1811. @item @emph{Description}:
  1812. Thie function sets the profiling status. Profiling is activated by passing
  1813. @code{STARPU_PROFILING_ENABLE} in @code{status}. Passing
  1814. @code{STARPU_PROFILING_DISABLE} disables profiling. Calling this function
  1815. resets all profiling measurements. When profiling is enabled, the
  1816. @code{profiling_info} field of the @code{struct starpu_task} structure points
  1817. to a valid @code{struct starpu_task_profiling_info} structure containing
  1818. information about the execution of the task.
  1819. @item @emph{Return value}:
  1820. Negative return values indicate an error, otherwise the previous status is
  1821. returned.
  1822. @item @emph{Prototype}:
  1823. @code{int starpu_profiling_status_set(int status);}
  1824. @end table
  1825. @node starpu_profiling_status_get
  1826. @subsection @code{starpu_profiling_status_get} -- Get current profiling status
  1827. @table @asis
  1828. @item @emph{Description}:
  1829. Return the current profiling status or a negative value in case there was an error.
  1830. @item @emph{Prototype}:
  1831. @code{int starpu_profiling_status_get(void);}
  1832. @end table
  1833. @node struct starpu_task_profiling_info
  1834. @subsection @code{struct starpu_task_profiling_info} -- Task profiling information
  1835. @table @asis
  1836. @item @emph{Description}:
  1837. This structure contains information about the execution of a task. It is
  1838. accessible from the @code{.profiling_info} field of the @code{starpu_task}
  1839. structure if profiling was enabled.
  1840. @item @emph{Fields}:
  1841. @table @asis
  1842. @item @code{submit_time}:
  1843. Date of task submission (relative to the initialization of StarPU).
  1844. @item @code{start_time}:
  1845. Date of task execution beginning (relative to the initialization of StarPU).
  1846. @item @code{end_time}:
  1847. Date of task execution termination (relative to the initialization of StarPU).
  1848. @item @code{workerid}:
  1849. Identifier of the worker which has executed the task.
  1850. @end table
  1851. @end table
  1852. @node struct starpu_worker_profiling_info
  1853. @subsection @code{struct starpu_worker_profiling_info} -- Worker profiling information
  1854. @table @asis
  1855. @item @emph{Description}:
  1856. This structure contains the profiling information associated to a worker.
  1857. @item @emph{Fields}:
  1858. @table @asis
  1859. @item @code{start_time}:
  1860. Starting date for the reported profiling measurements.
  1861. @item @code{total_time}:
  1862. Duration of the profiling measurement interval.
  1863. @item @code{executing_time}:
  1864. Time spent by the worker to execute tasks during the profiling measurement interval.
  1865. @item @code{sleeping_time}:
  1866. Time spent idling by the worker during the profiling measurement interval.
  1867. @item @code{executed_tasks}:
  1868. Number of tasks executed by the worker during the profiling measurement interval.
  1869. @end table
  1870. @end table
  1871. @node starpu_worker_get_profiling_info
  1872. @subsection @code{starpu_worker_get_profiling_info} -- Get worker profiling info
  1873. @table @asis
  1874. @item @emph{Description}:
  1875. Get the profiling info associated to the worker identified by @code{workerid},
  1876. and reset the profiling measurements. If the @code{worker_info} argument is
  1877. NULL, only reset the counters associated to worker @code{workerid}.
  1878. @item @emph{Return value}:
  1879. Upon successful completion, this function returns 0. Otherwise, a negative
  1880. value is returned.
  1881. @item @emph{Prototype}:
  1882. @code{int starpu_worker_get_profiling_info(int workerid, struct starpu_worker_profiling_info *worker_info);}
  1883. @end table
  1884. @node struct starpu_bus_profiling_info
  1885. @subsection @code{struct starpu_bus_profiling_info} -- Bus profiling information
  1886. @table @asis
  1887. @item @emph{Description}:
  1888. TODO
  1889. @item @emph{Fields}:
  1890. @table @asis
  1891. @item @code{start_time}:
  1892. TODO
  1893. @item @code{total_time}:
  1894. TODO
  1895. @item @code{transferred_bytes}:
  1896. TODO
  1897. @item @code{transfer_count}:
  1898. TODO
  1899. @end table
  1900. @end table
  1901. @node starpu_bus_get_count
  1902. @subsection @code{starpu_bus_get_count}
  1903. @table @asis
  1904. @item @emph{Description}:
  1905. TODO
  1906. @item @emph{Prototype}:
  1907. @code{int starpu_bus_get_count(void);}
  1908. @end table
  1909. @node starpu_bus_get_id
  1910. @subsection @code{starpu_bus_get_id}
  1911. @table @asis
  1912. @item @emph{Description}:
  1913. TODO
  1914. @item @emph{Prototype}:
  1915. @code{int starpu_bus_get_id(int src, int dst);}
  1916. @end table
  1917. @node starpu_bus_get_src
  1918. @subsection @code{starpu_bus_get_src}
  1919. @table @asis
  1920. @item @emph{Description}:
  1921. TODO
  1922. @item @emph{Prototype}:
  1923. @code{int starpu_bus_get_src(int busid);}
  1924. @end table
  1925. @node starpu_bus_get_dst
  1926. @subsection @code{starpu_bus_get_dst}
  1927. @table @asis
  1928. @item @emph{Description}:
  1929. TODO
  1930. @item @emph{Prototype}:
  1931. @code{int starpu_bus_get_dst(int busid);}
  1932. @end table
  1933. @node starpu_timing_timespec_delay_us
  1934. @subsection @code{starpu_timing_timespec_delay_us}
  1935. @table @asis
  1936. @item @emph{Description}:
  1937. TODO
  1938. @item @emph{Prototype}:
  1939. @code{double starpu_timing_timespec_delay_us(struct timespec *start, struct timespec *end);}
  1940. @end table
  1941. @node starpu_timing_timespec_to_us
  1942. @subsection @code{starpu_timing_timespec_to_us}
  1943. @table @asis
  1944. @item @emph{Description}:
  1945. TODO
  1946. @item @emph{Prototype}:
  1947. @code{double starpu_timing_timespec_to_us(struct timespec *ts);}
  1948. @end table
  1949. @node starpu_bus_profiling_helper_display_summary
  1950. @subsection @code{starpu_bus_profiling_helper_display_summary}
  1951. @table @asis
  1952. @item @emph{Description}:
  1953. TODO
  1954. @item @emph{Prototype}:
  1955. @code{void starpu_bus_profiling_helper_display_summary(void);}
  1956. @end table
  1957. @node CUDA extensions
  1958. @section CUDA extensions
  1959. @c void starpu_data_malloc_pinned_if_possible(float **A, size_t dim);
  1960. @menu
  1961. * starpu_cuda_get_local_stream:: Get current worker's CUDA stream
  1962. * starpu_helper_cublas_init:: Initialize CUBLAS on every CUDA device
  1963. * starpu_helper_cublas_shutdown:: Deinitialize CUBLAS on every CUDA device
  1964. @end menu
  1965. @node starpu_cuda_get_local_stream
  1966. @subsection @code{starpu_cuda_get_local_stream} -- Get current worker's CUDA stream
  1967. @table @asis
  1968. @item @emph{Description}:
  1969. StarPU provides a stream for every CUDA device controlled by StarPU. This
  1970. function is only provided for convenience so that programmers can easily use
  1971. asynchronous operations within codelets without having to create a stream by
  1972. hand. Note that the application is not forced to use the stream provided by
  1973. @code{starpu_cuda_get_local_stream} and may also create its own streams.
  1974. @item @emph{Prototype}:
  1975. @code{cudaStream_t *starpu_cuda_get_local_stream(void);}
  1976. @end table
  1977. @node starpu_helper_cublas_init
  1978. @subsection @code{starpu_helper_cublas_init} -- Initialize CUBLAS on every CUDA device
  1979. @table @asis
  1980. @item @emph{Description}:
  1981. The CUBLAS library must be initialized prior to any CUBLAS call. Calling
  1982. @code{starpu_helper_cublas_init} will initialize CUBLAS on every CUDA device
  1983. controlled by StarPU. This call blocks until CUBLAS has been properly
  1984. initialized on every device.
  1985. @item @emph{Prototype}:
  1986. @code{void starpu_helper_cublas_init(void);}
  1987. @end table
  1988. @node starpu_helper_cublas_shutdown
  1989. @subsection @code{starpu_helper_cublas_shutdown} -- Deinitialize CUBLAS on every CUDA device
  1990. @table @asis
  1991. @item @emph{Description}:
  1992. This function synchronously deinitializes the CUBLAS library on every CUDA device.
  1993. @item @emph{Prototype}:
  1994. @code{void starpu_helper_cublas_shutdown(void);}
  1995. @end table
  1996. @node OpenCL extensions
  1997. @section OpenCL extensions
  1998. @menu
  1999. * Enabling OpenCL:: Enabling OpenCL
  2000. * Compiling OpenCL codelets:: Compiling OpenCL codelets
  2001. * Loading OpenCL codelets:: Loading OpenCL codelets
  2002. @end menu
  2003. @node Enabling OpenCL
  2004. @subsection Enabling OpenCL
  2005. On GPU devices which can run both CUDA and OpenCL, CUDA will be
  2006. enabled by default. To enable OpenCL, you need either to disable CUDA
  2007. when configuring StarPU:
  2008. @example
  2009. % ./configure --disable-cuda
  2010. @end example
  2011. or when running applications:
  2012. @example
  2013. % STARPU_NCUDA=0 ./application
  2014. @end example
  2015. OpenCL will automatically be started on any device not yet used by
  2016. CUDA. So on a machine running 4 GPUS, it is therefore possible to
  2017. enable CUDA on 2 devices, and OpenCL on the 2 other devices by doing
  2018. so:
  2019. @example
  2020. % STARPU_NCUDA=2 ./application
  2021. @end example
  2022. @node Compiling OpenCL codelets
  2023. @subsection Compiling OpenCL codelets
  2024. Source codes for OpenCL codelets can be stored in a file or in a
  2025. string. StarPU provides functions to build the program executable for
  2026. each available OpenCL device as a @code{cl_program} object. This
  2027. program executable can then be loaded within a specific queue as
  2028. explained in the next section. These are only helpers, Applications
  2029. can also fill a @code{starpu_opencl_program} array by hand for more advanced
  2030. use (e.g. different programs on the different OpenCL devices, for
  2031. relocation purpose for instance).
  2032. @menu
  2033. * starpu_opencl_load_opencl_from_file:: Compiling OpenCL source code
  2034. * starpu_opencl_load_opencl_from_string:: Compiling OpenCL source code
  2035. * starpu_opencl_unload_opencl:: Releasing OpenCL code
  2036. @end menu
  2037. @node starpu_opencl_load_opencl_from_file
  2038. @subsubsection @code{starpu_opencl_load_opencl_from_file} -- Compiling OpenCL source code
  2039. @table @asis
  2040. @item @emph{Description}:
  2041. TODO
  2042. @item @emph{Prototype}:
  2043. @code{int starpu_opencl_load_opencl_from_file(char *source_file_name, struct starpu_opencl_program *opencl_programs);}
  2044. @end table
  2045. @node starpu_opencl_load_opencl_from_string
  2046. @subsubsection @code{starpu_opencl_load_opencl_from_string} -- Compiling OpenCL source code
  2047. @table @asis
  2048. @item @emph{Description}:
  2049. TODO
  2050. @item @emph{Prototype}:
  2051. @code{int starpu_opencl_load_opencl_from_string(char *opencl_program_source, struct starpu_opencl_program *opencl_programs);}
  2052. @end table
  2053. @node starpu_opencl_unload_opencl
  2054. @subsubsection @code{starpu_opencl_unload_opencl} -- Releasing OpenCL code
  2055. @table @asis
  2056. @item @emph{Description}:
  2057. TODO
  2058. @item @emph{Prototype}:
  2059. @code{int starpu_opencl_unload_opencl(struct starpu_opencl_program *opencl_programs);}
  2060. @end table
  2061. @node Loading OpenCL codelets
  2062. @subsection Loading OpenCL codelets
  2063. @menu
  2064. * starpu_opencl_load_kernel:: Loading a kernel
  2065. * starpu_opencl_relase_kernel:: Releasing a kernel
  2066. @end menu
  2067. @node starpu_opencl_load_kernel
  2068. @subsubsection @code{starpu_opencl_load_kernel} -- Loading a kernel
  2069. @table @asis
  2070. @item @emph{Description}:
  2071. TODO
  2072. @item @emph{Prototype}:
  2073. @code{int starpu_opencl_load_kernel(cl_kernel *kernel, cl_command_queue *queue, struct starpu_opencl_program *opencl_programs, char *kernel_name, int devid)
  2074. }
  2075. @end table
  2076. @node starpu_opencl_relase_kernel
  2077. @subsubsection @code{starpu_opencl_release_kernel} -- Releasing a kernel
  2078. @table @asis
  2079. @item @emph{Description}:
  2080. TODO
  2081. @item @emph{Prototype}:
  2082. @code{int starpu_opencl_release_kernel(cl_kernel kernel);}
  2083. @end table
  2084. @node Cell extensions
  2085. @section Cell extensions
  2086. nothing yet.
  2087. @node Miscellaneous helpers
  2088. @section Miscellaneous helpers
  2089. @menu
  2090. * starpu_execute_on_each_worker:: Execute a function on a subset of workers
  2091. @end menu
  2092. @node starpu_execute_on_each_worker
  2093. @subsection @code{starpu_execute_on_each_worker} -- Execute a function on a subset of workers
  2094. @table @asis
  2095. @item @emph{Description}:
  2096. When calling this method, the offloaded function specified by the first argument is
  2097. executed by every StarPU worker that may execute the function.
  2098. The second argument is passed to the offloaded function.
  2099. The last argument specifies on which types of processing units the function
  2100. should be executed. Similarly to the @code{where} field of the
  2101. @code{starpu_codelet} structure, it is possible to specify that the function
  2102. should be executed on every CUDA device and every CPU by passing
  2103. @code{STARPU_CPU|STARPU_CUDA}.
  2104. This function blocks until the function has been executed on every appropriate
  2105. processing units, so that it may not be called from a callback function for
  2106. instance.
  2107. @item @emph{Prototype}:
  2108. @code{void starpu_execute_on_each_worker(void (*func)(void *), void *arg, uint32_t where);}
  2109. @end table
  2110. @c ---------------------------------------------------------------------
  2111. @c Basic Examples
  2112. @c ---------------------------------------------------------------------
  2113. @node Basic Examples
  2114. @chapter Basic Examples
  2115. @menu
  2116. * Compiling and linking options::
  2117. * Hello World:: Submitting Tasks
  2118. * Scaling a Vector:: Manipulating Data
  2119. * Vector Scaling on an Hybrid CPU/GPU Machine:: Handling Heterogeneous Architectures
  2120. * Task and Worker Profiling::
  2121. * Partitioning Data:: Partitioning Data
  2122. * Performance model example::
  2123. * More examples:: More examples shipped with StarPU
  2124. @end menu
  2125. @node Compiling and linking options
  2126. @section Compiling and linking options
  2127. Let's suppose StarPU has been installed in the directory
  2128. @code{$STARPU_DIR}. As explained in @ref{Setting flags for compiling and linking applications},
  2129. the variable @code{PKG_CONFIG_PATH} needs to be set. It is also
  2130. necessary to set the variable @code{LD_LIBRARY_PATH} to locate dynamic
  2131. libraries at runtime.
  2132. @example
  2133. % PKG_CONFIG_PATH=$STARPU_DIR/lib/pkgconfig:$PKG_CONFIG_PATH
  2134. % LD_LIBRARY_PATH=$STARPU_DIR/lib:$LD_LIBRARY_PATH
  2135. @end example
  2136. The Makefile could for instance contain the following lines to define which
  2137. options must be given to the compiler and to the linker:
  2138. @cartouche
  2139. @example
  2140. CFLAGS += $$(pkg-config --cflags libstarpu)
  2141. LDFLAGS += $$(pkg-config --libs libstarpu)
  2142. @end example
  2143. @end cartouche
  2144. @node Hello World
  2145. @section Hello World
  2146. @menu
  2147. * Required Headers::
  2148. * Defining a Codelet::
  2149. * Submitting a Task::
  2150. * Execution of Hello World::
  2151. @end menu
  2152. In this section, we show how to implement a simple program that submits a task to StarPU.
  2153. @node Required Headers
  2154. @subsection Required Headers
  2155. The @code{starpu.h} header should be included in any code using StarPU.
  2156. @cartouche
  2157. @smallexample
  2158. #include <starpu.h>
  2159. @end smallexample
  2160. @end cartouche
  2161. @node Defining a Codelet
  2162. @subsection Defining a Codelet
  2163. @cartouche
  2164. @smallexample
  2165. void cpu_func(void *buffers[], void *cl_arg)
  2166. @{
  2167. float *array = cl_arg;
  2168. printf("Hello world (array = @{%f, %f@} )\n", array[0], array[1]);
  2169. @}
  2170. starpu_codelet cl =
  2171. @{
  2172. .where = STARPU_CPU,
  2173. .cpu_func = cpu_func,
  2174. .nbuffers = 0
  2175. @};
  2176. @end smallexample
  2177. @end cartouche
  2178. A codelet is a structure that represents a computational kernel. Such a codelet
  2179. may contain an implementation of the same kernel on different architectures
  2180. (e.g. CUDA, Cell's SPU, x86, ...).
  2181. The @code{nbuffers} field specifies the number of data buffers that are
  2182. manipulated by the codelet: here the codelet does not access or modify any data
  2183. that is controlled by our data management library. Note that the argument
  2184. passed to the codelet (the @code{cl_arg} field of the @code{starpu_task}
  2185. structure) does not count as a buffer since it is not managed by our data
  2186. management library.
  2187. @c TODO need a crossref to the proper description of "where" see bla for more ...
  2188. We create a codelet which may only be executed on the CPUs. The @code{where}
  2189. field is a bitmask that defines where the codelet may be executed. Here, the
  2190. @code{STARPU_CPU} value means that only CPUs can execute this codelet
  2191. (@pxref{Codelets and Tasks} for more details on this field).
  2192. When a CPU core executes a codelet, it calls the @code{cpu_func} function,
  2193. which @emph{must} have the following prototype:
  2194. @code{void (*cpu_func)(void *buffers[], void *cl_arg);}
  2195. In this example, we can ignore the first argument of this function which gives a
  2196. description of the input and output buffers (e.g. the size and the location of
  2197. the matrices). The second argument is a pointer to a buffer passed as an
  2198. argument to the codelet by the means of the @code{cl_arg} field of the
  2199. @code{starpu_task} structure.
  2200. @c TODO rewrite so that it is a little clearer ?
  2201. Be aware that this may be a pointer to a
  2202. @emph{copy} of the actual buffer, and not the pointer given by the programmer:
  2203. if the codelet modifies this buffer, there is no guarantee that the initial
  2204. buffer will be modified as well: this for instance implies that the buffer
  2205. cannot be used as a synchronization medium.
  2206. @node Submitting a Task
  2207. @subsection Submitting a Task
  2208. @cartouche
  2209. @smallexample
  2210. void callback_func(void *callback_arg)
  2211. @{
  2212. printf("Callback function (arg %x)\n", callback_arg);
  2213. @}
  2214. int main(int argc, char **argv)
  2215. @{
  2216. /* @b{initialize StarPU} */
  2217. starpu_init(NULL);
  2218. struct starpu_task *task = starpu_task_create();
  2219. task->cl = &cl; /* @b{Pointer to the codelet defined above} */
  2220. float array[2] = @{1.0f, -1.0f@};
  2221. task->cl_arg = &array;
  2222. task->cl_arg_size = sizeof(array);
  2223. task->callback_func = callback_func;
  2224. task->callback_arg = 0x42;
  2225. /* @b{starpu_task_submit will be a blocking call} */
  2226. task->synchronous = 1;
  2227. /* @b{submit the task to StarPU} */
  2228. starpu_task_submit(task);
  2229. /* @b{terminate StarPU} */
  2230. starpu_shutdown();
  2231. return 0;
  2232. @}
  2233. @end smallexample
  2234. @end cartouche
  2235. Before submitting any tasks to StarPU, @code{starpu_init} must be called. The
  2236. @code{NULL} argument specifies that we use default configuration. Tasks cannot
  2237. be submitted after the termination of StarPU by a call to
  2238. @code{starpu_shutdown}.
  2239. In the example above, a task structure is allocated by a call to
  2240. @code{starpu_task_create}. This function only allocates and fills the
  2241. corresponding structure with the default settings (@pxref{starpu_task_create}),
  2242. but it does not submit the task to StarPU.
  2243. @c not really clear ;)
  2244. The @code{cl} field is a pointer to the codelet which the task will
  2245. execute: in other words, the codelet structure describes which computational
  2246. kernel should be offloaded on the different architectures, and the task
  2247. structure is a wrapper containing a codelet and the piece of data on which the
  2248. codelet should operate.
  2249. The optional @code{cl_arg} field is a pointer to a buffer (of size
  2250. @code{cl_arg_size}) with some parameters for the kernel
  2251. described by the codelet. For instance, if a codelet implements a computational
  2252. kernel that multiplies its input vector by a constant, the constant could be
  2253. specified by the means of this buffer, instead of registering it.
  2254. Once a task has been executed, an optional callback function can be called.
  2255. While the computational kernel could be offloaded on various architectures, the
  2256. callback function is always executed on a CPU. The @code{callback_arg}
  2257. pointer is passed as an argument of the callback. The prototype of a callback
  2258. function must be:
  2259. @code{void (*callback_function)(void *);}
  2260. If the @code{synchronous} field is non-null, task submission will be
  2261. synchronous: the @code{starpu_task_submit} function will not return until the
  2262. task was executed. Note that the @code{starpu_shutdown} method does not
  2263. guarantee that asynchronous tasks have been executed before it returns.
  2264. @node Execution of Hello World
  2265. @subsection Execution of Hello World
  2266. @smallexample
  2267. % make hello_world
  2268. cc $(pkg-config --cflags libstarpu) $(pkg-config --libs libstarpu) hello_world.c -o hello_world
  2269. % ./hello_world
  2270. Hello world (array = @{1.000000, -1.000000@} )
  2271. Callback function (arg 42)
  2272. @end smallexample
  2273. @node Scaling a Vector
  2274. @section Manipulating Data: Scaling a Vector
  2275. The previous example has shown how to submit tasks. In this section,
  2276. we show how StarPU tasks can manipulate data. The full source code for
  2277. this example is given in @ref{Full source code for the 'Scaling a Vector' example}.
  2278. @menu
  2279. * Source code of Vector Scaling::
  2280. * Execution of Vector Scaling::
  2281. @end menu
  2282. @node Source code of Vector Scaling
  2283. @subsection Source code of Vector Scaling
  2284. Programmers can describe the data layout of their application so that StarPU is
  2285. responsible for enforcing data coherency and availability across the machine.
  2286. Instead of handling complex (and non-portable) mechanisms to perform data
  2287. movements, programmers only declare which piece of data is accessed and/or
  2288. modified by a task, and StarPU makes sure that when a computational kernel
  2289. starts somewhere (e.g. on a GPU), its data are available locally.
  2290. Before submitting those tasks, the programmer first needs to declare the
  2291. different pieces of data to StarPU using the @code{starpu_*_data_register}
  2292. functions. To ease the development of applications for StarPU, it is possible
  2293. to describe multiple types of data layout. A type of data layout is called an
  2294. @b{interface}. By default, there are different interfaces available in StarPU:
  2295. here we will consider the @b{vector interface}.
  2296. The following lines show how to declare an array of @code{NX} elements of type
  2297. @code{float} using the vector interface:
  2298. @cartouche
  2299. @smallexample
  2300. float vector[NX];
  2301. starpu_data_handle vector_handle;
  2302. starpu_vector_data_register(&vector_handle, 0, (uintptr_t)vector, NX,
  2303. sizeof(vector[0]));
  2304. @end smallexample
  2305. @end cartouche
  2306. The first argument, called the @b{data handle}, is an opaque pointer which
  2307. designates the array in StarPU. This is also the structure which is used to
  2308. describe which data is used by a task. The second argument is the node number
  2309. where the data currently resides. Here it is 0 since the @code{vector} array is in
  2310. the main memory. Then comes the pointer @code{vector} where the data can be found,
  2311. the number of elements in the vector and the size of each element.
  2312. It is possible to construct a StarPU task that will manipulate the
  2313. vector and a constant factor.
  2314. @cartouche
  2315. @smallexample
  2316. float factor = 3.14;
  2317. struct starpu_task *task = starpu_task_create();
  2318. task->cl = &cl; /* @b{Pointer to the codelet defined below} */
  2319. task->buffers[0].handle = vector_handle; /* @b{First parameter of the codelet} */
  2320. task->buffers[0].mode = STARPU_RW;
  2321. task->cl_arg = &factor;
  2322. task->cl_arg_size = sizeof(factor);
  2323. task->synchronous = 1;
  2324. starpu_task_submit(task);
  2325. @end smallexample
  2326. @end cartouche
  2327. Since the factor is a mere float value parameter, it does not need a preliminary registration, and
  2328. can just be passed through the @code{cl_arg} pointer like in the previous
  2329. example. The vector parameter is described by its handle.
  2330. There are two fields in each element of the @code{buffers} array.
  2331. @code{handle} is the handle of the data, and @code{mode} specifies how the
  2332. kernel will access the data (@code{STARPU_R} for read-only, @code{STARPU_W} for
  2333. write-only and @code{STARPU_RW} for read and write access).
  2334. The definition of the codelet can be written as follows:
  2335. @cartouche
  2336. @smallexample
  2337. void scal_cpu_func(void *buffers[], void *cl_arg)
  2338. @{
  2339. unsigned i;
  2340. float *factor = cl_arg;
  2341. /* length of the vector */
  2342. unsigned n = STARPU_VECTOR_GET_NX(buffers[0]);
  2343. /* local copy of the vector pointer */
  2344. float *val = (float *)STARPU_VECTOR_GET_PTR(buffers[0]);
  2345. for (i = 0; i < n; i++)
  2346. val[i] *= *factor;
  2347. @}
  2348. starpu_codelet cl = @{
  2349. .where = STARPU_CPU,
  2350. .cpu_func = scal_cpu_func,
  2351. .nbuffers = 1
  2352. @};
  2353. @end smallexample
  2354. @end cartouche
  2355. The second argument of the @code{scal_cpu_func} function contains a pointer to the
  2356. parameters of the codelet (given in @code{task->cl_arg}), so that we read the
  2357. constant factor from this pointer. The first argument is an array that gives
  2358. a description of all the buffers passed in the @code{task->buffers}@ array. The
  2359. size of this array is given by the @code{nbuffers} field of the codelet
  2360. structure. For the sake of generality, this array contains pointers to the
  2361. different interfaces describing each buffer. In the case of the @b{vector
  2362. interface}, the location of the vector (resp. its length) is accessible in the
  2363. @code{ptr} (resp. @code{nx}) of this array. Since the vector is accessed in a
  2364. read-write fashion, any modification will automatically affect future accesses
  2365. to this vector made by other tasks.
  2366. @node Execution of Vector Scaling
  2367. @subsection Execution of Vector Scaling
  2368. @smallexample
  2369. % make vector_scal
  2370. cc $(pkg-config --cflags libstarpu) $(pkg-config --libs libstarpu) vector_scal.c -o vector_scal
  2371. % ./vector_scal
  2372. 0.000000 3.000000 6.000000 9.000000 12.000000
  2373. @end smallexample
  2374. @node Vector Scaling on an Hybrid CPU/GPU Machine
  2375. @section Vector Scaling on an Hybrid CPU/GPU Machine
  2376. Contrary to the previous examples, the task submitted in this example may not
  2377. only be executed by the CPUs, but also by a CUDA device.
  2378. @menu
  2379. * Definition of the CUDA Codelet::
  2380. * Definition of the OpenCL Codelet::
  2381. * Definition of the Main Code::
  2382. * Execution of Hybrid Vector Scaling::
  2383. @end menu
  2384. @node Definition of the CUDA Codelet
  2385. @subsection Definition of the CUDA Codelet
  2386. The CUDA implementation can be written as follows. It needs to be
  2387. compiled with a CUDA compiler such as nvcc, the NVIDIA CUDA compiler
  2388. driver.
  2389. @cartouche
  2390. @smallexample
  2391. #include <starpu.h>
  2392. static __global__ void vector_mult_cuda(float *val, unsigned n,
  2393. float factor)
  2394. @{
  2395. unsigned i;
  2396. for(i = 0 ; i < n ; i++)
  2397. val[i] *= factor;
  2398. @}
  2399. extern "C" void scal_cuda_func(void *buffers[], void *_args)
  2400. @{
  2401. float *factor = (float *)_args;
  2402. /* length of the vector */
  2403. unsigned n = STARPU_VECTOR_GET_NX(buffers[0]);
  2404. /* local copy of the vector pointer */
  2405. float *val = (float *)STARPU_VECTOR_GET_PTR(buffers[0]);
  2406. @i{ vector_mult_cuda<<<1,1>>>(val, n, *factor);}
  2407. @i{ cudaThreadSynchronize();}
  2408. @}
  2409. @end smallexample
  2410. @end cartouche
  2411. @node Definition of the OpenCL Codelet
  2412. @subsection Definition of the OpenCL Codelet
  2413. The OpenCL implementation can be written as follows. StarPU provides
  2414. tools to compile a OpenCL codelet stored in a file.
  2415. @cartouche
  2416. @smallexample
  2417. __kernel void vector_mult_opencl(__global float* val, int nx, float factor)
  2418. @{
  2419. const int i = get_global_id(0);
  2420. if (i < nx) @{
  2421. val[i] *= factor;
  2422. @}
  2423. @}
  2424. @end smallexample
  2425. @end cartouche
  2426. @cartouche
  2427. @smallexample
  2428. #include <starpu.h>
  2429. @i{#include <starpu_opencl.h>}
  2430. @i{extern struct starpu_opencl_program programs;}
  2431. void scal_opencl_func(void *buffers[], void *_args)
  2432. @{
  2433. float *factor = _args;
  2434. @i{ int id, devid, err;}
  2435. @i{ cl_kernel kernel;}
  2436. @i{ cl_command_queue queue;}
  2437. /* length of the vector */
  2438. unsigned n = STARPU_VECTOR_GET_NX(buffers[0]);
  2439. /* local copy of the vector pointer */
  2440. float *val = (float *)STARPU_VECTOR_GET_PTR(buffers[0]);
  2441. @i{ id = starpu_worker_get_id();}
  2442. @i{ devid = starpu_worker_get_devid(id);}
  2443. @i{ err = starpu_opencl_load_kernel(&kernel, &queue, &programs,}
  2444. @i{ "vector_mult_opencl", devid); /* @b{Name of the codelet defined above} */}
  2445. @i{ if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);}
  2446. @i{ err = clSetKernelArg(kernel, 0, sizeof(cl_mem), &val);}
  2447. @i{ err |= clSetKernelArg(kernel, 1, sizeof(n), &n);}
  2448. @i{ err |= clSetKernelArg(kernel, 2, sizeof(*factor), factor);}
  2449. @i{ if (err) STARPU_OPENCL_REPORT_ERROR(err);}
  2450. @i{ @{}
  2451. @i{ size_t global=1;}
  2452. @i{ size_t local=1;}
  2453. @i{ err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &global, &local, 0, NULL, NULL);}
  2454. @i{ if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);}
  2455. @i{ @}}
  2456. @i{ clFinish(queue);}
  2457. @i{ starpu_opencl_release_kernel(kernel);}
  2458. @}
  2459. @end smallexample
  2460. @end cartouche
  2461. @node Definition of the Main Code
  2462. @subsection Definition of the Main Code
  2463. The CPU implementation is the same as in the previous section.
  2464. Here is the source of the main application. You can notice the value of the
  2465. field @code{where} for the codelet. We specify
  2466. @code{STARPU_CPU|STARPU_CUDA|STARPU_OPENCL} to indicate to StarPU that the codelet
  2467. can be executed either on a CPU or on a CUDA or an OpenCL device.
  2468. @cartouche
  2469. @smallexample
  2470. #include <starpu.h>
  2471. #define NX 2048
  2472. extern void scal_cuda_func(void *buffers[], void *_args);
  2473. extern void scal_cpu_func(void *buffers[], void *_args);
  2474. extern void scal_opencl_func(void *buffers[], void *_args);
  2475. /* @b{Definition of the codelet} */
  2476. static starpu_codelet cl = @{
  2477. .where = STARPU_CPU|STARPU_CUDA|STARPU_OPENCL; /* @b{It can be executed on a CPU,} */
  2478. /* @b{on a CUDA device, or on an OpenCL device} */
  2479. .cuda_func = scal_cuda_func;
  2480. .cpu_func = scal_cpu_func;
  2481. .opencl_func = scal_opencl_func;
  2482. .nbuffers = 1;
  2483. @}
  2484. #ifdef STARPU_USE_OPENCL
  2485. /* @b{The compiled version of the OpenCL program} */
  2486. struct starpu_opencl_program programs;
  2487. #endif
  2488. int main(int argc, char **argv)
  2489. @{
  2490. float *vector;
  2491. int i, ret;
  2492. float factor=3.0;
  2493. struct starpu_task *task;
  2494. starpu_data_handle vector_handle;
  2495. starpu_init(NULL); /* @b{Initialising StarPU} */
  2496. #ifdef STARPU_USE_OPENCL
  2497. starpu_opencl_load_opencl_from_file("examples/basic_examples/vector_scal_opencl_codelet.cl",
  2498. &programs);
  2499. #endif
  2500. vector = malloc(NX*sizeof(vector[0]));
  2501. assert(vector);
  2502. for(i=0 ; i<NX ; i++) vector[i] = i;
  2503. @end smallexample
  2504. @end cartouche
  2505. @cartouche
  2506. @smallexample
  2507. /* @b{Registering data within StarPU} */
  2508. starpu_vector_data_register(&vector_handle, 0, (uintptr_t)vector,
  2509. NX, sizeof(vector[0]));
  2510. /* @b{Definition of the task} */
  2511. task = starpu_task_create();
  2512. task->cl = &cl;
  2513. task->buffers[0].handle = vector_handle;
  2514. task->buffers[0].mode = STARPU_RW;
  2515. task->cl_arg = &factor;
  2516. task->cl_arg_size = sizeof(factor);
  2517. @end smallexample
  2518. @end cartouche
  2519. @cartouche
  2520. @smallexample
  2521. /* @b{Submitting the task} */
  2522. ret = starpu_task_submit(task);
  2523. if (ret == -ENODEV) @{
  2524. fprintf(stderr, "No worker may execute this task\n");
  2525. return 1;
  2526. @}
  2527. /* @b{Waiting for its termination} */
  2528. starpu_task_wait_for_all();
  2529. /* @b{Update the vector in RAM} */
  2530. starpu_data_acquire(vector_handle, STARPU_R);
  2531. @end smallexample
  2532. @end cartouche
  2533. @cartouche
  2534. @smallexample
  2535. /* @b{Access the data} */
  2536. for(i=0 ; i<NX; i++) @{
  2537. fprintf(stderr, "%f ", vector[i]);
  2538. @}
  2539. fprintf(stderr, "\n");
  2540. /* @b{Release the data and shutdown StarPU} */
  2541. starpu_data_release(vector_handle);
  2542. starpu_shutdown();
  2543. return 0;
  2544. @}
  2545. @end smallexample
  2546. @end cartouche
  2547. @node Execution of Hybrid Vector Scaling
  2548. @subsection Execution of Hybrid Vector Scaling
  2549. The Makefile given at the beginning of the section must be extended to
  2550. give the rules to compile the CUDA source code. Note that the source
  2551. file of the OpenCL codelet does not need to be compiled now, it will
  2552. be compiled at run-time when calling the function
  2553. @code{starpu_opencl_load_opencl_from_file} (@pxref{starpu_opencl_load_opencl_from_file}).
  2554. @cartouche
  2555. @smallexample
  2556. CFLAGS += $(shell pkg-config --cflags libstarpu)
  2557. LDFLAGS += $(shell pkg-config --libs libstarpu)
  2558. CC = gcc
  2559. vector_scal: vector_scal.o vector_scal_cpu.o vector_scal_cuda.o vector_scal_opencl.o
  2560. %.o: %.cu
  2561. nvcc $(CFLAGS) $< -c $@
  2562. clean:
  2563. rm -f vector_scal *.o
  2564. @end smallexample
  2565. @end cartouche
  2566. @smallexample
  2567. % make
  2568. @end smallexample
  2569. and to execute it, with the default configuration:
  2570. @smallexample
  2571. % ./vector_scal
  2572. 0.000000 3.000000 6.000000 9.000000 12.000000
  2573. @end smallexample
  2574. or for example, by disabling CPU devices:
  2575. @smallexample
  2576. % STARPU_NCPUS=0 ./vector_scal
  2577. 0.000000 3.000000 6.000000 9.000000 12.000000
  2578. @end smallexample
  2579. or by disabling CUDA devices:
  2580. @smallexample
  2581. % STARPU_NCUDA=0 ./vector_scal
  2582. 0.000000 3.000000 6.000000 9.000000 12.000000
  2583. @end smallexample
  2584. @node Task and Worker Profiling
  2585. @section Task and Worker Profiling
  2586. A full example showing how to use the profiling API is available in
  2587. the StarPU sources in the directory @code{examples/profiling/}.
  2588. @cartouche
  2589. @smallexample
  2590. struct starpu_task *task = starpu_task_create();
  2591. task->cl = &cl;
  2592. task->synchronous = 1;
  2593. /* We will destroy the task structure by hand so that we can
  2594. * query the profiling info before the task is destroyed. */
  2595. task->destroy = 0;
  2596. starpu_task_submit(task);
  2597. /* The task is finished, get profiling information */
  2598. struct starpu_task_profiling_info *info = task->profiling_info;
  2599. /* How much time did it take before the task started ? */
  2600. double delay += starpu_timing_timespec_delay_us(&info->submit_time, &info->start_time);
  2601. /* How long was the task execution ? */
  2602. double length += starpu_timing_timespec_delay_us(&info->start_time, &info->end_time);
  2603. /* We don't need the task structure anymore */
  2604. starpu_task_destroy(task);
  2605. @end smallexample
  2606. @end cartouche
  2607. @cartouche
  2608. @smallexample
  2609. /* Display the occupancy of all workers during the test */
  2610. int worker;
  2611. for (worker = 0; worker < starpu_worker_get_count(); worker++)
  2612. @{
  2613. struct starpu_worker_profiling_info worker_info;
  2614. int ret = starpu_worker_get_profiling_info(worker, &worker_info);
  2615. STARPU_ASSERT(!ret);
  2616. double total_time = starpu_timing_timespec_to_us(&worker_info.total_time);
  2617. double executing_time = starpu_timing_timespec_to_us(&worker_info.executing_time);
  2618. double sleeping_time = starpu_timing_timespec_to_us(&worker_info.sleeping_time);
  2619. float executing_ratio = 100.0*executing_time/total_time;
  2620. float sleeping_ratio = 100.0*sleeping_time/total_time;
  2621. char workername[128];
  2622. starpu_worker_get_name(worker, workername, 128);
  2623. fprintf(stderr, "Worker %s:\n", workername);
  2624. fprintf(stderr, "\ttotal time : %.2lf ms\n", total_time*1e-3);
  2625. fprintf(stderr, "\texec time : %.2lf ms (%.2f %%)\n", executing_time*1e-3,
  2626. executing_ratio);
  2627. fprintf(stderr, "\tblocked time : %.2lf ms (%.2f %%)\n", sleeping_time*1e-3,
  2628. sleeping_ratio);
  2629. @}
  2630. @end smallexample
  2631. @end cartouche
  2632. @node Partitioning Data
  2633. @section Partitioning Data
  2634. @cartouche
  2635. @smallexample
  2636. int vector[NX];
  2637. starpu_data_handle handle;
  2638. /* Declare data to StarPU */
  2639. starpu_vector_data_register(&handle, 0, (uintptr_t)vector, NX, sizeof(vector[0]));
  2640. /* Partition the vector in PARTS sub-vectors */
  2641. starpu_filter f =
  2642. @{
  2643. .filter_func = starpu_block_filter_func_vector,
  2644. .nchildren = PARTS,
  2645. .get_nchildren = NULL,
  2646. .get_child_ops = NULL
  2647. @};
  2648. starpu_data_partition(handle, &f);
  2649. @end smallexample
  2650. @end cartouche
  2651. @cartouche
  2652. @smallexample
  2653. /* Submit a task on each sub-vector */
  2654. for (i=0; i<starpu_data_get_nb_children(handle); i++) @{
  2655. starpu_data_handle sub_handle = starpu_data_get_sub_data(handle, 1, i);
  2656. struct starpu_task *task = starpu_task_create();
  2657. task->buffers[0].handle = sub_handle;
  2658. task->buffers[0].mode = STARPU_RW;
  2659. task->cl = &cl;
  2660. task->synchronous = 1;
  2661. task->cl_arg = &factor;
  2662. task->cl_arg_size = sizeof(factor);
  2663. starpu_task_submit(task);
  2664. @}
  2665. @end smallexample
  2666. @end cartouche
  2667. @node Performance model example
  2668. @section Performance model example
  2669. TODO
  2670. @cartouche
  2671. @smallexample
  2672. static struct starpu_perfmodel_t mult_perf_model = @{
  2673. .type = STARPU_HISTORY_BASED,
  2674. .symbol = "mult_perf_model"
  2675. @};
  2676. starpu_codelet cl = @{
  2677. .where = STARPU_CPU,
  2678. .cpu_func = cpu_mult,
  2679. .nbuffers = 3,
  2680. /* in case the scheduling policy may use performance models */
  2681. .model = &mult_perf_model
  2682. @};
  2683. @end smallexample
  2684. @end cartouche
  2685. @node More examples
  2686. @section More examples
  2687. More examples are available in the StarPU sources in the @code{examples/}
  2688. directory. Simple examples include:
  2689. @table @asis
  2690. @item @code{incrementer/}:
  2691. Trivial incrementation test.
  2692. @item @code{basic_examples/}:
  2693. Simple documented Hello world (as shown in @ref{Hello World}), vector/scalar product (as shown
  2694. in @ref{Vector Scaling on an Hybrid CPU/GPU Machine}), matrix
  2695. product examples (as shown in @ref{Performance model example}), an example using the blocked matrix data
  2696. interface, and an example using the variable data interface.
  2697. @item @code{matvecmult/}:
  2698. OpenCL example from NVidia, adapted to StarPU.
  2699. @item @code{axpy/}:
  2700. AXPY CUBLAS operation adapted to StarPU.
  2701. @item @code{fortran/}:
  2702. Example of Fortran bindings.
  2703. @end table
  2704. More advanced examples include:
  2705. @table @asis
  2706. @item @code{filters/}:
  2707. Examples using filters, as shown in @ref{Partitioning Data}.
  2708. @item @code{lu/}:
  2709. LU matrix factorization.
  2710. @end table
  2711. @c ---------------------------------------------------------------------
  2712. @c Advanced Topics
  2713. @c ---------------------------------------------------------------------
  2714. @node Advanced Topics
  2715. @chapter Advanced Topics
  2716. @menu
  2717. * Defining a new data interface::
  2718. * Defining a new scheduling policy::
  2719. @end menu
  2720. @node Defining a new data interface
  2721. @section Defining a new data interface
  2722. @menu
  2723. * struct starpu_data_interface_ops_t:: Per-interface methods
  2724. * struct starpu_data_copy_methods:: Per-interface data transfer methods
  2725. * An example of data interface:: An example of data interface
  2726. @end menu
  2727. @c void *starpu_data_get_interface_on_node(starpu_data_handle handle, unsigned memory_node); TODO
  2728. @node struct starpu_data_interface_ops_t
  2729. @subsection @code{struct starpu_data_interface_ops_t} -- Per-interface methods
  2730. @table @asis
  2731. @item @emph{Description}:
  2732. TODO describe all the different fields
  2733. @end table
  2734. @node struct starpu_data_copy_methods
  2735. @subsection @code{struct starpu_data_copy_methods} -- Per-interface data transfer methods
  2736. @table @asis
  2737. @item @emph{Description}:
  2738. TODO describe all the different fields
  2739. @end table
  2740. @node An example of data interface
  2741. @subsection An example of data interface
  2742. @table @asis
  2743. TODO
  2744. @end table
  2745. @node Defining a new scheduling policy
  2746. @section Defining a new scheduling policy
  2747. TODO
  2748. @c ---------------------------------------------------------------------
  2749. @c Appendices
  2750. @c ---------------------------------------------------------------------
  2751. @c ---------------------------------------------------------------------
  2752. @c Full source code for the 'Scaling a Vector' example
  2753. @c ---------------------------------------------------------------------
  2754. @node Full source code for the 'Scaling a Vector' example
  2755. @appendix Full source code for the 'Scaling a Vector' example
  2756. @menu
  2757. * Main application::
  2758. * CPU Codelet::
  2759. * CUDA Codelet::
  2760. * OpenCL Codelet::
  2761. @end menu
  2762. @node Main application
  2763. @section Main application
  2764. @smallexample
  2765. @include vector_scal_c.texi
  2766. @end smallexample
  2767. @node CPU Codelet
  2768. @section CPU Codelet
  2769. @smallexample
  2770. @include vector_scal_cpu.texi
  2771. @end smallexample
  2772. @node CUDA Codelet
  2773. @section CUDA Codelet
  2774. @smallexample
  2775. @include vector_scal_cuda.texi
  2776. @end smallexample
  2777. @node OpenCL Codelet
  2778. @section OpenCL Codelet
  2779. @menu
  2780. * Invoking the kernel::
  2781. * Source of the kernel::
  2782. @end menu
  2783. @node Invoking the kernel
  2784. @subsection Invoking the kernel
  2785. @smallexample
  2786. @include vector_scal_opencl.texi
  2787. @end smallexample
  2788. @node Source of the kernel
  2789. @subsection Source of the kernel
  2790. @smallexample
  2791. @include vector_scal_opencl_codelet.texi
  2792. @end smallexample
  2793. @bye