starpu.texi 161 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510
  1. \input texinfo @c -*-texinfo-*-
  2. @c %**start of header
  3. @setfilename starpu.info
  4. @settitle StarPU Handbook
  5. @c %**end of header
  6. @setchapternewpage odd
  7. @titlepage
  8. @title StarPU Handbook
  9. @page
  10. @vskip 0pt plus 1fill
  11. @comment For the @value{version-GCC} Version*
  12. @end titlepage
  13. @c @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. * Basic Examples:: Basic examples of the use of StarPU
  30. * Performance optimization:: How to optimize performance with StarPU
  31. * Performance feedback:: Performance debugging tools
  32. * StarPU MPI support:: How to combine StarPU with MPI
  33. * Configuring StarPU:: How to configure StarPU
  34. * StarPU API:: The API to use StarPU
  35. * Advanced Topics:: Advanced use of StarPU
  36. * Full source code for the 'Scaling a Vector' example::
  37. @end menu
  38. @c ---------------------------------------------------------------------
  39. @c Introduction to StarPU
  40. @c ---------------------------------------------------------------------
  41. @node Introduction
  42. @chapter Introduction to StarPU
  43. @menu
  44. * Motivation:: Why StarPU ?
  45. * StarPU in a Nutshell:: The Fundamentals of StarPU
  46. @end menu
  47. @node Motivation
  48. @section Motivation
  49. @c complex machines with heterogeneous cores/devices
  50. The use of specialized hardware such as accelerators or coprocessors offers an
  51. interesting approach to overcome the physical limits encountered by processor
  52. architects. As a result, many machines are now equipped with one or several
  53. accelerators (e.g. a GPU), in addition to the usual processor(s). While a lot of
  54. efforts have been devoted to offload computation onto such accelerators, very
  55. little attention as been paid to portability concerns on the one hand, and to the
  56. possibility of having heterogeneous accelerators and processors to interact on the other hand.
  57. StarPU is a runtime system that offers support for heterogeneous multicore
  58. architectures, it not only offers a unified view of the computational resources
  59. (i.e. CPUs and accelerators at the same time), but it also takes care of
  60. efficiently mapping and executing tasks onto an heterogeneous machine while
  61. transparently handling low-level issues such as data transfers in a portable
  62. fashion.
  63. @c this leads to a complicated distributed memory design
  64. @c which is not (easily) manageable by hand
  65. @c added value/benefits of StarPU
  66. @c - portability
  67. @c - scheduling, perf. portability
  68. @node StarPU in a Nutshell
  69. @section StarPU in a Nutshell
  70. @menu
  71. * Codelet and Tasks::
  72. * StarPU Data Management Library::
  73. * Research Papers::
  74. @end menu
  75. From a programming point of view, StarPU is not a new language but a library
  76. that executes tasks explicitly submitted by the application. The data that a
  77. task manipulates are automatically transferred onto the accelerator so that the
  78. programmer does not have to take care of complex data movements. StarPU also
  79. takes particular care of scheduling those tasks efficiently and allows
  80. scheduling experts to implement custom scheduling policies in a portable
  81. fashion.
  82. @c explain the notion of codelet and task (i.e. g(A, B)
  83. @node Codelet and Tasks
  84. @subsection Codelet and Tasks
  85. One of the StarPU primary data structures is the @b{codelet}. A codelet describes a
  86. computational kernel that can possibly be implemented on multiple architectures
  87. such as a CPU, a CUDA device or a Cell's SPU.
  88. @c TODO insert illustration f : f_spu, f_cpu, ...
  89. Another important data structure is the @b{task}. Executing a StarPU task
  90. consists in applying a codelet on a data set, on one of the architectures on
  91. which the codelet is implemented. In addition to the codelet that a task
  92. useuses, it also describes which data are accessed, and how they are
  93. accessed during the computation (read and/or write).
  94. StarPU tasks are asynchronous: submitting a task to StarPU is a non-blocking
  95. operation. The task structure can also specify a @b{callback} function that is
  96. called once StarPU has properly executed the task. It also contains optional
  97. fields that the application may use to give hints to the scheduler (such as
  98. priority levels).
  99. A task may be identified by a unique 64-bit number chosen by the application
  100. which we refer as a @b{tag}.
  101. Task dependencies can be enforced either by the means of callback functions, by
  102. expressing dependencies between explicit tasks or by expressing dependencies
  103. between tags (which can thus correspond to tasks that have not been submitted
  104. yet).
  105. @c TODO insert illustration f(Ar, Brw, Cr) + ..
  106. @c DSM
  107. @node StarPU Data Management Library
  108. @subsection StarPU Data Management Library
  109. Because StarPU schedules tasks at runtime, data transfers have to be
  110. done automatically and ``just-in-time'' between processing units,
  111. relieving the application programmer from explicit data transfers.
  112. Moreover, to avoid unnecessary transfers, StarPU keeps data
  113. where it was last needed, even if was modified there, and it
  114. allows multiple copies of the same data to reside at the same time on
  115. several processing units as long as it is not modified.
  116. @node Research Papers
  117. @subsection Research Papers
  118. Research papers about StarPU can be found at
  119. @indicateurl{http://runtime.bordeaux.inria.fr/Publis/Keyword/STARPU.html}
  120. Notably a good overview in the research report
  121. @indicateurl{http://hal.archives-ouvertes.fr/inria-00467677}
  122. @c ---------------------------------------------------------------------
  123. @c Installing StarPU
  124. @c ---------------------------------------------------------------------
  125. @node Installing StarPU
  126. @chapter Installing StarPU
  127. @menu
  128. * Downloading StarPU::
  129. * Configuration of StarPU::
  130. * Building and Installing StarPU::
  131. @end menu
  132. StarPU can be built and installed by the standard means of the GNU
  133. autotools. The following chapter is intended to briefly remind how these tools
  134. can be used to install StarPU.
  135. @node Downloading StarPU
  136. @section Downloading StarPU
  137. @menu
  138. * Getting Sources::
  139. * Optional dependencies::
  140. @end menu
  141. @node Getting Sources
  142. @subsection Getting Sources
  143. The simplest way to get StarPU sources is to download the latest official
  144. release tarball from @indicateurl{https://gforge.inria.fr/frs/?group_id=1570} ,
  145. or the latest nightly snapshot from
  146. @indicateurl{http://starpu.gforge.inria.fr/testing/} . The following documents
  147. how to get the very latest version from the subversion repository itself, it
  148. should be needed only if you need the very latest changes (i.e. less than a
  149. day!)
  150. The source code is managed by a Subversion server hosted by the
  151. InriaGforge. To get the source code, you need:
  152. @itemize
  153. @item
  154. To install the client side of the software Subversion if it is
  155. not already available on your system. The software can be obtained from
  156. @indicateurl{http://subversion.tigris.org} . If you are running
  157. on Windows, you will probably prefer to use TortoiseSVN from
  158. @indicateurl{http://tortoisesvn.tigris.org/} .
  159. @item
  160. You can check out the project's SVN repository through anonymous
  161. access. This will provide you with a read access to the
  162. repository.
  163. If you need to have write access on the StarPU project, you can also choose to
  164. become a member of the project @code{starpu}. For this, you first need to get
  165. an account to the gForge server. You can then send a request to join the project
  166. (@indicateurl{https://gforge.inria.fr/project/request.php?group_id=1570}).
  167. @item
  168. More information on how to get a gForge account, to become a member of
  169. a project, or on any other related task can be obtained from the
  170. InriaGforge at @indicateurl{https://gforge.inria.fr/}. The most important
  171. thing is to upload your public SSH key on the gForge server (see the
  172. FAQ at @indicateurl{http://siteadmin.gforge.inria.fr/FAQ.html#Q6} for
  173. instructions).
  174. @end itemize
  175. You can now check out the latest version from the Subversion server:
  176. @itemize
  177. @item
  178. using the anonymous access via svn:
  179. @example
  180. % svn checkout svn://scm.gforge.inria.fr/svn/starpu/trunk
  181. @end example
  182. @item
  183. using the anonymous access via https:
  184. @example
  185. % svn checkout --username anonsvn https://scm.gforge.inria.fr/svn/starpu/trunk
  186. @end example
  187. The password is @code{anonsvn}.
  188. @item
  189. using your gForge account
  190. @example
  191. % svn checkout svn+ssh://<login>@@scm.gforge.inria.fr/svn/starpu/trunk
  192. @end example
  193. @end itemize
  194. The following step requires the availability of @code{autoconf} and
  195. @code{automake} to generate the @code{./configure} script. This is
  196. done by calling @code{./autogen.sh}. The required version for
  197. @code{autoconf} is 2.60 or higher. You will also need @code{makeinfo}.
  198. @example
  199. % ./autogen.sh
  200. @end example
  201. If the autotools are not available on your machine or not recent
  202. enough, you can choose to download the latest nightly tarball, which
  203. is provided with a @code{configure} script.
  204. @example
  205. % wget http://starpu.gforge.inria.fr/testing/starpu-nightly-latest.tar.gz
  206. @end example
  207. @node Optional dependencies
  208. @subsection Optional dependencies
  209. The topology discovery library, @code{hwloc}, is not mandatory to use StarPU
  210. but strongly recommended. It allows to increase performance, and to
  211. perform some topology aware scheduling.
  212. @code{hwloc} is available in major distributions and for most OSes and can be
  213. downloaded from @indicateurl{http://www.open-mpi.org/software/hwloc}.
  214. @node Configuration of StarPU
  215. @section Configuration of StarPU
  216. @menu
  217. * Generating Makefiles and configuration scripts::
  218. * Running the configuration::
  219. @end menu
  220. @node Generating Makefiles and configuration scripts
  221. @subsection Generating Makefiles and configuration scripts
  222. This step is not necessary when using the tarball releases of StarPU. If you
  223. are using the source code from the svn repository, you first need to generate
  224. the configure scripts and the Makefiles.
  225. @example
  226. % ./autogen.sh
  227. @end example
  228. @node Running the configuration
  229. @subsection Running the configuration
  230. @example
  231. % ./configure
  232. @end example
  233. Details about options that are useful to give to @code{./configure} are given in
  234. @ref{Compilation configuration}.
  235. @node Building and Installing StarPU
  236. @section Building and Installing StarPU
  237. @menu
  238. * Building::
  239. * Sanity Checks::
  240. * Installing::
  241. @end menu
  242. @node Building
  243. @subsection Building
  244. @example
  245. % make
  246. @end example
  247. @node Sanity Checks
  248. @subsection Sanity Checks
  249. In order to make sure that StarPU is working properly on the system, it is also
  250. possible to run a test suite.
  251. @example
  252. % make check
  253. @end example
  254. @node Installing
  255. @subsection Installing
  256. In order to install StarPU at the location that was specified during
  257. configuration:
  258. @example
  259. % make install
  260. @end example
  261. @c ---------------------------------------------------------------------
  262. @c Using StarPU
  263. @c ---------------------------------------------------------------------
  264. @node Using StarPU
  265. @chapter Using StarPU
  266. @menu
  267. * Setting flags for compiling and linking applications::
  268. * Running a basic StarPU application::
  269. * Kernel threads started by StarPU::
  270. * Using accelerators::
  271. @end menu
  272. @node Setting flags for compiling and linking applications
  273. @section Setting flags for compiling and linking applications
  274. Compiling and linking an application against StarPU may require to use
  275. specific flags or libraries (for instance @code{CUDA} or @code{libspe2}).
  276. To this end, it is possible to use the @code{pkg-config} tool.
  277. If StarPU was not installed at some standard location, the path of StarPU's
  278. library must be specified in the @code{PKG_CONFIG_PATH} environment variable so
  279. that @code{pkg-config} can find it. For example if StarPU was installed in
  280. @code{$prefix_dir}:
  281. @example
  282. % PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$prefix_dir/lib/pkgconfig
  283. @end example
  284. The flags required to compile or link against StarPU are then
  285. accessible with the following commands:
  286. @example
  287. % pkg-config --cflags libstarpu # options for the compiler
  288. % pkg-config --libs libstarpu # options for the linker
  289. @end example
  290. @node Running a basic StarPU application
  291. @section Running a basic StarPU application
  292. Basic examples using StarPU have been built in the directory
  293. @code{$prefix_dir/lib/starpu/examples/}. You can for example run the
  294. example @code{vector_scal}.
  295. @example
  296. % $prefix_dir/lib/starpu/examples/vector_scal
  297. BEFORE : First element was 1.000000
  298. AFTER First element is 3.140000
  299. %
  300. @end example
  301. When StarPU is used for the first time, the directory
  302. @code{$HOME/.starpu/} is created, performance models will be stored in
  303. that directory.
  304. Please note that buses are benchmarked when StarPU is launched for the
  305. first time. This may take a few minutes, or less if @code{hwloc} is
  306. installed. This step is done only once per user and per machine.
  307. @node Kernel threads started by StarPU
  308. @section Kernel threads started by StarPU
  309. TODO: StarPU starts one thread per CPU core and binds them there, uses one of
  310. them per GPU. The application is not supposed to do computations in its own
  311. threads. TODO: add a StarPU function to bind an application thread (e.g. the
  312. main thread) to a dedicated core (and thus disable the corresponding StarPU CPU
  313. worker).
  314. @node Using accelerators
  315. @section Using accelerators
  316. When both CUDA and OpenCL drivers are enabled, StarPU will launch an
  317. OpenCL worker for NVIDIA GPUs only if CUDA is not already running on them.
  318. This design choice was necessary as OpenCL and CUDA can not run at the
  319. same time on the same NVIDIA GPU, as there is currently no interoperability
  320. between them.
  321. Details on how to specify devices running OpenCL and the ones running
  322. CUDA are given in @ref{Enabling OpenCL}.
  323. @c ---------------------------------------------------------------------
  324. @c Basic Examples
  325. @c ---------------------------------------------------------------------
  326. @node Basic Examples
  327. @chapter Basic Examples
  328. @menu
  329. * Compiling and linking options::
  330. * Hello World:: Submitting Tasks
  331. * Scaling a Vector:: Manipulating Data
  332. * Vector Scaling on an Hybrid CPU/GPU Machine:: Handling Heterogeneous Architectures
  333. * Task and Worker Profiling::
  334. * Partitioning Data:: Partitioning Data
  335. * Performance model example::
  336. * Theoretical lower bound on execution time::
  337. * Insert Task Utility::
  338. * More examples:: More examples shipped with StarPU
  339. @end menu
  340. @node Compiling and linking options
  341. @section Compiling and linking options
  342. Let's suppose StarPU has been installed in the directory
  343. @code{$STARPU_DIR}. As explained in @ref{Setting flags for compiling and linking applications},
  344. the variable @code{PKG_CONFIG_PATH} needs to be set. It is also
  345. necessary to set the variable @code{LD_LIBRARY_PATH} to locate dynamic
  346. libraries at runtime.
  347. @example
  348. % PKG_CONFIG_PATH=$STARPU_DIR/lib/pkgconfig:$PKG_CONFIG_PATH
  349. % LD_LIBRARY_PATH=$STARPU_DIR/lib:$LD_LIBRARY_PATH
  350. @end example
  351. The Makefile could for instance contain the following lines to define which
  352. options must be given to the compiler and to the linker:
  353. @cartouche
  354. @example
  355. CFLAGS += $$(pkg-config --cflags libstarpu)
  356. LDFLAGS += $$(pkg-config --libs libstarpu)
  357. @end example
  358. @end cartouche
  359. @node Hello World
  360. @section Hello World
  361. @menu
  362. * Required Headers::
  363. * Defining a Codelet::
  364. * Submitting a Task::
  365. * Execution of Hello World::
  366. @end menu
  367. In this section, we show how to implement a simple program that submits a task to StarPU.
  368. @node Required Headers
  369. @subsection Required Headers
  370. The @code{starpu.h} header should be included in any code using StarPU.
  371. @cartouche
  372. @smallexample
  373. #include <starpu.h>
  374. @end smallexample
  375. @end cartouche
  376. @node Defining a Codelet
  377. @subsection Defining a Codelet
  378. @cartouche
  379. @smallexample
  380. struct params @{
  381. int i;
  382. float f;
  383. @};
  384. void cpu_func(void *buffers[], void *cl_arg)
  385. @{
  386. struct params *params = cl_arg;
  387. printf("Hello world (params = @{%i, %f@} )\n", params->i, params->f);
  388. @}
  389. starpu_codelet cl =
  390. @{
  391. .where = STARPU_CPU,
  392. .cpu_func = cpu_func,
  393. .nbuffers = 0
  394. @};
  395. @end smallexample
  396. @end cartouche
  397. A codelet is a structure that represents a computational kernel. Such a codelet
  398. may contain an implementation of the same kernel on different architectures
  399. (e.g. CUDA, Cell's SPU, x86, ...).
  400. The @code{nbuffers} field specifies the number of data buffers that are
  401. manipulated by the codelet: here the codelet does not access or modify any data
  402. that is controlled by our data management library. Note that the argument
  403. passed to the codelet (the @code{cl_arg} field of the @code{starpu_task}
  404. structure) does not count as a buffer since it is not managed by our data
  405. management library, but just contain trivial parameters.
  406. @c TODO need a crossref to the proper description of "where" see bla for more ...
  407. We create a codelet which may only be executed on the CPUs. The @code{where}
  408. field is a bitmask that defines where the codelet may be executed. Here, the
  409. @code{STARPU_CPU} value means that only CPUs can execute this codelet
  410. (@pxref{Codelets and Tasks} for more details on this field).
  411. When a CPU core executes a codelet, it calls the @code{cpu_func} function,
  412. which @emph{must} have the following prototype:
  413. @code{void (*cpu_func)(void *buffers[], void *cl_arg);}
  414. In this example, we can ignore the first argument of this function which gives a
  415. description of the input and output buffers (e.g. the size and the location of
  416. the matrices) since there is none.
  417. The second argument is a pointer to a buffer passed as an
  418. argument to the codelet by the means of the @code{cl_arg} field of the
  419. @code{starpu_task} structure.
  420. @c TODO rewrite so that it is a little clearer ?
  421. Be aware that this may be a pointer to a
  422. @emph{copy} of the actual buffer, and not the pointer given by the programmer:
  423. if the codelet modifies this buffer, there is no guarantee that the initial
  424. buffer will be modified as well: this for instance implies that the buffer
  425. cannot be used as a synchronization medium. If synchronization is needed, data
  426. has to be registered to StarPU, see @ref{Scaling a Vector}.
  427. @node Submitting a Task
  428. @subsection Submitting a Task
  429. @cartouche
  430. @smallexample
  431. void callback_func(void *callback_arg)
  432. @{
  433. printf("Callback function (arg %x)\n", callback_arg);
  434. @}
  435. int main(int argc, char **argv)
  436. @{
  437. /* @b{initialize StarPU} */
  438. starpu_init(NULL);
  439. struct starpu_task *task = starpu_task_create();
  440. task->cl = &cl; /* @b{Pointer to the codelet defined above} */
  441. struct params params = @{ 1, 2.0f @};
  442. task->cl_arg = &params;
  443. task->cl_arg_size = sizeof(params);
  444. task->callback_func = callback_func;
  445. task->callback_arg = 0x42;
  446. /* @b{starpu_task_submit will be a blocking call} */
  447. task->synchronous = 1;
  448. /* @b{submit the task to StarPU} */
  449. starpu_task_submit(task);
  450. /* @b{terminate StarPU} */
  451. starpu_shutdown();
  452. return 0;
  453. @}
  454. @end smallexample
  455. @end cartouche
  456. Before submitting any tasks to StarPU, @code{starpu_init} must be called. The
  457. @code{NULL} argument specifies that we use default configuration. Tasks cannot
  458. be submitted after the termination of StarPU by a call to
  459. @code{starpu_shutdown}.
  460. In the example above, a task structure is allocated by a call to
  461. @code{starpu_task_create}. This function only allocates and fills the
  462. corresponding structure with the default settings (@pxref{starpu_task_create}),
  463. but it does not submit the task to StarPU.
  464. @c not really clear ;)
  465. The @code{cl} field is a pointer to the codelet which the task will
  466. execute: in other words, the codelet structure describes which computational
  467. kernel should be offloaded on the different architectures, and the task
  468. structure is a wrapper containing a codelet and the piece of data on which the
  469. codelet should operate.
  470. The optional @code{cl_arg} field is a pointer to a buffer (of size
  471. @code{cl_arg_size}) with some parameters for the kernel
  472. described by the codelet. For instance, if a codelet implements a computational
  473. kernel that multiplies its input vector by a constant, the constant could be
  474. specified by the means of this buffer, instead of registering it as a StarPU
  475. data.
  476. Once a task has been executed, an optional callback function is be called.
  477. While the computational kernel could be offloaded on various architectures, the
  478. callback function is always executed on a CPU. The @code{callback_arg}
  479. pointer is passed as an argument of the callback. The prototype of a callback
  480. function must be:
  481. @code{void (*callback_function)(void *);}
  482. If the @code{synchronous} field is non-zero, task submission will be
  483. synchronous: the @code{starpu_task_submit} function will not return until the
  484. task was executed. Note that the @code{starpu_shutdown} method does not
  485. guarantee that asynchronous tasks have been executed before it returns,
  486. @code{starpu_task_wait_for_all} can be used to that effect..
  487. @node Execution of Hello World
  488. @subsection Execution of Hello World
  489. @smallexample
  490. % make hello_world
  491. cc $(pkg-config --cflags libstarpu) $(pkg-config --libs libstarpu) hello_world.c -o hello_world
  492. % ./hello_world
  493. Hello world (params = @{1, 2.000000@} )
  494. Callback function (arg 42)
  495. @end smallexample
  496. @node Scaling a Vector
  497. @section Manipulating Data: Scaling a Vector
  498. The previous example has shown how to submit tasks. In this section,
  499. we show how StarPU tasks can manipulate data. The full source code for
  500. this example is given in @ref{Full source code for the 'Scaling a Vector' example}.
  501. @menu
  502. * Source code of Vector Scaling::
  503. * Execution of Vector Scaling::
  504. @end menu
  505. @node Source code of Vector Scaling
  506. @subsection Source code of Vector Scaling
  507. Programmers can describe the data layout of their application so that StarPU is
  508. responsible for enforcing data coherency and availability across the machine.
  509. Instead of handling complex (and non-portable) mechanisms to perform data
  510. movements, programmers only declare which piece of data is accessed and/or
  511. modified by a task, and StarPU makes sure that when a computational kernel
  512. starts somewhere (e.g. on a GPU), its data are available locally.
  513. Before submitting those tasks, the programmer first needs to declare the
  514. different pieces of data to StarPU using the @code{starpu_*_data_register}
  515. functions. To ease the development of applications for StarPU, it is possible
  516. to describe multiple types of data layout. A type of data layout is called an
  517. @b{interface}. There are different predefined interfaces available in StarPU:
  518. here we will consider the @b{vector interface}.
  519. The following lines show how to declare an array of @code{NX} elements of type
  520. @code{float} using the vector interface:
  521. @cartouche
  522. @smallexample
  523. float vector[NX];
  524. starpu_data_handle vector_handle;
  525. starpu_vector_data_register(&vector_handle, 0, (uintptr_t)vector, NX,
  526. sizeof(vector[0]));
  527. @end smallexample
  528. @end cartouche
  529. The first argument, called the @b{data handle}, is an opaque pointer which
  530. designates the array in StarPU. This is also the structure which is used to
  531. describe which data is used by a task. The second argument is the node number
  532. where the data originally resides. Here it is 0 since the @code{vector} array is in
  533. the main memory. Then comes the pointer @code{vector} where the data can be found in main memory,
  534. the number of elements in the vector and the size of each element.
  535. The following shows how to construct a StarPU task that will manipulate the
  536. vector and a constant factor.
  537. @cartouche
  538. @smallexample
  539. float factor = 3.14;
  540. struct starpu_task *task = starpu_task_create();
  541. task->cl = &cl; /* @b{Pointer to the codelet defined below} */
  542. task->buffers[0].handle = vector_handle; /* @b{First parameter of the codelet} */
  543. task->buffers[0].mode = STARPU_RW;
  544. task->cl_arg = &factor;
  545. task->cl_arg_size = sizeof(factor);
  546. task->synchronous = 1;
  547. starpu_task_submit(task);
  548. @end smallexample
  549. @end cartouche
  550. Since the factor is a mere constant float value parameter,
  551. it does not need a preliminary registration, and
  552. can just be passed through the @code{cl_arg} pointer like in the previous
  553. example. The vector parameter is described by its handle.
  554. There are two fields in each element of the @code{buffers} array.
  555. @code{handle} is the handle of the data, and @code{mode} specifies how the
  556. kernel will access the data (@code{STARPU_R} for read-only, @code{STARPU_W} for
  557. write-only and @code{STARPU_RW} for read and write access).
  558. The definition of the codelet can be written as follows:
  559. @cartouche
  560. @smallexample
  561. void scal_cpu_func(void *buffers[], void *cl_arg)
  562. @{
  563. unsigned i;
  564. float *factor = cl_arg;
  565. /* length of the vector */
  566. unsigned n = STARPU_VECTOR_GET_NX(buffers[0]);
  567. /* local copy of the vector pointer */
  568. float *val = (float *)STARPU_VECTOR_GET_PTR(buffers[0]);
  569. for (i = 0; i < n; i++)
  570. val[i] *= *factor;
  571. @}
  572. starpu_codelet cl = @{
  573. .where = STARPU_CPU,
  574. .cpu_func = scal_cpu_func,
  575. .nbuffers = 1
  576. @};
  577. @end smallexample
  578. @end cartouche
  579. The first argument is an array that gives
  580. a description of all the buffers passed in the @code{task->buffers}@ array. The
  581. size of this array is given by the @code{nbuffers} field of the codelet
  582. structure. For the sake of genericity, this array contains pointers to the
  583. different interfaces describing each buffer. In the case of the @b{vector
  584. interface}, the location of the vector (resp. its length) is accessible in the
  585. @code{ptr} (resp. @code{nx}) of this array. Since the vector is accessed in a
  586. read-write fashion, any modification will automatically affect future accesses
  587. to this vector made by other tasks.
  588. The second argument of the @code{scal_cpu_func} function contains a pointer to the
  589. parameters of the codelet (given in @code{task->cl_arg}), so that we read the
  590. constant factor from this pointer.
  591. @node Execution of Vector Scaling
  592. @subsection Execution of Vector Scaling
  593. @smallexample
  594. % make vector_scal
  595. cc $(pkg-config --cflags libstarpu) $(pkg-config --libs libstarpu) vector_scal.c -o vector_scal
  596. % ./vector_scal
  597. 0.000000 3.000000 6.000000 9.000000 12.000000
  598. @end smallexample
  599. @node Vector Scaling on an Hybrid CPU/GPU Machine
  600. @section Vector Scaling on an Hybrid CPU/GPU Machine
  601. Contrary to the previous examples, the task submitted in this example may not
  602. only be executed by the CPUs, but also by a CUDA device.
  603. @menu
  604. * Definition of the CUDA Kernel::
  605. * Definition of the OpenCL Kernel::
  606. * Definition of the Main Code::
  607. * Execution of Hybrid Vector Scaling::
  608. @end menu
  609. @node Definition of the CUDA Kernel
  610. @subsection Definition of the CUDA Kernel
  611. The CUDA implementation can be written as follows. It needs to be
  612. compiled with a CUDA compiler such as nvcc, the NVIDIA CUDA compiler
  613. driver.
  614. @cartouche
  615. @smallexample
  616. #include <starpu.h>
  617. static __global__ void vector_mult_cuda(float *val, unsigned n,
  618. float factor)
  619. @{
  620. unsigned i;
  621. if (i < n)
  622. val[i] *= factor;
  623. @}
  624. extern "C" void scal_cuda_func(void *buffers[], void *_args)
  625. @{
  626. float *factor = (float *)_args;
  627. /* length of the vector */
  628. unsigned n = STARPU_VECTOR_GET_NX(buffers[0]);
  629. /* local copy of the vector pointer */
  630. float *val = (float *)STARPU_VECTOR_GET_PTR(buffers[0]);
  631. unsigned threads_per_block = 64;
  632. unsigned nblocks = (n + threads_per_block-1) / threads_per_block;
  633. @i{ vector_mult_cuda<<<nblocks,threads_per_block, 0, starpu_cuda_get_local_stream()>>>(val, n, *factor);}
  634. @i{ cudaStreamSynchronize(starpu_cuda_get_local_stream());}
  635. @}
  636. @end smallexample
  637. @end cartouche
  638. @node Definition of the OpenCL Kernel
  639. @subsection Definition of the OpenCL Kernel
  640. The OpenCL implementation can be written as follows. StarPU provides
  641. tools to compile a OpenCL kernel stored in a file.
  642. @cartouche
  643. @smallexample
  644. __kernel void vector_mult_opencl(__global float* val, int nx, float factor)
  645. @{
  646. const int i = get_global_id(0);
  647. if (i < nx) @{
  648. val[i] *= factor;
  649. @}
  650. @}
  651. @end smallexample
  652. @end cartouche
  653. @cartouche
  654. @smallexample
  655. #include <starpu.h>
  656. @i{#include <starpu_opencl.h>}
  657. @i{extern struct starpu_opencl_program programs;}
  658. void scal_opencl_func(void *buffers[], void *_args)
  659. @{
  660. float *factor = _args;
  661. @i{ int id, devid, err;}
  662. @i{ cl_kernel kernel;}
  663. @i{ cl_command_queue queue;}
  664. @i{ cl_event event;}
  665. /* length of the vector */
  666. unsigned n = STARPU_VECTOR_GET_NX(buffers[0]);
  667. /* local copy of the vector pointer */
  668. float *val = (float *)STARPU_VECTOR_GET_PTR(buffers[0]);
  669. @i{ id = starpu_worker_get_id();}
  670. @i{ devid = starpu_worker_get_devid(id);}
  671. @i{ err = starpu_opencl_load_kernel(&kernel, &queue, &programs,}
  672. @i{ "vector_mult_opencl", devid); /* @b{Name of the codelet defined above} */}
  673. @i{ if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);}
  674. @i{ err = clSetKernelArg(kernel, 0, sizeof(cl_mem), &val);}
  675. @i{ err |= clSetKernelArg(kernel, 1, sizeof(n), &n);}
  676. @i{ err |= clSetKernelArg(kernel, 2, sizeof(*factor), factor);}
  677. @i{ if (err) STARPU_OPENCL_REPORT_ERROR(err);}
  678. @i{ @{}
  679. @i{ size_t global=1;}
  680. @i{ size_t local=1;}
  681. @i{ err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &global, &local, 0, NULL, &event);}
  682. @i{ if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);}
  683. @i{ @}}
  684. @i{ clFinish(queue);}
  685. @i{ starpu_opencl_collect_stats(event);}
  686. @i{ clReleaseEvent(event);}
  687. @i{ starpu_opencl_release_kernel(kernel);}
  688. @}
  689. @end smallexample
  690. @end cartouche
  691. @node Definition of the Main Code
  692. @subsection Definition of the Main Code
  693. The CPU implementation is the same as in the previous section.
  694. Here is the source of the main application. You can notice the value of the
  695. field @code{where} for the codelet. We specify
  696. @code{STARPU_CPU|STARPU_CUDA|STARPU_OPENCL} to indicate to StarPU that the codelet
  697. can be executed either on a CPU or on a CUDA or an OpenCL device.
  698. @cartouche
  699. @smallexample
  700. #include <starpu.h>
  701. #define NX 2048
  702. extern void scal_cuda_func(void *buffers[], void *_args);
  703. extern void scal_cpu_func(void *buffers[], void *_args);
  704. extern void scal_opencl_func(void *buffers[], void *_args);
  705. /* @b{Definition of the codelet} */
  706. static starpu_codelet cl = @{
  707. .where = STARPU_CPU|STARPU_CUDA|STARPU_OPENCL; /* @b{It can be executed on a CPU,} */
  708. /* @b{on a CUDA device, or on an OpenCL device} */
  709. .cuda_func = scal_cuda_func;
  710. .cpu_func = scal_cpu_func;
  711. .opencl_func = scal_opencl_func;
  712. .nbuffers = 1;
  713. @}
  714. #ifdef STARPU_USE_OPENCL
  715. /* @b{The compiled version of the OpenCL program} */
  716. struct starpu_opencl_program programs;
  717. #endif
  718. int main(int argc, char **argv)
  719. @{
  720. float *vector;
  721. int i, ret;
  722. float factor=3.0;
  723. struct starpu_task *task;
  724. starpu_data_handle vector_handle;
  725. starpu_init(NULL); /* @b{Initialising StarPU} */
  726. #ifdef STARPU_USE_OPENCL
  727. starpu_opencl_load_opencl_from_file(
  728. "examples/basic_examples/vector_scal_opencl_codelet.cl", &programs);
  729. #endif
  730. vector = malloc(NX*sizeof(vector[0]));
  731. assert(vector);
  732. for(i=0 ; i<NX ; i++) vector[i] = i;
  733. @end smallexample
  734. @end cartouche
  735. @cartouche
  736. @smallexample
  737. /* @b{Registering data within StarPU} */
  738. starpu_vector_data_register(&vector_handle, 0, (uintptr_t)vector,
  739. NX, sizeof(vector[0]));
  740. /* @b{Definition of the task} */
  741. task = starpu_task_create();
  742. task->cl = &cl;
  743. task->buffers[0].handle = vector_handle;
  744. task->buffers[0].mode = STARPU_RW;
  745. task->cl_arg = &factor;
  746. task->cl_arg_size = sizeof(factor);
  747. @end smallexample
  748. @end cartouche
  749. @cartouche
  750. @smallexample
  751. /* @b{Submitting the task} */
  752. ret = starpu_task_submit(task);
  753. if (ret == -ENODEV) @{
  754. fprintf(stderr, "No worker may execute this task\n");
  755. return 1;
  756. @}
  757. @c TODO: Mmm, should rather be an unregistration with an implicit dependency, no?
  758. /* @b{Waiting for its termination} */
  759. starpu_task_wait_for_all();
  760. /* @b{Update the vector in RAM} */
  761. starpu_data_acquire(vector_handle, STARPU_R);
  762. @end smallexample
  763. @end cartouche
  764. @cartouche
  765. @smallexample
  766. /* @b{Access the data} */
  767. for(i=0 ; i<NX; i++) @{
  768. fprintf(stderr, "%f ", vector[i]);
  769. @}
  770. fprintf(stderr, "\n");
  771. /* @b{Release the data and shutdown StarPU} */
  772. starpu_data_release(vector_handle);
  773. starpu_shutdown();
  774. return 0;
  775. @}
  776. @end smallexample
  777. @end cartouche
  778. @node Execution of Hybrid Vector Scaling
  779. @subsection Execution of Hybrid Vector Scaling
  780. The Makefile given at the beginning of the section must be extended to
  781. give the rules to compile the CUDA source code. Note that the source
  782. file of the OpenCL kernel does not need to be compiled now, it will
  783. be compiled at run-time when calling the function
  784. @code{starpu_opencl_load_opencl_from_file()} (@pxref{starpu_opencl_load_opencl_from_file}).
  785. @cartouche
  786. @smallexample
  787. CFLAGS += $(shell pkg-config --cflags libstarpu)
  788. LDFLAGS += $(shell pkg-config --libs libstarpu)
  789. CC = gcc
  790. vector_scal: vector_scal.o vector_scal_cpu.o vector_scal_cuda.o vector_scal_opencl.o
  791. %.o: %.cu
  792. nvcc $(CFLAGS) $< -c $@
  793. clean:
  794. rm -f vector_scal *.o
  795. @end smallexample
  796. @end cartouche
  797. @smallexample
  798. % make
  799. @end smallexample
  800. and to execute it, with the default configuration:
  801. @smallexample
  802. % ./vector_scal
  803. 0.000000 3.000000 6.000000 9.000000 12.000000
  804. @end smallexample
  805. or for example, by disabling CPU devices:
  806. @smallexample
  807. % STARPU_NCPUS=0 ./vector_scal
  808. 0.000000 3.000000 6.000000 9.000000 12.000000
  809. @end smallexample
  810. or by disabling CUDA devices (which may permit to enable the use of OpenCL,
  811. see @ref{Using accelerators}):
  812. @smallexample
  813. % STARPU_NCUDA=0 ./vector_scal
  814. 0.000000 3.000000 6.000000 9.000000 12.000000
  815. @end smallexample
  816. @node Task and Worker Profiling
  817. @section Task and Worker Profiling
  818. A full example showing how to use the profiling API is available in
  819. the StarPU sources in the directory @code{examples/profiling/}.
  820. @cartouche
  821. @smallexample
  822. struct starpu_task *task = starpu_task_create();
  823. task->cl = &cl;
  824. task->synchronous = 1;
  825. /* We will destroy the task structure by hand so that we can
  826. * query the profiling info before the task is destroyed. */
  827. task->destroy = 0;
  828. /* Submit and wait for completion (since synchronous was set to 1) */
  829. starpu_task_submit(task);
  830. /* The task is finished, get profiling information */
  831. struct starpu_task_profiling_info *info = task->profiling_info;
  832. /* How much time did it take before the task started ? */
  833. double delay += starpu_timing_timespec_delay_us(&info->submit_time, &info->start_time);
  834. /* How long was the task execution ? */
  835. double length += starpu_timing_timespec_delay_us(&info->start_time, &info->end_time);
  836. /* We don't need the task structure anymore */
  837. starpu_task_destroy(task);
  838. @end smallexample
  839. @end cartouche
  840. @cartouche
  841. @smallexample
  842. /* Display the occupancy of all workers during the test */
  843. int worker;
  844. for (worker = 0; worker < starpu_worker_get_count(); worker++)
  845. @{
  846. struct starpu_worker_profiling_info worker_info;
  847. int ret = starpu_worker_get_profiling_info(worker, &worker_info);
  848. STARPU_ASSERT(!ret);
  849. double total_time = starpu_timing_timespec_to_us(&worker_info.total_time);
  850. double executing_time = starpu_timing_timespec_to_us(&worker_info.executing_time);
  851. double sleeping_time = starpu_timing_timespec_to_us(&worker_info.sleeping_time);
  852. float executing_ratio = 100.0*executing_time/total_time;
  853. float sleeping_ratio = 100.0*sleeping_time/total_time;
  854. char workername[128];
  855. starpu_worker_get_name(worker, workername, 128);
  856. fprintf(stderr, "Worker %s:\n", workername);
  857. fprintf(stderr, "\ttotal time : %.2lf ms\n", total_time*1e-3);
  858. fprintf(stderr, "\texec time : %.2lf ms (%.2f %%)\n", executing_time*1e-3,
  859. executing_ratio);
  860. fprintf(stderr, "\tblocked time : %.2lf ms (%.2f %%)\n", sleeping_time*1e-3,
  861. sleeping_ratio);
  862. @}
  863. @end smallexample
  864. @end cartouche
  865. @node Partitioning Data
  866. @section Partitioning Data
  867. An existing piece of data can be partitioned in sub parts to be used by different tasks, for instance:
  868. @cartouche
  869. @smallexample
  870. int vector[NX];
  871. starpu_data_handle handle;
  872. /* Declare data to StarPU */
  873. starpu_vector_data_register(&handle, 0, (uintptr_t)vector, NX, sizeof(vector[0]));
  874. /* Partition the vector in PARTS sub-vectors */
  875. starpu_filter f =
  876. @{
  877. .filter_func = starpu_block_filter_func_vector,
  878. .nchildren = PARTS,
  879. .get_nchildren = NULL,
  880. .get_child_ops = NULL
  881. @};
  882. starpu_data_partition(handle, &f);
  883. @end smallexample
  884. @end cartouche
  885. @cartouche
  886. @smallexample
  887. /* Submit a task on each sub-vector */
  888. for (i=0; i<starpu_data_get_nb_children(handle); i++) @{
  889. /* Get subdata number i (there is only 1 dimension) */
  890. starpu_data_handle sub_handle = starpu_data_get_sub_data(handle, 1, i);
  891. struct starpu_task *task = starpu_task_create();
  892. task->buffers[0].handle = sub_handle;
  893. task->buffers[0].mode = STARPU_RW;
  894. task->cl = &cl;
  895. task->synchronous = 1;
  896. task->cl_arg = &factor;
  897. task->cl_arg_size = sizeof(factor);
  898. starpu_task_submit(task);
  899. @}
  900. @end smallexample
  901. @end cartouche
  902. Partitioning can be applied several times, see
  903. @code{examples/basic_examples/mult.c} and @code{examples/filters/}.
  904. @node Performance model example
  905. @section Performance model example
  906. To achieve good scheduling, StarPU scheduling policies need to be able to
  907. estimate in advance the duration of a task. This is done by giving to codelets a
  908. performance model. There are several kinds of performance models.
  909. @itemize
  910. @item
  911. Providing an estimation from the application itself (@code{STARPU_COMMON} model type and @code{cost_model} field),
  912. see for instance
  913. @code{examples/common/blas_model.h} and @code{examples/common/blas_model.c}. It can also be provided for each architecture (@code{STARPU_PER_ARCH} model type and @code{per_arch} field)
  914. @item
  915. Measured at runtime (STARPU_HISTORY_BASED model type). This assumes that for a
  916. given set of data input/output sizes, the performance will always be about the
  917. same. This is very true for regular kernels on GPUs for instance (<0.1% error),
  918. and just a bit less true on CPUs (~=1% error). This also assumes that there are
  919. few different sets of data input/output sizes. StarPU will then keep record of
  920. the average time of previous executions on the various processing units, and use
  921. it as an estimation. It will also save it in @code{~/.starpu/sampling/codelets}
  922. for further executions. The following is a small code example.
  923. @cartouche
  924. @smallexample
  925. static struct starpu_perfmodel_t mult_perf_model = @{
  926. .type = STARPU_HISTORY_BASED,
  927. .symbol = "mult_perf_model"
  928. @};
  929. starpu_codelet cl = @{
  930. .where = STARPU_CPU,
  931. .cpu_func = cpu_mult,
  932. .nbuffers = 3,
  933. /* for the scheduling policy to be able to use performance models */
  934. .model = &mult_perf_model
  935. @};
  936. @end smallexample
  937. @end cartouche
  938. @item
  939. Measured at runtime and refined by regression (STARPU_REGRESSION_BASED model
  940. type). This still assumes performance regularity, but can work with various data
  941. input sizes, by applying a*n^b+c regression over observed execution times.
  942. @end itemize
  943. The same can be done for task power consumption estimation, by setting the
  944. @code{power_model} field the same way as the @code{model} field. Note: for
  945. now, the application has to give to the power consumption performance model
  946. a different name.
  947. @node Theoretical lower bound on execution time
  948. @section Theoretical lower bound on execution time
  949. For kernels with history-based performance models, StarPU can very easily provide a theoretical lower
  950. bound for the execution time of a whole set of tasks. See for
  951. instance @code{examples/lu/lu_example.c}: before submitting tasks,
  952. call @code{starpu_bound_start}, and after complete execution, call
  953. @code{starpu_bound_stop}. @code{starpu_bound_print_lp} or
  954. @code{starpu_bound_print_mps} can then be used to output a Linear Programming
  955. problem corresponding to the schedule of your tasks. Run it through
  956. @code{lp_solve} or any other linear programming solver, and that will give you a
  957. lower bound for the total execution time of your tasks. If StarPU was compiled
  958. with the glpk library installed, @code{starpu_bound_compute} can be used to
  959. solve it immediately and get the optimized minimum. Its @code{integer}
  960. parameter allows to decide whether integer resolution should be computed
  961. and returned.
  962. The @code{deps} parameter tells StarPU whether to take tasks and implicit data
  963. dependencies into account. It must be understood that the linear programming
  964. problem size is quadratic with the number of tasks and thus the time to solve it
  965. will be very long, it could be minutes for just a few dozen tasks. You should
  966. probably use @code{lp_solve -timeout 1 test.pl -wmps test.mps} to convert the
  967. problem to MPS format and then use a better solver, @code{glpsol} might be
  968. better than @code{lp_solve} for instance (the @code{--pcost} option may be
  969. useful), but sometimes doesn't manage to converge. @code{cbc} might look
  970. slower, but it is parallel. Be sure to try at least all the @code{-B} options
  971. of @code{lp_solve}. For instance, we often just use
  972. @code{lp_solve -cc -B1 -Bb -Bg -Bp -Bf -Br -BG -Bd -Bs -BB -Bo -Bc -Bi} , and
  973. the @code{-gr} option can also be quite useful.
  974. Setting @code{deps} to 0 will only take into account the actual computations
  975. on processing units. It however still properly takes into account the varying
  976. performances of kernels and processing units, which is quite more accurate than
  977. just comparing StarPU performances with the fastest of the kernels being used.
  978. The @code{prio} parameter tells StarPU whether to simulate taking into account
  979. the priorities as the StarPU scheduler would, i.e. schedule prioritized
  980. tasks before less prioritized tasks, to check to which extend this results
  981. to a less optimal solution. This increases even more computation time.
  982. Note that for simplicity, all this however doesn't take into account data
  983. transfers, which are assumed to be completely overlapped.
  984. @node Insert Task Utility
  985. @section Insert Task Utility
  986. StarPU provides the wrapper function @code{starpu_insert_task} to ease
  987. the creation and submission of tasks.
  988. @emph{Prototype}:
  989. @code{int starpu_insert_task(starpu_codelet *cl, ...);}
  990. The arguments following the codelets can be of the following types:
  991. @itemize
  992. @item
  993. @code{STARPU_R}, @code{STARPU_W}, @code{STARPU_RW}, @code{STARPU_SCRATCH} an access mode followed by a data handle;
  994. @item
  995. @code{STARPU_VALUE} followed by a pointer to a constant value and
  996. the size of the constant;
  997. @item
  998. @code{STARPU_CALLBACK} followed by a pointer to a callback function;
  999. @item
  1000. @code{STARPU_CALLBACK_ARG} followed by a pointer to be given as an
  1001. argument to the callback function;
  1002. @item
  1003. @code{STARPU_PRIORITY} followed by a integer defining a priority level.
  1004. @end itemize
  1005. A call to @code{starpu_insert_task} will create and submit the task
  1006. based on the given arguments. The list of varying arguments has to be
  1007. ended by the value @code{0}.
  1008. Parameters to be passed to the codelet implementation are defined
  1009. through the type @code{STARPU_VALUE}. The function
  1010. @code{starpu_unpack_cl_args} must be called within the codelet
  1011. implementation to retrieve them.
  1012. Here the implementation of the codelet:
  1013. @smallexample
  1014. void func_cpu(void *descr[], void *_args)
  1015. @{
  1016. int *x0 = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  1017. float *x1 = (float *)STARPU_VARIABLE_GET_PTR(descr[1]);
  1018. int ifactor;
  1019. float ffactor;
  1020. starpu_unpack_cl_args(_args, &ifactor, &ffactor);
  1021. *x0 = *x0 * ifactor;
  1022. *x1 = *x1 * ffactor;
  1023. @}
  1024. starpu_codelet mycodelet = @{
  1025. .where = STARPU_CPU,
  1026. .cpu_func = func_cpu,
  1027. .nbuffers = 2
  1028. @};
  1029. @end smallexample
  1030. And the call to the @code{starpu_insert_task} wrapper:
  1031. @smallexample
  1032. starpu_insert_task(&mycodelet,
  1033. STARPU_VALUE, &ifactor, sizeof(ifactor),
  1034. STARPU_VALUE, &ffactor, sizeof(ffactor),
  1035. STARPU_RW, data_handles[0], STARPU_RW, data_handles[1],
  1036. 0);
  1037. @end smallexample
  1038. The call to @code{starpu_insert_task} is equivalent to the following
  1039. code:
  1040. @smallexample
  1041. struct starpu_task *task = starpu_task_create();
  1042. task->cl = &mycodelet;
  1043. task->buffers[0].handle = data_handles[0];
  1044. task->buffers[0].mode = STARPU_RW;
  1045. task->buffers[1].handle = data_handles[1];
  1046. task->buffers[1].mode = STARPU_RW;
  1047. char *arg_buffer;
  1048. size_t arg_buffer_size;
  1049. starpu_pack_cl_args(&arg_buffer, &arg_buffer_size,
  1050. STARPU_VALUE, &ifactor, sizeof(ifactor),
  1051. STARPU_VALUE, &ffactor, sizeof(ffactor),
  1052. 0);
  1053. task->cl_arg = arg_buffer;
  1054. task->cl_arg_size = arg_buffer_size;
  1055. int ret = starpu_task_submit(task);
  1056. @end smallexample
  1057. @node More examples
  1058. @section More examples
  1059. More examples are available in the StarPU sources in the @code{examples/}
  1060. directory. Simple examples include:
  1061. @table @asis
  1062. @item @code{incrementer/}:
  1063. Trivial incrementation test.
  1064. @item @code{basic_examples/}:
  1065. Simple documented Hello world (as shown in @ref{Hello World}), vector/scalar product (as shown
  1066. in @ref{Vector Scaling on an Hybrid CPU/GPU Machine}), matrix
  1067. product examples (as shown in @ref{Performance model example}), an example using the blocked matrix data
  1068. interface, and an example using the variable data interface.
  1069. @item @code{matvecmult/}:
  1070. OpenCL example from NVidia, adapted to StarPU.
  1071. @item @code{axpy/}:
  1072. AXPY CUBLAS operation adapted to StarPU.
  1073. @item @code{fortran/}:
  1074. Example of Fortran bindings.
  1075. @end table
  1076. More advanced examples include:
  1077. @table @asis
  1078. @item @code{filters/}:
  1079. Examples using filters, as shown in @ref{Partitioning Data}.
  1080. @item @code{lu/}:
  1081. LU matrix factorization, see for instance @code{xlu_implicit.c}
  1082. @item @code{cholesky/}:
  1083. Cholesky matrix factorization, see for instance @code{cholesky_implicit.c}.
  1084. @end table
  1085. @c ---------------------------------------------------------------------
  1086. @c Performance options
  1087. @c ---------------------------------------------------------------------
  1088. @node Performance optimization
  1089. @chapter How to optimize performance with StarPU
  1090. TODO: improve!
  1091. @menu
  1092. * Data management::
  1093. * Task submission::
  1094. * Task priorities::
  1095. * Task scheduling policy::
  1096. * Task distribution vs Data transfer::
  1097. * Power-based scheduling::
  1098. * Profiling::
  1099. * CUDA-specific optimizations::
  1100. @end menu
  1101. Simply encapsulating application kernels into tasks already permits to
  1102. seamlessly support CPU and GPUs at the same time. To achieve good performance, a
  1103. few additional changes are needed.
  1104. @node Data management
  1105. @section Data management
  1106. By default, StarPU does not enable data prefetching, because CUDA does
  1107. not announce when too many data transfers were scheduled and can thus block
  1108. unexpectedly... To enable data prefetching, use @code{export STARPU_PREFETCH=1}
  1109. .
  1110. By default, StarPU leaves replicates of data wherever they were used, in case they
  1111. will be re-used by other tasks, thus saving the data transfer time. When some
  1112. task modifies some data, all the other replicates are invalidated, and only the
  1113. processing unit will have a valid replicate of the data. If the application knows
  1114. that this data will not be re-used by further tasks, it should advise StarPU to
  1115. immediately replicate it to a desired list of memory nodes (given through a
  1116. bitmask). This can be understood like the write-through mode of CPU caches.
  1117. @example
  1118. starpu_data_set_wt_mask(img_handle, 1<<0);
  1119. @end example
  1120. will for instance request to always transfer a replicate into the main memory (node
  1121. 0), as bit 0 of the write-through bitmask is being set.
  1122. When the application allocates data, whenever possible it should use the
  1123. @code{starpu_data_malloc_pinned_if_possible} function, which will ask CUDA or
  1124. OpenCL to make the allocation itself and pin the corresponding allocated
  1125. memory. This is needed to permit asynchronous data transfer, i.e. permit data
  1126. transfer to overlap with computations.
  1127. @node Task submission
  1128. @section Task submission
  1129. To let StarPU make online optimizations, tasks should be submitted
  1130. asynchronously as much as possible. Ideally, all the tasks should be
  1131. submitted, and a mere @code{starpu_task_wait_for_all} call be done to wait for
  1132. termination. StarPU will then be able to rework the whole schedule, overlap
  1133. computation with communication, manage accelerator local memory usage, etc.
  1134. @node Task priorities
  1135. @section Task priorities
  1136. By default, StarPU will consider the tasks in the order they are submitted by
  1137. the application. If the application programmer knows that some tasks should
  1138. be performed in priority (for instance because their output is needed by many
  1139. other tasks and may thus be a bottleneck if not executed early enough), the
  1140. @code{priority} field of the task structure should be set to transmit the
  1141. priority information to StarPU.
  1142. @node Task scheduling policy
  1143. @section Task scheduling policy
  1144. By default, StarPU uses the @code{eager} simple greedy scheduler. This is
  1145. because it provides correct load balance even if the application codelets do not
  1146. have performance models. If your application codelets have performance models,
  1147. you should change the scheduler thanks to the @code{STARPU_SCHED} environment
  1148. variable. For instance @code{export STARPU_SCHED=dmda} . Use @code{help} to get
  1149. the list of available schedulers.
  1150. Most schedulers are based on an estimation of codelet duration on each kind
  1151. of processing unit. For this to be possible, the application programmer needs
  1152. to configure a performance model for the codelets of the application (see
  1153. @ref{Performance model example} for instance). History-based performance models
  1154. use on-line calibration. StarPU will automatically calibrate codelets
  1155. which have never been calibrated yet. To force continuing calibration, use
  1156. @code{export STARPU_CALIBRATE=1} . To drop existing calibration information
  1157. completely and re-calibrate from start, use @code{export STARPU_CALIBRATE=2}.
  1158. Note: due to CUDA limitations, to be able to measure kernel duration,
  1159. calibration mode needs to disable asynchronous data transfers. Calibration thus
  1160. disables data transfer / computation overlapping, and should thus not be used
  1161. for eventual benchmarks.
  1162. @node Task distribution vs Data transfer
  1163. @section Task distribution vs Data transfer
  1164. Distributing tasks to balance the load induces data transfer penalty. StarPU
  1165. thus needs to find a balance between both. The target function that the
  1166. @code{dmda} scheduler of StarPU
  1167. tries to minimize is @code{alpha * T_execution + beta * T_data_transfer}, where
  1168. @code{T_execution} is the estimated execution time of the codelet (usually
  1169. accurate), and @code{T_data_transfer} is the estimated data transfer time. The
  1170. latter is however estimated based on bus calibration before execution start,
  1171. i.e. with an idle machine. You can force bus re-calibration by running
  1172. @code{starpu_calibrate_bus}. The beta parameter defaults to 1, but it can be
  1173. worth trying to tweak it by using @code{export STARPU_BETA=2} for instance.
  1174. This is of course imprecise, but in practice, a rough estimation already gives
  1175. the good results that a precise estimation would give.
  1176. @node Power-based scheduling
  1177. @section Power-based scheduling
  1178. If the application can provide some power performance model (through
  1179. the @code{power_model} field of the codelet structure), StarPU will
  1180. take it into account when distributing tasks. The target function that
  1181. the @code{dmda} scheduler minimizes becomes @code{alpha * T_execution +
  1182. beta * T_data_transfer + gamma * Consumption} , where @code{Consumption}
  1183. is the estimated task consumption in Joules. To tune this parameter, use
  1184. @code{export STARPU_GAMMA=3000} for instance, to express that each Joule
  1185. (i.e kW during 1000us) is worth 3000us execution time penalty. Setting
  1186. alpha and beta to zero permits to only take into account power consumption.
  1187. This is however not sufficient to correctly optimize power: the scheduler would
  1188. simply tend to run all computations on the most energy-conservative processing
  1189. unit. To account for the consumption of the whole machine (including idle
  1190. processing units), the idle power of the machine should be given by setting
  1191. @code{export STARPU_IDLE_POWER=200} for 200W, for instance. This value can often
  1192. be obtained from the machine power supplier.
  1193. The power actually consumed by the total execution can be displayed by setting
  1194. @code{export STARPU_PROFILING=1 STARPU_WORKER_STATS=1} .
  1195. @node Profiling
  1196. @section Profiling
  1197. Profiling can be enabled by using @code{export STARPU_PROFILING=1} or by
  1198. calling @code{starpu_profiling_status_set} from the source code.
  1199. Statistics on the execution can then be obtained by using @code{export
  1200. STARPU_BUS_STATS=1} and @code{export STARPU_WORKER_STATS=1} . Workers
  1201. stats will include an approximation of the number of executed tasks even if
  1202. @code{STARPU_PROFILING} is not set. This is a convenient way to check that
  1203. execution did happen on accelerators without penalizing performance with
  1204. the profiling overhead. More details on performance feedback are provided by the
  1205. next chapter.
  1206. @node CUDA-specific optimizations
  1207. @section CUDA-specific optimizations
  1208. Due to CUDA limitations, StarPU will have a hard time overlapping
  1209. communications and computations if the application does not use a dedicated
  1210. CUDA stream for its computations. StarPU provides one by the use of
  1211. @code{starpu_cuda_get_local_stream()}. For instance:
  1212. @example
  1213. func <<<grid,block,0,starpu_cuda_get_local_stream()>>> (foo, bar);
  1214. cudaStreamSynchronize(starpu_cuda_get_local_stream());
  1215. @end example
  1216. Unfortunately, a lot of cuda libraries do not have stream variants of kernels.
  1217. @c ---------------------------------------------------------------------
  1218. @c Performance feedback
  1219. @c ---------------------------------------------------------------------
  1220. @node Performance feedback
  1221. @chapter Performance feedback
  1222. @menu
  1223. * On-line:: On-line performance feedback
  1224. * Off-line:: Off-line performance feedback
  1225. * Codelet performance:: Performance of codelets
  1226. @end menu
  1227. @node On-line
  1228. @section On-line performance feedback
  1229. @menu
  1230. * Enabling monitoring:: Enabling on-line performance monitoring
  1231. * Task feedback:: Per-task feedback
  1232. * Codelet feedback:: Per-codelet feedback
  1233. * Worker feedback:: Per-worker feedback
  1234. * Bus feedback:: Bus-related feedback
  1235. @end menu
  1236. @node Enabling monitoring
  1237. @subsection Enabling on-line performance monitoring
  1238. In order to enable online performance monitoring, the application can call
  1239. @code{starpu_profiling_status_set(STARPU_PROFILING_ENABLE)}. It is possible to
  1240. detect whether monitoring is already enabled or not by calling
  1241. @code{starpu_profiling_status_get()}. Enabling monitoring also reinitialize all
  1242. previously collected feedback. The @code{STARPU_PROFILING} environment variable
  1243. can also be set to 1 to achieve the same effect.
  1244. Likewise, performance monitoring is stopped by calling
  1245. @code{starpu_profiling_status_set(STARPU_PROFILING_DISABLE)}. Note that this
  1246. does not reset the performance counters so that the application may consult
  1247. them later on.
  1248. More details about the performance monitoring API are available in section
  1249. @ref{Profiling API}.
  1250. @node Task feedback
  1251. @subsection Per-task feedback
  1252. If profiling is enabled, a pointer to a @code{starpu_task_profiling_info}
  1253. structure is put in the @code{.profiling_info} field of the @code{starpu_task}
  1254. structure when a task terminates.
  1255. This structure is automatically destroyed when the task structure is destroyed,
  1256. either automatically or by calling @code{starpu_task_destroy}.
  1257. The @code{starpu_task_profiling_info} structure indicates the date when the
  1258. task was submitted (@code{submit_time}), started (@code{start_time}), and
  1259. terminated (@code{end_time}), relative to the initialization of
  1260. StarPU with @code{starpu_init}. It also specifies the identifier of the worker
  1261. that has executed the task (@code{workerid}).
  1262. These date are stored as @code{timespec} structures which the user may convert
  1263. into micro-seconds using the @code{starpu_timing_timespec_to_us} helper
  1264. function.
  1265. It it worth noting that the application may directly access this structure from
  1266. the callback executed at the end of the task. The @code{starpu_task} structure
  1267. associated to the callback currently being executed is indeed accessible with
  1268. the @code{starpu_get_current_task()} function.
  1269. @node Codelet feedback
  1270. @subsection Per-codelet feedback
  1271. The @code{per_worker_stats} field of the @code{starpu_codelet_t} structure is
  1272. an array of counters. The i-th entry of the array is incremented every time a
  1273. task implementing the codelet is executed on the i-th worker.
  1274. This array is not reinitialized when profiling is enabled or disabled.
  1275. @node Worker feedback
  1276. @subsection Per-worker feedback
  1277. The second argument returned by the @code{starpu_worker_get_profiling_info}
  1278. function is a @code{starpu_worker_profiling_info} structure that gives
  1279. statistics about the specified worker. This structure specifies when StarPU
  1280. started collecting profiling information for that worker (@code{start_time}),
  1281. the duration of the profiling measurement interval (@code{total_time}), the
  1282. time spent executing kernels (@code{executing_time}), the time spent sleeping
  1283. because there is no task to execute at all (@code{sleeping_time}), and the
  1284. number of tasks that were executed while profiling was enabled.
  1285. These values give an estimation of the proportion of time spent do real work,
  1286. and the time spent either sleeping because there are not enough executable
  1287. tasks or simply wasted in pure StarPU overhead.
  1288. Calling @code{starpu_worker_get_profiling_info} resets the profiling
  1289. information associated to a worker.
  1290. When an FxT trace is generated (see @ref{Generating traces}), it is also
  1291. possible to use the @code{starpu_top} script (described in @ref{starpu-top}) to
  1292. generate a graphic showing the evolution of these values during the time, for
  1293. the different workers.
  1294. @node Bus feedback
  1295. @subsection Bus-related feedback
  1296. TODO
  1297. @c how to enable/disable performance monitoring
  1298. @c what kind of information do we get ?
  1299. @node Off-line
  1300. @section Off-line performance feedback
  1301. @menu
  1302. * Generating traces:: Generating traces with FxT
  1303. * Gantt diagram:: Creating a Gantt Diagram
  1304. * DAG:: Creating a DAG with graphviz
  1305. * starpu-top:: Monitoring activity
  1306. @end menu
  1307. @node Generating traces
  1308. @subsection Generating traces with FxT
  1309. StarPU can use the FxT library (see
  1310. @indicateurl{https://savannah.nongnu.org/projects/fkt/}) to generate traces
  1311. with a limited runtime overhead.
  1312. You can either get the FxT library from CVS (autotools are required):
  1313. @example
  1314. % cvs -d :pserver:anonymous@@cvs.sv.gnu.org:/sources/fkt co FxT
  1315. % ./bootstrap
  1316. @end example
  1317. If autotools are not available on your machine, or if you prefer to do so,
  1318. FxT's code is also available as a tarball:
  1319. @example
  1320. % wget http://download.savannah.gnu.org/releases/fkt/fxt-0.2.tar.gz
  1321. @end example
  1322. Compiling and installing the FxT library in the @code{$FXTDIR} path is
  1323. done following the standard procedure:
  1324. @example
  1325. % ./configure --prefix=$FXTDIR
  1326. % make
  1327. % make install
  1328. @end example
  1329. In order to have StarPU to generate traces, StarPU should be configured with
  1330. the @code{--with-fxt} option:
  1331. @example
  1332. $ ./configure --with-fxt=$FXTDIR
  1333. @end example
  1334. When FxT is enabled, a trace is generated when StarPU is terminated by calling
  1335. @code{starpu_shutdown()}). The trace is a binary file whose name has the form
  1336. @code{prof_file_XXX_YYY} where @code{XXX} is the user name, and
  1337. @code{YYY} is the pid of the process that used StarPU. This file is saved in the
  1338. @code{/tmp/} directory by default, or by the directory specified by
  1339. the @code{STARPU_FXT_PREFIX} environment variable.
  1340. @node Gantt diagram
  1341. @subsection Creating a Gantt Diagram
  1342. When the FxT trace file @code{filename} has been generated, it is possible to
  1343. generate a trace in the Paje format by calling:
  1344. @example
  1345. % starpu_fxt_tool -i filename
  1346. @end example
  1347. Or alternatively, setting the @code{STARPU_GENERATE_TRACE} environment variable
  1348. to 1 before application execution will make StarPU do it automatically at
  1349. application shutdown.
  1350. This will create a @code{paje.trace} file in the current directory that can be
  1351. inspected with the ViTE trace visualizing open-source tool. More information
  1352. about ViTE is available at @indicateurl{http://vite.gforge.inria.fr/}. It is
  1353. possible to open the @code{paje.trace} file with ViTE by using the following
  1354. command:
  1355. @example
  1356. % vite paje.trace
  1357. @end example
  1358. @node DAG
  1359. @subsection Creating a DAG with graphviz
  1360. When the FxT trace file @code{filename} has been generated, it is possible to
  1361. generate a task graph in the DOT format by calling:
  1362. @example
  1363. $ starpu_fxt_tool -i filename
  1364. @end example
  1365. This will create a @code{dag.dot} file in the current directory. This file is a
  1366. task graph described using the DOT language. It is possible to get a
  1367. graphical output of the graph by using the graphviz library:
  1368. @example
  1369. $ dot -Tpdf dag.dot -o output.pdf
  1370. @end example
  1371. @node starpu-top
  1372. @subsection Monitoring activity
  1373. When the FxT trace file @code{filename} has been generated, it is possible to
  1374. generate a activity trace by calling:
  1375. @example
  1376. $ starpu_fxt_tool -i filename
  1377. @end example
  1378. This will create an @code{activity.data} file in the current
  1379. directory. A profile of the application showing the activity of StarPU
  1380. during the execution of the program can be generated:
  1381. @example
  1382. $ starpu_top.sh activity.data
  1383. @end example
  1384. This will create a file named @code{activity.eps} in the current directory.
  1385. This picture is composed of two parts.
  1386. The first part shows the activity of the different workers. The green sections
  1387. indicate which proportion of the time was spent executed kernels on the
  1388. processing unit. The red sections indicate the proportion of time spent in
  1389. StartPU: an important overhead may indicate that the granularity may be too
  1390. low, and that bigger tasks may be appropriate to use the processing unit more
  1391. efficiently. The black sections indicate that the processing unit was blocked
  1392. because there was no task to process: this may indicate a lack of parallelism
  1393. which may be alleviated by creating more tasks when it is possible.
  1394. The second part of the @code{activity.eps} picture is a graph showing the
  1395. evolution of the number of tasks available in the system during the execution.
  1396. Ready tasks are shown in black, and tasks that are submitted but not
  1397. schedulable yet are shown in grey.
  1398. @node Codelet performance
  1399. @section Performance of codelets
  1400. The performance model of codelets can be examined by using the
  1401. @code{starpu_perfmodel_display} tool:
  1402. @example
  1403. $ starpu_perfmodel_display -l
  1404. file: <malloc_pinned.hannibal>
  1405. file: <starpu_slu_lu_model_21.hannibal>
  1406. file: <starpu_slu_lu_model_11.hannibal>
  1407. file: <starpu_slu_lu_model_22.hannibal>
  1408. file: <starpu_slu_lu_model_12.hannibal>
  1409. @end example
  1410. Here, the codelets of the lu example are available. We can examine the
  1411. performance of the 22 kernel:
  1412. @example
  1413. $ starpu_perfmodel_display -s starpu_slu_lu_model_22
  1414. performance model for cpu
  1415. # hash size mean dev n
  1416. 57618ab0 19660800 2.851069e+05 1.829369e+04 109
  1417. performance model for cuda_0
  1418. # hash size mean dev n
  1419. 57618ab0 19660800 1.164144e+04 1.556094e+01 315
  1420. performance model for cuda_1
  1421. # hash size mean dev n
  1422. 57618ab0 19660800 1.164271e+04 1.330628e+01 360
  1423. performance model for cuda_2
  1424. # hash size mean dev n
  1425. 57618ab0 19660800 1.166730e+04 3.390395e+02 456
  1426. @end example
  1427. We can see that for the given size, over a sample of a few hundreds of
  1428. execution, the GPUs are about 20 times faster than the CPUs (numbers are in
  1429. us). The standard deviation is extremely low for the GPUs, and less than 10% for
  1430. CPUs.
  1431. @c ---------------------------------------------------------------------
  1432. @c MPI support
  1433. @c ---------------------------------------------------------------------
  1434. @node StarPU MPI support
  1435. @chapter StarPU MPI support
  1436. TODO: document include/starpu_mpi.h and explain a simple example (pingpong?)
  1437. @c ---------------------------------------------------------------------
  1438. @c Configuration options
  1439. @c ---------------------------------------------------------------------
  1440. @node Configuring StarPU
  1441. @chapter Configuring StarPU
  1442. @menu
  1443. * Compilation configuration::
  1444. * Execution configuration through environment variables::
  1445. @end menu
  1446. @node Compilation configuration
  1447. @section Compilation configuration
  1448. The following arguments can be given to the @code{configure} script.
  1449. @menu
  1450. * Common configuration::
  1451. * Configuring workers::
  1452. * Advanced configuration::
  1453. @end menu
  1454. @node Common configuration
  1455. @subsection Common configuration
  1456. @menu
  1457. * --enable-debug::
  1458. * --enable-fast::
  1459. * --enable-verbose::
  1460. * --enable-coverage::
  1461. @end menu
  1462. @node --enable-debug
  1463. @subsubsection @code{--enable-debug}
  1464. @table @asis
  1465. @item @emph{Description}:
  1466. Enable debugging messages.
  1467. @end table
  1468. @node --enable-fast
  1469. @subsubsection @code{--enable-fast}
  1470. @table @asis
  1471. @item @emph{Description}:
  1472. Do not enforce assertions, saves a lot of time spent to compute them otherwise.
  1473. @end table
  1474. @node --enable-verbose
  1475. @subsubsection @code{--enable-verbose}
  1476. @table @asis
  1477. @item @emph{Description}:
  1478. Augment the verbosity of the debugging messages. This can be disabled
  1479. at runtime by setting the environment variable @code{STARPU_SILENT} to
  1480. any value.
  1481. @smallexample
  1482. % STARPU_SILENT=1 ./vector_scal
  1483. @end smallexample
  1484. @end table
  1485. @node --enable-coverage
  1486. @subsubsection @code{--enable-coverage}
  1487. @table @asis
  1488. @item @emph{Description}:
  1489. Enable flags for the @code{gcov} coverage tool.
  1490. @end table
  1491. @node Configuring workers
  1492. @subsection Configuring workers
  1493. @menu
  1494. * --enable-nmaxcpus::
  1495. * --disable-cpu::
  1496. * --enable-maxcudadev::
  1497. * --disable-cuda::
  1498. * --with-cuda-dir::
  1499. * --with-cuda-include-dir::
  1500. * --with-cuda-lib-dir::
  1501. * --enable-maxopencldev::
  1502. * --disable-opencl::
  1503. * --with-opencl-dir::
  1504. * --with-opencl-include-dir::
  1505. * --with-opencl-lib-dir::
  1506. * --enable-gordon::
  1507. * --with-gordon-dir::
  1508. @end menu
  1509. @node --enable-nmaxcpus
  1510. @subsubsection @code{--enable-nmaxcpus=<number>}
  1511. @table @asis
  1512. @item @emph{Description}:
  1513. Defines the maximum number of CPU cores that StarPU will support, then
  1514. available as the @code{STARPU_NMAXCPUS} macro.
  1515. @end table
  1516. @node --disable-cpu
  1517. @subsubsection @code{--disable-cpu}
  1518. @table @asis
  1519. @item @emph{Description}:
  1520. Disable the use of CPUs of the machine. Only GPUs etc. will be used.
  1521. @end table
  1522. @node --enable-maxcudadev
  1523. @subsubsection @code{--enable-maxcudadev=<number>}
  1524. @table @asis
  1525. @item @emph{Description}:
  1526. Defines the maximum number of CUDA devices that StarPU will support, then
  1527. available as the @code{STARPU_MAXCUDADEVS} macro.
  1528. @end table
  1529. @node --disable-cuda
  1530. @subsubsection @code{--disable-cuda}
  1531. @table @asis
  1532. @item @emph{Description}:
  1533. Disable the use of CUDA, even if a valid CUDA installation was detected.
  1534. @end table
  1535. @node --with-cuda-dir
  1536. @subsubsection @code{--with-cuda-dir=<path>}
  1537. @table @asis
  1538. @item @emph{Description}:
  1539. Specify the directory where CUDA is installed. This directory should notably contain
  1540. @code{include/cuda.h}.
  1541. @end table
  1542. @node --with-cuda-include-dir
  1543. @subsubsection @code{--with-cuda-include-dir=<path>}
  1544. @table @asis
  1545. @item @emph{Description}:
  1546. Specify the directory where CUDA headers are installed. This directory should
  1547. notably contain @code{cuda.h}. This defaults to @code{/include} appended to the
  1548. value given to @code{--with-cuda-dir}.
  1549. @end table
  1550. @node --with-cuda-lib-dir
  1551. @subsubsection @code{--with-cuda-lib-dir=<path>}
  1552. @table @asis
  1553. @item @emph{Description}:
  1554. Specify the directory where the CUDA library is installed. This directory should
  1555. notably contain the CUDA shared libraries (e.g. libcuda.so). This defaults to
  1556. @code{/lib} appended to the value given to @code{--with-cuda-dir}.
  1557. @end table
  1558. @node --enable-maxopencldev
  1559. @subsubsection @code{--enable-maxopencldev=<number>}
  1560. @table @asis
  1561. @item @emph{Description}:
  1562. Defines the maximum number of OpenCL devices that StarPU will support, then
  1563. available as the @code{STARPU_MAXOPENCLDEVS} macro.
  1564. @end table
  1565. @node --disable-opencl
  1566. @subsubsection @code{--disable-opencl}
  1567. @table @asis
  1568. @item @emph{Description}:
  1569. Disable the use of OpenCL, even if the SDK is detected.
  1570. @end table
  1571. @node --with-opencl-dir
  1572. @subsubsection @code{--with-opencl-dir=<path>}
  1573. @table @asis
  1574. @item @emph{Description}:
  1575. Specify the location of the OpenCL SDK. This directory should notably contain
  1576. @code{include/CL/cl.h} (or @code{include/OpenCL/cl.h} on Mac OS).
  1577. @end table
  1578. @node --with-opencl-include-dir
  1579. @subsubsection @code{--with-opencl-include-dir=<path>}
  1580. @table @asis
  1581. @item @emph{Description}:
  1582. Specify the location of OpenCL headers. This directory should notably contain
  1583. @code{CL/cl.h} (or @code{OpenCL/cl.h} on Mac OS). This defaults to
  1584. @code{/include} appended to the value given to @code{--with-opencl-dir}.
  1585. @end table
  1586. @node --with-opencl-lib-dir
  1587. @subsubsection @code{--with-opencl-lib-dir=<path>}
  1588. @table @asis
  1589. @item @emph{Description}:
  1590. Specify the location of the OpenCL library. This directory should notably
  1591. contain the OpenCL shared libraries (e.g. libOpenCL.so). This defaults to
  1592. @code{/lib} appended to the value given to @code{--with-opencl-dir}.
  1593. @end table
  1594. @node --enable-gordon
  1595. @subsubsection @code{--enable-gordon}
  1596. @table @asis
  1597. @item @emph{Description}:
  1598. Enable the use of the Gordon runtime for Cell SPUs.
  1599. @c TODO: rather default to enabled when detected
  1600. @end table
  1601. @node --with-gordon-dir
  1602. @subsubsection @code{--with-gordon-dir=<path>}
  1603. @table @asis
  1604. @item @emph{Description}:
  1605. Specify the location of the Gordon SDK.
  1606. @end table
  1607. @node Advanced configuration
  1608. @subsection Advanced configuration
  1609. @menu
  1610. * --enable-perf-debug::
  1611. * --enable-model-debug::
  1612. * --enable-stats::
  1613. * --enable-maxbuffers::
  1614. * --enable-allocation-cache::
  1615. * --enable-opengl-render::
  1616. * --enable-blas-lib::
  1617. * --with-magma::
  1618. * --with-fxt::
  1619. * --with-perf-model-dir::
  1620. * --with-mpicc::
  1621. * --with-goto-dir::
  1622. * --with-atlas-dir::
  1623. * --with-mkl-cflags::
  1624. * --with-mkl-ldflags::
  1625. @end menu
  1626. @node --enable-perf-debug
  1627. @subsubsection @code{--enable-perf-debug}
  1628. @table @asis
  1629. @item @emph{Description}:
  1630. Enable performance debugging.
  1631. @end table
  1632. @node --enable-model-debug
  1633. @subsubsection @code{--enable-model-debug}
  1634. @table @asis
  1635. @item @emph{Description}:
  1636. Enable performance model debugging.
  1637. @end table
  1638. @node --enable-stats
  1639. @subsubsection @code{--enable-stats}
  1640. @table @asis
  1641. @item @emph{Description}:
  1642. Enable statistics.
  1643. @end table
  1644. @node --enable-maxbuffers
  1645. @subsubsection @code{--enable-maxbuffers=<nbuffers>}
  1646. @table @asis
  1647. @item @emph{Description}:
  1648. Define the maximum number of buffers that tasks will be able to take
  1649. as parameters, then available as the @code{STARPU_NMAXBUFS} macro.
  1650. @end table
  1651. @node --enable-allocation-cache
  1652. @subsubsection @code{--enable-allocation-cache}
  1653. @table @asis
  1654. @item @emph{Description}:
  1655. Enable the use of a data allocation cache to avoid the cost of it with
  1656. CUDA. Still experimental.
  1657. @end table
  1658. @node --enable-opengl-render
  1659. @subsubsection @code{--enable-opengl-render}
  1660. @table @asis
  1661. @item @emph{Description}:
  1662. Enable the use of OpenGL for the rendering of some examples.
  1663. @c TODO: rather default to enabled when detected
  1664. @end table
  1665. @node --enable-blas-lib
  1666. @subsubsection @code{--enable-blas-lib=<name>}
  1667. @table @asis
  1668. @item @emph{Description}:
  1669. Specify the blas library to be used by some of the examples. The
  1670. library has to be 'atlas' or 'goto'.
  1671. @end table
  1672. @node --with-magma
  1673. @subsubsection @code{--with-magma=<path>}
  1674. @table @asis
  1675. @item @emph{Description}:
  1676. Specify where magma is installed. This directory should notably contain
  1677. @code{include/magmablas.h}.
  1678. @end table
  1679. @node --with-fxt
  1680. @subsubsection @code{--with-fxt=<path>}
  1681. @table @asis
  1682. @item @emph{Description}:
  1683. Specify the location of FxT (for generating traces and rendering them
  1684. using ViTE). This directory should notably contain
  1685. @code{include/fxt/fxt.h}.
  1686. @c TODO add ref to other section
  1687. @end table
  1688. @node --with-perf-model-dir
  1689. @subsubsection @code{--with-perf-model-dir=<dir>}
  1690. @table @asis
  1691. @item @emph{Description}:
  1692. Specify where performance models should be stored (instead of defaulting to the
  1693. current user's home).
  1694. @end table
  1695. @node --with-mpicc
  1696. @subsubsection @code{--with-mpicc=<path to mpicc>}
  1697. @table @asis
  1698. @item @emph{Description}:
  1699. Specify the location of the @code{mpicc} compiler to be used for starpumpi.
  1700. @end table
  1701. @node --with-goto-dir
  1702. @subsubsection @code{--with-goto-dir=<dir>}
  1703. @table @asis
  1704. @item @emph{Description}:
  1705. Specify the location of GotoBLAS.
  1706. @end table
  1707. @node --with-atlas-dir
  1708. @subsubsection @code{--with-atlas-dir=<dir>}
  1709. @table @asis
  1710. @item @emph{Description}:
  1711. Specify the location of ATLAS. This directory should notably contain
  1712. @code{include/cblas.h}.
  1713. @end table
  1714. @node --with-mkl-cflags
  1715. @subsubsection @code{--with-mkl-cflags=<cflags>}
  1716. @table @asis
  1717. @item @emph{Description}:
  1718. Specify the compilation flags for the MKL Library.
  1719. @end table
  1720. @node --with-mkl-ldflags
  1721. @subsubsection @code{--with-mkl-ldflags=<ldflags>}
  1722. @table @asis
  1723. @item @emph{Description}:
  1724. Specify the linking flags for the MKL Library. Note that the
  1725. @url{http://software.intel.com/en-us/articles/intel-mkl-link-line-advisor/}
  1726. website provides a script to determine the linking flags.
  1727. @end table
  1728. @c ---------------------------------------------------------------------
  1729. @c Environment variables
  1730. @c ---------------------------------------------------------------------
  1731. @node Execution configuration through environment variables
  1732. @section Execution configuration through environment variables
  1733. @menu
  1734. * Workers:: Configuring workers
  1735. * Scheduling:: Configuring the Scheduling engine
  1736. * Misc:: Miscellaneous and debug
  1737. @end menu
  1738. Note: the values given in @code{starpu_conf} structure passed when
  1739. calling @code{starpu_init} will override the values of the environment
  1740. variables.
  1741. @node Workers
  1742. @subsection Configuring workers
  1743. @menu
  1744. * STARPU_NCPUS:: Number of CPU workers
  1745. * STARPU_NCUDA:: Number of CUDA workers
  1746. * STARPU_NOPENCL:: Number of OpenCL workers
  1747. * STARPU_NGORDON:: Number of SPU workers (Cell)
  1748. * STARPU_WORKERS_CPUID:: Bind workers to specific CPUs
  1749. * STARPU_WORKERS_CUDAID:: Select specific CUDA devices
  1750. * STARPU_WORKERS_OPENCLID:: Select specific OpenCL devices
  1751. @end menu
  1752. @node STARPU_NCPUS
  1753. @subsubsection @code{STARPU_NCPUS} -- Number of CPU workers
  1754. @table @asis
  1755. @item @emph{Description}:
  1756. Specify the number of CPU workers. Note that by default, StarPU will not allocate
  1757. more CPUs than there are physical CPUs, and that some CPUs are used to control
  1758. the accelerators.
  1759. @end table
  1760. @node STARPU_NCUDA
  1761. @subsubsection @code{STARPU_NCUDA} -- Number of CUDA workers
  1762. @table @asis
  1763. @item @emph{Description}:
  1764. Specify the number of CUDA devices that StarPU can use. If
  1765. @code{STARPU_NCUDA} is lower than the number of physical devices, it is
  1766. possible to select which CUDA devices should be used by the means of the
  1767. @code{STARPU_WORKERS_CUDAID} environment variable. By default, StarPU will
  1768. create as many CUDA workers as there are CUDA devices.
  1769. @end table
  1770. @node STARPU_NOPENCL
  1771. @subsubsection @code{STARPU_NOPENCL} -- Number of OpenCL workers
  1772. @table @asis
  1773. @item @emph{Description}:
  1774. OpenCL equivalent of the @code{STARPU_NCUDA} environment variable.
  1775. @end table
  1776. @node STARPU_NGORDON
  1777. @subsubsection @code{STARPU_NGORDON} -- Number of SPU workers (Cell)
  1778. @table @asis
  1779. @item @emph{Description}:
  1780. Specify the number of SPUs that StarPU can use.
  1781. @end table
  1782. @node STARPU_WORKERS_CPUID
  1783. @subsubsection @code{STARPU_WORKERS_CPUID} -- Bind workers to specific CPUs
  1784. @table @asis
  1785. @item @emph{Description}:
  1786. Passing an array of integers (starting from 0) in @code{STARPU_WORKERS_CPUID}
  1787. specifies on which logical CPU the different workers should be
  1788. bound. For instance, if @code{STARPU_WORKERS_CPUID = "0 1 4 5"}, the first
  1789. worker will be bound to logical CPU #0, the second CPU worker will be bound to
  1790. logical CPU #1 and so on. Note that the logical ordering of the CPUs is either
  1791. determined by the OS, or provided by the @code{hwloc} library in case it is
  1792. available.
  1793. Note that the first workers correspond to the CUDA workers, then come the
  1794. OpenCL and the SPU, and finally the CPU workers. For example if
  1795. we have @code{STARPU_NCUDA=1}, @code{STARPU_NOPENCL=1}, @code{STARPU_NCPUS=2}
  1796. and @code{STARPU_WORKERS_CPUID = "0 2 1 3"}, the CUDA device will be controlled
  1797. by logical CPU #0, the OpenCL device will be controlled by logical CPU #2, and
  1798. the logical CPUs #1 and #3 will be used by the CPU workers.
  1799. If the number of workers is larger than the array given in
  1800. @code{STARPU_WORKERS_CPUID}, the workers are bound to the logical CPUs in a
  1801. round-robin fashion: if @code{STARPU_WORKERS_CPUID = "0 1"}, the first and the
  1802. third (resp. second and fourth) workers will be put on CPU #0 (resp. CPU #1).
  1803. This variable is ignored if the @code{use_explicit_workers_bindid} flag of the
  1804. @code{starpu_conf} structure passed to @code{starpu_init} is set.
  1805. @end table
  1806. @node STARPU_WORKERS_CUDAID
  1807. @subsubsection @code{STARPU_WORKERS_CUDAID} -- Select specific CUDA devices
  1808. @table @asis
  1809. @item @emph{Description}:
  1810. Similarly to the @code{STARPU_WORKERS_CPUID} environment variable, it is
  1811. possible to select which CUDA devices should be used by StarPU. On a machine
  1812. equipped with 4 GPUs, setting @code{STARPU_WORKERS_CUDAID = "1 3"} and
  1813. @code{STARPU_NCUDA=2} specifies that 2 CUDA workers should be created, and that
  1814. they should use CUDA devices #1 and #3 (the logical ordering of the devices is
  1815. the one reported by CUDA).
  1816. This variable is ignored if the @code{use_explicit_workers_cuda_gpuid} flag of
  1817. the @code{starpu_conf} structure passed to @code{starpu_init} is set.
  1818. @end table
  1819. @node STARPU_WORKERS_OPENCLID
  1820. @subsubsection @code{STARPU_WORKERS_OPENCLID} -- Select specific OpenCL devices
  1821. @table @asis
  1822. @item @emph{Description}:
  1823. OpenCL equivalent of the @code{STARPU_WORKERS_CUDAID} environment variable.
  1824. This variable is ignored if the @code{use_explicit_workers_opencl_gpuid} flag of
  1825. the @code{starpu_conf} structure passed to @code{starpu_init} is set.
  1826. @end table
  1827. @node Scheduling
  1828. @subsection Configuring the Scheduling engine
  1829. @menu
  1830. * STARPU_SCHED:: Scheduling policy
  1831. * STARPU_CALIBRATE:: Calibrate performance models
  1832. * STARPU_PREFETCH:: Use data prefetch
  1833. * STARPU_SCHED_ALPHA:: Computation factor
  1834. * STARPU_SCHED_BETA:: Communication factor
  1835. @end menu
  1836. @node STARPU_SCHED
  1837. @subsubsection @code{STARPU_SCHED} -- Scheduling policy
  1838. @table @asis
  1839. @item @emph{Description}:
  1840. This chooses between the different scheduling policies proposed by StarPU: work
  1841. random, stealing, greedy, with performance models, etc.
  1842. Use @code{STARPU_SCHED=help} to get the list of available schedulers.
  1843. @end table
  1844. @node STARPU_CALIBRATE
  1845. @subsubsection @code{STARPU_CALIBRATE} -- Calibrate performance models
  1846. @table @asis
  1847. @item @emph{Description}:
  1848. If this variable is set to 1, the performance models are calibrated during
  1849. the execution. If it is set to 2, the previous values are dropped to restart
  1850. calibration from scratch. Setting this variable to 0 disable calibration, this
  1851. is the default behaviour.
  1852. Note: this currently only applies to dm and dmda scheduling policies.
  1853. @end table
  1854. @node STARPU_PREFETCH
  1855. @subsubsection @code{STARPU_PREFETCH} -- Use data prefetch
  1856. @table @asis
  1857. @item @emph{Description}:
  1858. This variable indicates whether data prefetching should be enabled (0 means
  1859. that it is disabled). If prefetching is enabled, when a task is scheduled to be
  1860. executed e.g. on a GPU, StarPU will request an asynchronous transfer in
  1861. advance, so that data is already present on the GPU when the task starts. As a
  1862. result, computation and data transfers are overlapped.
  1863. @end table
  1864. @node STARPU_SCHED_ALPHA
  1865. @subsubsection @code{STARPU_SCHED_ALPHA} -- Computation factor
  1866. @table @asis
  1867. @item @emph{Description}:
  1868. To estimate the cost of a task StarPU takes into account the estimated
  1869. computation time (obtained thanks to performance models). The alpha factor is
  1870. the coefficient to be applied to it before adding it to the communication part.
  1871. @end table
  1872. @node STARPU_SCHED_BETA
  1873. @subsubsection @code{STARPU_SCHED_BETA} -- Communication factor
  1874. @table @asis
  1875. @item @emph{Description}:
  1876. To estimate the cost of a task StarPU takes into account the estimated
  1877. data transfer time (obtained thanks to performance models). The beta factor is
  1878. the coefficient to be applied to it before adding it to the computation part.
  1879. @end table
  1880. @node Misc
  1881. @subsection Miscellaneous and debug
  1882. @menu
  1883. * STARPU_SILENT:: Disable verbose mode
  1884. * STARPU_LOGFILENAME:: Select debug file name
  1885. * STARPU_FXT_PREFIX:: FxT trace location
  1886. * STARPU_LIMIT_GPU_MEM:: Restrict memory size on the GPUs
  1887. * STARPU_GENERATE_TRACE:: Generate a Paje trace when StarPU is shut down
  1888. @end menu
  1889. @node STARPU_SILENT
  1890. @subsubsection @code{STARPU_SILENT} -- Disable verbose mode
  1891. @table @asis
  1892. @item @emph{Description}:
  1893. This variable allows to disable verbose mode at runtime when StarPU
  1894. has been configured with the option @code{--enable-verbose}.
  1895. @end table
  1896. @node STARPU_LOGFILENAME
  1897. @subsubsection @code{STARPU_LOGFILENAME} -- Select debug file name
  1898. @table @asis
  1899. @item @emph{Description}:
  1900. This variable specifies in which file the debugging output should be saved to.
  1901. @end table
  1902. @node STARPU_FXT_PREFIX
  1903. @subsubsection @code{STARPU_FXT_PREFIX} -- FxT trace location
  1904. @table @asis
  1905. @item @emph{Description}
  1906. This variable specifies in which directory to save the trace generated if FxT is enabled.
  1907. @end table
  1908. @node STARPU_LIMIT_GPU_MEM
  1909. @subsubsection @code{STARPU_LIMIT_GPU_MEM} -- Restrict memory size on the GPUs
  1910. @table @asis
  1911. @item @emph{Description}
  1912. This variable specifies the maximum number of megabytes that should be
  1913. available to the application on each GPUs. In case this value is smaller than
  1914. the size of the memory of a GPU, StarPU pre-allocates a buffer to waste memory
  1915. on the device. This variable is intended to be used for experimental purposes
  1916. as it emulates devices that have a limited amount of memory.
  1917. @end table
  1918. @node STARPU_GENERATE_TRACE
  1919. @subsubsection @code{STARPU_GENERATE_TRACE} -- Generate a Paje trace when StarPU is shut down
  1920. @table @asis
  1921. @item @emph{Description}
  1922. When set to 1, this variable indicates that StarPU should automatically
  1923. generate a Paje trace when starpu_shutdown is called.
  1924. @end table
  1925. @c ---------------------------------------------------------------------
  1926. @c StarPU API
  1927. @c ---------------------------------------------------------------------
  1928. @node StarPU API
  1929. @chapter StarPU API
  1930. @menu
  1931. * Initialization and Termination:: Initialization and Termination methods
  1932. * Workers' Properties:: Methods to enumerate workers' properties
  1933. * Data Library:: Methods to manipulate data
  1934. * Data Interfaces::
  1935. * Data Partition::
  1936. * Codelets and Tasks:: Methods to construct tasks
  1937. * Explicit Dependencies:: Explicit Dependencies
  1938. * Implicit Data Dependencies:: Implicit Data Dependencies
  1939. * Performance Model API::
  1940. * Profiling API:: Profiling API
  1941. * CUDA extensions:: CUDA extensions
  1942. * OpenCL extensions:: OpenCL extensions
  1943. * Cell extensions:: Cell extensions
  1944. * Miscellaneous helpers::
  1945. @end menu
  1946. @node Initialization and Termination
  1947. @section Initialization and Termination
  1948. @menu
  1949. * starpu_init:: Initialize StarPU
  1950. * struct starpu_conf:: StarPU runtime configuration
  1951. * starpu_conf_init:: Initialize starpu_conf structure
  1952. * starpu_shutdown:: Terminate StarPU
  1953. @end menu
  1954. @node starpu_init
  1955. @subsection @code{starpu_init} -- Initialize StarPU
  1956. @table @asis
  1957. @item @emph{Description}:
  1958. This is StarPU initialization method, which must be called prior to any other
  1959. StarPU call. It is possible to specify StarPU's configuration (e.g. scheduling
  1960. policy, number of cores, ...) by passing a non-null argument. Default
  1961. configuration is used if the passed argument is @code{NULL}.
  1962. @item @emph{Return value}:
  1963. Upon successful completion, this function returns 0. Otherwise, @code{-ENODEV}
  1964. indicates that no worker was available (so that StarPU was not initialized).
  1965. @item @emph{Prototype}:
  1966. @code{int starpu_init(struct starpu_conf *conf);}
  1967. @end table
  1968. @node struct starpu_conf
  1969. @subsection @code{struct starpu_conf} -- StarPU runtime configuration
  1970. @table @asis
  1971. @item @emph{Description}:
  1972. This structure is passed to the @code{starpu_init} function in order
  1973. to configure StarPU.
  1974. When the default value is used, StarPU automatically selects the number
  1975. of processing units and takes the default scheduling policy. This parameter
  1976. overwrites the equivalent environment variables.
  1977. @item @emph{Fields}:
  1978. @table @asis
  1979. @item @code{sched_policy_name} (default = NULL):
  1980. This is the name of the scheduling policy. This can also be specified with the
  1981. @code{STARPU_SCHED} environment variable.
  1982. @item @code{sched_policy} (default = NULL):
  1983. This is the definition of the scheduling policy. This field is ignored
  1984. if @code{sched_policy_name} is set.
  1985. @item @code{ncpus} (default = -1):
  1986. This is the number of CPU cores that StarPU can use. This can also be
  1987. specified with the @code{STARPU_NCPUS} environment variable.
  1988. @item @code{ncuda} (default = -1):
  1989. This is the number of CUDA devices that StarPU can use. This can also be
  1990. specified with the @code{STARPU_NCUDA} environment variable.
  1991. @item @code{nopencl} (default = -1):
  1992. This is the number of OpenCL devices that StarPU can use. This can also be
  1993. specified with the @code{STARPU_NOPENCL} environment variable.
  1994. @item @code{nspus} (default = -1):
  1995. This is the number of Cell SPUs that StarPU can use. This can also be
  1996. specified with the @code{STARPU_NGORDON} environment variable.
  1997. @item @code{use_explicit_workers_bindid} (default = 0)
  1998. If this flag is set, the @code{workers_bindid} array indicates where the
  1999. different workers are bound, otherwise StarPU automatically selects where to
  2000. bind the different workers unless the @code{STARPU_WORKERS_CPUID} environment
  2001. variable is set. The @code{STARPU_WORKERS_CPUID} environment variable is
  2002. ignored if the @code{use_explicit_workers_bindid} flag is set.
  2003. @item @code{workers_bindid[STARPU_NMAXWORKERS]}
  2004. If the @code{use_explicit_workers_bindid} flag is set, this array indicates
  2005. where to bind the different workers. The i-th entry of the
  2006. @code{workers_bindid} indicates the logical identifier of the processor which
  2007. should execute the i-th worker. Note that the logical ordering of the CPUs is
  2008. either determined by the OS, or provided by the @code{hwloc} library in case it
  2009. is available.
  2010. When this flag is set, the @ref{STARPU_WORKERS_CPUID} environment variable is
  2011. ignored.
  2012. @item @code{use_explicit_workers_cuda_gpuid} (default = 0)
  2013. If this flag is set, the CUDA workers will be attached to the CUDA devices
  2014. specified in the @code{workers_cuda_gpuid} array. Otherwise, StarPU affects the
  2015. CUDA devices in a round-robin fashion.
  2016. When this flag is set, the @ref{STARPU_WORKERS_CUDAID} environment variable is
  2017. ignored.
  2018. @item @code{workers_cuda_gpuid[STARPU_NMAXWORKERS]}
  2019. If the @code{use_explicit_workers_cuda_gpuid} flag is set, this array contains
  2020. the logical identifiers of the CUDA devices (as used by @code{cudaGetDevice}).
  2021. @item @code{use_explicit_workers_opencl_gpuid} (default = 0)
  2022. If this flag is set, the OpenCL workers will be attached to the OpenCL devices
  2023. specified in the @code{workers_opencl_gpuid} array. Otherwise, StarPU affects the
  2024. OpenCL devices in a round-robin fashion.
  2025. @item @code{workers_opencl_gpuid[STARPU_NMAXWORKERS]}:
  2026. @item @code{calibrate} (default = 0):
  2027. If this flag is set, StarPU will calibrate the performance models when
  2028. executing tasks. If this value is equal to -1, the default value is used. The
  2029. default value is overwritten by the @code{STARPU_CALIBRATE} environment
  2030. variable when it is set.
  2031. @end table
  2032. @end table
  2033. @node starpu_conf_init
  2034. @subsection @code{starpu_conf_init} -- Initialize starpu_conf structure
  2035. @table @asis
  2036. This function initializes the @code{starpu_conf} structure passed as argument
  2037. with the default values. In case some configuration parameters are already
  2038. specified through environment variables, @code{starpu_conf_init} initializes
  2039. the fields of the structure according to the environment variables. For
  2040. instance if @code{STARPU_CALIBRATE} is set, its value is put in the
  2041. @code{.ncuda} field of the structure passed as argument.
  2042. @item @emph{Return value}:
  2043. Upon successful completion, this function returns 0. Otherwise, @code{-EINVAL}
  2044. indicates that the argument was NULL.
  2045. @item @emph{Prototype}:
  2046. @code{int starpu_conf_init(struct starpu_conf *conf);}
  2047. @end table
  2048. @node starpu_shutdown
  2049. @subsection @code{starpu_shutdown} -- Terminate StarPU
  2050. @table @asis
  2051. @item @emph{Description}:
  2052. This is StarPU termination method. It must be called at the end of the
  2053. application: statistics and other post-mortem debugging information are not
  2054. guaranteed to be available until this method has been called.
  2055. @item @emph{Prototype}:
  2056. @code{void starpu_shutdown(void);}
  2057. @end table
  2058. @node Workers' Properties
  2059. @section Workers' Properties
  2060. @menu
  2061. * starpu_worker_get_count:: Get the number of processing units
  2062. * starpu_cpu_worker_get_count:: Get the number of CPU controlled by StarPU
  2063. * starpu_cuda_worker_get_count:: Get the number of CUDA devices controlled by StarPU
  2064. * starpu_opencl_worker_get_count:: Get the number of OpenCL devices controlled by StarPU
  2065. * starpu_spu_worker_get_count:: Get the number of Cell SPUs controlled by StarPU
  2066. * starpu_worker_get_id:: Get the identifier of the current worker
  2067. * starpu_worker_get_devid:: Get the device identifier of a worker
  2068. * starpu_worker_get_type:: Get the type of processing unit associated to a worker
  2069. * starpu_worker_get_name:: Get the name of a worker
  2070. * starpu_worker_get_memory_node:: Get the memory node of a worker
  2071. @end menu
  2072. @node starpu_worker_get_count
  2073. @subsection @code{starpu_worker_get_count} -- Get the number of processing units
  2074. @table @asis
  2075. @item @emph{Description}:
  2076. This function returns the number of workers (i.e. processing units executing
  2077. StarPU tasks). The returned value should be at most @code{STARPU_NMAXWORKERS}.
  2078. @item @emph{Prototype}:
  2079. @code{unsigned starpu_worker_get_count(void);}
  2080. @end table
  2081. @node starpu_cpu_worker_get_count
  2082. @subsection @code{starpu_cpu_worker_get_count} -- Get the number of CPU controlled by StarPU
  2083. @table @asis
  2084. @item @emph{Description}:
  2085. This function returns the number of CPUs controlled by StarPU. The returned
  2086. value should be at most @code{STARPU_NMAXCPUS}.
  2087. @item @emph{Prototype}:
  2088. @code{unsigned starpu_cpu_worker_get_count(void);}
  2089. @end table
  2090. @node starpu_cuda_worker_get_count
  2091. @subsection @code{starpu_cuda_worker_get_count} -- Get the number of CUDA devices controlled by StarPU
  2092. @table @asis
  2093. @item @emph{Description}:
  2094. This function returns the number of CUDA devices controlled by StarPU. The returned
  2095. value should be at most @code{STARPU_MAXCUDADEVS}.
  2096. @item @emph{Prototype}:
  2097. @code{unsigned starpu_cuda_worker_get_count(void);}
  2098. @end table
  2099. @node starpu_opencl_worker_get_count
  2100. @subsection @code{starpu_opencl_worker_get_count} -- Get the number of OpenCL devices controlled by StarPU
  2101. @table @asis
  2102. @item @emph{Description}:
  2103. This function returns the number of OpenCL devices controlled by StarPU. The returned
  2104. value should be at most @code{STARPU_MAXOPENCLDEVS}.
  2105. @item @emph{Prototype}:
  2106. @code{unsigned starpu_opencl_worker_get_count(void);}
  2107. @end table
  2108. @node starpu_spu_worker_get_count
  2109. @subsection @code{starpu_spu_worker_get_count} -- Get the number of Cell SPUs controlled by StarPU
  2110. @table @asis
  2111. @item @emph{Description}:
  2112. This function returns the number of Cell SPUs controlled by StarPU.
  2113. @item @emph{Prototype}:
  2114. @code{unsigned starpu_opencl_worker_get_count(void);}
  2115. @end table
  2116. @node starpu_worker_get_id
  2117. @subsection @code{starpu_worker_get_id} -- Get the identifier of the current worker
  2118. @table @asis
  2119. @item @emph{Description}:
  2120. This function returns the identifier of the worker associated to the calling
  2121. thread. The returned value is either -1 if the current context is not a StarPU
  2122. worker (i.e. when called from the application outside a task or a callback), or
  2123. an integer between 0 and @code{starpu_worker_get_count() - 1}.
  2124. @item @emph{Prototype}:
  2125. @code{int starpu_worker_get_id(void);}
  2126. @end table
  2127. @node starpu_worker_get_devid
  2128. @subsection @code{starpu_worker_get_devid} -- Get the device identifier of a worker
  2129. @table @asis
  2130. @item @emph{Description}:
  2131. This functions returns the device id of the worker associated to an identifier
  2132. (as returned by the @code{starpu_worker_get_id} function). In the case of a
  2133. CUDA worker, this device identifier is the logical device identifier exposed by
  2134. CUDA (used by the @code{cudaGetDevice} function for instance). The device
  2135. identifier of a CPU worker is the logical identifier of the core on which the
  2136. worker was bound; this identifier is either provided by the OS or by the
  2137. @code{hwloc} library in case it is available.
  2138. @item @emph{Prototype}:
  2139. @code{int starpu_worker_get_devid(int id);}
  2140. @end table
  2141. @node starpu_worker_get_type
  2142. @subsection @code{starpu_worker_get_type} -- Get the type of processing unit associated to a worker
  2143. @table @asis
  2144. @item @emph{Description}:
  2145. This function returns the type of worker associated to an identifier (as
  2146. returned by the @code{starpu_worker_get_id} function). The returned value
  2147. indicates the architecture of the worker: @code{STARPU_CPU_WORKER} for a CPU
  2148. core, @code{STARPU_CUDA_WORKER} for a CUDA device,
  2149. @code{STARPU_OPENCL_WORKER} for a OpenCL device, and
  2150. @code{STARPU_GORDON_WORKER} for a Cell SPU. The value returned for an invalid
  2151. identifier is unspecified.
  2152. @item @emph{Prototype}:
  2153. @code{enum starpu_archtype starpu_worker_get_type(int id);}
  2154. @end table
  2155. @node starpu_worker_get_name
  2156. @subsection @code{starpu_worker_get_name} -- Get the name of a worker
  2157. @table @asis
  2158. @item @emph{Description}:
  2159. StarPU associates a unique human readable string to each processing unit. This
  2160. function copies at most the @code{maxlen} first bytes of the unique string
  2161. associated to a worker identified by its identifier @code{id} into the
  2162. @code{dst} buffer. The caller is responsible for ensuring that the @code{dst}
  2163. is a valid pointer to a buffer of @code{maxlen} bytes at least. Calling this
  2164. function on an invalid identifier results in an unspecified behaviour.
  2165. @item @emph{Prototype}:
  2166. @code{void starpu_worker_get_name(int id, char *dst, size_t maxlen);}
  2167. @end table
  2168. @node starpu_worker_get_memory_node
  2169. @subsection @code{starpu_worker_get_memory_node} -- Get the memory node of a worker
  2170. @table @asis
  2171. @item @emph{Description}:
  2172. This function returns the identifier of the memory node associated to the
  2173. worker identified by @code{workerid}.
  2174. @item @emph{Prototype}:
  2175. @code{unsigned starpu_worker_get_memory_node(unsigned workerid);}
  2176. @end table
  2177. @node Data Library
  2178. @section Data Library
  2179. This section describes the data management facilities provided by StarPU.
  2180. We show how to use existing data interfaces in @ref{Data Interfaces}, but developers can
  2181. design their own data interfaces if required.
  2182. @menu
  2183. * starpu_data_malloc_pinned_if_possible:: Allocate data and pin it
  2184. * starpu_access_mode:: Data access mode
  2185. * unsigned memory_node:: Memory node
  2186. * starpu_data_handle:: StarPU opaque data handle
  2187. * void *interface:: StarPU data interface
  2188. * starpu_data_register:: Register a piece of data to StarPU
  2189. * starpu_data_unregister:: Unregister a piece of data from StarPU
  2190. * starpu_data_invalidate:: Invalidate all data replicates
  2191. * starpu_data_acquire:: Access registered data from the application
  2192. * starpu_data_acquire_cb:: Access registered data from the application asynchronously
  2193. * starpu_data_release:: Release registered data from the application
  2194. * starpu_data_set_wt_mask:: Set the Write-Through mask
  2195. @end menu
  2196. @node starpu_data_malloc_pinned_if_possible
  2197. @subsection @code{starpu_data_malloc_pinned_if_possible} -- Allocate data and pin it
  2198. @table @asis
  2199. @item @emph{Description}:
  2200. This function allocates data of the given size. It will also try to pin it in
  2201. CUDA or OpenGL, so that data transfers from this buffer can be asynchronous, and
  2202. thus permit data transfer and computation overlapping.
  2203. @item @emph{Prototype}:
  2204. @code{int starpu_data_malloc_pinned_if_possible(void **A, size_t dim);}
  2205. @end table
  2206. @node starpu_access_mode
  2207. @subsection @code{starpu_access_mode} -- Data access mode
  2208. This datatype describes a data access mode. The different available modes are:
  2209. @table @asis
  2210. @table @asis
  2211. @item @code{STARPU_R} read-only mode.
  2212. @item @code{STARPU_W} write-only mode.
  2213. @item @code{STARPU_RW} read-write mode. This is equivalent to @code{STARPU_R|STARPU_W}.
  2214. @item @code{STARPU_SCRATCH} scratch memory. A temporary buffer is allocated for the task, but StarPU does not enforce data consistency, i.e. each device has its own buffer, independently from each other (even for CPUs). This is useful for temporary variables. For now, no behaviour is defined concerning the relation with STARPU_R/W modes and the value provided at registration, i.e. the value of the scratch buffer is undefined at entry of the codelet function, but this is being considered for future extensions.
  2215. @end table
  2216. @end table
  2217. @node unsigned memory_node
  2218. @subsection @code{unsigned memory_node} -- Memory node
  2219. @table @asis
  2220. @item @emph{Description}:
  2221. Every worker is associated to a memory node which is a logical abstraction of
  2222. the address space from which the processing unit gets its data. For instance,
  2223. the memory node associated to the different CPU workers represents main memory
  2224. (RAM), the memory node associated to a GPU is DRAM embedded on the device.
  2225. Every memory node is identified by a logical index which is accessible from the
  2226. @code{starpu_worker_get_memory_node} function. When registering a piece of data
  2227. to StarPU, the specified memory node indicates where the piece of data
  2228. initially resides (we also call this memory node the home node of a piece of
  2229. data).
  2230. @end table
  2231. @node starpu_data_handle
  2232. @subsection @code{starpu_data_handle} -- StarPU opaque data handle
  2233. @table @asis
  2234. @item @emph{Description}:
  2235. StarPU uses @code{starpu_data_handle} as an opaque handle to manage a piece of
  2236. data. Once a piece of data has been registered to StarPU, it is associated to a
  2237. @code{starpu_data_handle} which keeps track of the state of the piece of data
  2238. over the entire machine, so that we can maintain data consistency and locate
  2239. data replicates for instance.
  2240. @end table
  2241. @node void *interface
  2242. @subsection @code{void *interface} -- StarPU data interface
  2243. @table @asis
  2244. @item @emph{Description}:
  2245. Data management is done at a high-level in StarPU: rather than accessing a mere
  2246. list of contiguous buffers, the tasks may manipulate data that are described by
  2247. a high-level construct which we call data interface.
  2248. An example of data interface is the "vector" interface which describes a
  2249. contiguous data array on a spefic memory node. This interface is a simple
  2250. structure containing the number of elements in the array, the size of the
  2251. elements, and the address of the array in the appropriate address space (this
  2252. address may be invalid if there is no valid copy of the array in the memory
  2253. node). More informations on the data interfaces provided by StarPU are
  2254. given in @ref{Data Interfaces}.
  2255. When a piece of data managed by StarPU is used by a task, the task
  2256. implementation is given a pointer to an interface describing a valid copy of
  2257. the data that is accessible from the current processing unit.
  2258. @end table
  2259. @node starpu_data_register
  2260. @subsection @code{starpu_data_register} -- Register a piece of data to StarPU
  2261. @table @asis
  2262. @item @emph{Description}:
  2263. Register a piece of data into the handle located at the @code{handleptr}
  2264. address. The @code{interface} buffer contains the initial description of the
  2265. data in the home node. The @code{ops} argument is a pointer to a structure
  2266. describing the different methods used to manipulate this type of interface. See
  2267. @ref{struct starpu_data_interface_ops_t} for more details on this structure.
  2268. If @code{home_node} is -1, StarPU will automatically
  2269. allocate the memory when it is used for the
  2270. first time in write-only mode. Once such data handle has been automatically
  2271. allocated, it is possible to access it using any access mode.
  2272. Note that StarPU supplies a set of predefined types of interface (e.g. vector or
  2273. matrix) which can be registered by the means of helper functions (e.g.
  2274. @code{starpu_vector_data_register} or @code{starpu_matrix_data_register}).
  2275. @item @emph{Prototype}:
  2276. @code{void starpu_data_register(starpu_data_handle *handleptr,
  2277. uint32_t home_node,
  2278. void *interface,
  2279. struct starpu_data_interface_ops_t *ops);}
  2280. @end table
  2281. @node starpu_data_unregister
  2282. @subsection @code{starpu_data_unregister} -- Unregister a piece of data from StarPU
  2283. @table @asis
  2284. @item @emph{Description}:
  2285. This function unregisters a data handle from StarPU. If the data was
  2286. automatically allocated by StarPU because the home node was -1, all
  2287. automatically allocated buffers are freed. Otherwise, a valid copy of the data
  2288. is put back into the home node in the buffer that was initially registered.
  2289. Using a data handle that has been unregistered from StarPU results in an
  2290. undefined behaviour.
  2291. @item @emph{Prototype}:
  2292. @code{void starpu_data_unregister(starpu_data_handle handle);}
  2293. @end table
  2294. @node starpu_data_invalidate
  2295. @subsection @code{starpu_data_invalidate} -- Invalidate all data replicates
  2296. @table @asis
  2297. @item @emph{Description}:
  2298. Destroy all replicates of the data handle. After data invalidation, the first
  2299. access to the handle must be performed in write-only mode. Accessing an
  2300. invalidated data in read-mode results in undefined behaviour.
  2301. @item @emph{Prototype}:
  2302. @code{void starpu_data_invalidate(starpu_data_handle handle);}
  2303. @end table
  2304. @c TODO create a specific sections about user interaction with the DSM ?
  2305. @node starpu_data_acquire
  2306. @subsection @code{starpu_data_acquire} -- Access registered data from the application
  2307. @table @asis
  2308. @item @emph{Description}:
  2309. The application must call this function prior to accessing registered data from
  2310. main memory outside tasks. StarPU ensures that the application will get an
  2311. up-to-date copy of the data in main memory located where the data was
  2312. originally registered, and that all concurrent accesses (e.g. from tasks) will
  2313. be consistent with the access mode specified in the @code{mode} argument.
  2314. @code{starpu_data_release} must be called once the application does not need to
  2315. access the piece of data anymore.
  2316. Note that implicit data dependencies are also enforced by
  2317. @code{starpu_data_acquire} in case they are enabled.
  2318. @code{starpu_data_acquire} is a blocking call, so that it cannot be called from
  2319. tasks or from their callbacks (in that case, @code{starpu_data_acquire} returns
  2320. @code{-EDEADLK}). Upon successful completion, this function returns 0.
  2321. @item @emph{Prototype}:
  2322. @code{int starpu_data_acquire(starpu_data_handle handle, starpu_access_mode mode);}
  2323. @end table
  2324. @node starpu_data_acquire_cb
  2325. @subsection @code{starpu_data_acquire_cb} -- Access registered data from the application asynchronously
  2326. @table @asis
  2327. @item @emph{Description}:
  2328. @code{starpu_data_acquire_cb} is the asynchronous equivalent of
  2329. @code{starpu_data_release}. When the data specified in the first argument is
  2330. available in the appropriate access mode, the callback function is executed.
  2331. The application may access the requested data during the execution of this
  2332. callback. The callback function must call @code{starpu_data_release} once the
  2333. application does not need to access the piece of data anymore.
  2334. Note that implicit data dependencies are also enforced by
  2335. @code{starpu_data_acquire_cb} in case they are enabled.
  2336. Contrary to @code{starpu_data_acquire}, this function is non-blocking and may
  2337. be called from task callbacks. Upon successful completion, this function
  2338. returns 0.
  2339. @item @emph{Prototype}:
  2340. @code{int starpu_data_acquire_cb(starpu_data_handle handle, starpu_access_mode mode, void (*callback)(void *), void *arg);}
  2341. @end table
  2342. @node starpu_data_release
  2343. @subsection @code{starpu_data_release} -- Release registered data from the application
  2344. @table @asis
  2345. @item @emph{Description}:
  2346. This function releases the piece of data acquired by the application either by
  2347. @code{starpu_data_acquire} or by @code{starpu_data_acquire_cb}.
  2348. @item @emph{Prototype}:
  2349. @code{void starpu_data_release(starpu_data_handle handle);}
  2350. @end table
  2351. @node starpu_data_set_wt_mask
  2352. @subsection @code{starpu_data_set_wt_mask} -- Set the Write-Through mask
  2353. @table @asis
  2354. @item @emph{Description}:
  2355. This function sets the write-through mask of a given data, i.e. a bitmask of
  2356. nodes where the data should be always replicated after modification.
  2357. @item @emph{Prototype}:
  2358. @code{void starpu_data_set_wt_mask(starpu_data_handle handle, uint32_t wt_mask);}
  2359. @end table
  2360. @node Data Interfaces
  2361. @section Data Interfaces
  2362. @menu
  2363. * Variable Interface::
  2364. * Vector Interface::
  2365. * Matrix Interface::
  2366. * 3D Matrix Interface::
  2367. * BCSR Interface for Sparse Matrices (Blocked Compressed Sparse Row Representation)::
  2368. * CSR Interface for Sparse Matrices (Compressed Sparse Row Representation)::
  2369. @end menu
  2370. @node Variable Interface
  2371. @subsection Variable Interface
  2372. @table @asis
  2373. @item @emph{Description}:
  2374. This variant of @code{starpu_data_register} uses the variable interface,
  2375. i.e. for a mere single variable. @code{ptr} is the address of the variable,
  2376. and @code{elemsize} is the size of the variable.
  2377. @item @emph{Prototype}:
  2378. @code{void starpu_variable_data_register(starpu_data_handle *handle,
  2379. uint32_t home_node,
  2380. uintptr_t ptr, size_t elemsize);}
  2381. @item @emph{Example}:
  2382. @cartouche
  2383. @smallexample
  2384. float var;
  2385. starpu_data_handle var_handle;
  2386. starpu_variable_data_register(&var_handle, 0, (uintptr_t)&var, sizeof(var));
  2387. @end smallexample
  2388. @end cartouche
  2389. @end table
  2390. @node Vector Interface
  2391. @subsection Vector Interface
  2392. @table @asis
  2393. @item @emph{Description}:
  2394. This variant of @code{starpu_data_register} uses the vector interface,
  2395. i.e. for mere arrays of elements. @code{ptr} is the address of the first
  2396. element in the home node. @code{nx} is the number of elements in the vector.
  2397. @code{elemsize} is the size of each element.
  2398. @item @emph{Prototype}:
  2399. @code{void starpu_vector_data_register(starpu_data_handle *handle, uint32_t home_node,
  2400. uintptr_t ptr, uint32_t nx, size_t elemsize);}
  2401. @item @emph{Example}:
  2402. @cartouche
  2403. @smallexample
  2404. float vector[NX];
  2405. starpu_data_handle vector_handle;
  2406. starpu_vector_data_register(&vector_handle, 0, (uintptr_t)vector, NX,
  2407. sizeof(vector[0]));
  2408. @end smallexample
  2409. @end cartouche
  2410. @end table
  2411. @node Matrix Interface
  2412. @subsection Matrix Interface
  2413. @table @asis
  2414. @item @emph{Description}:
  2415. This variant of @code{starpu_data_register} uses the matrix interface, i.e. for
  2416. matrices of elements. @code{ptr} is the address of the first element in the home
  2417. node. @code{ld} is the number of elements between rows. @code{nx} is the number
  2418. of elements in a row (this can be different from @code{ld} if there are extra
  2419. elements for alignment for instance). @code{ny} is the number of rows.
  2420. @code{elemsize} is the size of each element.
  2421. @item @emph{Prototype}:
  2422. @code{void starpu_matrix_data_register(starpu_data_handle *handle, uint32_t home_node,
  2423. uintptr_t ptr, uint32_t ld, uint32_t nx,
  2424. uint32_t ny, size_t elemsize);}
  2425. @item @emph{Example}:
  2426. @cartouche
  2427. @smallexample
  2428. float *matrix;
  2429. starpu_data_handle matrix_handle;
  2430. matrix = (float*)malloc(width * height * sizeof(float));
  2431. starpu_matrix_data_register(&matrix_handle, 0, (uintptr_t)matrix,
  2432. width, width, height, sizeof(float));
  2433. @end smallexample
  2434. @end cartouche
  2435. @end table
  2436. @node 3D Matrix Interface
  2437. @subsection 3D Matrix Interface
  2438. @table @asis
  2439. @item @emph{Description}:
  2440. This variant of @code{starpu_data_register} uses the 3D matrix interface.
  2441. @code{ptr} is the address of the array of first element in the home node.
  2442. @code{ldy} is the number of elements between rows. @code{ldz} is the number
  2443. of rows between z planes. @code{nx} is the number of elements in a row (this
  2444. can be different from @code{ldy} if there are extra elements for alignment
  2445. for instance). @code{ny} is the number of rows in a z plane (likewise with
  2446. @code{ldz}). @code{nz} is the number of z planes. @code{elemsize} is the size of
  2447. each element.
  2448. @item @emph{Prototype}:
  2449. @code{void starpu_block_data_register(starpu_data_handle *handle, uint32_t home_node,
  2450. uintptr_t ptr, uint32_t ldy, uint32_t ldz, uint32_t nx,
  2451. uint32_t ny, uint32_t nz, size_t elemsize);}
  2452. @item @emph{Example}:
  2453. @cartouche
  2454. @smallexample
  2455. float *block;
  2456. starpu_data_handle block_handle;
  2457. block = (float*)malloc(nx*ny*nz*sizeof(float));
  2458. starpu_block_data_register(&block_handle, 0, (uintptr_t)block,
  2459. nx, nx*ny, nx, ny, nz, sizeof(float));
  2460. @end smallexample
  2461. @end cartouche
  2462. @end table
  2463. @node BCSR Interface for Sparse Matrices (Blocked Compressed Sparse Row Representation)
  2464. @subsection BCSR Interface for Sparse Matrices (Blocked Compressed Sparse Row Representation)
  2465. @table @asis
  2466. @item @emph{Description}:
  2467. This variant of @code{starpu_data_register} uses the BCSR sparse matrix interface.
  2468. TODO
  2469. @item @emph{Prototype}:
  2470. @code{void starpu_bcsr_data_register(starpu_data_handle *handle, uint32_t home_node, uint32_t nnz, uint32_t nrow,
  2471. uintptr_t nzval, uint32_t *colind, uint32_t *rowptr, uint32_t firstentry, uint32_t r, uint32_t c, size_t elemsize);}
  2472. @item @emph{Example}:
  2473. @cartouche
  2474. @smallexample
  2475. @end smallexample
  2476. @end cartouche
  2477. @end table
  2478. @node CSR Interface for Sparse Matrices (Compressed Sparse Row Representation)
  2479. @subsection CSR Interface for Sparse Matrices (Compressed Sparse Row Representation)
  2480. @table @asis
  2481. @item @emph{Description}:
  2482. This variant of @code{starpu_data_register} uses the CSR sparse matrix interface.
  2483. TODO
  2484. @item @emph{Prototype}:
  2485. @code{void starpu_csr_data_register(starpu_data_handle *handle, uint32_t home_node, uint32_t nnz, uint32_t nrow,
  2486. uintptr_t nzval, uint32_t *colind, uint32_t *rowptr, uint32_t firstentry, size_t elemsize);}
  2487. @item @emph{Example}:
  2488. @cartouche
  2489. @smallexample
  2490. @end smallexample
  2491. @end cartouche
  2492. @end table
  2493. @node Data Partition
  2494. @section Data Partition
  2495. @menu
  2496. * struct starpu_data_filter:: StarPU filter structure
  2497. * starpu_data_partition:: Partition Data
  2498. * starpu_data_unpartition:: Unpartition Data
  2499. * starpu_data_get_nb_children::
  2500. * starpu_data_get_sub_data::
  2501. * Predefined filter functions::
  2502. @end menu
  2503. @node struct starpu_data_filter
  2504. @subsection @code{struct starpu_data_filter} -- StarPU filter structure
  2505. @table @asis
  2506. @item @emph{Description}:
  2507. The filter structure describes a data partitioning operation, to be given to the
  2508. @code{starpu_data_partition} function, see @ref{starpu_data_partition} for an example.
  2509. @item @emph{Fields}:
  2510. @table @asis
  2511. @item @code{filter_func}:
  2512. This function fills the @code{child_interface} structure with interface
  2513. information for the @code{id}-th child of the parent @code{father_interface} (among @code{nparts}).
  2514. @code{void (*filter_func)(void *father_interface, void* child_interface, struct starpu_data_filter *, unsigned id, unsigned nparts);}
  2515. @item @code{nchildren}:
  2516. This is the number of parts to partition the data into.
  2517. @item @code{get_nchildren}:
  2518. This returns the number of children. This can be used instead of @code{nchildren} when the number of
  2519. children depends on the actual data (e.g. the number of blocks in a sparse
  2520. matrix).
  2521. @code{unsigned (*get_nchildren)(struct starpu_data_filter *, starpu_data_handle initial_handle);}
  2522. @item @code{get_child_ops}:
  2523. In case the resulting children use a different data interface, this function
  2524. returns which interface is used by child number @code{id}.
  2525. @code{struct starpu_data_interface_ops_t *(*get_child_ops)(struct starpu_data_filter *, unsigned id);}
  2526. @item @code{filter_arg}:
  2527. Some filters take an addition parameter, but this is usually unused.
  2528. @item @code{filter_arg_ptr}:
  2529. Some filters take an additional array parameter like the sizes of the parts, but
  2530. this is usually unused.
  2531. @end table
  2532. @end table
  2533. @node starpu_data_partition
  2534. @subsection starpu_data_partition -- Partition Data
  2535. @table @asis
  2536. @item @emph{Description}:
  2537. This requests partitioning one StarPU data @code{initial_handle} into several
  2538. subdata according to the filter @code{f}
  2539. @item @emph{Prototype}:
  2540. @code{void starpu_data_partition(starpu_data_handle initial_handle, struct starpu_data_filter *f);}
  2541. @item @emph{Example}:
  2542. @cartouche
  2543. @smallexample
  2544. struct starpu_data_filter f = @{
  2545. .filter_func = starpu_vertical_block_filter_func,
  2546. .nchildren = nslicesx,
  2547. .get_nchildren = NULL,
  2548. .get_child_ops = NULL
  2549. @};
  2550. starpu_data_partition(A_handle, &f);
  2551. @end smallexample
  2552. @end cartouche
  2553. @end table
  2554. @node starpu_data_unpartition
  2555. @subsection starpu_data_unpartition -- Unpartition data
  2556. @table @asis
  2557. @item @emph{Description}:
  2558. This unapplies one filter, thus unpartitioning the data. The pieces of data are
  2559. collected back into one big piece in the @code{gathering_node} (usually 0).
  2560. @item @emph{Prototype}:
  2561. @code{void starpu_data_unpartition(starpu_data_handle root_data, uint32_t gathering_node);}
  2562. @item @emph{Example}:
  2563. @cartouche
  2564. @smallexample
  2565. starpu_data_unpartition(A_handle, 0);
  2566. @end smallexample
  2567. @end cartouche
  2568. @end table
  2569. @node starpu_data_get_nb_children
  2570. @subsection starpu_data_get_nb_children
  2571. @table @asis
  2572. @item @emph{Description}:
  2573. This function returns the number of children.
  2574. @item @emph{Return value}:
  2575. The number of children.
  2576. @item @emph{Prototype}:
  2577. @code{int starpu_data_get_nb_children(starpu_data_handle handle);}
  2578. @end table
  2579. @c starpu_data_handle starpu_data_get_child(starpu_data_handle handle, unsigned i);
  2580. @node starpu_data_get_sub_data
  2581. @subsection starpu_data_get_sub_data
  2582. @table @asis
  2583. @item @emph{Description}:
  2584. After partitioning a StarPU data by applying a filter,
  2585. @code{starpu_data_get_sub_data} can be used to get handles for each of the data
  2586. portions. @code{root_data} is the parent data that was partitioned. @code{depth}
  2587. is the number of filters to traverse (in case several filters have been applied,
  2588. to e.g. partition in row blocks, and then in column blocks), and the subsequent
  2589. parameters are the indexes.
  2590. @item @emph{Return value}:
  2591. A handle to the subdata.
  2592. @item @emph{Prototype}:
  2593. @code{starpu_data_handle starpu_data_get_sub_data(starpu_data_handle root_data, unsigned depth, ... );}
  2594. @item @emph{Example}:
  2595. @cartouche
  2596. @smallexample
  2597. h = starpu_data_get_sub_data(A_handle, 1, taskx);
  2598. @end smallexample
  2599. @end cartouche
  2600. @end table
  2601. @node Predefined filter functions
  2602. @subsection Predefined filter functions
  2603. @menu
  2604. * Partitioning BCSR Data::
  2605. * Partitioning BLAS interface::
  2606. * Partitioning Vector Data::
  2607. * Partitioning Block Data::
  2608. @end menu
  2609. This section gives a partial list of the predefined partitioning functions.
  2610. Examples on how to use them are shown in @ref{Partitioning Data}. The complete
  2611. list can be found in @code{starpu_data_filters.h} .
  2612. @node Partitioning BCSR Data
  2613. @subsubsection Partitioning BCSR Data
  2614. @table @asis
  2615. @item @emph{Description}:
  2616. TODO
  2617. @item @emph{Prototype}:
  2618. @code{void starpu_canonical_block_filter_bcsr(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts);}
  2619. @end table
  2620. @table @asis
  2621. @item @emph{Description}:
  2622. TODO
  2623. @item @emph{Prototype}:
  2624. @code{void starpu_vertical_block_filter_func_csr(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts);}
  2625. @end table
  2626. @node Partitioning BLAS interface
  2627. @subsubsection Partitioning BLAS interface
  2628. @table @asis
  2629. @item @emph{Description}:
  2630. This partitions a dense Matrix into horizontal blocks.
  2631. @item @emph{Prototype}:
  2632. @code{void starpu_block_filter_func(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts);}
  2633. @end table
  2634. @table @asis
  2635. @item @emph{Description}:
  2636. This partitions a dense Matrix into vertical blocks.
  2637. @item @emph{Prototype}:
  2638. @code{void starpu_vertical_block_filter_func(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts);}
  2639. @end table
  2640. @node Partitioning Vector Data
  2641. @subsubsection Partitioning Vector Data
  2642. @table @asis
  2643. @item @emph{Description}:
  2644. This partitions a vector into blocks of the same size.
  2645. @item @emph{Prototype}:
  2646. @code{void starpu_block_filter_func_vector(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts);}
  2647. @end table
  2648. @table @asis
  2649. @item @emph{Description}:
  2650. This partitions a vector into blocks of sizes given in @code{filter_arg_ptr}.
  2651. @item @emph{Prototype}:
  2652. @code{void starpu_vector_list_filter_func(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts);}
  2653. @end table
  2654. @table @asis
  2655. @item @emph{Description}:
  2656. This partitions a vector into two blocks, the first block size being given in @code{filter_arg}.
  2657. @item @emph{Prototype}:
  2658. @code{void starpu_vector_divide_in_2_filter_func(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts);}
  2659. @end table
  2660. @node Partitioning Block Data
  2661. @subsubsection Partitioning Block Data
  2662. @table @asis
  2663. @item @emph{Description}:
  2664. This partitions a 3D matrix along the X axis.
  2665. @item @emph{Prototype}:
  2666. @code{void starpu_block_filter_func_block(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts);}
  2667. @end table
  2668. @node Codelets and Tasks
  2669. @section Codelets and Tasks
  2670. @menu
  2671. * struct starpu_codelet:: StarPU codelet structure
  2672. * struct starpu_task:: StarPU task structure
  2673. * starpu_task_init:: Initialize a Task
  2674. * starpu_task_create:: Allocate and Initialize a Task
  2675. * starpu_task_deinit:: Release all the resources used by a Task
  2676. * starpu_task_destroy:: Destroy a dynamically allocated Task
  2677. * starpu_task_wait:: Wait for the termination of a Task
  2678. * starpu_task_submit:: Submit a Task
  2679. * starpu_task_wait_for_all:: Wait for the termination of all Tasks
  2680. * starpu_get_current_task:: Return the task currently executed by the worker
  2681. * starpu_display_codelet_stats:: Display statistics
  2682. @end menu
  2683. @node struct starpu_codelet
  2684. @subsection @code{struct starpu_codelet} -- StarPU codelet structure
  2685. @table @asis
  2686. @item @emph{Description}:
  2687. The codelet structure describes a kernel that is possibly implemented on various
  2688. targets. For compatibility, make sure to initialize the whole structure to zero.
  2689. @item @emph{Fields}:
  2690. @table @asis
  2691. @item @code{where}:
  2692. Indicates which types of processing units are able to execute the codelet.
  2693. @code{STARPU_CPU|STARPU_CUDA} for instance indicates that the codelet is
  2694. implemented for both CPU cores and CUDA devices while @code{STARPU_GORDON}
  2695. indicates that it is only available on Cell SPUs.
  2696. @item @code{cpu_func} (optional):
  2697. Is a function pointer to the CPU implementation of the codelet. Its prototype
  2698. must be: @code{void cpu_func(void *buffers[], void *cl_arg)}. The first
  2699. argument being the array of data managed by the data management library, and
  2700. the second argument is a pointer to the argument passed from the @code{cl_arg}
  2701. field of the @code{starpu_task} structure.
  2702. The @code{cpu_func} field is ignored if @code{STARPU_CPU} does not appear in
  2703. the @code{where} field, it must be non-null otherwise.
  2704. @item @code{cuda_func} (optional):
  2705. Is a function pointer to the CUDA implementation of the codelet. @emph{This
  2706. must be a host-function written in the CUDA runtime API}. Its prototype must
  2707. be: @code{void cuda_func(void *buffers[], void *cl_arg);}. The @code{cuda_func}
  2708. field is ignored if @code{STARPU_CUDA} does not appear in the @code{where}
  2709. field, it must be non-null otherwise.
  2710. @item @code{opencl_func} (optional):
  2711. Is a function pointer to the OpenCL implementation of the codelet. Its
  2712. prototype must be:
  2713. @code{void opencl_func(starpu_data_interface_t *descr, void *arg);}.
  2714. This pointer is ignored if @code{STARPU_OPENCL} does not appear in the
  2715. @code{where} field, it must be non-null otherwise.
  2716. @item @code{gordon_func} (optional):
  2717. This is the index of the Cell SPU implementation within the Gordon library.
  2718. See Gordon documentation for more details on how to register a kernel and
  2719. retrieve its index.
  2720. @item @code{nbuffers}:
  2721. Specifies the number of arguments taken by the codelet. These arguments are
  2722. managed by the DSM and are accessed from the @code{void *buffers[]}
  2723. array. The constant argument passed with the @code{cl_arg} field of the
  2724. @code{starpu_task} structure is not counted in this number. This value should
  2725. not be above @code{STARPU_NMAXBUFS}.
  2726. @item @code{model} (optional):
  2727. This is a pointer to the task duration performance model associated to this
  2728. codelet. This optional field is ignored when set to @code{NULL}.
  2729. TODO
  2730. @item @code{power_model} (optional):
  2731. This is a pointer to the task power consumption performance model associated
  2732. to this codelet. This optional field is ignored when set to @code{NULL}.
  2733. In the case of parallel codelets, this has to account for all processing units
  2734. involved in the parallel execution.
  2735. TODO
  2736. @end table
  2737. @end table
  2738. @node struct starpu_task
  2739. @subsection @code{struct starpu_task} -- StarPU task structure
  2740. @table @asis
  2741. @item @emph{Description}:
  2742. The @code{starpu_task} structure describes a task that can be offloaded on the various
  2743. processing units managed by StarPU. It instantiates a codelet. It can either be
  2744. allocated dynamically with the @code{starpu_task_create} method, or declared
  2745. statically. In the latter case, the programmer has to zero the
  2746. @code{starpu_task} structure and to fill the different fields properly. The
  2747. indicated default values correspond to the configuration of a task allocated
  2748. with @code{starpu_task_create}.
  2749. @item @emph{Fields}:
  2750. @table @asis
  2751. @item @code{cl}:
  2752. Is a pointer to the corresponding @code{starpu_codelet} data structure. This
  2753. describes where the kernel should be executed, and supplies the appropriate
  2754. implementations. When set to @code{NULL}, no code is executed during the tasks,
  2755. such empty tasks can be useful for synchronization purposes.
  2756. @item @code{buffers}:
  2757. Is an array of @code{starpu_buffer_descr_t} structures. It describes the
  2758. different pieces of data accessed by the task, and how they should be accessed.
  2759. The @code{starpu_buffer_descr_t} structure is composed of two fields, the
  2760. @code{handle} field specifies the handle of the piece of data, and the
  2761. @code{mode} field is the required access mode (eg @code{STARPU_RW}). The number
  2762. of entries in this array must be specified in the @code{nbuffers} field of the
  2763. @code{starpu_codelet} structure, and should not excede @code{STARPU_NMAXBUFS}.
  2764. If unsufficient, this value can be set with the @code{--enable-maxbuffers}
  2765. option when configuring StarPU.
  2766. @item @code{cl_arg} (optional) (default = NULL):
  2767. This pointer is passed to the codelet through the second argument
  2768. of the codelet implementation (e.g. @code{cpu_func} or @code{cuda_func}).
  2769. In the specific case of the Cell processor, see the @code{cl_arg_size}
  2770. argument.
  2771. @item @code{cl_arg_size} (optional, Cell specific):
  2772. In the case of the Cell processor, the @code{cl_arg} pointer is not directly
  2773. given to the SPU function. A buffer of size @code{cl_arg_size} is allocated on
  2774. the SPU. This buffer is then filled with the @code{cl_arg_size} bytes starting
  2775. at address @code{cl_arg}. In this case, the argument given to the SPU codelet
  2776. is therefore not the @code{cl_arg} pointer, but the address of the buffer in
  2777. local store (LS) instead. This field is ignored for CPU, CUDA and OpenCL
  2778. codelets.
  2779. @item @code{callback_func} (optional) (default = @code{NULL}):
  2780. This is a function pointer of prototype @code{void (*f)(void *)} which
  2781. specifies a possible callback. If this pointer is non-null, the callback
  2782. function is executed @emph{on the host} after the execution of the task. The
  2783. callback is passed the value contained in the @code{callback_arg} field. No
  2784. callback is executed if the field is set to @code{NULL}.
  2785. @item @code{callback_arg} (optional) (default = @code{NULL}):
  2786. This is the pointer passed to the callback function. This field is ignored if
  2787. the @code{callback_func} is set to @code{NULL}.
  2788. @item @code{use_tag} (optional) (default = 0):
  2789. If set, this flag indicates that the task should be associated with the tag
  2790. contained in the @code{tag_id} field. Tag allow the application to synchronize
  2791. with the task and to express task dependencies easily.
  2792. @item @code{tag_id}:
  2793. This fields contains the tag associated to the task if the @code{use_tag} field
  2794. was set, it is ignored otherwise.
  2795. @item @code{synchronous}:
  2796. If this flag is set, the @code{starpu_task_submit} function is blocking and
  2797. returns only when the task has been executed (or if no worker is able to
  2798. process the task). Otherwise, @code{starpu_task_submit} returns immediately.
  2799. @item @code{priority} (optional) (default = @code{STARPU_DEFAULT_PRIO}):
  2800. This field indicates a level of priority for the task. This is an integer value
  2801. that must be set between the return values of the
  2802. @code{starpu_sched_get_min_priority} function for the least important tasks,
  2803. and that of the @code{starpu_sched_get_max_priority} for the most important
  2804. tasks (included). The @code{STARPU_MIN_PRIO} and @code{STARPU_MAX_PRIO} macros
  2805. are provided for convenience and respectively returns value of
  2806. @code{starpu_sched_get_min_priority} and @code{starpu_sched_get_max_priority}.
  2807. Default priority is @code{STARPU_DEFAULT_PRIO}, which is always defined as 0 in
  2808. order to allow static task initialization. Scheduling strategies that take
  2809. priorities into account can use this parameter to take better scheduling
  2810. decisions, but the scheduling policy may also ignore it.
  2811. @item @code{execute_on_a_specific_worker} (default = 0):
  2812. If this flag is set, StarPU will bypass the scheduler and directly affect this
  2813. task to the worker specified by the @code{workerid} field.
  2814. @item @code{workerid} (optional):
  2815. If the @code{execute_on_a_specific_worker} field is set, this field indicates
  2816. which is the identifier of the worker that should process this task (as
  2817. returned by @code{starpu_worker_get_id}). This field is ignored if
  2818. @code{execute_on_a_specific_worker} field is set to 0.
  2819. @item @code{detach} (optional) (default = 1):
  2820. If this flag is set, it is not possible to synchronize with the task
  2821. by the means of @code{starpu_task_wait} later on. Internal data structures
  2822. are only guaranteed to be freed once @code{starpu_task_wait} is called if the
  2823. flag is not set.
  2824. @item @code{destroy} (optional) (default = 1):
  2825. If this flag is set, the task structure will automatically be freed, either
  2826. after the execution of the callback if the task is detached, or during
  2827. @code{starpu_task_wait} otherwise. If this flag is not set, dynamically
  2828. allocated data structures will not be freed until @code{starpu_task_destroy} is
  2829. called explicitly. Setting this flag for a statically allocated task structure
  2830. will result in undefined behaviour.
  2831. @item @code{predicted} (output field):
  2832. Predicted duration of the task. This field is only set if the scheduling
  2833. strategy used performance models.
  2834. @end table
  2835. @end table
  2836. @node starpu_task_init
  2837. @subsection @code{starpu_task_init} -- Initialize a Task
  2838. @table @asis
  2839. @item @emph{Description}:
  2840. Initialize a task structure with default values. This function is implicitly
  2841. called by @code{starpu_task_create}. By default, tasks initialized with
  2842. @code{starpu_task_init} must be deinitialized explicitly with
  2843. @code{starpu_task_deinit}. Tasks can also be initialized statically, using the
  2844. constant @code{STARPU_TASK_INITIALIZER}.
  2845. @item @emph{Prototype}:
  2846. @code{void starpu_task_init(struct starpu_task *task);}
  2847. @end table
  2848. @node starpu_task_create
  2849. @subsection @code{starpu_task_create} -- Allocate and Initialize a Task
  2850. @table @asis
  2851. @item @emph{Description}:
  2852. Allocate a task structure and initialize it with default values. Tasks
  2853. allocated dynamically with @code{starpu_task_create} are automatically freed when the
  2854. task is terminated. If the destroy flag is explicitly unset, the resources used
  2855. by the task are freed by calling
  2856. @code{starpu_task_destroy}.
  2857. @item @emph{Prototype}:
  2858. @code{struct starpu_task *starpu_task_create(void);}
  2859. @end table
  2860. @node starpu_task_deinit
  2861. @subsection @code{starpu_task_deinit} -- Release all the resources used by a Task
  2862. @table @asis
  2863. @item @emph{Description}:
  2864. Release all the structures automatically allocated to execute the task. This is
  2865. called automatically by @code{starpu_task_destroy}, but the task structure itself is not
  2866. freed. This should be used for statically allocated tasks for instance.
  2867. @item @emph{Prototype}:
  2868. @code{void starpu_task_deinit(struct starpu_task *task);}
  2869. @end table
  2870. @node starpu_task_destroy
  2871. @subsection @code{starpu_task_destroy} -- Destroy a dynamically allocated Task
  2872. @table @asis
  2873. @item @emph{Description}:
  2874. Free the resource allocated during @code{starpu_task_create}. This function can be
  2875. called automatically after the execution of a task by setting the
  2876. @code{destroy} flag of the @code{starpu_task} structure (default behaviour).
  2877. Calling this function on a statically allocated task results in an undefined
  2878. behaviour.
  2879. @item @emph{Prototype}:
  2880. @code{void starpu_task_destroy(struct starpu_task *task);}
  2881. @end table
  2882. @node starpu_task_wait
  2883. @subsection @code{starpu_task_wait} -- Wait for the termination of a Task
  2884. @table @asis
  2885. @item @emph{Description}:
  2886. This function blocks until the task has been executed. It is not possible to
  2887. synchronize with a task more than once. It is not possible to wait for
  2888. synchronous or detached tasks.
  2889. @item @emph{Return value}:
  2890. Upon successful completion, this function returns 0. Otherwise, @code{-EINVAL}
  2891. indicates that the specified task was either synchronous or detached.
  2892. @item @emph{Prototype}:
  2893. @code{int starpu_task_wait(struct starpu_task *task);}
  2894. @end table
  2895. @node starpu_task_submit
  2896. @subsection @code{starpu_task_submit} -- Submit a Task
  2897. @table @asis
  2898. @item @emph{Description}:
  2899. This function submits a task to StarPU. Calling this function does
  2900. not mean that the task will be executed immediately as there can be data or task
  2901. (tag) dependencies that are not fulfilled yet: StarPU will take care of
  2902. scheduling this task with respect to such dependencies.
  2903. This function returns immediately if the @code{synchronous} field of the
  2904. @code{starpu_task} structure was set to 0, and block until the termination of
  2905. the task otherwise. It is also possible to synchronize the application with
  2906. asynchronous tasks by the means of tags, using the @code{starpu_tag_wait}
  2907. function for instance.
  2908. @item @emph{Return value}:
  2909. In case of success, this function returns 0, a return value of @code{-ENODEV}
  2910. means that there is no worker able to process this task (e.g. there is no GPU
  2911. available and this task is only implemented for CUDA devices).
  2912. @item @emph{Prototype}:
  2913. @code{int starpu_task_submit(struct starpu_task *task);}
  2914. @end table
  2915. @node starpu_task_wait_for_all
  2916. @subsection @code{starpu_task_wait_for_all} -- Wait for the termination of all Tasks
  2917. @table @asis
  2918. @item @emph{Description}:
  2919. This function blocks until all the tasks that were submitted are terminated.
  2920. @item @emph{Prototype}:
  2921. @code{void starpu_task_wait_for_all(void);}
  2922. @end table
  2923. @node starpu_get_current_task
  2924. @subsection @code{starpu_get_current_task} -- Return the task currently executed by the worker
  2925. @table @asis
  2926. @item @emph{Description}:
  2927. This function returns the task currently executed by the worker, or
  2928. NULL if it is called either from a thread that is not a task or simply
  2929. because there is no task being executed at the moment.
  2930. @item @emph{Prototype}:
  2931. @code{struct starpu_task *starpu_get_current_task(void);}
  2932. @end table
  2933. @node starpu_display_codelet_stats
  2934. @subsection @code{starpu_display_codelet_stats} -- Display statistics
  2935. @table @asis
  2936. @item @emph{Description}:
  2937. Output on @code{stderr} some statistics on the codelet @code{cl}.
  2938. @item @emph{Prototype}:
  2939. @code{void starpu_display_codelet_stats(struct starpu_codelet_t *cl);}
  2940. @end table
  2941. @c Callbacks : what can we put in callbacks ?
  2942. @node Explicit Dependencies
  2943. @section Explicit Dependencies
  2944. @menu
  2945. * starpu_task_declare_deps_array:: starpu_task_declare_deps_array
  2946. * starpu_tag_t:: Task logical identifier
  2947. * starpu_tag_declare_deps:: Declare the Dependencies of a Tag
  2948. * starpu_tag_declare_deps_array:: Declare the Dependencies of a Tag
  2949. * starpu_tag_wait:: Block until a Tag is terminated
  2950. * starpu_tag_wait_array:: Block until a set of Tags is terminated
  2951. * starpu_tag_remove:: Destroy a Tag
  2952. * starpu_tag_notify_from_apps:: Feed a tag explicitly
  2953. @end menu
  2954. @node starpu_task_declare_deps_array
  2955. @subsection @code{starpu_task_declare_deps_array} -- Declare task dependencies
  2956. @table @asis
  2957. @item @emph{Description}:
  2958. Declare task dependencies between a @code{task} and an array of tasks of length
  2959. @code{ndeps}. This function must be called prior to the submission of the task,
  2960. but it may called after the submission or the execution of the tasks in the
  2961. array provided the tasks are still valid (ie. they were not automatically
  2962. destroyed). Calling this function on a task that was already submitted or with
  2963. an entry of @code{task_array} that is not a valid task anymore results in an
  2964. undefined behaviour. If @code{ndeps} is null, no dependency is added. It is
  2965. possible to call @code{starpu_task_declare_deps_array} multiple times on the
  2966. same task, in this case, the dependencies are added. It is possible to have
  2967. redundancy in the task dependencies.
  2968. @item @emph{Prototype}:
  2969. @code{void starpu_task_declare_deps_array(struct starpu_task *task, unsigned ndeps, struct starpu_task *task_array[]);}
  2970. @end table
  2971. @node starpu_tag_t
  2972. @subsection @code{starpu_tag_t} -- Task logical identifier
  2973. @table @asis
  2974. @item @emph{Description}:
  2975. It is possible to associate a task with a unique ``tag'' chosen by the application, and to express
  2976. dependencies between tasks by the means of those tags. To do so, fill the
  2977. @code{tag_id} field of the @code{starpu_task} structure with a tag number (can
  2978. be arbitrary) and set the @code{use_tag} field to 1.
  2979. If @code{starpu_tag_declare_deps} is called with this tag number, the task will
  2980. not be started until the tasks which holds the declared dependency tags are
  2981. completed.
  2982. @end table
  2983. @node starpu_tag_declare_deps
  2984. @subsection @code{starpu_tag_declare_deps} -- Declare the Dependencies of a Tag
  2985. @table @asis
  2986. @item @emph{Description}:
  2987. Specify the dependencies of the task identified by tag @code{id}. The first
  2988. argument specifies the tag which is configured, the second argument gives the
  2989. number of tag(s) on which @code{id} depends. The following arguments are the
  2990. tags which have to be terminated to unlock the task.
  2991. This function must be called before the associated task is submitted to StarPU
  2992. with @code{starpu_task_submit}.
  2993. @item @emph{Remark}
  2994. Because of the variable arity of @code{starpu_tag_declare_deps}, note that the
  2995. last arguments @emph{must} be of type @code{starpu_tag_t}: constant values
  2996. typically need to be explicitly casted. Using the
  2997. @code{starpu_tag_declare_deps_array} function avoids this hazard.
  2998. @item @emph{Prototype}:
  2999. @code{void starpu_tag_declare_deps(starpu_tag_t id, unsigned ndeps, ...);}
  3000. @item @emph{Example}:
  3001. @cartouche
  3002. @example
  3003. /* Tag 0x1 depends on tags 0x32 and 0x52 */
  3004. starpu_tag_declare_deps((starpu_tag_t)0x1,
  3005. 2, (starpu_tag_t)0x32, (starpu_tag_t)0x52);
  3006. @end example
  3007. @end cartouche
  3008. @end table
  3009. @node starpu_tag_declare_deps_array
  3010. @subsection @code{starpu_tag_declare_deps_array} -- Declare the Dependencies of a Tag
  3011. @table @asis
  3012. @item @emph{Description}:
  3013. This function is similar to @code{starpu_tag_declare_deps}, except that its
  3014. does not take a variable number of arguments but an array of tags of size
  3015. @code{ndeps}.
  3016. @item @emph{Prototype}:
  3017. @code{void starpu_tag_declare_deps_array(starpu_tag_t id, unsigned ndeps, starpu_tag_t *array);}
  3018. @item @emph{Example}:
  3019. @cartouche
  3020. @example
  3021. /* Tag 0x1 depends on tags 0x32 and 0x52 */
  3022. starpu_tag_t tag_array[2] = @{0x32, 0x52@};
  3023. starpu_tag_declare_deps_array((starpu_tag_t)0x1, 2, tag_array);
  3024. @end example
  3025. @end cartouche
  3026. @end table
  3027. @node starpu_tag_wait
  3028. @subsection @code{starpu_tag_wait} -- Block until a Tag is terminated
  3029. @table @asis
  3030. @item @emph{Description}:
  3031. This function blocks until the task associated to tag @code{id} has been
  3032. executed. This is a blocking call which must therefore not be called within
  3033. tasks or callbacks, but only from the application directly. It is possible to
  3034. synchronize with the same tag multiple times, as long as the
  3035. @code{starpu_tag_remove} function is not called. Note that it is still
  3036. possible to synchronize with a tag associated to a task which @code{starpu_task}
  3037. data structure was freed (e.g. if the @code{destroy} flag of the
  3038. @code{starpu_task} was enabled).
  3039. @item @emph{Prototype}:
  3040. @code{void starpu_tag_wait(starpu_tag_t id);}
  3041. @end table
  3042. @node starpu_tag_wait_array
  3043. @subsection @code{starpu_tag_wait_array} -- Block until a set of Tags is terminated
  3044. @table @asis
  3045. @item @emph{Description}:
  3046. This function is similar to @code{starpu_tag_wait} except that it blocks until
  3047. @emph{all} the @code{ntags} tags contained in the @code{id} array are
  3048. terminated.
  3049. @item @emph{Prototype}:
  3050. @code{void starpu_tag_wait_array(unsigned ntags, starpu_tag_t *id);}
  3051. @end table
  3052. @node starpu_tag_remove
  3053. @subsection @code{starpu_tag_remove} -- Destroy a Tag
  3054. @table @asis
  3055. @item @emph{Description}:
  3056. This function releases the resources associated to tag @code{id}. It can be
  3057. called once the corresponding task has been executed and when there is
  3058. no other tag that depend on this tag anymore.
  3059. @item @emph{Prototype}:
  3060. @code{void starpu_tag_remove(starpu_tag_t id);}
  3061. @end table
  3062. @node starpu_tag_notify_from_apps
  3063. @subsection @code{starpu_tag_notify_from_apps} -- Feed a Tag explicitly
  3064. @table @asis
  3065. @item @emph{Description}:
  3066. This function explicitly unlocks tag @code{id}. It may be useful in the
  3067. case of applications which execute part of their computation outside StarPU
  3068. tasks (e.g. third-party libraries). It is also provided as a
  3069. convenient tool for the programmer, for instance to entirely construct the task
  3070. DAG before actually giving StarPU the opportunity to execute the tasks.
  3071. @item @emph{Prototype}:
  3072. @code{void starpu_tag_notify_from_apps(starpu_tag_t id);}
  3073. @end table
  3074. @node Implicit Data Dependencies
  3075. @section Implicit Data Dependencies
  3076. @menu
  3077. * starpu_data_set_default_sequential_consistency_flag:: starpu_data_set_default_sequential_consistency_flag
  3078. * starpu_data_get_default_sequential_consistency_flag:: starpu_data_get_default_sequential_consistency_flag
  3079. * starpu_data_set_sequential_consistency_flag:: starpu_data_set_sequential_consistency_flag
  3080. @end menu
  3081. In this section, we describe how StarPU makes it possible to insert implicit
  3082. task dependencies in order to enforce sequential data consistency. When this
  3083. data consistency is enabled on a specific data handle, any data access will
  3084. appear as sequentially consistent from the application. For instance, if the
  3085. application submits two tasks that access the same piece of data in read-only
  3086. mode, and then a third task that access it in write mode, dependencies will be
  3087. added between the two first tasks and the third one. Implicit data dependencies
  3088. are also inserted in the case of data accesses from the application.
  3089. @node starpu_data_set_default_sequential_consistency_flag
  3090. @subsection @code{starpu_data_set_default_sequential_consistency_flag} -- Set default sequential consistency flag
  3091. @table @asis
  3092. @item @emph{Description}:
  3093. Set the default sequential consistency flag. If a non-zero value is passed, a
  3094. sequential data consistency will be enforced for all handles registered after
  3095. this function call, otherwise it is disabled. By default, StarPU enables
  3096. sequential data consistency. It is also possible to select the data consistency
  3097. mode of a specific data handle with the
  3098. @code{starpu_data_set_sequential_consistency_flag} function.
  3099. @item @emph{Prototype}:
  3100. @code{void starpu_data_set_default_sequential_consistency_flag(unsigned flag);}
  3101. @end table
  3102. @node starpu_data_get_default_sequential_consistency_flag
  3103. @subsection @code{starpu_data_get_default_sequential_consistency_flag} -- Get current default sequential consistency flag
  3104. @table @asis
  3105. @item @emph{Description}:
  3106. This function returns the current default sequential consistency flag.
  3107. @item @emph{Prototype}:
  3108. @code{unsigned starpu_data_set_default_sequential_consistency_flag(void);}
  3109. @end table
  3110. @node starpu_data_set_sequential_consistency_flag
  3111. @subsection @code{starpu_data_set_sequential_consistency_flag} -- Set data sequential consistency mode
  3112. @table @asis
  3113. @item @emph{Description}:
  3114. Select the data consistency mode associated to a data handle. The consistency
  3115. mode set using this function has the priority over the default mode which can
  3116. be set with @code{starpu_data_set_sequential_consistency_flag}.
  3117. @item @emph{Prototype}:
  3118. @code{void starpu_data_set_sequential_consistency_flag(starpu_data_handle handle, unsigned flag);}
  3119. @end table
  3120. @node Performance Model API
  3121. @section Performance Model API
  3122. @menu
  3123. * starpu_load_history_debug::
  3124. * starpu_perfmodel_debugfilepath::
  3125. * starpu_perfmodel_get_arch_name::
  3126. * starpu_force_bus_sampling::
  3127. @end menu
  3128. @node starpu_load_history_debug
  3129. @subsection @code{starpu_load_history_debug}
  3130. @table @asis
  3131. @item @emph{Description}:
  3132. TODO
  3133. @item @emph{Prototype}:
  3134. @code{int starpu_load_history_debug(const char *symbol, struct starpu_perfmodel_t *model);}
  3135. @end table
  3136. @node starpu_perfmodel_debugfilepath
  3137. @subsection @code{starpu_perfmodel_debugfilepath}
  3138. @table @asis
  3139. @item @emph{Description}:
  3140. TODO
  3141. @item @emph{Prototype}:
  3142. @code{void starpu_perfmodel_debugfilepath(struct starpu_perfmodel_t *model, enum starpu_perf_archtype arch, char *path, size_t maxlen);}
  3143. @end table
  3144. @node starpu_perfmodel_get_arch_name
  3145. @subsection @code{starpu_perfmodel_get_arch_name}
  3146. @table @asis
  3147. @item @emph{Description}:
  3148. TODO
  3149. @item @emph{Prototype}:
  3150. @code{void starpu_perfmodel_get_arch_name(enum starpu_perf_archtype arch, char *archname, size_t maxlen);}
  3151. @end table
  3152. @node starpu_force_bus_sampling
  3153. @subsection @code{starpu_force_bus_sampling}
  3154. @table @asis
  3155. @item @emph{Description}:
  3156. This forces sampling the bus performance model again.
  3157. @item @emph{Prototype}:
  3158. @code{void starpu_force_bus_sampling(void);}
  3159. @end table
  3160. @node Profiling API
  3161. @section Profiling API
  3162. @menu
  3163. * starpu_profiling_status_set:: starpu_profiling_status_set
  3164. * starpu_profiling_status_get:: starpu_profiling_status_get
  3165. * struct starpu_task_profiling_info:: task profiling information
  3166. * struct starpu_worker_profiling_info:: worker profiling information
  3167. * starpu_worker_get_profiling_info:: starpu_worker_get_profiling_info
  3168. * struct starpu_bus_profiling_info:: bus profiling information
  3169. * starpu_bus_get_count::
  3170. * starpu_bus_get_id::
  3171. * starpu_bus_get_src::
  3172. * starpu_bus_get_dst::
  3173. * starpu_timing_timespec_delay_us::
  3174. * starpu_timing_timespec_to_us::
  3175. * starpu_bus_profiling_helper_display_summary::
  3176. * starpu_worker_profiling_helper_display_summary::
  3177. @end menu
  3178. @node starpu_profiling_status_set
  3179. @subsection @code{starpu_profiling_status_set} -- Set current profiling status
  3180. @table @asis
  3181. @item @emph{Description}:
  3182. Thie function sets the profiling status. Profiling is activated by passing
  3183. @code{STARPU_PROFILING_ENABLE} in @code{status}. Passing
  3184. @code{STARPU_PROFILING_DISABLE} disables profiling. Calling this function
  3185. resets all profiling measurements. When profiling is enabled, the
  3186. @code{profiling_info} field of the @code{struct starpu_task} structure points
  3187. to a valid @code{struct starpu_task_profiling_info} structure containing
  3188. information about the execution of the task.
  3189. @item @emph{Return value}:
  3190. Negative return values indicate an error, otherwise the previous status is
  3191. returned.
  3192. @item @emph{Prototype}:
  3193. @code{int starpu_profiling_status_set(int status);}
  3194. @end table
  3195. @node starpu_profiling_status_get
  3196. @subsection @code{starpu_profiling_status_get} -- Get current profiling status
  3197. @table @asis
  3198. @item @emph{Description}:
  3199. Return the current profiling status or a negative value in case there was an error.
  3200. @item @emph{Prototype}:
  3201. @code{int starpu_profiling_status_get(void);}
  3202. @end table
  3203. @node struct starpu_task_profiling_info
  3204. @subsection @code{struct starpu_task_profiling_info} -- Task profiling information
  3205. @table @asis
  3206. @item @emph{Description}:
  3207. This structure contains information about the execution of a task. It is
  3208. accessible from the @code{.profiling_info} field of the @code{starpu_task}
  3209. structure if profiling was enabled.
  3210. @item @emph{Fields}:
  3211. @table @asis
  3212. @item @code{submit_time}:
  3213. Date of task submission (relative to the initialization of StarPU).
  3214. @item @code{start_time}:
  3215. Date of task execution beginning (relative to the initialization of StarPU).
  3216. @item @code{end_time}:
  3217. Date of task execution termination (relative to the initialization of StarPU).
  3218. @item @code{workerid}:
  3219. Identifier of the worker which has executed the task.
  3220. @end table
  3221. @end table
  3222. @node struct starpu_worker_profiling_info
  3223. @subsection @code{struct starpu_worker_profiling_info} -- Worker profiling information
  3224. @table @asis
  3225. @item @emph{Description}:
  3226. This structure contains the profiling information associated to a worker.
  3227. @item @emph{Fields}:
  3228. @table @asis
  3229. @item @code{start_time}:
  3230. Starting date for the reported profiling measurements.
  3231. @item @code{total_time}:
  3232. Duration of the profiling measurement interval.
  3233. @item @code{executing_time}:
  3234. Time spent by the worker to execute tasks during the profiling measurement interval.
  3235. @item @code{sleeping_time}:
  3236. Time spent idling by the worker during the profiling measurement interval.
  3237. @item @code{executed_tasks}:
  3238. Number of tasks executed by the worker during the profiling measurement interval.
  3239. @end table
  3240. @end table
  3241. @node starpu_worker_get_profiling_info
  3242. @subsection @code{starpu_worker_get_profiling_info} -- Get worker profiling info
  3243. @table @asis
  3244. @item @emph{Description}:
  3245. Get the profiling info associated to the worker identified by @code{workerid},
  3246. and reset the profiling measurements. If the @code{worker_info} argument is
  3247. NULL, only reset the counters associated to worker @code{workerid}.
  3248. @item @emph{Return value}:
  3249. Upon successful completion, this function returns 0. Otherwise, a negative
  3250. value is returned.
  3251. @item @emph{Prototype}:
  3252. @code{int starpu_worker_get_profiling_info(int workerid, struct starpu_worker_profiling_info *worker_info);}
  3253. @end table
  3254. @node struct starpu_bus_profiling_info
  3255. @subsection @code{struct starpu_bus_profiling_info} -- Bus profiling information
  3256. @table @asis
  3257. @item @emph{Description}:
  3258. TODO
  3259. @item @emph{Fields}:
  3260. @table @asis
  3261. @item @code{start_time}:
  3262. TODO
  3263. @item @code{total_time}:
  3264. TODO
  3265. @item @code{transferred_bytes}:
  3266. TODO
  3267. @item @code{transfer_count}:
  3268. TODO
  3269. @end table
  3270. @end table
  3271. @node starpu_bus_get_count
  3272. @subsection @code{starpu_bus_get_count}
  3273. @table @asis
  3274. @item @emph{Description}:
  3275. TODO
  3276. @item @emph{Prototype}:
  3277. @code{int starpu_bus_get_count(void);}
  3278. @end table
  3279. @node starpu_bus_get_id
  3280. @subsection @code{starpu_bus_get_id}
  3281. @table @asis
  3282. @item @emph{Description}:
  3283. TODO
  3284. @item @emph{Prototype}:
  3285. @code{int starpu_bus_get_id(int src, int dst);}
  3286. @end table
  3287. @node starpu_bus_get_src
  3288. @subsection @code{starpu_bus_get_src}
  3289. @table @asis
  3290. @item @emph{Description}:
  3291. TODO
  3292. @item @emph{Prototype}:
  3293. @code{int starpu_bus_get_src(int busid);}
  3294. @end table
  3295. @node starpu_bus_get_dst
  3296. @subsection @code{starpu_bus_get_dst}
  3297. @table @asis
  3298. @item @emph{Description}:
  3299. TODO
  3300. @item @emph{Prototype}:
  3301. @code{int starpu_bus_get_dst(int busid);}
  3302. @end table
  3303. @node starpu_timing_timespec_delay_us
  3304. @subsection @code{starpu_timing_timespec_delay_us}
  3305. @table @asis
  3306. @item @emph{Description}:
  3307. TODO
  3308. @item @emph{Prototype}:
  3309. @code{double starpu_timing_timespec_delay_us(struct timespec *start, struct timespec *end);}
  3310. @end table
  3311. @node starpu_timing_timespec_to_us
  3312. @subsection @code{starpu_timing_timespec_to_us}
  3313. @table @asis
  3314. @item @emph{Description}:
  3315. TODO
  3316. @item @emph{Prototype}:
  3317. @code{double starpu_timing_timespec_to_us(struct timespec *ts);}
  3318. @end table
  3319. @node starpu_bus_profiling_helper_display_summary
  3320. @subsection @code{starpu_bus_profiling_helper_display_summary}
  3321. @table @asis
  3322. @item @emph{Description}:
  3323. TODO
  3324. @item @emph{Prototype}:
  3325. @code{void starpu_bus_profiling_helper_display_summary(void);}
  3326. @end table
  3327. @node starpu_worker_profiling_helper_display_summary
  3328. @subsection @code{starpu_worker_profiling_helper_display_summary}
  3329. @table @asis
  3330. @item @emph{Description}:
  3331. TODO
  3332. @item @emph{Prototype}:
  3333. @code{void starpu_worker_profiling_helper_display_summary(void);}
  3334. @end table
  3335. @node CUDA extensions
  3336. @section CUDA extensions
  3337. @c void starpu_data_malloc_pinned_if_possible(float **A, size_t dim);
  3338. @menu
  3339. * starpu_cuda_get_local_stream:: Get current worker's CUDA stream
  3340. * starpu_helper_cublas_init:: Initialize CUBLAS on every CUDA device
  3341. * starpu_helper_cublas_shutdown:: Deinitialize CUBLAS on every CUDA device
  3342. @end menu
  3343. @node starpu_cuda_get_local_stream
  3344. @subsection @code{starpu_cuda_get_local_stream} -- Get current worker's CUDA stream
  3345. @table @asis
  3346. @item @emph{Description}:
  3347. StarPU provides a stream for every CUDA device controlled by StarPU. This
  3348. function is only provided for convenience so that programmers can easily use
  3349. asynchronous operations within codelets without having to create a stream by
  3350. hand. Note that the application is not forced to use the stream provided by
  3351. @code{starpu_cuda_get_local_stream} and may also create its own streams.
  3352. Synchronizing with @code{cudaThreadSynchronize()} is allowed, but will reduce
  3353. the likelihood of having all transfers overlapped.
  3354. @item @emph{Prototype}:
  3355. @code{cudaStream_t *starpu_cuda_get_local_stream(void);}
  3356. @end table
  3357. @node starpu_helper_cublas_init
  3358. @subsection @code{starpu_helper_cublas_init} -- Initialize CUBLAS on every CUDA device
  3359. @table @asis
  3360. @item @emph{Description}:
  3361. The CUBLAS library must be initialized prior to any CUBLAS call. Calling
  3362. @code{starpu_helper_cublas_init} will initialize CUBLAS on every CUDA device
  3363. controlled by StarPU. This call blocks until CUBLAS has been properly
  3364. initialized on every device.
  3365. @item @emph{Prototype}:
  3366. @code{void starpu_helper_cublas_init(void);}
  3367. @end table
  3368. @node starpu_helper_cublas_shutdown
  3369. @subsection @code{starpu_helper_cublas_shutdown} -- Deinitialize CUBLAS on every CUDA device
  3370. @table @asis
  3371. @item @emph{Description}:
  3372. This function synchronously deinitializes the CUBLAS library on every CUDA device.
  3373. @item @emph{Prototype}:
  3374. @code{void starpu_helper_cublas_shutdown(void);}
  3375. @end table
  3376. @node OpenCL extensions
  3377. @section OpenCL extensions
  3378. @menu
  3379. * Enabling OpenCL:: Enabling OpenCL
  3380. * Compiling OpenCL kernels:: Compiling OpenCL kernels
  3381. * Loading OpenCL kernels:: Loading OpenCL kernels
  3382. * OpenCL statistics:: Collecting statistics from OpenCL
  3383. @end menu
  3384. @node Enabling OpenCL
  3385. @subsection Enabling OpenCL
  3386. On GPU devices which can run both CUDA and OpenCL, CUDA will be
  3387. enabled by default. To enable OpenCL, you need either to disable CUDA
  3388. when configuring StarPU:
  3389. @example
  3390. % ./configure --disable-cuda
  3391. @end example
  3392. or when running applications:
  3393. @example
  3394. % STARPU_NCUDA=0 ./application
  3395. @end example
  3396. OpenCL will automatically be started on any device not yet used by
  3397. CUDA. So on a machine running 4 GPUS, it is therefore possible to
  3398. enable CUDA on 2 devices, and OpenCL on the 2 other devices by doing
  3399. so:
  3400. @example
  3401. % STARPU_NCUDA=2 ./application
  3402. @end example
  3403. @node Compiling OpenCL kernels
  3404. @subsection Compiling OpenCL kernels
  3405. Source codes for OpenCL kernels can be stored in a file or in a
  3406. string. StarPU provides functions to build the program executable for
  3407. each available OpenCL device as a @code{cl_program} object. This
  3408. program executable can then be loaded within a specific queue as
  3409. explained in the next section. These are only helpers, Applications
  3410. can also fill a @code{starpu_opencl_program} array by hand for more advanced
  3411. use (e.g. different programs on the different OpenCL devices, for
  3412. relocation purpose for instance).
  3413. @menu
  3414. * starpu_opencl_load_opencl_from_file:: Compiling OpenCL source code
  3415. * starpu_opencl_load_opencl_from_string:: Compiling OpenCL source code
  3416. * starpu_opencl_unload_opencl:: Releasing OpenCL code
  3417. @end menu
  3418. @node starpu_opencl_load_opencl_from_file
  3419. @subsubsection @code{starpu_opencl_load_opencl_from_file} -- Compiling OpenCL source code
  3420. @table @asis
  3421. @item @emph{Description}:
  3422. TODO
  3423. @item @emph{Prototype}:
  3424. @code{int starpu_opencl_load_opencl_from_file(char *source_file_name, struct starpu_opencl_program *opencl_programs);}
  3425. @end table
  3426. @node starpu_opencl_load_opencl_from_string
  3427. @subsubsection @code{starpu_opencl_load_opencl_from_string} -- Compiling OpenCL source code
  3428. @table @asis
  3429. @item @emph{Description}:
  3430. TODO
  3431. @item @emph{Prototype}:
  3432. @code{int starpu_opencl_load_opencl_from_string(char *opencl_program_source, struct starpu_opencl_program *opencl_programs);}
  3433. @end table
  3434. @node starpu_opencl_unload_opencl
  3435. @subsubsection @code{starpu_opencl_unload_opencl} -- Releasing OpenCL code
  3436. @table @asis
  3437. @item @emph{Description}:
  3438. TODO
  3439. @item @emph{Prototype}:
  3440. @code{int starpu_opencl_unload_opencl(struct starpu_opencl_program *opencl_programs);}
  3441. @end table
  3442. @node Loading OpenCL kernels
  3443. @subsection Loading OpenCL kernels
  3444. @menu
  3445. * starpu_opencl_load_kernel:: Loading a kernel
  3446. * starpu_opencl_relase_kernel:: Releasing a kernel
  3447. @end menu
  3448. @node starpu_opencl_load_kernel
  3449. @subsubsection @code{starpu_opencl_load_kernel} -- Loading a kernel
  3450. @table @asis
  3451. @item @emph{Description}:
  3452. TODO
  3453. @item @emph{Prototype}:
  3454. @code{int starpu_opencl_load_kernel(cl_kernel *kernel, cl_command_queue *queue, struct starpu_opencl_program *opencl_programs, char *kernel_name, int devid)
  3455. }
  3456. @end table
  3457. @node starpu_opencl_relase_kernel
  3458. @subsubsection @code{starpu_opencl_release_kernel} -- Releasing a kernel
  3459. @table @asis
  3460. @item @emph{Description}:
  3461. TODO
  3462. @item @emph{Prototype}:
  3463. @code{int starpu_opencl_release_kernel(cl_kernel kernel);}
  3464. @end table
  3465. @node OpenCL statistics
  3466. @subsection OpenCL statistics
  3467. @menu
  3468. * starpu_opencl_collect_stats:: Collect statistics on a kernel execution
  3469. @end menu
  3470. @node starpu_opencl_collect_stats
  3471. @subsubsection @code{starpu_opencl_collect_stats} -- Collect statistics on a kernel execution
  3472. @table @asis
  3473. @item @emph{Description}:
  3474. After termination of the kernels, the OpenCL codelet should call this function
  3475. to pass it the even returned by @code{clEnqueueNDRangeKernel}, to let StarPU
  3476. collect statistics about the kernel execution (used cycles, consumed power).
  3477. @item @emph{Prototype}:
  3478. @code{int starpu_opencl_collect_stats(cl_event event);}
  3479. @end table
  3480. @node Cell extensions
  3481. @section Cell extensions
  3482. nothing yet.
  3483. @node Miscellaneous helpers
  3484. @section Miscellaneous helpers
  3485. @menu
  3486. * starpu_data_cpy:: Copy a data handle into another data handle
  3487. * starpu_execute_on_each_worker:: Execute a function on a subset of workers
  3488. @end menu
  3489. @node starpu_data_cpy
  3490. @subsection @code{starpu_data_cpy} -- Copy a data handle into another data handle
  3491. @table @asis
  3492. @item @emph{Description}:
  3493. Copy the content of the @code{src_handle} into the @code{dst_handle} handle.
  3494. The @code{asynchronous} parameter indicates whether the function should
  3495. block or not. In the case of an asynchronous call, it is possible to
  3496. synchronize with the termination of this operation either by the means of
  3497. implicit dependencies (if enabled) or by calling
  3498. @code{starpu_task_wait_for_all()}. If @code{callback_func} is not @code{NULL},
  3499. this callback function is executed after the handle has been copied, and it is
  3500. given the @code{callback_arg} pointer as argument.
  3501. @item @emph{Prototype}:
  3502. @code{int starpu_data_cpy(starpu_data_handle dst_handle, starpu_data_handle src_handle, int asynchronous, void (*callback_func)(void*), void *callback_arg);}
  3503. @end table
  3504. @node starpu_execute_on_each_worker
  3505. @subsection @code{starpu_execute_on_each_worker} -- Execute a function on a subset of workers
  3506. @table @asis
  3507. @item @emph{Description}:
  3508. When calling this method, the offloaded function specified by the first argument is
  3509. executed by every StarPU worker that may execute the function.
  3510. The second argument is passed to the offloaded function.
  3511. The last argument specifies on which types of processing units the function
  3512. should be executed. Similarly to the @code{where} field of the
  3513. @code{starpu_codelet} structure, it is possible to specify that the function
  3514. should be executed on every CUDA device and every CPU by passing
  3515. @code{STARPU_CPU|STARPU_CUDA}.
  3516. This function blocks until the function has been executed on every appropriate
  3517. processing units, so that it may not be called from a callback function for
  3518. instance.
  3519. @item @emph{Prototype}:
  3520. @code{void starpu_execute_on_each_worker(void (*func)(void *), void *arg, uint32_t where);}
  3521. @end table
  3522. @c ---------------------------------------------------------------------
  3523. @c Advanced Topics
  3524. @c ---------------------------------------------------------------------
  3525. @node Advanced Topics
  3526. @chapter Advanced Topics
  3527. @menu
  3528. * Defining a new data interface::
  3529. * Defining a new scheduling policy::
  3530. @end menu
  3531. @node Defining a new data interface
  3532. @section Defining a new data interface
  3533. @menu
  3534. * struct starpu_data_interface_ops_t:: Per-interface methods
  3535. * struct starpu_data_copy_methods:: Per-interface data transfer methods
  3536. * An example of data interface:: An example of data interface
  3537. @end menu
  3538. @c void *starpu_data_get_interface_on_node(starpu_data_handle handle, unsigned memory_node); TODO
  3539. @node struct starpu_data_interface_ops_t
  3540. @subsection @code{struct starpu_data_interface_ops_t} -- Per-interface methods
  3541. @table @asis
  3542. @item @emph{Description}:
  3543. TODO describe all the different fields
  3544. @end table
  3545. @node struct starpu_data_copy_methods
  3546. @subsection @code{struct starpu_data_copy_methods} -- Per-interface data transfer methods
  3547. @table @asis
  3548. @item @emph{Description}:
  3549. TODO describe all the different fields
  3550. @end table
  3551. @node An example of data interface
  3552. @subsection An example of data interface
  3553. @table @asis
  3554. TODO
  3555. @end table
  3556. @node Defining a new scheduling policy
  3557. @section Defining a new scheduling policy
  3558. TODO
  3559. A full example showing how to define a new scheduling policy is available in
  3560. the StarPU sources in the directory @code{examples/scheduler/}.
  3561. @menu
  3562. * struct starpu_sched_policy_s::
  3563. * starpu_worker_set_sched_condition::
  3564. * starpu_sched_set_min_priority:: Set the minimum priority level
  3565. * starpu_sched_set_max_priority:: Set the maximum priority level
  3566. * starpu_push_local_task:: Assign a task to a worker
  3567. * Source code::
  3568. @end menu
  3569. @node struct starpu_sched_policy_s
  3570. @subsection @code{struct starpu_sched_policy_s} -- Scheduler methods
  3571. @table @asis
  3572. @item @emph{Description}:
  3573. This structure contains all the methods that implement a scheduling policy. An
  3574. application may specify which scheduling strategy in the @code{sched_policy}
  3575. field of the @code{starpu_conf} structure passed to the @code{starpu_init}
  3576. function.
  3577. @item @emph{Fields}:
  3578. @table @asis
  3579. @item @code{init_sched}:
  3580. Initialize the scheduling policy.
  3581. @item @code{deinit_sched}:
  3582. Cleanup the scheduling policy.
  3583. @item @code{push_task}:
  3584. Insert a task into the scheduler.
  3585. @item @code{push_prio_task}:
  3586. Insert a priority task into the scheduler.
  3587. @item @code{push_prio_notify}:
  3588. Notify the scheduler that a task was pushed on the worker. This method is
  3589. called when a task that was explicitely assigned to a worker is scheduled. This
  3590. method therefore permits to keep the state of of the scheduler coherent even
  3591. when StarPU bypasses the scheduling strategy.
  3592. @item @code{pop_task}:
  3593. Get a task from the scheduler. The mutex associated to the worker is already
  3594. taken when this method is called. If this method is defined as @code{NULL}, the
  3595. worker will only execute tasks from its local queue. In this case, the
  3596. @code{push_task} method should use the @code{starpu_push_local_task} method to
  3597. assign tasks to the different workers.
  3598. @item @code{pop_every_task}:
  3599. Remove all available tasks from the scheduler (tasks are chained by the means
  3600. of the prev and next fields of the starpu_task structure). The mutex associated
  3601. to the worker is already taken when this method is called.
  3602. @item @code{post_exec_hook} (optionnal):
  3603. This method is called every time a task has been executed.
  3604. @item @code{policy_name}:
  3605. Name of the policy (optionnal).
  3606. @item @code{policy_description}:
  3607. Description of the policy (optionnal).
  3608. @end table
  3609. @end table
  3610. @node starpu_worker_set_sched_condition
  3611. @subsection @code{starpu_worker_set_sched_condition} -- Specify the condition variable associated to a worker
  3612. @table @asis
  3613. @item @emph{Description}:
  3614. When there is no available task for a worker, StarPU blocks this worker on a
  3615. condition variable. This function specifies which condition variable (and the
  3616. associated mutex) should be used to block (and to wake up) a worker. Note that
  3617. multiple workers may use the same condition variable. For instance, in the case
  3618. of a scheduling strategy with a single task queue, the same condition variable
  3619. would be used to block and wake up all workers.
  3620. The initialization method of a scheduling strategy (@code{init_sched}) must
  3621. call this function once per worker.
  3622. @item @emph{Prototype}:
  3623. @code{void starpu_worker_set_sched_condition(int workerid, pthread_cond_t *sched_cond, pthread_mutex_t *sched_mutex);}
  3624. @end table
  3625. @node starpu_sched_set_min_priority
  3626. @subsection @code{starpu_sched_set_min_priority}
  3627. @table @asis
  3628. @item @emph{Description}:
  3629. Defines the minimum priority level supported by the scheduling policy. The
  3630. default minimum priority level is the same as the default priority level which
  3631. is 0 by convention. The application may access that value by calling the
  3632. @code{starpu_sched_get_min_priority} function. This function should only be
  3633. called from the initialization method of the scheduling policy, and should not
  3634. be used directly from the application.
  3635. @item @emph{Prototype}:
  3636. @code{void starpu_sched_set_min_priority(int min_prio);}
  3637. @end table
  3638. @node starpu_sched_set_max_priority
  3639. @subsection @code{starpu_sched_set_max_priority}
  3640. @table @asis
  3641. @item @emph{Description}:
  3642. Defines the maximum priority level supported by the scheduling policy. The
  3643. default maximum priority level is 1. The application may access that value by
  3644. calling the @code{starpu_sched_get_max_priority} function. This function should
  3645. only be called from the initialization method of the scheduling policy, and
  3646. should not be used directly from the application.
  3647. @item @emph{Prototype}:
  3648. @code{void starpu_sched_set_min_priority(int max_prio);}
  3649. @end table
  3650. @node starpu_push_local_task
  3651. @subsection @code{starpu_push_local_task}
  3652. @table @asis
  3653. @item @emph{Description}:
  3654. The scheduling policy may put tasks directly into a worker's local queue so
  3655. that it is not always necessary to create its own queue when the local queue
  3656. is sufficient. If "back" not null, the task is put at the back of the queue
  3657. where the worker will pop tasks first. Setting "back" to 0 therefore ensures
  3658. a FIFO ordering.
  3659. @item @emph{Prototype}:
  3660. @code{int starpu_push_local_task(int workerid, struct starpu_task *task, int back);}
  3661. @end table
  3662. @node Source code
  3663. @subsection Source code
  3664. @cartouche
  3665. @smallexample
  3666. static struct starpu_sched_policy_s dummy_sched_policy = @{
  3667. .init_sched = init_dummy_sched,
  3668. .deinit_sched = deinit_dummy_sched,
  3669. .push_task = push_task_dummy,
  3670. .push_prio_task = NULL,
  3671. .pop_task = pop_task_dummy,
  3672. .post_exec_hook = NULL,
  3673. .pop_every_task = NULL,
  3674. .policy_name = "dummy",
  3675. .policy_description = "dummy scheduling strategy"
  3676. @};
  3677. @end smallexample
  3678. @end cartouche
  3679. @c ---------------------------------------------------------------------
  3680. @c Appendices
  3681. @c ---------------------------------------------------------------------
  3682. @c ---------------------------------------------------------------------
  3683. @c Full source code for the 'Scaling a Vector' example
  3684. @c ---------------------------------------------------------------------
  3685. @node Full source code for the 'Scaling a Vector' example
  3686. @appendix Full source code for the 'Scaling a Vector' example
  3687. @menu
  3688. * Main application::
  3689. * CPU Kernel::
  3690. * CUDA Kernel::
  3691. * OpenCL Kernel::
  3692. @end menu
  3693. @node Main application
  3694. @section Main application
  3695. @smallexample
  3696. @include vector_scal_c.texi
  3697. @end smallexample
  3698. @node CPU Kernel
  3699. @section CPU Kernel
  3700. @smallexample
  3701. @include vector_scal_cpu.texi
  3702. @end smallexample
  3703. @node CUDA Kernel
  3704. @section CUDA Kernel
  3705. @smallexample
  3706. @include vector_scal_cuda.texi
  3707. @end smallexample
  3708. @node OpenCL Kernel
  3709. @section OpenCL Kernel
  3710. @menu
  3711. * Invoking the kernel::
  3712. * Source of the kernel::
  3713. @end menu
  3714. @node Invoking the kernel
  3715. @subsection Invoking the kernel
  3716. @smallexample
  3717. @include vector_scal_opencl.texi
  3718. @end smallexample
  3719. @node Source of the kernel
  3720. @subsection Source of the kernel
  3721. @smallexample
  3722. @include vector_scal_opencl_codelet.texi
  3723. @end smallexample
  3724. @bye