starpu.texi 196 KB

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