starpu.texi 197 KB

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