starpu.texi 193 KB

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