starpu.texi 190 KB

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