starpu.texi 190 KB

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