heteroprio.c 128 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2015-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. * Copyright (C) 2016 Uppsala University
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. /* Distributed queues using performance modeling to assign tasks */
  18. #include <starpu_scheduler.h>
  19. #include <common/graph.h>
  20. #include <starpu_config.h>
  21. #include <starpu_scheduler.h>
  22. #include <schedulers/starpu_heteroprio.h>
  23. #include "heteroprio.h"
  24. #include <common/fxt.h>
  25. #include <core/task.h>
  26. #include <core/workers.h>
  27. #include <core/debug.h>
  28. #include <starpu_bitmap.h>
  29. #include <datawizard/memory_nodes.h>
  30. #include <sched_policies/prio_deque.h>
  31. #include <starpu_task_list.h>
  32. #include <limits.h>
  33. #include <errno.h>
  34. #ifndef DBL_MIN
  35. #define DBL_MIN __DBL_MIN__
  36. #endif
  37. #ifndef DBL_MAX
  38. #define DBL_MAX __DBL_MAX__
  39. #endif
  40. #define STARPU_NB_TYPES STARPU_NARCH
  41. #define STR_MAX_SIZE 64
  42. #define STRINGIFY(x) _STR(x)
  43. #define _STR(x) #x
  44. /** Push strategy for use_locality */
  45. enum laheteroprio_push_strategy
  46. {
  47. PUSH_LS_SDH,
  48. PUSH_LS_SDH2,
  49. PUSH_LS_SDHB,
  50. PUSH_LC_SMWB,
  51. PUSH_NB_AUTO, // Always last to limit auto
  52. PUSH_LcS,
  53. PUSH_WORKER,
  54. PUSH_AUTO
  55. };
  56. /** Queue used when use_locality is enabled */
  57. struct laqueue
  58. {
  59. unsigned char* data;
  60. long int capacity;
  61. long int current_index;
  62. long int size_of_element;
  63. };
  64. static struct laqueue laqueue_init(const long int size_of_element);
  65. static void laqueue_destroy(struct laqueue* q);
  66. static long int laqueue_size(struct laqueue* q);
  67. static void laqueue_push(struct laqueue* q, void* data);
  68. static void* laqueue_pop(struct laqueue* q);
  69. static void* laqueue_top(struct laqueue* q);
  70. struct starpu_laheteroprio_access_item
  71. {
  72. unsigned prio_idx;
  73. unsigned wgroup_idx;
  74. };
  75. static struct laqueue laqueue_init(const long int size_of_element)
  76. {
  77. struct laqueue q;
  78. q.data = NULL;
  79. q.capacity = 0;
  80. q.current_index = 0;
  81. q.size_of_element = size_of_element;
  82. return q;
  83. }
  84. static void laqueue_destroy(struct laqueue* q)
  85. {
  86. STARPU_ASSERT(q->current_index == 0);
  87. free(q->data);
  88. }
  89. static long int laqueue_size(struct laqueue* q)
  90. {
  91. return q->capacity;
  92. }
  93. static void laqueue_push(struct laqueue* q, void* data)
  94. {
  95. if(q->current_index == q->capacity)
  96. {
  97. q->capacity = (q->capacity+10)*2;
  98. _STARPU_REALLOC(q->data, q->size_of_element*q->capacity);
  99. }
  100. memcpy(&q->data[(q->current_index++)*q->size_of_element], data, q->size_of_element);
  101. }
  102. static void* laqueue_pop(struct laqueue* q)
  103. {
  104. STARPU_ASSERT(q->current_index-1 >= 0);
  105. unsigned char* data = &q->data[(q->current_index-1)*q->size_of_element];
  106. q->current_index -= 1;
  107. return data;
  108. }
  109. static void* laqueue_top(struct laqueue* q)
  110. {
  111. STARPU_ASSERT(q->current_index-1 >= 0);
  112. return &q->data[(q->current_index-1)*q->size_of_element];
  113. }
  114. /** How are codelet grouped by priority */
  115. enum autoheteroprio_codelet_grouping_strategy
  116. {
  117. BY_PERF_MODEL_OR_NAME = 0, /** Using perfmodel symbol or codelet's name if no perfmodel */
  118. BY_NAME_ONLY = 1 /** Based on the codelet's name only */
  119. };
  120. /* A bucket corresponds to a Pair of priorities
  121. * When a task is pushed with a priority X, it will be stored
  122. * into the bucket X.
  123. * All the tasks stored in the fifo should be computable by the arch
  124. * in valid_archs.
  125. * For example if valid_archs = (STARPU_CPU|STARPU_CUDA)
  126. * Then task->task->where should be at least (STARPU_CPU|STARPU_CUDA)
  127. */
  128. struct _heteroprio_bucket
  129. {
  130. /* Tasks of the current bucket */
  131. /* In case data locality is NOT used, only the first element of the array is used */
  132. /* In case data locality IS used, the element refers to a worker group */
  133. struct starpu_task_list tasks_queue[LAHETEROPRIO_MAX_WORKER_GROUPS];
  134. /* The correct arch for the current bucket */
  135. unsigned valid_archs;
  136. /* The slow factors for any archs */
  137. float slow_factors_per_index[STARPU_NB_TYPES];
  138. /* The base arch for the slow factor (the fatest arch for the current task in the bucket */
  139. unsigned factor_base_arch_index;
  140. /**** Fields used when use_locality == 1 : ****/
  141. /* the number of tasks in all the queues (was previously tasks_queue.ntasks) */
  142. unsigned tasks_queue_ntasks;
  143. /* to keep track of the mn at push time */
  144. struct laqueue auto_mn[LAHETEROPRIO_MAX_WORKER_GROUPS];
  145. };
  146. static int use_la_mode = 0;
  147. static int use_auto_mode = 0;
  148. /* Init a bucket */
  149. static void _heteroprio_bucket_init(struct _heteroprio_bucket* bucket)
  150. {
  151. if(use_la_mode)
  152. {
  153. unsigned i;
  154. memset(bucket, 0, sizeof(*bucket));
  155. for(i = 0 ; i < LAHETEROPRIO_MAX_WORKER_GROUPS ; ++i)
  156. {
  157. starpu_task_list_init(&bucket->tasks_queue[i]);
  158. bucket->auto_mn[i] = laqueue_init(sizeof(unsigned)*PUSH_NB_AUTO);
  159. }
  160. }
  161. else
  162. {
  163. memset(bucket, 0, sizeof(*bucket));
  164. starpu_task_list_init(&bucket->tasks_queue[0]);
  165. }
  166. }
  167. /* Release a bucket */
  168. static void _heteroprio_bucket_release(struct _heteroprio_bucket* bucket)
  169. {
  170. if(use_la_mode)
  171. {
  172. unsigned i;
  173. for(i = 0 ; i < LAHETEROPRIO_MAX_WORKER_GROUPS ; ++i)
  174. {
  175. STARPU_ASSERT(starpu_task_list_empty(&bucket->tasks_queue[i]) != 0);
  176. laqueue_destroy(&bucket->auto_mn[i]);
  177. }
  178. }
  179. else
  180. {
  181. STARPU_ASSERT(starpu_task_list_empty(&bucket->tasks_queue[0]) != 0);
  182. // don't task_lists need to be destroyed ?
  183. }
  184. }
  185. // Must be manually add to get more stats
  186. //#define LAHETEROPRIO_PRINT_STAT
  187. static enum laheteroprio_push_strategy getEnvAdvPush()
  188. {
  189. const char *push = starpu_getenv("STARPU_LAHETEROPRIO_PUSH");
  190. if (push)
  191. {
  192. if(strcmp(push, "WORKER") == 0)
  193. {
  194. #ifdef LAHETEROPRIO_PRINT_STAT
  195. _STARPU_MSG("[LAHETEROPRIO] Use PUSH_WORKER\n");
  196. #endif
  197. return PUSH_WORKER;
  198. }
  199. if(strcmp(push, "LcS") == 0)
  200. {
  201. #ifdef LAHETEROPRIO_PRINT_STAT
  202. _STARPU_MSG("[LAHETEROPRIO] Use PUSH_LcS\n");
  203. #endif
  204. return PUSH_LcS;
  205. }
  206. if(strcmp(push, "LS_SDH") == 0)
  207. {
  208. #ifdef LAHETEROPRIO_PRINT_STAT
  209. _STARPU_MSG("[LAHETEROPRIO] Use PUSH_LS_SDH\n");
  210. #endif
  211. return PUSH_LS_SDH;
  212. }
  213. if(strcmp(push, "LS_SDH2") == 0)
  214. {
  215. #ifdef LAHETEROPRIO_PRINT_STAT
  216. _STARPU_MSG("[LAHETEROPRIO] Use PUSH_LS_SDH2\n");
  217. #endif
  218. return PUSH_LS_SDH2;
  219. }
  220. if(strcmp(push, "LS_SDHB") == 0)
  221. {
  222. #ifdef LAHETEROPRIO_PRINT_STAT
  223. _STARPU_MSG("[LAHETEROPRIO] Use PUSH_LS_SDHB\n");
  224. #endif
  225. return PUSH_LS_SDHB;
  226. }
  227. if(strcmp(push, "LC_SMWB") == 0)
  228. {
  229. #ifdef LAHETEROPRIO_PRINT_STAT
  230. _STARPU_MSG("[LAHETEROPRIO] Use PUSH_LC_SMWB\n");
  231. #endif
  232. return PUSH_LC_SMWB;
  233. }
  234. if(strcmp(push, "AUTO") == 0)
  235. {
  236. #ifdef LAHETEROPRIO_PRINT_STAT
  237. _STARPU_MSG("[LAHETEROPRIO] Use PUSH_AUTO\n");
  238. #endif
  239. return PUSH_AUTO;
  240. }
  241. _STARPU_MSG("Undefined push strategy %s\n", push);
  242. }
  243. #ifdef LAHETEROPRIO_PRINT_STAT
  244. _STARPU_MSG("[LAHETEROPRIO] Use PUSH_AUTO\n");
  245. #endif
  246. return PUSH_AUTO;
  247. }
  248. /* A worker is mainly composed of a fifo for the tasks
  249. * and some direct access to worker properties.
  250. * The fifo is implemented with any array,
  251. * to read a task, access tasks_queue[tasks_queue_index]
  252. * to write a task, access tasks_queue[(tasks_queue_index+tasks_queue_size)%HETEROPRIO_MAX_PREFETCH]
  253. */
  254. /* ANDRA_MODIF: can use starpu fifo + starpu sched_mutex*/
  255. struct _heteroprio_worker_wrapper
  256. {
  257. unsigned arch_type;
  258. unsigned arch_index;
  259. /** Only used when use_locality==0 : */
  260. struct _starpu_prio_deque tasks_queue;
  261. };
  262. static unsigned heteroprio_get_worker_arch_type(struct _heteroprio_worker_wrapper* worker)
  263. {
  264. return starpu_arch_mask_to_worker_archtype(worker->arch_type);
  265. }
  266. struct _starpu_heteroprio_data
  267. {
  268. starpu_pthread_mutex_t policy_mutex;
  269. struct starpu_bitmap waiters;
  270. /* The bucket to store the tasks */
  271. struct _heteroprio_bucket buckets[HETEROPRIO_MAX_PRIO];
  272. /* Whether heteroprio should consider data locality or not */
  273. unsigned use_locality;
  274. /* The number of buckets for each arch */
  275. unsigned nb_prio_per_arch_index[STARPU_NB_TYPES];
  276. /* The mapping to the corresponding buckets */
  277. unsigned prio_mapping_per_arch_index[STARPU_NB_TYPES][HETEROPRIO_MAX_PRIO];
  278. /* The number of available tasks for a given arch (not prefetched) */
  279. unsigned nb_remaining_tasks_per_arch_index[STARPU_NB_TYPES];
  280. /* The total number of tasks in the bucket (not prefetched) */
  281. unsigned total_tasks_in_buckets;
  282. /* The number of workers for a given arch */
  283. unsigned nb_workers_per_arch_index[STARPU_NB_TYPES];
  284. /* Information on all the workers */
  285. struct _heteroprio_worker_wrapper workers_heteroprio[STARPU_NMAXWORKERS];
  286. /*** use_locality==0 specific : */
  287. /* The total number of prefetched tasks for a given arch */
  288. unsigned nb_prefetched_tasks_per_arch_index[STARPU_NB_TYPES];
  289. /*** use_locality==1 (laheteroprio) specific : */
  290. /* Helps ensuring laheteroprio has been correctly initalized */
  291. unsigned map_wgroup_has_been_called;
  292. /* Helps ensuring laheteroprio has been correctly initalized */
  293. unsigned warned_change_nb_memory_nodes;
  294. /* Number of memory nodes */
  295. unsigned nb_memory_nodes;
  296. /* The mapping to the corresponding prio prio_mapping_per_arch_index[x][prio_mapping_per_arch_index[x][y]] = y */
  297. unsigned bucket_mapping_per_arch_index[STARPU_NB_TYPES][HETEROPRIO_MAX_PRIO];
  298. /* The wgroup for all the workers */
  299. unsigned workers_laheteroprio_wgroup_index[STARPU_NMAXWORKERS];
  300. /* Number of wgroups */
  301. unsigned nb_wgroups;
  302. /* The task queue for the tasks inserted by the master thread */
  303. unsigned master_tasks_queue_idx;
  304. /* Arch related to each wgroup (for now only one kind of arch per wgroup */
  305. unsigned arch_of_wgroups[LAHETEROPRIO_MAX_WORKER_GROUPS];
  306. /* The pop offset per group */
  307. struct starpu_laheteroprio_access_item wgroup_pop_access_orders[LAHETEROPRIO_MAX_WORKER_GROUPS][LAHETEROPRIO_MAX_WORKER_GROUPS*HETEROPRIO_MAX_PRIO];
  308. /* Size of wgroup_pop_access_orders items */
  309. unsigned wgroup_pop_access_orders_size[LAHETEROPRIO_MAX_WORKER_GROUPS];
  310. /* The push strategy */
  311. enum laheteroprio_push_strategy pushStrategyToUse;
  312. enum laheteroprio_push_strategy pushStrategySet;
  313. int pushStrategyHistory[PUSH_NB_AUTO];
  314. starpu_pthread_mutex_t push_history_mutex;
  315. /*** auto-heteroprio specific : */
  316. /** Strategy to determine on which base which can assign same priority to codelets */
  317. enum autoheteroprio_codelet_grouping_strategy codelet_grouping_strategy;
  318. unsigned use_auto_calibration;
  319. starpu_pthread_mutex_t auto_calibration_mutex;
  320. // parameters:
  321. unsigned autoheteroprio_priority_ordering_policy;
  322. // reorder priority every priority_ordering_interval pushed tasks
  323. int priority_ordering_interval;
  324. // if set to 0: will gather data from execution (task time, NOD, etc.)
  325. unsigned freeze_data_gathering;
  326. unsigned autoheteroprio_print_prio_after_ordering;
  327. unsigned autoheteroprio_print_data_on_update;
  328. // 0 = if a task has no implementation on arch, expected time will be AUTOHETEROPRIO_LONG_TIME
  329. // 1 = if a task has no implementation on arch, expected time will be the shortest time among all archs
  330. unsigned autoheteroprio_time_estimation_policy;
  331. // environment hyperparameters
  332. double NTnodPond;
  333. double NTexpVal;
  334. double BNexpVal;
  335. double URTurt;
  336. double URT2urt;
  337. double URT2prop;
  338. double and2pond;
  339. double and3pond;
  340. double and4pond;
  341. double and5xoffset;
  342. double and5yoffset;
  343. double and9xoffset;
  344. double and9yoffset;
  345. double and10xoffset;
  346. double and10yoffset;
  347. double and11xoffset;
  348. double and11yoffset;
  349. double ANTnodPond;
  350. double ANTexpVal;
  351. int priority_last_ordering;
  352. // task data:
  353. unsigned found_codelet_names_length;
  354. char found_codelet_names[HETEROPRIO_MAX_PRIO][CODELET_MAX_NAME_LENGTH];
  355. unsigned found_codelet_names_on_arch[STARPU_NB_TYPES];
  356. // busy time and free time of each arch
  357. double average_arch_busy_time[STARPU_NB_TYPES];
  358. double average_arch_free_time[STARPU_NB_TYPES];
  359. // boolean, true if there exist workers of a given type
  360. unsigned has_worker_of_arch_type[STARPU_NB_TYPES];
  361. // average prio NOD for each task
  362. double prio_average_NOD[HETEROPRIO_MAX_PRIO];
  363. // NOD sample size
  364. unsigned prio_average_NOD_count[HETEROPRIO_MAX_PRIO];
  365. // average prio URT for each task
  366. double prio_average_URT[STARPU_NB_TYPES][HETEROPRIO_MAX_PRIO];
  367. // URT sample size
  368. unsigned prio_average_URT_count[HETEROPRIO_MAX_PRIO];
  369. // average execution time for each arch
  370. double prio_average_time_arch[STARPU_NB_TYPES][HETEROPRIO_MAX_PRIO];
  371. // sample size of execution times
  372. unsigned prio_average_time_arch_count[STARPU_NB_TYPES][HETEROPRIO_MAX_PRIO];
  373. // true if we have at least one sample to compute the average execution time
  374. unsigned prio_arch_has_time_info[STARPU_NB_TYPES][HETEROPRIO_MAX_PRIO];
  375. // proportion of each task during execution (sum of each prio should equal 1)
  376. double prio_overall_proportion[HETEROPRIO_MAX_PRIO];
  377. // sample size (number of added tasks of a type)
  378. unsigned prio_overall_proportion_count[HETEROPRIO_MAX_PRIO];
  379. // actual location of a task execution (~= probability of being executed on an arch) (sum of each arch for a prio should equal 1)
  380. double prio_arch_proportion[STARPU_NB_TYPES][HETEROPRIO_MAX_PRIO];
  381. unsigned prio_arch_proportion_count[HETEROPRIO_MAX_PRIO];
  382. // sum of each successor's best time (better arch)
  383. double prio_average_successors_best_time_sum[HETEROPRIO_MAX_PRIO];
  384. // sample size
  385. unsigned prio_average_successors_best_time_sum_count[HETEROPRIO_MAX_PRIO];
  386. // best possible time of a prio (between archs)
  387. double prio_average_best[HETEROPRIO_MAX_PRIO];
  388. unsigned prio_average_best_count[HETEROPRIO_MAX_PRIO];
  389. };
  390. // declare prototypes
  391. void starpu_heteroprio_map_wgroup_memory_nodes_hp(struct _starpu_heteroprio_data *hp);
  392. static double get_best_autoheteroprio_estimated_time(struct _starpu_heteroprio_data *hp, unsigned priority);
  393. static int starpu_heteroprio_types_to_arch(enum starpu_worker_archtype arch)
  394. {
  395. if (arch >= STARPU_NARCH)
  396. return 0;
  397. return STARPU_WORKER_TO_MASK(arch);
  398. }
  399. static int arch_can_execute_prio(struct _starpu_heteroprio_data *hp, unsigned arch, unsigned prio)
  400. {
  401. return (hp->buckets[prio].valid_archs&starpu_heteroprio_types_to_arch(arch))!=0;
  402. }
  403. void starpu_heteroprio_set_use_locality(unsigned sched_ctx_id, unsigned use_locality)
  404. {
  405. struct _starpu_heteroprio_data *hp = (struct _starpu_heteroprio_data*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  406. STARPU_ASSERT(use_locality == 0 || use_locality == 1);
  407. hp->use_locality = use_locality;
  408. }
  409. /** Tell how many prio there are for a given arch */
  410. void starpu_heteroprio_set_nb_prios_hp(struct _starpu_heteroprio_data *hp, enum starpu_worker_archtype arch, unsigned max_prio)
  411. {
  412. STARPU_ASSERT(max_prio <= HETEROPRIO_MAX_PRIO);
  413. hp->nb_prio_per_arch_index[arch] = max_prio;
  414. if(hp->use_locality)
  415. {
  416. starpu_heteroprio_map_wgroup_memory_nodes_hp(hp);
  417. }
  418. }
  419. /** Tell how many prio there are for a given arch */
  420. void starpu_heteroprio_set_nb_prios(unsigned sched_ctx_id, enum starpu_worker_archtype arch, unsigned max_prio)
  421. {
  422. struct _starpu_heteroprio_data *hp = (struct _starpu_heteroprio_data*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  423. starpu_heteroprio_set_nb_prios_hp(hp, arch, max_prio);
  424. }
  425. void starpu_heteroprio_set_mapping_hp_without_arch(struct _starpu_heteroprio_data *hp, enum starpu_worker_archtype arch, unsigned source_prio, unsigned dest_bucket_id)
  426. {
  427. STARPU_ASSERT(dest_bucket_id < HETEROPRIO_MAX_PRIO);
  428. hp->prio_mapping_per_arch_index[arch][source_prio] = dest_bucket_id;
  429. if(hp->use_locality == 1)
  430. {
  431. hp->bucket_mapping_per_arch_index[arch][dest_bucket_id] = source_prio;
  432. }
  433. }
  434. void starpu_heteroprio_set_mapping_without_arch(unsigned sched_ctx_id, enum starpu_worker_archtype arch, unsigned source_prio, unsigned dest_bucket_id)
  435. {
  436. struct _starpu_heteroprio_data *hp = (struct _starpu_heteroprio_data*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  437. starpu_heteroprio_set_mapping_hp_without_arch(hp, arch, source_prio, dest_bucket_id);
  438. }
  439. /** Set the mapping for a given arch prio=>bucket */
  440. void starpu_heteroprio_set_mapping_hp(struct _starpu_heteroprio_data *hp, enum starpu_worker_archtype arch, unsigned source_prio, unsigned dest_bucket_id)
  441. {
  442. starpu_heteroprio_set_mapping_hp_without_arch(hp, arch, source_prio, dest_bucket_id);
  443. hp->buckets[dest_bucket_id].valid_archs |= starpu_heteroprio_types_to_arch(arch);
  444. _STARPU_DEBUG("Adding arch %d to bucket %u\n", arch, dest_bucket_id);
  445. }
  446. inline void starpu_heteroprio_set_mapping(unsigned sched_ctx_id, enum starpu_worker_archtype arch, unsigned source_prio, unsigned dest_bucket_id)
  447. {
  448. struct _starpu_heteroprio_data *hp = (struct _starpu_heteroprio_data*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  449. starpu_heteroprio_set_mapping_hp(hp, arch, source_prio, dest_bucket_id);
  450. }
  451. void starpu_heteroprio_clear_mapping_hp(struct _starpu_heteroprio_data *hp)
  452. {
  453. // direct mapping for all archs (and overwrite any changes to bucket archs)
  454. unsigned arch;
  455. for(arch=0;arch<STARPU_NB_TYPES;++arch)
  456. {
  457. int prio;
  458. for(prio=0 ; prio<HETEROPRIO_MAX_PRIO ; prio++)
  459. {
  460. starpu_heteroprio_set_mapping_hp_without_arch(hp, arch, prio, prio);
  461. hp->buckets[prio].valid_archs = 0;
  462. }
  463. }
  464. }
  465. void starpu_heteroprio_set_faster_arch_hp(struct _starpu_heteroprio_data *hp, enum starpu_worker_archtype arch, unsigned bucket_id)
  466. {
  467. STARPU_ASSERT(bucket_id < HETEROPRIO_MAX_PRIO);
  468. hp->buckets[bucket_id].factor_base_arch_index = arch;
  469. hp->buckets[bucket_id].slow_factors_per_index[arch] = 0;
  470. }
  471. /** Tell which arch is the faster for the tasks of a bucket (optional) */
  472. inline void starpu_heteroprio_set_faster_arch(unsigned sched_ctx_id, enum starpu_worker_archtype arch, unsigned bucket_id)
  473. {
  474. struct _starpu_heteroprio_data *hp = (struct _starpu_heteroprio_data*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  475. starpu_heteroprio_set_faster_arch_hp(hp, arch, bucket_id);
  476. }
  477. void starpu_heteroprio_set_arch_slow_factor_hp(struct _starpu_heteroprio_data *hp, enum starpu_worker_archtype arch, unsigned bucket_id, float slow_factor)
  478. {
  479. STARPU_ASSERT(bucket_id < HETEROPRIO_MAX_PRIO);
  480. hp->buckets[bucket_id].slow_factors_per_index[arch] = slow_factor;
  481. }
  482. /** Tell how slow is a arch for the tasks of a bucket (optional) */
  483. inline void starpu_heteroprio_set_arch_slow_factor(unsigned sched_ctx_id, enum starpu_worker_archtype arch, unsigned bucket_id, float slow_factor)
  484. {
  485. struct _starpu_heteroprio_data *hp = (struct _starpu_heteroprio_data*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  486. starpu_heteroprio_set_arch_slow_factor_hp(hp, arch, bucket_id, slow_factor);
  487. }
  488. void starpu_heteroprio_set_pop_access_order_hp(struct _starpu_heteroprio_data *hp, unsigned wgroup_id, const struct starpu_laheteroprio_access_item access_items[], const unsigned size)
  489. {
  490. STARPU_ASSERT(size <= LAHETEROPRIO_MAX_WORKER_GROUPS * HETEROPRIO_MAX_PRIO);
  491. const unsigned arch_of_wgroup = hp->arch_of_wgroups[wgroup_id];
  492. const unsigned nb_prios = hp->nb_prio_per_arch_index[arch_of_wgroup];
  493. const unsigned nb_wgroups = hp->nb_wgroups;
  494. STARPU_ASSERT(size <= nb_wgroups *nb_prios);
  495. memcpy(hp->wgroup_pop_access_orders[wgroup_id], access_items, sizeof(struct starpu_laheteroprio_access_item) *size);
  496. hp->wgroup_pop_access_orders_size[wgroup_id] = size;
  497. }
  498. void starpu_heteroprio_set_pop_access_order(unsigned sched_ctx_id, unsigned wgroup_id, const struct starpu_laheteroprio_access_item access_items[], const unsigned size)
  499. {
  500. STARPU_ASSERT(size <= LAHETEROPRIO_MAX_WORKER_GROUPS * HETEROPRIO_MAX_PRIO);
  501. struct _starpu_heteroprio_data *hp = (struct _starpu_heteroprio_data *) starpu_sched_ctx_get_policy_data(sched_ctx_id);
  502. starpu_heteroprio_set_pop_access_order_hp(hp, wgroup_id, access_items, size);
  503. }
  504. struct dist
  505. {
  506. double dist;
  507. unsigned wgroup_idx;
  508. };
  509. static int comp_dist(const void *elem1, const void *elem2)
  510. {
  511. const struct dist *d1 = ((struct dist *) elem1);
  512. const struct dist *d2 = ((struct dist *) elem2);
  513. if (d1->dist > d2->dist) return 1;
  514. if (d1->dist < d2->dist) return -1;
  515. return 0;
  516. }
  517. void starpu_heteroprio_map_wgroup_memory_nodes_hp(struct _starpu_heteroprio_data *hp)
  518. {
  519. STARPU_ASSERT_MSG(hp->use_locality == 1, "starpu_heteroprio_map_wgroup_memory_nodes has been called without enabling LA mode\n");
  520. hp->map_wgroup_has_been_called = 1; // Set flag to 1
  521. // Set the number of memory nodes
  522. hp->nb_memory_nodes = starpu_memory_nodes_get_count();
  523. const unsigned current_nb_memory_nodes = hp->nb_memory_nodes;
  524. hp->warned_change_nb_memory_nodes = 0;
  525. hp->nb_wgroups = current_nb_memory_nodes;
  526. // Set memory nodes' type
  527. {
  528. unsigned idx_memnode;
  529. for (idx_memnode = 0; idx_memnode < current_nb_memory_nodes; ++idx_memnode)
  530. {
  531. const enum starpu_node_kind memnode_kind = starpu_node_get_kind(idx_memnode);
  532. hp->arch_of_wgroups[idx_memnode] = starpu_memory_node_get_worker_archtype(memnode_kind);
  533. }
  534. }
  535. // Set workers' type
  536. {
  537. unsigned idx_worker;
  538. for (idx_worker = 0; idx_worker < starpu_worker_get_count(); ++idx_worker)
  539. {
  540. hp->workers_laheteroprio_wgroup_index[idx_worker] = starpu_worker_get_memory_node(idx_worker);
  541. }
  542. }
  543. if (starpu_cpu_worker_get_count() != 0)
  544. {
  545. unsigned cpu_0 = starpu_worker_get_by_type(STARPU_CPU_WORKER, 0);
  546. hp->master_tasks_queue_idx = starpu_worker_get_memory_node(cpu_0);
  547. }
  548. else
  549. {
  550. // Consider memory node 0 as the CPU
  551. STARPU_ASSERT(starpu_node_get_kind(0) == STARPU_CPU_RAM);
  552. hp->master_tasks_queue_idx = 0;
  553. }
  554. // Build memory distance matrix
  555. double dist_mem_matrix[LAHETEROPRIO_MAX_WORKER_GROUPS][LAHETEROPRIO_MAX_WORKER_GROUPS] = {{ 0 }};
  556. {
  557. unsigned idx_mem_node1;
  558. unsigned idx_mem_node2;
  559. double max_dist_mem = 0;
  560. for (idx_mem_node1 = 0; idx_mem_node1 < current_nb_memory_nodes; ++idx_mem_node1)
  561. {
  562. for (idx_mem_node2 = 0; idx_mem_node2 < current_nb_memory_nodes; ++idx_mem_node2)
  563. {
  564. if (idx_mem_node1 == idx_mem_node2)
  565. {
  566. dist_mem_matrix[idx_mem_node1][idx_mem_node2] = 0;
  567. }
  568. else
  569. {
  570. dist_mem_matrix[idx_mem_node1][idx_mem_node2] = starpu_transfer_predict(idx_mem_node2, idx_mem_node1, 1024 * 1024 *1024);
  571. max_dist_mem = STARPU_MAX(max_dist_mem, dist_mem_matrix[idx_mem_node1][idx_mem_node2]);
  572. }
  573. }
  574. }
  575. for (idx_mem_node1 = 0; idx_mem_node1 < current_nb_memory_nodes; ++idx_mem_node1)
  576. {
  577. for (idx_mem_node2 = 0; idx_mem_node2 < current_nb_memory_nodes; ++idx_mem_node2)
  578. {
  579. dist_mem_matrix[idx_mem_node1][idx_mem_node2] /= max_dist_mem;
  580. }
  581. }
  582. }
  583. // Build priority distance matrix
  584. double dist_prio_matrix[LAHETEROPRIO_MAX_WORKER_GROUPS][LAHETEROPRIO_MAX_WORKER_GROUPS] = {{ 0 }};
  585. {
  586. unsigned idx_prio_node1;
  587. unsigned idx_prio_node2;
  588. for (idx_prio_node1 = 0; idx_prio_node1 < current_nb_memory_nodes; ++idx_prio_node1)
  589. {
  590. for (idx_prio_node2 = 0; idx_prio_node2 < current_nb_memory_nodes; ++idx_prio_node2)
  591. {
  592. if (idx_prio_node1 == idx_prio_node2)
  593. {
  594. dist_prio_matrix[idx_prio_node1][idx_prio_node2] = 0;
  595. }
  596. else
  597. {
  598. const unsigned arch_wgroup1 = hp->arch_of_wgroups[idx_prio_node1];
  599. const unsigned arch_wgroup2 = hp->arch_of_wgroups[idx_prio_node2];
  600. double diff = 0;
  601. int cpt1 = 0;
  602. int cpt2 = 0;
  603. unsigned idx;
  604. for(idx = 0; idx < HETEROPRIO_MAX_PRIO; ++idx)
  605. {
  606. diff += fabs((double)(hp->bucket_mapping_per_arch_index[arch_wgroup1][idx] + 1) - (double)(hp->bucket_mapping_per_arch_index[arch_wgroup2][idx] + 1));
  607. if (hp->bucket_mapping_per_arch_index[arch_wgroup1][idx] != (unsigned)-1) cpt1 += 1;
  608. if (hp->bucket_mapping_per_arch_index[arch_wgroup2][idx] != (unsigned)-1) cpt2 += 1;
  609. }
  610. const int maxcpt = STARPU_MAX(cpt1, cpt2);
  611. diff /= (maxcpt + 1) *(maxcpt + 2) / 2.;
  612. dist_prio_matrix[idx_prio_node1][idx_prio_node2] = diff;
  613. }
  614. }
  615. }
  616. }
  617. // Build final distance matrix
  618. double dist_matrix[LAHETEROPRIO_MAX_WORKER_GROUPS][LAHETEROPRIO_MAX_WORKER_GROUPS] = {{ 0 }};
  619. {
  620. const double alpha = 0.5;
  621. unsigned idx_node1;
  622. unsigned idx_node2;
  623. for (idx_node1 = 0; idx_node1 < current_nb_memory_nodes; ++idx_node1)
  624. {
  625. for (idx_node2 = 0; idx_node2 < current_nb_memory_nodes; ++idx_node2)
  626. {
  627. dist_matrix[idx_node1][idx_node2] = (1 - dist_prio_matrix[idx_node1][idx_node2]) *alpha + dist_mem_matrix[idx_node1][idx_node2] *(1 - alpha);
  628. }
  629. }
  630. }
  631. unsigned nb_closed_nodes[STARPU_NB_TYPES];
  632. {
  633. char var_name[STR_MAX_SIZE];
  634. // Retrieving environment variable STARPU_LAHETEROPRIO_S_* for each architecture
  635. unsigned arch;
  636. for(arch = 0; arch < STARPU_NB_TYPES; ++arch)
  637. {
  638. const char *arch_env_name = starpu_worker_get_type_as_env_var(arch);
  639. if(arch_env_name)
  640. {
  641. snprintf(var_name, STR_MAX_SIZE, "STARPU_LAHETEROPRIO_S_%s",
  642. arch_env_name);
  643. unsigned default_value = arch == STARPU_CPU_WORKER ? current_nb_memory_nodes - 1 : 1;
  644. nb_closed_nodes[arch] = starpu_get_env_number_default(var_name, default_value);
  645. }
  646. }
  647. }
  648. unsigned nb_prio_step[STARPU_NB_TYPES];
  649. {
  650. char var_name[STR_MAX_SIZE];
  651. // Retrieving environment variable STARPU_LAHETEROPRIO_PRIO_STEP_* for each architecture
  652. unsigned arch;
  653. for(arch = 0; arch < STARPU_NB_TYPES; ++arch)
  654. {
  655. const char *arch_env_name = starpu_worker_get_type_as_env_var(arch);
  656. if(arch_env_name)
  657. {
  658. snprintf(var_name, STR_MAX_SIZE, "STARPU_LAHETEROPRIO_PRIO_STEP_%s",
  659. arch_env_name);
  660. unsigned default_value = arch != STARPU_CPU_WORKER ? hp->nb_prio_per_arch_index[arch] : 1;
  661. nb_prio_step[arch] = starpu_get_env_number_default(var_name, default_value);
  662. }
  663. }
  664. }
  665. #ifdef LAHETEROPRIO_PRINT_STAT
  666. _STARPU_MSG("[LAHETEROPRIO] nb_closed_nodes[STARPU_CPU_WORKER] %u\n", nb_closed_nodes[STARPU_CPU_WORKER]);
  667. _STARPU_MSG("[LAHETEROPRIO] nb_closed_nodes[STARPU_CUDA_WORKER] %u\n", nb_closed_nodes[STARPU_CUDA_WORKER]);
  668. _STARPU_MSG("[LAHETEROPRIO] nb_prio_step[STARPU_CPU_WORKER] %u\n", nb_prio_step[STARPU_CPU_WORKER]);
  669. _STARPU_MSG("[LAHETEROPRIO] nb_prio_step[STARPU_CUDA_WORKER] %u\n", nb_prio_step[STARPU_CUDA_WORKER]);
  670. #endif
  671. STARPU_ASSERT(hp->nb_wgroups == current_nb_memory_nodes);
  672. unsigned wgroup_idx;
  673. for (wgroup_idx = 0; wgroup_idx < current_nb_memory_nodes; ++wgroup_idx)
  674. {
  675. const unsigned wgroup_arch = hp->arch_of_wgroups[wgroup_idx];
  676. struct dist others[LAHETEROPRIO_MAX_WORKER_GROUPS];
  677. unsigned access_wgroup_idx;
  678. for (access_wgroup_idx = 0; access_wgroup_idx < current_nb_memory_nodes; ++access_wgroup_idx)
  679. {
  680. others[access_wgroup_idx].wgroup_idx = access_wgroup_idx;
  681. others[access_wgroup_idx].dist = dist_matrix[wgroup_idx][access_wgroup_idx];
  682. }
  683. {
  684. struct dist tmp = others[wgroup_idx];
  685. others[wgroup_idx] = others[0];
  686. others[0] = tmp;
  687. }
  688. qsort(others + 1, current_nb_memory_nodes - 1, sizeof(struct dist), comp_dist);
  689. struct starpu_laheteroprio_access_item buffer_access_items[LAHETEROPRIO_MAX_WORKER_GROUPS *HETEROPRIO_MAX_PRIO];
  690. const unsigned nb_prio_in_wgroup = hp->nb_prio_per_arch_index[hp->arch_of_wgroups[wgroup_idx]];
  691. unsigned access_idx = 0;
  692. unsigned prio_block_idx;
  693. for (prio_block_idx = 0; prio_block_idx < nb_prio_in_wgroup; prio_block_idx += nb_prio_step[wgroup_arch])
  694. {
  695. {
  696. access_wgroup_idx = 0;
  697. unsigned prio_idx;
  698. for (prio_idx = prio_block_idx; prio_idx < STARPU_MIN(prio_block_idx + nb_prio_step[wgroup_arch], nb_prio_in_wgroup); ++prio_idx)
  699. {
  700. buffer_access_items[access_idx].prio_idx = prio_idx;
  701. buffer_access_items[access_idx].wgroup_idx = others[access_wgroup_idx].wgroup_idx;
  702. access_idx += 1;
  703. }
  704. }
  705. unsigned prio_idx;
  706. for (prio_idx = prio_block_idx; prio_idx < STARPU_MIN(prio_block_idx + nb_prio_step[wgroup_arch], nb_prio_in_wgroup); ++prio_idx)
  707. {
  708. for (access_wgroup_idx = 1; access_wgroup_idx < STARPU_MIN(nb_closed_nodes[wgroup_arch] + 1, current_nb_memory_nodes); ++access_wgroup_idx)
  709. {
  710. buffer_access_items[access_idx].prio_idx = prio_idx;
  711. buffer_access_items[access_idx].wgroup_idx = others[access_wgroup_idx].wgroup_idx;
  712. access_idx += 1;
  713. }
  714. }
  715. }
  716. unsigned prio_idx;
  717. for (prio_idx = 0; prio_idx < nb_prio_in_wgroup; ++prio_idx)
  718. {
  719. for (access_wgroup_idx = nb_closed_nodes[wgroup_arch] + 1; access_wgroup_idx < current_nb_memory_nodes; ++access_wgroup_idx)
  720. {
  721. buffer_access_items[access_idx].prio_idx = prio_idx;
  722. buffer_access_items[access_idx].wgroup_idx = others[access_wgroup_idx].wgroup_idx;
  723. access_idx += 1;
  724. }
  725. }
  726. starpu_heteroprio_set_pop_access_order_hp(hp, wgroup_idx, buffer_access_items, access_idx);
  727. }
  728. }
  729. void starpu_heteroprio_map_wgroup_memory_nodes(unsigned sched_ctx_id)
  730. {
  731. struct _starpu_heteroprio_data *hp = (struct _starpu_heteroprio_data *) starpu_sched_ctx_get_policy_data(sched_ctx_id);
  732. starpu_heteroprio_map_wgroup_memory_nodes_hp(hp);
  733. }
  734. void starpu_heteroprio_print_wgroups(FILE *stream, unsigned sched_ctx_id)
  735. {
  736. struct _starpu_heteroprio_data *hp = (struct _starpu_heteroprio_data *) starpu_sched_ctx_get_policy_data(sched_ctx_id);
  737. STARPU_ASSERT_MSG(hp->use_locality == 1, "starpu_heteroprio_print_wgroups has been called without enabling LA mode\n");
  738. fprintf(stream, "[STARPU-LAHETEROPRIO] There are %d groups\n", hp->nb_wgroups);
  739. char dest_name[512];
  740. unsigned worker_id;
  741. for (worker_id = 0; worker_id < starpu_worker_get_count(); ++worker_id)
  742. {
  743. starpu_worker_get_name(worker_id, dest_name, 512);
  744. fprintf(stream, "[STARPU-LAHETEROPRIO] Worker %d => group %d (%s)\n", worker_id, hp->workers_laheteroprio_wgroup_index[worker_id], dest_name);
  745. }
  746. fprintf(stream, "\n");
  747. unsigned idx_wgroup;
  748. for (idx_wgroup = 0; idx_wgroup < hp->nb_wgroups; ++idx_wgroup)
  749. {
  750. int access_order[LAHETEROPRIO_MAX_WORKER_GROUPS][HETEROPRIO_MAX_PRIO] = {{ 0 }};
  751. memset(access_order, -1, sizeof(access_order[0][0]) *LAHETEROPRIO_MAX_WORKER_GROUPS * HETEROPRIO_MAX_PRIO);
  752. const unsigned wgroup_arch = hp->arch_of_wgroups[idx_wgroup];
  753. const unsigned nb_prios = hp->nb_prio_per_arch_index[wgroup_arch];
  754. const unsigned nb_wgroups = hp->nb_wgroups;
  755. const struct starpu_laheteroprio_access_item *wgroup_access_order = hp->wgroup_pop_access_orders[idx_wgroup];
  756. const unsigned wgroup_access_order_size = hp->wgroup_pop_access_orders_size[idx_wgroup];
  757. unsigned idx_access_item;
  758. for (idx_access_item = 0; idx_access_item < wgroup_access_order_size; ++idx_access_item)
  759. {
  760. const unsigned current_wgroupid = wgroup_access_order[idx_access_item].wgroup_idx;
  761. const unsigned current_prio = wgroup_access_order[idx_access_item].prio_idx;
  762. access_order[current_wgroupid][current_prio] = idx_access_item;
  763. }
  764. fprintf(stream, "[STARPU-LAHETEROPRIO] Access order for wgroup %d (of arch type %d):\n", idx_wgroup, wgroup_arch);
  765. unsigned idx_prio;
  766. for (idx_prio = nb_prios; idx_prio > 0; --idx_prio)
  767. {
  768. const unsigned current_bucket = hp->prio_mapping_per_arch_index[wgroup_arch][idx_prio - 1];
  769. fprintf(stream, "[STARPU-LAHETEROPRIO] Prio %3d (Bucket %3d) => ", idx_prio - 1, current_bucket);
  770. unsigned idx_wgroup_prio;
  771. for (idx_wgroup_prio = 0; idx_wgroup_prio < nb_wgroups; ++idx_wgroup_prio)
  772. {
  773. if (access_order[idx_wgroup][idx_prio - 1] == -1)
  774. {
  775. fprintf(stream, "[XX] ");
  776. }
  777. else
  778. {
  779. fprintf(stream, "[%2d] ", access_order[idx_wgroup][idx_prio - 1]);
  780. }
  781. }
  782. fprintf(stream, "\n");
  783. }
  784. fprintf(stream, "\n");
  785. }
  786. }
  787. /** If the user does not provide an init callback we create a single bucket for all architectures */
  788. static inline void default_init_sched(unsigned sched_ctx_id)
  789. {
  790. int min_prio = starpu_sched_ctx_get_min_priority(sched_ctx_id);
  791. int max_prio = starpu_sched_ctx_get_max_priority(sched_ctx_id);
  792. STARPU_ASSERT(min_prio >= 0);
  793. STARPU_ASSERT(max_prio >= 0);
  794. enum starpu_worker_archtype type;
  795. // By default each type of devices uses 1 bucket and no slow factor
  796. for (type = 0; type < STARPU_NARCH; type++)
  797. if (starpu_worker_get_count_by_type(type) > 0)
  798. starpu_heteroprio_set_nb_prios(sched_ctx_id, type, max_prio-min_prio+1);
  799. // Direct mapping
  800. int prio;
  801. for(prio=min_prio ; prio<=max_prio ; prio++)
  802. {
  803. // By default each type of devices uses 1 bucket and no slow factor
  804. for (type = 0; type < STARPU_NARCH; type++)
  805. if (starpu_worker_get_count_by_type(type) > 0)
  806. starpu_heteroprio_set_mapping(sched_ctx_id, type, prio, prio);
  807. }
  808. }
  809. /** stats of heteroprio when use_locality==1 */
  810. #ifdef LAHETEROPRIO_PRINT_STAT
  811. struct laheteropriostats
  812. {
  813. long int nb_tasks;
  814. long int nb_tasks_per_worker[128][HETEROPRIO_MAX_PRIO];
  815. long int nb_tasks_per_wgroup[LAHETEROPRIO_MAX_WORKER_GROUPS][HETEROPRIO_MAX_PRIO];
  816. long int task_skipt_due_to_factor_per_worker[128][HETEROPRIO_MAX_PRIO];
  817. long int task_list_empty_per_worker[128][HETEROPRIO_MAX_PRIO];
  818. long int task_stolen_per_worker[128][HETEROPRIO_MAX_PRIO];
  819. long int task_stolen_in_wgroup[LAHETEROPRIO_MAX_WORKER_GROUPS][HETEROPRIO_MAX_PRIO];
  820. long int push_redirect[128+1][LAHETEROPRIO_MAX_WORKER_GROUPS];
  821. long int pop_redirect[128][LAHETEROPRIO_MAX_WORKER_GROUPS];
  822. long int push_to_use[128][PUSH_NB_AUTO];
  823. };
  824. struct laheteropriostats lastats;
  825. #endif
  826. static void check_heteroprio_mapping(struct _starpu_heteroprio_data *hp)
  827. {
  828. //return 0;
  829. unsigned idx_prio;
  830. /* Ensure that information have been correctly filled */
  831. unsigned check_all_archs[HETEROPRIO_MAX_PRIO];
  832. memset(check_all_archs, 0, sizeof(unsigned)*HETEROPRIO_MAX_PRIO);
  833. unsigned arch_index;
  834. for(arch_index = 0; arch_index < STARPU_NB_TYPES; ++arch_index)
  835. {
  836. STARPU_ASSERT(hp->nb_prio_per_arch_index[arch_index] <= HETEROPRIO_MAX_PRIO);
  837. unsigned check_archs[HETEROPRIO_MAX_PRIO];
  838. memset(check_archs, 0, sizeof(unsigned)*HETEROPRIO_MAX_PRIO);
  839. for(idx_prio = 0; idx_prio < hp->nb_prio_per_arch_index[arch_index]; ++idx_prio)
  840. {
  841. const unsigned mapped_prio = hp->prio_mapping_per_arch_index[arch_index][idx_prio];
  842. STARPU_ASSERT(mapped_prio <= HETEROPRIO_MAX_PRIO);
  843. STARPU_ASSERT(hp->buckets[mapped_prio].slow_factors_per_index[arch_index] >= 0.0);
  844. STARPU_ASSERT(hp->buckets[mapped_prio].valid_archs & starpu_heteroprio_types_to_arch(arch_index));
  845. check_archs[mapped_prio] = 1;
  846. check_all_archs[mapped_prio] += 1;
  847. }
  848. for(idx_prio = 0; idx_prio < HETEROPRIO_MAX_PRIO; ++idx_prio)
  849. {
  850. /* Ensure the current arch use a bucket or someone else can use it */
  851. STARPU_ASSERT(check_archs[idx_prio] == 1 || hp->buckets[idx_prio].valid_archs == 0
  852. || (hp->buckets[idx_prio].valid_archs & ~starpu_heteroprio_types_to_arch(arch_index)) != 0);
  853. }
  854. }
  855. /* Ensure that if a valid_archs = (STARPU_CPU|STARPU_CUDA) then check_all_archs[] = 2 for example */
  856. for(idx_prio = 0; idx_prio < HETEROPRIO_MAX_PRIO; ++idx_prio)
  857. {
  858. unsigned nb_arch_on_bucket = 0;
  859. for(arch_index = 0; arch_index < STARPU_NB_TYPES; ++arch_index)
  860. {
  861. if(hp->buckets[idx_prio].valid_archs & starpu_heteroprio_types_to_arch(arch_index))
  862. {
  863. nb_arch_on_bucket += 1;
  864. }
  865. }
  866. STARPU_ASSERT_MSG(check_all_archs[idx_prio] == nb_arch_on_bucket, "check_all_archs[idx_prio(%u)] = %u != nb_arch_on_bucket = %u\n", idx_prio, check_all_archs[idx_prio], nb_arch_on_bucket);
  867. }
  868. }
  869. static void starpu_autoheteroprio_add_task(struct _starpu_heteroprio_data *hp, const char name[CODELET_MAX_NAME_LENGTH], unsigned archs[STARPU_NB_TYPES])
  870. {
  871. unsigned arch;
  872. for(arch=0;arch<STARPU_NB_TYPES;++arch)
  873. {
  874. if(archs[arch])
  875. { // task is considered to be able to run on this arch
  876. starpu_heteroprio_set_mapping_hp(hp, arch, hp->found_codelet_names_on_arch[arch], hp->found_codelet_names_length);
  877. ++hp->found_codelet_names_on_arch[arch];
  878. starpu_heteroprio_set_nb_prios_hp(hp, arch, hp->found_codelet_names_on_arch[arch]);
  879. }
  880. }
  881. // TODO: remap laheteroprio policy
  882. strncpy(&hp->found_codelet_names[hp->found_codelet_names_length][0], name, CODELET_MAX_NAME_LENGTH);
  883. ++hp->found_codelet_names_length;
  884. check_heteroprio_mapping(hp); // ensures that priorities are correctly mapped
  885. }
  886. static char *_heteroprio_data_dir = NULL;
  887. #define _HETEROPRIO_DIR_MAXLEN 256
  888. /* Try to get the name of the program, to get specific data file for each program */
  889. #ifdef STARPU_HAVE_PROGRAM_INVOCATION_SHORT_NAME
  890. #define _progname program_invocation_short_name
  891. #else
  892. #define _progname "UNKNOWN_PROGRAM"
  893. #endif
  894. static char *_starpu_heteroprio_get_data_dir()
  895. {
  896. static int directory_existence_was_tested = 0;
  897. if(!directory_existence_was_tested)
  898. {
  899. _STARPU_MALLOC(_heteroprio_data_dir, _HETEROPRIO_DIR_MAXLEN);
  900. char *path = starpu_getenv("STARPU_HETEROPRIO_DATA_DIR");
  901. if(path)
  902. {
  903. snprintf(_heteroprio_data_dir, _HETEROPRIO_DIR_MAXLEN, "%s/", path);
  904. }
  905. else
  906. {
  907. snprintf(_heteroprio_data_dir, _HETEROPRIO_DIR_MAXLEN, "%s/heteroprio/", _starpu_get_perf_model_dir());
  908. }
  909. _starpu_mkpath_and_check(_heteroprio_data_dir, S_IRWXU);
  910. directory_existence_was_tested = 1;
  911. }
  912. return _heteroprio_data_dir;
  913. }
  914. static void starpu_autoheteroprio_fetch_task_data(struct _starpu_heteroprio_data *hp)
  915. {
  916. const char *custom_path = starpu_getenv("STARPU_HETEROPRIO_DATA_FILE");
  917. #ifndef STARPU_HAVE_PROGRAM_INVOCATION_SHORT_NAME
  918. if(!custom_path)
  919. {
  920. _STARPU_MSG("[HETEROPRIO][INITIALIZATION] Warning, autoheteroprio can't determine the program's name to automatically store performance data. "
  921. "You can specify a path to store program associated data with STARPU_HETEROPRIO_DATA_FILE\n");
  922. }
  923. #endif
  924. char path[_HETEROPRIO_DIR_MAXLEN];
  925. if(!custom_path)
  926. {
  927. snprintf(path, _HETEROPRIO_DIR_MAXLEN, "%s/%s.data", _starpu_heteroprio_get_data_dir(),
  928. _progname);
  929. }
  930. FILE *autoheteroprio_file;
  931. int locked;
  932. autoheteroprio_file = fopen(custom_path ? custom_path : path, "r");
  933. if(autoheteroprio_file == NULL)
  934. {
  935. // unable to open heteroprio data file
  936. return;
  937. }
  938. locked = _starpu_frdlock(autoheteroprio_file) == 0;
  939. _starpu_drop_comments(autoheteroprio_file);
  940. unsigned number_of_archs;
  941. unsigned archs[STARPU_NB_TYPES];
  942. unsigned arch_ind, arch_type;
  943. int c;
  944. if(fscanf(autoheteroprio_file, "%u", &number_of_archs) != 1)
  945. {
  946. fclose(autoheteroprio_file);
  947. _STARPU_MSG("[HETEROPRIO][INITIALIZATION] Warning, autoheteroprio's data file is missing a number of architectures\n");
  948. return;
  949. }
  950. // Count number of archs not available in this version
  951. const unsigned ignored_archs = STARPU_MAX(0, (int) (number_of_archs - STARPU_NB_TYPES));
  952. const unsigned supported_archs = STARPU_MIN(STARPU_NB_TYPES, number_of_archs);
  953. // Reading list of supported architectures
  954. for(arch_ind = 0; arch_ind < supported_archs; ++arch_ind)
  955. {
  956. if(fscanf(autoheteroprio_file, "%u", &arch_type) != 1)
  957. {
  958. fclose(autoheteroprio_file);
  959. _STARPU_MSG("[HETEROPRIO][INITIALIZATION] Warning, autoheteroprio's data file is missing an architecture id\n");
  960. return;
  961. }
  962. archs[arch_ind] = arch_type;
  963. }
  964. for(arch_ind = 0; arch_ind < ignored_archs; ++arch_ind)
  965. {
  966. if(fscanf(autoheteroprio_file, "%u", &arch_type) != 1)
  967. {
  968. fclose(autoheteroprio_file);
  969. _STARPU_MSG("[HETEROPRIO][INITIALIZATION] Warning, autoheteroprio's data file is missing an architecture id\n");
  970. return;
  971. }
  972. }
  973. if(getc(autoheteroprio_file) != '\n')
  974. {
  975. fclose(autoheteroprio_file);
  976. _STARPU_MSG("[HETEROPRIO][INITIALIZATION] Warning, autoheteroprio's data file is improperly formatted\n");
  977. return;
  978. }
  979. _starpu_drop_comments(autoheteroprio_file);
  980. // Reading architectures average times
  981. double avg_arch_busy_time, avg_arch_free_time;
  982. for(arch_ind = 0; arch_ind < supported_archs; ++arch_ind)
  983. {
  984. if(fscanf(autoheteroprio_file, "%lf %lf", &avg_arch_busy_time, &avg_arch_free_time) != 2)
  985. {
  986. fclose(autoheteroprio_file);
  987. _STARPU_MSG("[HETEROPRIO][INITIALIZATION] Warning, autoheteroprio's data file is missing an architecture average times id\n");
  988. return;
  989. }
  990. else if(arch_ind < STARPU_NB_TYPES && archs[arch_ind] < STARPU_NB_TYPES)
  991. {
  992. hp->average_arch_busy_time[archs[arch_ind]] = avg_arch_busy_time;
  993. hp->average_arch_free_time[archs[arch_ind]] = avg_arch_free_time;
  994. }
  995. }
  996. for(arch_ind = 0; arch_ind < ignored_archs; ++arch_ind)
  997. {
  998. if(fscanf(autoheteroprio_file, "%lf %lf", &avg_arch_busy_time, &avg_arch_free_time) != 2)
  999. {
  1000. fclose(autoheteroprio_file);
  1001. _STARPU_MSG("[HETEROPRIO][INITIALIZATION] Warning, autoheteroprio's data file is missing an architecture average times id\n");
  1002. return;
  1003. }
  1004. }
  1005. if(getc(autoheteroprio_file) != '\n')
  1006. {
  1007. fclose(autoheteroprio_file);
  1008. _STARPU_MSG("[HETEROPRIO][INITIALIZATION] Warning, autoheteroprio's data file is improperly formatted\n");
  1009. return;
  1010. }
  1011. _starpu_drop_comments(autoheteroprio_file);
  1012. unsigned codelet_archs[STARPU_NB_TYPES];
  1013. unsigned codelet_exec_archs[STARPU_NB_TYPES];
  1014. unsigned prio = hp->found_codelet_names_length;
  1015. char codelet_name[CODELET_MAX_NAME_LENGTH+1];
  1016. unsigned ignored_lines, arch_can_execute;
  1017. // Read saved stats for each codelet
  1018. while(fscanf(autoheteroprio_file, "%" STRINGIFY(CODELET_MAX_NAME_LENGTH) "s", codelet_name) == 1)
  1019. {
  1020. memset(codelet_exec_archs, 0, STARPU_NB_TYPES * sizeof(unsigned));
  1021. // Read compatible architectures
  1022. ignored_lines = 0;
  1023. for(arch_ind = 0; arch_ind < number_of_archs; ++arch_ind)
  1024. {
  1025. if(fscanf(autoheteroprio_file, "%u", &arch_can_execute) != 1)
  1026. {
  1027. fclose(autoheteroprio_file);
  1028. _STARPU_MSG("[HETEROPRIO][INITIALIZATION] Warning, autoheteroprio's data file is missing an architecture information for a codelet\n");
  1029. return;
  1030. }
  1031. else if(arch_ind < STARPU_NB_TYPES)
  1032. {
  1033. codelet_archs[arch_ind] = arch_can_execute;
  1034. if(archs[arch_ind] < STARPU_NB_TYPES)
  1035. codelet_exec_archs[archs[arch_ind]] = arch_can_execute;
  1036. }
  1037. else if(arch_can_execute)
  1038. {
  1039. ignored_lines += 1;
  1040. }
  1041. }
  1042. // Read general codelet data
  1043. if(fscanf(autoheteroprio_file, "%lf %d %d %lf %d %d %lf %d %lf %d",
  1044. &hp->prio_average_NOD[prio], &hp->prio_average_NOD_count[prio],
  1045. &hp->prio_average_URT_count[prio],
  1046. &hp->prio_overall_proportion[prio], &hp->prio_overall_proportion_count[prio],
  1047. &hp->prio_arch_proportion_count[prio],
  1048. &hp->prio_average_successors_best_time_sum[prio], &hp->prio_average_successors_best_time_sum_count[prio],
  1049. &hp->prio_average_best[prio], &hp->prio_average_best_count[prio]
  1050. ) != 10)
  1051. {
  1052. fclose(autoheteroprio_file);
  1053. _STARPU_MSG("[HETEROPRIO][INITIALIZATION] Warning, autoheteroprio's data file is improperly formatted\n");
  1054. return;
  1055. }
  1056. // Read architecture specific data
  1057. for(arch_ind = 0; arch_ind < supported_archs; ++arch_ind)
  1058. {
  1059. if(codelet_archs[arch_ind] && archs[arch_ind] < STARPU_NB_TYPES)
  1060. {
  1061. if(fscanf(autoheteroprio_file, "%lf %lf %d %lf\n",
  1062. &hp->prio_average_URT[archs[arch_ind]][prio],
  1063. &hp->prio_average_time_arch[archs[arch_ind]][prio], &hp->prio_average_time_arch_count[archs[arch_ind]][prio],
  1064. &hp->prio_arch_proportion[archs[arch_ind]][prio]
  1065. ) != 4)
  1066. {
  1067. fclose(autoheteroprio_file);
  1068. _STARPU_MSG("[HETEROPRIO][INITIALIZATION] Warning, autoheteroprio's data file is improperly formatted\n");
  1069. return;
  1070. }
  1071. hp->prio_arch_has_time_info[archs[arch_ind]][prio] = 1;
  1072. }
  1073. else if(codelet_archs[arch_ind] && archs[arch_ind] >= STARPU_NB_TYPES)
  1074. {
  1075. while((c = getc(autoheteroprio_file)) != '\n')
  1076. if(c == EOF)
  1077. {
  1078. fclose(autoheteroprio_file);
  1079. _STARPU_MSG("[HETEROPRIO][INITIALIZATION] Warning, autoheteroprio's data file ended abruptly\n");
  1080. return;
  1081. }
  1082. }
  1083. }
  1084. for(arch_ind = 0; arch_ind < ignored_lines; ++arch_ind)
  1085. {
  1086. while((c = getc(autoheteroprio_file)) != '\n')
  1087. if(c == EOF)
  1088. {
  1089. fclose(autoheteroprio_file);
  1090. _STARPU_MSG("[HETEROPRIO][INITIALIZATION] Warning, autoheteroprio's data file ended abruptly\n");
  1091. return;
  1092. }
  1093. }
  1094. starpu_autoheteroprio_add_task(hp, codelet_name, codelet_exec_archs);
  1095. prio = hp->found_codelet_names_length; // update current prio (+1)
  1096. _starpu_drop_comments(autoheteroprio_file);
  1097. }
  1098. if(locked)
  1099. _starpu_frdunlock(autoheteroprio_file);
  1100. fclose(autoheteroprio_file);
  1101. }
  1102. static void starpu_autoheteroprio_save_task_data(struct _starpu_heteroprio_data *hp)
  1103. {
  1104. const char *custom_path = starpu_getenv("STARPU_HETEROPRIO_DATA_FILE");
  1105. char path[_HETEROPRIO_DIR_MAXLEN];
  1106. if(!custom_path)
  1107. {
  1108. snprintf(path, _HETEROPRIO_DIR_MAXLEN, "%s/%s.data", _starpu_heteroprio_get_data_dir(),
  1109. _progname);
  1110. }
  1111. FILE *autoheteroprio_file;
  1112. int locked;
  1113. autoheteroprio_file = fopen(custom_path ? custom_path : path, "w+");
  1114. if(autoheteroprio_file == NULL)
  1115. {
  1116. _STARPU_MSG("[HETEROPRIO][DEINITIALIZATION] Warning: unable to save task data\n");
  1117. return;
  1118. }
  1119. locked = _starpu_fwrlock(autoheteroprio_file) == 0;
  1120. fseek(autoheteroprio_file, 0, SEEK_SET);
  1121. _starpu_fftruncate(autoheteroprio_file, 0);
  1122. unsigned number_of_archs = 0;
  1123. unsigned is_arch_used[STARPU_NB_TYPES];
  1124. unsigned arch_ind;
  1125. fprintf(autoheteroprio_file, "##################\n");
  1126. fprintf(autoheteroprio_file, "# Known architectures\n");
  1127. fprintf(autoheteroprio_file, "# number_of_archs arch_ids (");
  1128. for(arch_ind = 0; arch_ind < STARPU_NB_TYPES; ++arch_ind)
  1129. {
  1130. if(hp->found_codelet_names_on_arch[arch_ind] > 0)
  1131. {
  1132. // Architecture was used
  1133. is_arch_used[arch_ind] = 1;
  1134. number_of_archs += 1;
  1135. fprintf(autoheteroprio_file, "%s - %u, ",
  1136. starpu_worker_get_type_as_string(arch_ind), arch_ind);
  1137. }
  1138. else
  1139. is_arch_used[arch_ind] = 0;
  1140. }
  1141. fprintf(autoheteroprio_file, ")\n");
  1142. // List of used architectures designed by their id
  1143. fprintf(autoheteroprio_file, "%u", number_of_archs);
  1144. for(arch_ind = 0; arch_ind < STARPU_NB_TYPES; ++arch_ind)
  1145. {
  1146. if(is_arch_used[arch_ind])
  1147. fprintf(autoheteroprio_file, " %u", arch_ind);
  1148. }
  1149. fprintf(autoheteroprio_file, "\n");
  1150. fprintf(autoheteroprio_file, "##################\n");
  1151. fprintf(autoheteroprio_file, "# Busy/Free proportion per architecture\n");
  1152. fprintf(autoheteroprio_file, "# ARCH1_busy_time ARCH1_free_time ... ARCHn_busy_time ARCHn_free_time\n");
  1153. // Busy and free proportion per architecture
  1154. for(arch_ind = 0; arch_ind < STARPU_NB_TYPES; ++arch_ind)
  1155. {
  1156. if(is_arch_used[arch_ind])
  1157. fprintf(autoheteroprio_file, " %lf %lf",
  1158. hp->average_arch_busy_time[arch_ind], hp->average_arch_free_time[arch_ind]);
  1159. }
  1160. fprintf(autoheteroprio_file, "\n");
  1161. fprintf(autoheteroprio_file, "##################\n");
  1162. fprintf(autoheteroprio_file, "# Codelets specific data\n");
  1163. fprintf(autoheteroprio_file, "# codelet_name arch_1_can_exec ... arch_n_can_exec\n");
  1164. fprintf(autoheteroprio_file, "# average_NOD average_NOD_count average_URT_count overall_proportion overall_proportion_count arch_proportion_count avg_best_successor_time avg_best_successor_time_count prio_average_best prio_average_best_count\n");
  1165. fprintf(autoheteroprio_file, "# for each arch which can exec: average_URT_ARCH average_time_ARCH average_time_ARCH_count ARCH_proportion\n");
  1166. fprintf(autoheteroprio_file, "##########\n");
  1167. unsigned prio;
  1168. unsigned codelet_archs[STARPU_NB_TYPES];
  1169. for(prio = 0; prio < hp->found_codelet_names_length; ++prio)
  1170. {
  1171. fprintf(autoheteroprio_file, "%s", hp->found_codelet_names[prio]);
  1172. // Indicate if each can execute codelet
  1173. for(arch_ind = 0; arch_ind < STARPU_NB_TYPES; ++arch_ind)
  1174. {
  1175. if(is_arch_used[arch_ind])
  1176. {
  1177. codelet_archs[arch_ind] = arch_can_execute_prio(hp, arch_ind, prio);
  1178. fprintf(autoheteroprio_file, " %u", codelet_archs[arch_ind]);
  1179. }
  1180. else
  1181. codelet_archs[arch_ind] = 0;
  1182. }
  1183. fprintf(autoheteroprio_file, "\n");
  1184. // Non specific codelet data
  1185. fprintf(autoheteroprio_file, "%lf %d %d %lf %d %d %lf %d %lf %d\n",
  1186. hp->prio_average_NOD[prio], hp->prio_average_NOD_count[prio],
  1187. hp->prio_average_URT_count[prio],
  1188. hp->prio_overall_proportion[prio], hp->prio_overall_proportion_count[prio],
  1189. hp->prio_arch_proportion_count[prio],
  1190. hp->prio_average_successors_best_time_sum[prio], hp->prio_average_successors_best_time_sum_count[prio],
  1191. hp->prio_average_best[prio], hp->prio_average_best_count[prio]);
  1192. // Architecture specific data
  1193. for(arch_ind = 0; arch_ind < STARPU_NB_TYPES; ++arch_ind)
  1194. {
  1195. if(codelet_archs[arch_ind])
  1196. {
  1197. fprintf(autoheteroprio_file, "%lf %lf %d %lf\n",
  1198. hp->prio_average_URT[arch_ind][prio],
  1199. hp->prio_average_time_arch[arch_ind][prio], hp->prio_average_time_arch_count[arch_ind][prio],
  1200. hp->prio_arch_proportion[arch_ind][prio]);
  1201. }
  1202. }
  1203. fprintf(autoheteroprio_file, "#####\n");
  1204. }
  1205. if(locked)
  1206. _starpu_fwrunlock(autoheteroprio_file);
  1207. fclose(autoheteroprio_file);
  1208. }
  1209. static void initialize_heteroprio_policy(unsigned sched_ctx_id)
  1210. {
  1211. #ifdef LAHETEROPRIO_PRINT_STAT
  1212. memset(&lastats, 0, sizeof(lastats));
  1213. #endif
  1214. int max_priority = starpu_sched_ctx_get_max_priority(sched_ctx_id);
  1215. if(max_priority < HETEROPRIO_MAX_PRIO-1)
  1216. {
  1217. starpu_sched_ctx_set_max_priority(sched_ctx_id, HETEROPRIO_MAX_PRIO-1);
  1218. _STARPU_MSG("[HETEROPRIO][INITIALIZATION] Max priority has been set to %d\n", HETEROPRIO_MAX_PRIO-1);
  1219. }
  1220. int min_priority = starpu_sched_ctx_get_min_priority(sched_ctx_id);
  1221. if(min_priority > 0)
  1222. {
  1223. starpu_sched_ctx_set_min_priority(sched_ctx_id, 0);
  1224. _STARPU_MSG("[HETEROPRIO][INITIALIZATION] Min priority has been set to 0\n");
  1225. }
  1226. /* Alloc the scheduler data */
  1227. struct _starpu_heteroprio_data *hp;
  1228. _STARPU_MALLOC(hp, sizeof(struct _starpu_heteroprio_data));
  1229. memset(hp, 0, sizeof(*hp));
  1230. hp->use_locality = use_la_mode = starpu_get_env_number_default("STARPU_HETEROPRIO_USE_LA", 0);
  1231. _STARPU_MSG("[HETEROPRIO] Data locality : %s\n", hp->use_locality?"ENABLED":"DISABLED");
  1232. hp->codelet_grouping_strategy = use_auto_mode = starpu_get_env_number_default("STARPU_HETEROPRIO_CODELET_GROUPING_STRATEGY", 0);
  1233. switch(hp->codelet_grouping_strategy)
  1234. {
  1235. case BY_PERF_MODEL_OR_NAME:
  1236. _STARPU_MSG("[HETEROPRIO] Codelet grouping strategy : BY_PERF_MODEL_OR_NAME\n");
  1237. break;
  1238. case BY_NAME_ONLY:
  1239. _STARPU_MSG("[HETEROPRIO] Codelet grouping strategy : BY_NAME\n");
  1240. break;
  1241. default:
  1242. _STARPU_MSG("[HETEROPRIO] Codelet grouping strategy : UNKNOWN\n");
  1243. hp->codelet_grouping_strategy = BY_PERF_MODEL_OR_NAME; // setting to default
  1244. }
  1245. hp->use_auto_calibration = use_auto_mode = starpu_get_env_number_default("STARPU_HETEROPRIO_USE_AUTO_CALIBRATION", 1);
  1246. _STARPU_MSG("[HETEROPRIO] Auto calibration : %s\n", hp->use_auto_calibration?"ENABLED":"DISABLED");
  1247. if(hp->use_auto_calibration)
  1248. {
  1249. const int ordering_policy = starpu_get_env_number_default("STARPU_AUTOHETEROPRIO_PRIORITY_ORDERING_POLICY", STARPU_HETEROPRIO_URT_DOT_DIFF_4);
  1250. STARPU_ASSERT_MSG(ordering_policy < STARPU_AUTOHETEROPRIO_PRIORITY_ORDERING_POLICY_COUNT, "STARPU_AUTOHETEROPRIO_PRIORITY_ORDERING_POLICY must be < %d.\n", STARPU_AUTOHETEROPRIO_PRIORITY_ORDERING_POLICY_COUNT);
  1251. STARPU_ASSERT_MSG(ordering_policy >= 0, "STARPU_AUTOHETEROPRIO_PRIORITY_ORDERING_POLICY must be >= 0.\n");
  1252. hp->autoheteroprio_priority_ordering_policy = ordering_policy;
  1253. _STARPU_MSG("[AUTOHETEROPRIO] Priority ordering policy : %s\n", &starpu_autoheteroprio_priority_ordering_policy_names[hp->autoheteroprio_priority_ordering_policy][0]);
  1254. hp->priority_ordering_interval = starpu_get_env_number_default("STARPU_AUTOHETEROPRIO_ORDERING_INTERVAL", 32);
  1255. hp->freeze_data_gathering = starpu_get_env_number_default("STARPU_AUTOHETEROPRIO_FREEZE_GATHERING", 0);
  1256. _STARPU_MSG("[AUTOHETEROPRIO] Data gathering : %s\n", !hp->freeze_data_gathering?"ENABLED":"DISABLED");
  1257. hp->autoheteroprio_print_prio_after_ordering = starpu_get_env_number_default("STARPU_AUTOHETEROPRIO_PRINT_AFTER_ORDERING", 0);
  1258. _STARPU_MSG("[AUTOHETEROPRIO] Print after ordering : %s\n", hp->autoheteroprio_print_prio_after_ordering?"ENABLED":"DISABLED");
  1259. hp->autoheteroprio_print_data_on_update = starpu_get_env_number_default("STARPU_AUTOHETEROPRIO_PRINT_DATA_ON_UPDATE", 0);
  1260. _STARPU_MSG("[AUTOHETEROPRIO] Print on update : %s\n", hp->autoheteroprio_print_data_on_update?"ENABLED":"DISABLED");
  1261. hp->autoheteroprio_time_estimation_policy = starpu_get_env_number_default("STARPU_AUTOHETEROPRIO_TIME_ESTIMATION_POLICY", 0);
  1262. }
  1263. if(hp->use_auto_calibration && !hp->freeze_data_gathering && starpu_profiling_status_get() != STARPU_PROFILING_ENABLE)
  1264. {
  1265. starpu_profiling_status_set(STARPU_PROFILING_ENABLE);
  1266. _STARPU_MSG("[HETEROPRIO][INITIALIZATION] STARPU PROFILING has been enabled : needed by auto-heteroprio (STARPU_HETEROPRIO_USE_AUTO_CALIBRATION)\n");
  1267. }
  1268. starpu_bitmap_init(&hp->waiters);
  1269. if(hp->use_locality)
  1270. {
  1271. hp->pushStrategySet = getEnvAdvPush();
  1272. if(hp->pushStrategySet != PUSH_AUTO)
  1273. {
  1274. hp->pushStrategyToUse = hp->pushStrategySet;
  1275. }
  1276. else
  1277. {
  1278. hp->pushStrategyToUse = PUSH_LS_SDHB;
  1279. }
  1280. }
  1281. starpu_sched_ctx_set_policy_data(sched_ctx_id, (void*)hp);
  1282. STARPU_PTHREAD_MUTEX_INIT(&hp->policy_mutex, NULL);
  1283. if(hp->use_locality)
  1284. {
  1285. STARPU_PTHREAD_MUTEX_INIT(&hp->push_history_mutex, NULL);
  1286. }
  1287. if(hp->use_auto_calibration)
  1288. {
  1289. STARPU_PTHREAD_MUTEX_INIT(&hp->auto_calibration_mutex, NULL);
  1290. }
  1291. // get environment hyperparameters
  1292. hp->NTnodPond = starpu_get_env_float_default("STARPU_HETEROPRIO_NOD_TIME_COMBINATION_NOD_MULTIPLIER", 0.3);
  1293. hp->NTexpVal = starpu_get_env_float_default("STARPU_HETEROPRIO_NOD_TIME_COMBINATION_EXP_SELECTIVITY", 0.5);
  1294. hp->BNexpVal = starpu_get_env_float_default("STARPU_HETEROPRIO_BEST_NODS_SCORE_EXP_SELECTIVITY", 0.5);
  1295. hp->URTurt = starpu_get_env_float_default("STARPU_HETEROPRIO_URT_URT_MULTIPLIER", 0.5);
  1296. hp->URT2urt = starpu_get_env_float_default("STARPU_HETEROPRIO_URT_2_URT_MULTIPLIER", 0.5);
  1297. hp->URT2prop = starpu_get_env_float_default("STARPU_HETEROPRIO_URT_2_ARCH_NEED_MULTIPLIER", 2.0);
  1298. hp->and2pond = starpu_get_env_float_default("STARPU_HETEROPRIO_URT_DOT_DIFF_2_ARCH_NEED_MULTIPLIER", 1.0);
  1299. hp->and3pond = starpu_get_env_float_default("STARPU_HETEROPRIO_URT_DOT_DIFF_3_ARCH_NEED_MULTIPLIER", 1.0);
  1300. hp->and4pond = starpu_get_env_float_default("STARPU_HETEROPRIO_URT_DOT_DIFF_4_ARCH_NEED_MULTIPLIER", 1.0);
  1301. hp->and5xoffset = starpu_get_env_float_default("STARPU_HETEROPRIO_URT_DOT_DIFF_5_NOD_OFFSET", 1.3);
  1302. hp->and5yoffset = starpu_get_env_float_default("STARPU_HETEROPRIO_URT_DOT_DIFF_5_ARCH_DIFF_OFFSET", 1.0);
  1303. hp->and9xoffset = starpu_get_env_float_default("STARPU_HETEROPRIO_URT_DOT_DIFF_9_NOD_OFFSET", 1.3);
  1304. hp->and9yoffset = starpu_get_env_float_default("STARPU_HETEROPRIO_URT_DOT_DIFF_9_ARCH_DIFF_OFFSET", 1.0);
  1305. hp->and10xoffset = starpu_get_env_float_default("STARPU_HETEROPRIO_AURT_DOT_DIFF_10_NOD_OFFSET", 1.3);
  1306. hp->and10yoffset = starpu_get_env_float_default("STARPU_HETEROPRIO_URT_DOT_DIFF_10_ARCH_DIFF_OFFSET", 1.0);
  1307. hp->and11xoffset = starpu_get_env_float_default("STARPU_HETEROPRIO_URT_DOT_DIFF_11_NOD_OFFSET", 1.3);
  1308. hp->and11yoffset = starpu_get_env_float_default("STARPU_HETEROPRIO_URT_DOT_DIFF_11_ARCH_DIFF_OFFSET", 1.0);
  1309. hp->ANTnodPond = starpu_get_env_float_default("STARPU_HETEROPRIO_URTS_TIME_COMBINATION_NOD_MULTIPLIER", 0.3);
  1310. hp->ANTexpVal = starpu_get_env_float_default("STARPU_HETEROPRIO_URTS_TIME_COMBINATION_EXP_SELECTIVITY", 0.5);
  1311. unsigned idx_prio;
  1312. for(idx_prio = 0; idx_prio < HETEROPRIO_MAX_PRIO; ++idx_prio)
  1313. _heteroprio_bucket_init(&hp->buckets[idx_prio]);
  1314. if(hp->use_locality)
  1315. {
  1316. hp->nb_wgroups = LAHETEROPRIO_MAX_WORKER_GROUPS;
  1317. unsigned idx_wgroup;
  1318. for(idx_wgroup = 0 ; idx_wgroup < LAHETEROPRIO_MAX_WORKER_GROUPS ; ++idx_wgroup)
  1319. {
  1320. hp->arch_of_wgroups[idx_wgroup] = STARPU_ANY_WORKER; // We set STARPU_ANY_WORKER = default (none) value
  1321. }
  1322. memset(hp->bucket_mapping_per_arch_index, -1, sizeof(unsigned)*STARPU_NB_TYPES*HETEROPRIO_MAX_PRIO);
  1323. }
  1324. void (*callback_sched)(unsigned) = starpu_sched_ctx_get_sched_policy_callback(sched_ctx_id);
  1325. if(callback_sched)
  1326. {
  1327. if(hp->use_auto_calibration)
  1328. {
  1329. _STARPU_MSG("[HETEROPRIO][INITIALIZATION] Warning: a custom sched init function has been detected while being in auto calibration mode (STARPU_HETEROPRIO_USE_AUTO_CALIBRATION). Custom changes to priority mapping will be overwritten.\n");
  1330. }
  1331. callback_sched(sched_ctx_id);
  1332. }
  1333. else
  1334. {
  1335. default_init_sched(sched_ctx_id);
  1336. }
  1337. check_heteroprio_mapping(hp);
  1338. if(hp->use_auto_calibration)
  1339. {
  1340. unsigned arch;
  1341. for(idx_prio = 0; idx_prio < HETEROPRIO_MAX_PRIO; ++idx_prio)
  1342. {
  1343. hp->prio_average_NOD[idx_prio] = 0.f;
  1344. hp->prio_average_NOD_count[idx_prio] = 0;
  1345. hp->prio_average_URT_count[idx_prio] = 0;
  1346. hp->prio_overall_proportion[idx_prio] = 0.f;
  1347. hp->prio_overall_proportion_count[idx_prio] = 0;
  1348. hp->prio_arch_proportion_count[idx_prio] = 0;
  1349. hp->prio_average_successors_best_time_sum[idx_prio] = 0.f;
  1350. hp->prio_average_successors_best_time_sum_count[idx_prio] = 0;
  1351. hp->prio_average_best[idx_prio] = 0.f;
  1352. hp->prio_average_best_count[idx_prio] = 0;
  1353. for(arch=0;arch<STARPU_NB_TYPES;++arch)
  1354. {
  1355. hp->prio_average_URT[arch][idx_prio] = 0.f;
  1356. hp->prio_average_time_arch[arch][idx_prio] = 0.f;
  1357. hp->prio_average_time_arch_count[arch][idx_prio] = 0;
  1358. hp->prio_arch_proportion[arch][idx_prio] = 0.f;
  1359. if(arch != STARPU_CPU_WORKER)
  1360. {
  1361. starpu_heteroprio_set_arch_slow_factor_hp(hp, arch, idx_prio, 1.0f);
  1362. }
  1363. }
  1364. starpu_heteroprio_set_faster_arch_hp(hp, STARPU_CPU_WORKER, idx_prio);
  1365. }
  1366. starpu_heteroprio_clear_mapping_hp(hp);
  1367. for(arch=0;arch<STARPU_NB_TYPES;++arch)
  1368. {
  1369. starpu_heteroprio_set_nb_prios(sched_ctx_id, arch, 0);
  1370. }
  1371. starpu_autoheteroprio_fetch_task_data(hp);
  1372. if(!hp->freeze_data_gathering)
  1373. {
  1374. _starpu_graph_record = 1; // allow starpu graph recording
  1375. }
  1376. }
  1377. }
  1378. static void register_arch_times(struct _starpu_heteroprio_data *hp, unsigned arch, double busy_time, double free_time);
  1379. static void deinitialize_heteroprio_policy(unsigned sched_ctx_id)
  1380. {
  1381. struct _starpu_heteroprio_data *hp = (struct _starpu_heteroprio_data*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  1382. /* Ensure there are no more tasks */
  1383. STARPU_ASSERT(hp->total_tasks_in_buckets == 0);
  1384. unsigned arch_index;
  1385. for(arch_index = 0; arch_index < STARPU_NB_TYPES; ++arch_index)
  1386. {
  1387. if(hp->use_locality)
  1388. {
  1389. STARPU_ASSERT(hp->nb_remaining_tasks_per_arch_index[arch_index] == 0);
  1390. }
  1391. else
  1392. {
  1393. STARPU_ASSERT(hp->nb_remaining_tasks_per_arch_index[arch_index] == 0);
  1394. STARPU_ASSERT(hp->nb_prefetched_tasks_per_arch_index[arch_index] == 0);
  1395. }
  1396. }
  1397. unsigned idx_prio;
  1398. for(idx_prio = 0; idx_prio < HETEROPRIO_MAX_PRIO; ++idx_prio)
  1399. {
  1400. STARPU_ASSERT(hp->buckets[idx_prio].tasks_queue_ntasks == 0); // potentially not wanted if use_la==0
  1401. _heteroprio_bucket_release(&hp->buckets[idx_prio]);
  1402. }
  1403. if(hp->use_locality)
  1404. {
  1405. #ifdef LAHETEROPRIO_PRINT_STAT
  1406. _STARPU_MSG("[LASTATS] nb tasks %ld\n", lastats.nb_tasks);
  1407. {
  1408. _STARPU_MSG("[LASTATS] Tasks pushed per workers of kind:\n");
  1409. unsigned nb_tasks = 0;
  1410. unsigned worker_id;
  1411. for (worker_id = 0; worker_id < starpu_worker_get_count(); ++worker_id)
  1412. {
  1413. const unsigned worker_arch = hp->workers_heteroprio[worker_id].arch_index;
  1414. const unsigned nb_prios = hp->nb_prio_per_arch_index[worker_arch];
  1415. _STARPU_MSG("[LASTATS] ");
  1416. for (idx_prio = 0; idx_prio < nb_prios; ++idx_prio)
  1417. {
  1418. fprintf(stderr, "[%3u] %9ld ", idx_prio, lastats.nb_tasks_per_worker[worker_id][idx_prio]);
  1419. nb_tasks += lastats.nb_tasks_per_worker[worker_id][idx_prio];
  1420. }
  1421. fprintf(stderr, "\n");
  1422. }
  1423. _STARPU_MSG("[LASTATS] Total tasks pushed per workers of kind: %u\n\n", nb_tasks);
  1424. }
  1425. {
  1426. _STARPU_MSG("[LASTATS] Tasks pushed per workers to mem node:\n");
  1427. unsigned nb_tasks = 0;
  1428. _STARPU_MSG("[LASTATS] Master: ");
  1429. unsigned idx_mem;
  1430. for (idx_mem = 0; idx_mem < hp->nb_wgroups; ++idx_mem)
  1431. {
  1432. fprintf(stderr, "[%3u] %9ld ", idx_mem, lastats.push_redirect[0][idx_mem]);
  1433. nb_tasks += lastats.push_redirect[0][idx_mem];
  1434. }
  1435. fprintf(stderr, "\n");
  1436. _STARPU_MSG("[LASTATS] Total tasks pushed per workers to mem node: %u\n\n", nb_tasks);
  1437. }
  1438. {
  1439. unsigned worker_id;
  1440. for (worker_id = 0; worker_id < starpu_worker_get_count(); ++worker_id)
  1441. {
  1442. _STARPU_MSG("[LASTATS] %u: ", worker_id);
  1443. unsigned idx_mem;
  1444. for (idx_mem = 0; idx_mem < hp->nb_wgroups; ++idx_mem)
  1445. {
  1446. fprintf(stderr, "[%3u] %9ld ", idx_mem, lastats.push_redirect[worker_id + 1][idx_mem]);
  1447. }
  1448. fprintf(stderr, "\n");
  1449. }
  1450. fprintf(stderr, "\n");
  1451. }
  1452. {
  1453. _STARPU_MSG("[LASTATS] Tasks per wgroup:\n");
  1454. unsigned nb_tasks = 0;
  1455. unsigned idx_wgroup;
  1456. for (idx_wgroup = 0; idx_wgroup < hp->nb_wgroups; ++idx_wgroup)
  1457. {
  1458. const unsigned wgroup_arch = hp->arch_of_wgroups[idx_wgroup];
  1459. const unsigned nb_prios = hp->nb_prio_per_arch_index[wgroup_arch];
  1460. _STARPU_MSG("[LASTATS] ");
  1461. for (idx_prio = 0; idx_prio < nb_prios; ++idx_prio)
  1462. {
  1463. fprintf(stderr, "[%3u] %9ld ", idx_prio, lastats.nb_tasks_per_wgroup[idx_wgroup][idx_prio]);
  1464. nb_tasks += lastats.nb_tasks_per_wgroup[idx_wgroup][idx_prio];
  1465. }
  1466. fprintf(stderr, "\n");
  1467. }
  1468. _STARPU_MSG("[LASTATS] Total tasks pushed per wgroup: %u\n\n", nb_tasks);
  1469. }
  1470. {
  1471. _STARPU_MSG("[LASTATS] Tasks skipt per workers:\n");
  1472. unsigned worker_id;
  1473. for (worker_id = 0; worker_id < starpu_worker_get_count(); ++worker_id)
  1474. {
  1475. const unsigned worker_arch = hp->workers_heteroprio[worker_id].arch_index;
  1476. const unsigned nb_prios = hp->nb_prio_per_arch_index[worker_arch];
  1477. _STARPU_MSG("[LASTATS] ");
  1478. for (idx_prio = 0; idx_prio < nb_prios; ++idx_prio)
  1479. {
  1480. fprintf(stderr, "[%3u] %9ld ", idx_prio, lastats.task_skipt_due_to_factor_per_worker[worker_id][idx_prio]);
  1481. }
  1482. fprintf(stderr, "\n");
  1483. }
  1484. fprintf(stderr, "\n");
  1485. }
  1486. {
  1487. _STARPU_MSG("[LASTATS] Tasks list empty per workers:\n");
  1488. unsigned worker_id;
  1489. for (worker_id = 0; worker_id < starpu_worker_get_count(); ++worker_id)
  1490. {
  1491. const unsigned worker_arch = hp->workers_heteroprio[worker_id].arch_index;
  1492. const unsigned nb_prios = hp->nb_prio_per_arch_index[worker_arch];
  1493. _STARPU_MSG("[LASTATS] ");
  1494. for (idx_prio = 0; idx_prio < nb_prios; ++idx_prio)
  1495. {
  1496. fprintf(stderr, "[%3u] %9ld ", idx_prio, lastats.task_list_empty_per_worker[worker_id][idx_prio]);
  1497. }
  1498. fprintf(stderr, "\n");
  1499. }
  1500. fprintf(stderr, "\n");
  1501. }
  1502. {
  1503. _STARPU_MSG("[LASTATS] Tasks stolen per workers:\n");
  1504. unsigned nb_tasks = 0;
  1505. unsigned worker_id;
  1506. for (worker_id = 0; worker_id < starpu_worker_get_count(); ++worker_id)
  1507. {
  1508. const unsigned worker_arch = hp->workers_heteroprio[worker_id].arch_index;
  1509. const unsigned nb_prios = hp->nb_prio_per_arch_index[worker_arch];
  1510. _STARPU_MSG("[LASTATS] ");
  1511. for (idx_prio = 0; idx_prio < nb_prios; ++idx_prio)
  1512. {
  1513. fprintf(stderr, "[%3u] %9ld ", idx_prio, lastats.task_stolen_per_worker[worker_id][idx_prio]);
  1514. nb_tasks += lastats.task_stolen_per_worker[worker_id][idx_prio];
  1515. }
  1516. fprintf(stderr, "\n");
  1517. }
  1518. _STARPU_MSG("[LASTATS] Total tasks stolen per worker: %u\n\n", nb_tasks);
  1519. }
  1520. {
  1521. _STARPU_MSG("[LASTATS] Tasks stolen in wgroup:\n");
  1522. unsigned nb_tasks = 0;
  1523. unsigned idx_wgroup;
  1524. for (idx_wgroup = 0; idx_wgroup < hp->nb_wgroups; ++idx_wgroup)
  1525. {
  1526. const unsigned wgroup_arch = hp->arch_of_wgroups[idx_wgroup];
  1527. const unsigned nb_prios = hp->nb_prio_per_arch_index[wgroup_arch];
  1528. _STARPU_MSG("[LASTATS] ");
  1529. for (idx_prio = 0; idx_prio < nb_prios; ++idx_prio)
  1530. {
  1531. fprintf(stderr, "[%3u] %9ld ", idx_prio, lastats.task_stolen_in_wgroup[idx_wgroup][idx_prio]);
  1532. nb_tasks += lastats.task_stolen_in_wgroup[idx_wgroup][idx_prio];
  1533. }
  1534. fprintf(stderr, "\n");
  1535. }
  1536. _STARPU_MSG("[LASTATS] Total tasks stolen in wgroup: %u\n\n", nb_tasks);
  1537. }
  1538. {
  1539. _STARPU_MSG("[LASTATS] Tasks push/pop different wgroup:\n");
  1540. unsigned nb_tasks = 0;
  1541. unsigned worker_id;
  1542. for (worker_id = 0; worker_id < starpu_worker_get_count(); ++worker_id)
  1543. {
  1544. _STARPU_MSG("[LASTATS] %u: ", worker_id);
  1545. unsigned idx_mem;
  1546. for (idx_mem = 0; idx_mem < hp->nb_wgroups; ++idx_mem)
  1547. {
  1548. fprintf(stderr, "[%3u] %9ld ", idx_mem, lastats.pop_redirect[worker_id][idx_mem]);
  1549. nb_tasks += lastats.pop_redirect[worker_id][idx_mem];
  1550. }
  1551. fprintf(stderr, "\n");
  1552. }
  1553. _STARPU_MSG("[LASTATS] Total tasks push/pop different wgroup: %u\n\n", nb_tasks);
  1554. }
  1555. {
  1556. _STARPU_MSG("[LASTATS] push strategy used:\n");
  1557. unsigned worker_id;
  1558. unsigned counter[PUSH_NB_AUTO] = { 0 };
  1559. unsigned idx_more_used = 0;
  1560. for (worker_id = 0; worker_id <= starpu_worker_get_count(); ++worker_id)
  1561. {
  1562. _STARPU_MSG("[LASTATS] %u: ", worker_id);
  1563. unsigned idx_strategy;
  1564. for (idx_strategy = 0; idx_strategy < PUSH_NB_AUTO; ++idx_strategy)
  1565. {
  1566. fprintf(stderr, "[%3u] %9ld ", idx_strategy, lastats.push_to_use[worker_id][idx_strategy]);
  1567. counter[idx_strategy] += lastats.push_to_use[worker_id][idx_strategy];
  1568. if (counter[idx_strategy] > counter[idx_more_used])
  1569. {
  1570. idx_more_used = idx_strategy;
  1571. }
  1572. }
  1573. fprintf(stderr, "\n");
  1574. }
  1575. _STARPU_MSG("[LASTATS] More used push: %u\n\n", idx_more_used);
  1576. }
  1577. {
  1578. _STARPU_MSG("[LASTATS] correct MN pushes:\n");
  1579. unsigned idx_strategy;
  1580. for (idx_strategy = 0; idx_strategy < PUSH_NB_AUTO; ++idx_strategy)
  1581. {
  1582. _STARPU_MSG("[LASTATS][%u] %u \n", idx_strategy, hp->pushStrategyHistory[idx_strategy]);
  1583. }
  1584. }
  1585. #endif
  1586. }
  1587. STARPU_PTHREAD_MUTEX_DESTROY(&hp->policy_mutex);
  1588. if(hp->use_locality)
  1589. {
  1590. STARPU_PTHREAD_MUTEX_DESTROY(&hp->push_history_mutex);
  1591. }
  1592. if(hp->use_auto_calibration)
  1593. {
  1594. STARPU_PTHREAD_MUTEX_DESTROY(&hp->auto_calibration_mutex);
  1595. }
  1596. if(hp->use_auto_calibration && !hp->freeze_data_gathering)
  1597. {
  1598. double arch_busy_time[STARPU_NB_TYPES] = {0.0f};
  1599. double arch_free_time[STARPU_NB_TYPES] = {0.0f};
  1600. struct starpu_worker_collection *workers = starpu_sched_ctx_get_worker_collection(sched_ctx_id);
  1601. struct starpu_sched_ctx_iterator it;
  1602. workers->init_iterator(workers, &it);
  1603. while(workers->has_next(workers, &it))
  1604. { // loop through workers to get executing and sleeping time
  1605. unsigned workerid = workers->get_next(workers, &it);
  1606. struct _heteroprio_worker_wrapper* worker = &hp->workers_heteroprio[workerid];
  1607. struct starpu_profiling_worker_info worker_info;
  1608. if(starpu_profiling_worker_get_info(workerid, &worker_info) == 0)
  1609. {
  1610. arch_busy_time[heteroprio_get_worker_arch_type(worker)] += starpu_timing_timespec_to_us(&worker_info.executing_time);
  1611. arch_free_time[heteroprio_get_worker_arch_type(worker)] += starpu_timing_timespec_to_us(&worker_info.sleeping_time);
  1612. }
  1613. }
  1614. // update autoheteroprio data with free and busy worker time
  1615. for(arch_index = 0; arch_index < STARPU_NB_TYPES; ++arch_index)
  1616. {
  1617. register_arch_times(hp, arch_index, arch_busy_time[arch_index], arch_free_time[arch_index]);
  1618. }
  1619. starpu_autoheteroprio_save_task_data(hp);
  1620. }
  1621. _starpu_graph_record = 0; // disable starpu graph recording (that may have been activated due to hp->use_auto_calibration)
  1622. free(hp);
  1623. }
  1624. static void add_workers_heteroprio_policy(unsigned sched_ctx_id, int *workerids, unsigned nworkers)
  1625. {
  1626. struct _starpu_heteroprio_data *hp = (struct _starpu_heteroprio_data*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  1627. unsigned i;
  1628. for (i = 0; i < nworkers; i++)
  1629. {
  1630. int workerid = workerids[i];
  1631. memset(&hp->workers_heteroprio[workerid], 0, sizeof(hp->workers_heteroprio[workerid]));
  1632. if(!hp->use_locality)
  1633. {
  1634. /* if the worker has already belonged to this context
  1635. the queue and the synchronization variables have been already initialized */
  1636. _starpu_prio_deque_init(&hp->workers_heteroprio[workerid].tasks_queue);
  1637. }
  1638. enum starpu_worker_archtype arch_index = starpu_worker_get_type(workerid);
  1639. hp->workers_heteroprio[workerid].arch_index = arch_index;
  1640. hp->workers_heteroprio[workerid].arch_type = starpu_heteroprio_types_to_arch(arch_index);
  1641. hp->nb_workers_per_arch_index[hp->workers_heteroprio[workerid].arch_index]++;
  1642. }
  1643. }
  1644. static void remove_workers_heteroprio_policy(unsigned sched_ctx_id, int *workerids, unsigned nworkers)
  1645. {
  1646. struct _starpu_heteroprio_data *hp = (struct _starpu_heteroprio_data*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  1647. if(!hp->use_locality)
  1648. {
  1649. unsigned i;
  1650. for (i = 0; i < nworkers; i++)
  1651. {
  1652. int workerid = workerids[i];
  1653. _starpu_prio_deque_destroy(&hp->workers_heteroprio[workerid].tasks_queue);
  1654. }
  1655. }
  1656. }
  1657. static unsigned get_best_mem_node(struct starpu_task *task, struct _starpu_heteroprio_data *hp, const enum laheteroprio_push_strategy pushStrategy)
  1658. {
  1659. const unsigned workerid = starpu_worker_get_id();
  1660. unsigned best_mem_node;
  1661. STARPU_ASSERT(task != NULL);
  1662. if (pushStrategy != PUSH_WORKER)
  1663. {
  1664. if(!hp->warned_change_nb_memory_nodes && starpu_memory_nodes_get_count() != hp->nb_memory_nodes)
  1665. {
  1666. _STARPU_MSG("[HETEROPRIO][INITIALIZATION][get_best_mem_node] Warning: current memory node number is different from the one retrieved at initialization.\n\
  1667. This warning will only be displayed once.\n");
  1668. hp->warned_change_nb_memory_nodes = 1;
  1669. }
  1670. const unsigned nnodes = hp->nb_memory_nodes; // == starpu_memory_nodes_get_count() if number of mem nodes didnt change during execution
  1671. if (pushStrategy == PUSH_LcS)
  1672. {
  1673. int node_to_worker[LAHETEROPRIO_MAX_WORKER_GROUPS];
  1674. unsigned idx_worker;
  1675. for (idx_worker = 0; idx_worker < starpu_worker_get_count(); ++idx_worker)
  1676. {
  1677. // overwrite, we simply need one worker per mem node
  1678. node_to_worker[starpu_worker_get_memory_node(idx_worker)] = idx_worker;
  1679. }
  1680. double bestTransferTime = starpu_task_expected_data_transfer_time_for(task, node_to_worker[0]);
  1681. best_mem_node = 0;
  1682. unsigned idx_node;
  1683. for (idx_node = 1; idx_node < nnodes; ++idx_node)
  1684. {
  1685. const double transferTime = starpu_task_expected_data_transfer_time_for(task, node_to_worker[idx_node]);
  1686. if (transferTime < bestTransferTime)
  1687. {
  1688. bestTransferTime = transferTime;
  1689. best_mem_node = idx_node;
  1690. }
  1691. }
  1692. }
  1693. else if (pushStrategy == PUSH_LS_SDH || pushStrategy == PUSH_LS_SDH2)
  1694. {
  1695. size_t max_size_so_far = 0;
  1696. unsigned idx_max_size = 0;
  1697. const unsigned wgroupid = (workerid == (unsigned)-1 ? hp->master_tasks_queue_idx : hp->workers_laheteroprio_wgroup_index[workerid]);
  1698. size_t data_per_mem_node[LAHETEROPRIO_MAX_WORKER_GROUPS] = { 0 };
  1699. assert(nnodes <= LAHETEROPRIO_MAX_WORKER_GROUPS);
  1700. unsigned idx_data;
  1701. for (idx_data = 0; idx_data < STARPU_TASK_GET_NBUFFERS(task); ++idx_data)
  1702. {
  1703. const starpu_data_handle_t handle = STARPU_TASK_GET_HANDLE(task, idx_data);
  1704. const size_t raw_data_size = starpu_data_get_size(handle);
  1705. const unsigned is_read = (STARPU_TASK_GET_MODE(task, idx_data) == STARPU_R);
  1706. // Easy:
  1707. size_t data_size;
  1708. if (pushStrategy == PUSH_LS_SDH)
  1709. {
  1710. data_size = raw_data_size;
  1711. }
  1712. else
  1713. {
  1714. assert(pushStrategy == PUSH_LS_SDH2);
  1715. data_size = (is_read ? raw_data_size : raw_data_size *raw_data_size);
  1716. }
  1717. unsigned idx_node;
  1718. for (idx_node = 0; idx_node < nnodes; ++idx_node)
  1719. {
  1720. if (starpu_data_is_on_node(handle, idx_node))
  1721. {
  1722. data_per_mem_node[idx_node] += data_size;
  1723. if (max_size_so_far < data_per_mem_node[idx_node] ||
  1724. (max_size_so_far == data_per_mem_node[idx_node] &&
  1725. idx_node == wgroupid))
  1726. {
  1727. max_size_so_far = data_per_mem_node[idx_node];
  1728. idx_max_size = idx_node;
  1729. }
  1730. }
  1731. }
  1732. }
  1733. best_mem_node = idx_max_size;
  1734. }
  1735. else if (pushStrategy == PUSH_LC_SMWB)
  1736. {
  1737. const unsigned wgroupid = (workerid == (unsigned)-1 ? hp->master_tasks_queue_idx : hp->workers_laheteroprio_wgroup_index[workerid]);
  1738. assert(nnodes <= LAHETEROPRIO_MAX_WORKER_GROUPS);
  1739. const unsigned N = STARPU_TASK_GET_NBUFFERS(task);
  1740. unsigned data_exist_every_where[128] = { 0 };
  1741. unsigned nb_data_exist_every_where = 0;
  1742. {
  1743. unsigned idx_data;
  1744. for (idx_data = 0; idx_data < N; ++idx_data)
  1745. {
  1746. const starpu_data_handle_t handle = STARPU_TASK_GET_HANDLE(task, idx_data);
  1747. data_exist_every_where[idx_data] = 1;
  1748. unsigned idx_node;
  1749. for (idx_node = 0; idx_node < nnodes; ++idx_node)
  1750. {
  1751. if (starpu_data_is_on_node(handle, idx_node))
  1752. {
  1753. // Ok
  1754. }
  1755. else
  1756. {
  1757. data_exist_every_where[idx_data] = 0;
  1758. break;
  1759. }
  1760. }
  1761. if (data_exist_every_where[idx_data])
  1762. {
  1763. nb_data_exist_every_where += 1;
  1764. }
  1765. }
  1766. }
  1767. assert(N <= 128);
  1768. unsigned data_is_read[128] = { 0 };
  1769. unsigned Nw = 0;
  1770. size_t total_size = 0;
  1771. size_t total_size_in_read = 0;
  1772. size_t total_size_in_write = 0;
  1773. size_t data_sizes[128] = { 0 };
  1774. unsigned data_Ri[128] = { 0 };
  1775. size_t data_per_mem_node[LAHETEROPRIO_MAX_WORKER_GROUPS] = { 0 };
  1776. size_t data_per_mem_node_in_read[LAHETEROPRIO_MAX_WORKER_GROUPS] = { 0 };
  1777. size_t data_per_mem_node_in_write[LAHETEROPRIO_MAX_WORKER_GROUPS] = { 0 };
  1778. unsigned nb_data_per_mem_node[LAHETEROPRIO_MAX_WORKER_GROUPS] = { 0 };
  1779. unsigned nb_data_in_w_per_mem_node[LAHETEROPRIO_MAX_WORKER_GROUPS] = { 0 };
  1780. {
  1781. unsigned idx_data;
  1782. for (idx_data = 0; idx_data < N; ++idx_data)
  1783. {
  1784. if (data_exist_every_where[idx_data] == 0)
  1785. {
  1786. const starpu_data_handle_t handle = STARPU_TASK_GET_HANDLE(task, idx_data);
  1787. data_sizes[idx_data] = starpu_data_get_size(handle);
  1788. data_is_read[idx_data] = (STARPU_TASK_GET_MODE(task, idx_data) == STARPU_R);
  1789. total_size += data_sizes[idx_data];
  1790. if (data_is_read[idx_data])
  1791. {
  1792. total_size_in_read += data_sizes[idx_data];
  1793. }
  1794. else
  1795. {
  1796. total_size_in_write += data_sizes[idx_data];
  1797. Nw += 1;
  1798. }
  1799. unsigned idx_node;
  1800. for (idx_node = 0; idx_node < nnodes; ++idx_node)
  1801. {
  1802. if (starpu_data_is_on_node(handle, idx_node))
  1803. {
  1804. data_Ri[idx_data] += 1;
  1805. data_per_mem_node[idx_node] += data_sizes[idx_data];
  1806. nb_data_per_mem_node[idx_node] += 1;
  1807. if (data_is_read[idx_data])
  1808. {
  1809. data_per_mem_node_in_read[idx_node] += data_sizes[idx_data];
  1810. }
  1811. else
  1812. {
  1813. data_per_mem_node_in_write[idx_node] += data_sizes[idx_data];
  1814. nb_data_in_w_per_mem_node[idx_node] += 1;
  1815. }
  1816. }
  1817. }
  1818. }
  1819. }
  1820. }
  1821. double max_score_so_far = 0;
  1822. unsigned idx_max_score = 0;
  1823. unsigned idx_node;
  1824. for (idx_node = 0; idx_node < nnodes; ++idx_node)
  1825. {
  1826. double current_score = 0;
  1827. current_score = (data_per_mem_node_in_read[idx_node]) +
  1828. 1000. *(data_per_mem_node_in_write[idx_node] *nb_data_in_w_per_mem_node[idx_node]);
  1829. if (max_score_so_far < current_score ||
  1830. (max_score_so_far == current_score &&
  1831. idx_node == wgroupid))
  1832. {
  1833. max_score_so_far = current_score;
  1834. idx_max_score = idx_node;
  1835. }
  1836. }
  1837. best_mem_node = idx_max_score;
  1838. }
  1839. else
  1840. {
  1841. const unsigned wgroupid = (workerid == (unsigned)-1 ? hp->master_tasks_queue_idx : hp->workers_laheteroprio_wgroup_index[workerid]);
  1842. assert(nnodes <= LAHETEROPRIO_MAX_WORKER_GROUPS);
  1843. const unsigned N = STARPU_TASK_GET_NBUFFERS(task);
  1844. assert(N <= 128);
  1845. unsigned data_is_read[128] = { 0 };
  1846. unsigned Nw = 0;
  1847. size_t total_size = 0;
  1848. size_t total_size_in_read = 0;
  1849. size_t total_size_in_write = 0;
  1850. size_t data_sizes[128] = { 0 };
  1851. unsigned data_Ri[128] = { 0 };
  1852. size_t data_per_mem_node[LAHETEROPRIO_MAX_WORKER_GROUPS] = { 0 };
  1853. size_t data_per_mem_node_in_read[LAHETEROPRIO_MAX_WORKER_GROUPS] = { 0 };
  1854. size_t data_per_mem_node_in_write[LAHETEROPRIO_MAX_WORKER_GROUPS] = { 0 };
  1855. unsigned nb_data_per_mem_node[LAHETEROPRIO_MAX_WORKER_GROUPS] = { 0 };
  1856. unsigned nb_data_in_w_per_mem_node[LAHETEROPRIO_MAX_WORKER_GROUPS] = { 0 };
  1857. {
  1858. unsigned idx_data;
  1859. for (idx_data = 0; idx_data < N; ++idx_data)
  1860. {
  1861. const starpu_data_handle_t handle = STARPU_TASK_GET_HANDLE(task, idx_data);
  1862. data_sizes[idx_data] = starpu_data_get_size(handle);
  1863. data_is_read[idx_data] = (STARPU_TASK_GET_MODE(task, idx_data) == STARPU_R);
  1864. total_size += data_sizes[idx_data];
  1865. if (data_is_read[idx_data])
  1866. {
  1867. total_size_in_read += data_sizes[idx_data];
  1868. }
  1869. else
  1870. {
  1871. total_size_in_write += data_sizes[idx_data];
  1872. Nw += 1;
  1873. }
  1874. unsigned idx_node;
  1875. for (idx_node = 0; idx_node < nnodes; ++idx_node)
  1876. {
  1877. if (starpu_data_is_on_node(handle, idx_node))
  1878. {
  1879. data_Ri[idx_data] += 1;
  1880. data_per_mem_node[idx_node] += data_sizes[idx_data];
  1881. nb_data_per_mem_node[idx_node] += 1;
  1882. if (data_is_read[idx_data])
  1883. {
  1884. data_per_mem_node_in_read[idx_node] += data_sizes[idx_data];
  1885. }
  1886. else
  1887. {
  1888. data_per_mem_node_in_write[idx_node] += data_sizes[idx_data];
  1889. nb_data_in_w_per_mem_node[idx_node] += 1;
  1890. }
  1891. }
  1892. }
  1893. }
  1894. }
  1895. double max_score_so_far = DBL_MAX;
  1896. unsigned idx_max_score = 0;
  1897. unsigned idx_node;
  1898. for (idx_node = 0; idx_node < nnodes; ++idx_node)
  1899. {
  1900. /*
  1901. const enum starpu_node_kind memnode_kind = starpu_node_get_kind(idx_node);
  1902. if(memnode_kind == STARPU_DISK_RAM)
  1903. {
  1904. continue; // a disk has no associated worker
  1905. }
  1906. */
  1907. double current_score = 0;
  1908. assert(pushStrategy == PUSH_LS_SDHB);
  1909. current_score = (total_size_in_read - data_per_mem_node_in_read[idx_node]) +
  1910. ((total_size_in_write - data_per_mem_node_in_write[idx_node]) *(2. - (double)(Nw) / (double)(N)));
  1911. if (max_score_so_far > current_score ||
  1912. (max_score_so_far == current_score &&
  1913. idx_node == wgroupid))
  1914. {
  1915. max_score_so_far = current_score;
  1916. idx_max_score = idx_node;
  1917. }
  1918. }
  1919. best_mem_node = idx_max_score;
  1920. }
  1921. #ifdef LAHETEROPRIO_PRINT_STAT
  1922. lastats.push_redirect[workerid + 1][best_mem_node] += 1;
  1923. #endif // LAHETEROPRIO_PRINT_STAT
  1924. }
  1925. else
  1926. {
  1927. if (workerid == (unsigned)-1)
  1928. { /*master thread */
  1929. best_mem_node = hp->master_tasks_queue_idx;
  1930. }
  1931. else
  1932. {
  1933. const unsigned wgroupid = hp->workers_laheteroprio_wgroup_index[workerid];
  1934. best_mem_node = wgroupid;
  1935. }
  1936. }
  1937. return best_mem_node;
  1938. }
  1939. static void print_priorities(struct _starpu_heteroprio_data *hp)
  1940. {
  1941. STARPU_ASSERT(hp->autoheteroprio_print_prio_after_ordering);
  1942. starpu_worker_relax_on();
  1943. STARPU_PTHREAD_MUTEX_LOCK(&hp->auto_calibration_mutex);
  1944. starpu_worker_relax_off();
  1945. fprintf(stderr, "Updated task priorities :\n");
  1946. unsigned arch;
  1947. for(arch=0;arch<STARPU_NARCH;++arch)
  1948. {
  1949. if(starpu_worker_archtype_is_valid(arch))
  1950. {
  1951. fprintf(stderr, "\t%s : ", starpu_worker_get_type_as_string(arch));
  1952. }
  1953. else
  1954. {
  1955. continue;
  1956. }
  1957. unsigned p;
  1958. for(p=0;p<hp->found_codelet_names_on_arch[arch];++p)
  1959. {
  1960. fprintf(stderr, "%s ", hp->found_codelet_names[hp->prio_mapping_per_arch_index[arch][p]]);
  1961. }
  1962. fprintf(stderr, "\n");
  1963. }
  1964. STARPU_PTHREAD_MUTEX_UNLOCK(&hp->auto_calibration_mutex);
  1965. }
  1966. static double get_autoheteroprio_arch_busy_proportion(struct _starpu_heteroprio_data *hp, unsigned arch)
  1967. {
  1968. double total = hp->average_arch_busy_time[arch] + hp->average_arch_free_time[arch];
  1969. if(total <= 0)
  1970. { // if we have no info on workers times, we assume they are never busy (near-arbitrary choice)
  1971. return 0;
  1972. }
  1973. return hp->average_arch_busy_time[arch]/total;
  1974. }
  1975. static double get_autoheteroprio_estimated_time(struct _starpu_heteroprio_data *hp, unsigned priority, unsigned arch)
  1976. {
  1977. if(hp->prio_arch_has_time_info[arch][priority])
  1978. {
  1979. return hp->prio_average_time_arch[arch][priority];
  1980. }
  1981. if(arch_can_execute_prio(hp, arch, priority))
  1982. { // if arch is legit but we have no time information, return a decent arbitrary time
  1983. return AUTOHETEROPRIO_FAIR_TIME;
  1984. }
  1985. if(hp->autoheteroprio_time_estimation_policy == 0)
  1986. {
  1987. return AUTOHETEROPRIO_LONG_TIME;
  1988. }
  1989. else if(hp->autoheteroprio_time_estimation_policy == 1)
  1990. {
  1991. // we can't execute this task on this arch, we therefore act as if it would be executed as fast as on the fastest architecture
  1992. double bestTime = AUTOHETEROPRIO_EXTREMELY_LONG_TIME;
  1993. unsigned a;
  1994. for(a=0;a<STARPU_NB_TYPES;++a)
  1995. {
  1996. if(a == arch)
  1997. {
  1998. continue;
  1999. }
  2000. if(arch_can_execute_prio(hp, a, priority))
  2001. {
  2002. // recursive call, but garanteed to stop because we know that arch_can_execute_prio(hp, a, prio)
  2003. double time = get_autoheteroprio_estimated_time(hp, priority, a);
  2004. if(time < bestTime)
  2005. {
  2006. bestTime = time;
  2007. }
  2008. }
  2009. }
  2010. return bestTime;
  2011. }
  2012. else
  2013. {
  2014. STARPU_ASSERT(hp->autoheteroprio_time_estimation_policy == 0 || hp->autoheteroprio_time_estimation_policy == 1);
  2015. return 0.; // to get rid of warning
  2016. }
  2017. }
  2018. static double get_autoheteroprio_prio_proportion(struct _starpu_heteroprio_data *hp, unsigned priority)
  2019. {
  2020. if(hp->prio_overall_proportion_count[priority] > 0)
  2021. {
  2022. return hp->prio_overall_proportion[priority];
  2023. }
  2024. // no prio of this type has ever been recorded
  2025. return 0;
  2026. }
  2027. // get normalized time (no unit, with average best arch executes tasks in 1.0)
  2028. static double get_autoheteroprio_normalized_time(struct _starpu_heteroprio_data *hp, unsigned priority, unsigned arch)
  2029. {
  2030. double sum = 0.f;
  2031. unsigned p;
  2032. for(p=0;p<hp->found_codelet_names_length;++p)
  2033. {
  2034. sum += get_autoheteroprio_prio_proportion(hp, p) * get_best_autoheteroprio_estimated_time(hp, p);
  2035. }
  2036. if(sum <= 0.f)
  2037. {
  2038. return 1.0;
  2039. }
  2040. return get_autoheteroprio_estimated_time(hp, priority, arch) / sum;
  2041. }
  2042. static double get_autoheteroprio_prio_arch_proportion(struct _starpu_heteroprio_data *hp, unsigned priority, unsigned arch)
  2043. {
  2044. if(hp->prio_arch_proportion_count[priority] > 0)
  2045. {
  2046. return hp->prio_arch_proportion[arch][priority];
  2047. }
  2048. // this prio has never been executed on this arch
  2049. return 0;
  2050. }
  2051. static double get_autoheteroprio_successors_best_time_sum(struct _starpu_heteroprio_data *hp, unsigned priority)
  2052. {
  2053. if(hp->prio_average_successors_best_time_sum_count[priority] > 0)
  2054. {
  2055. return hp->prio_average_successors_best_time_sum[priority];
  2056. }
  2057. return AUTOHETEROPRIO_FAIR_TIME;
  2058. }
  2059. // best execution time of a prio
  2060. static double get_autoheteroprio_best_time(struct _starpu_heteroprio_data *hp, unsigned priority)
  2061. {
  2062. if(hp->prio_average_best_count[priority] > 0)
  2063. {
  2064. return hp->prio_average_best[priority];
  2065. }
  2066. return AUTOHETEROPRIO_FAIR_TIME;
  2067. }
  2068. static double get_autoheteroprio_NOD(struct _starpu_heteroprio_data *hp, unsigned priority)
  2069. {
  2070. if(hp->prio_average_NOD_count[priority] > 0)
  2071. {
  2072. return hp->prio_average_NOD[priority];
  2073. }
  2074. return 1.0f;
  2075. }
  2076. static double get_autoheteroprio_URT(struct _starpu_heteroprio_data *hp, unsigned arch, unsigned priority)
  2077. {
  2078. if(hp->prio_average_URT_count[priority] > 0)
  2079. {
  2080. return hp->prio_average_URT[arch][priority];
  2081. }
  2082. return AUTOHETEROPRIO_FAIR_TIME;
  2083. }
  2084. static double reLU(double x)
  2085. {
  2086. if(x<0.0f)
  2087. {
  2088. return 0.0f;
  2089. }
  2090. return x;
  2091. }
  2092. static double rpg(double x)
  2093. {
  2094. if(x > 1.0f)
  2095. {
  2096. return 1.0f;
  2097. }
  2098. return sqrt(x)*sqrt(2.0f-x);
  2099. }
  2100. struct prio_score
  2101. {
  2102. unsigned index;
  2103. double score;
  2104. };
  2105. static int compare_prio_scores(const void* elem1, const void* elem2)
  2106. {
  2107. if(((const struct prio_score*)elem1)->score > ((const struct prio_score*)elem2)->score)
  2108. return -1;
  2109. return ((const struct prio_score*)elem1)->score < ((const struct prio_score*)elem2)->score;
  2110. }
  2111. static void order_priorities(struct _starpu_heteroprio_data *hp)
  2112. {
  2113. STARPU_ASSERT(use_auto_mode);
  2114. STARPU_ASSERT(hp->use_auto_calibration); // priorities should only be changed during execution if in auto calibration mode
  2115. struct prio_score prio_arch[STARPU_NB_TYPES][HETEROPRIO_MAX_PRIO];
  2116. unsigned prio_arch_index[STARPU_NB_TYPES] = {0};
  2117. // lock the global policy mutex
  2118. _starpu_worker_relax_on();
  2119. STARPU_PTHREAD_MUTEX_LOCK(&hp->auto_calibration_mutex);
  2120. starpu_worker_relax_off();
  2121. unsigned p, a;
  2122. for(p=0;p<hp->found_codelet_names_length;++p)
  2123. {
  2124. int worst_arch = -1;
  2125. double worstTime = -1.0f;
  2126. int second_worst_arch = -1;
  2127. double secondWorstTime = -1.0f;
  2128. // Find the worst architecture and the second worst if there is one
  2129. for(a = 0; a < STARPU_NB_TYPES; ++a)
  2130. {
  2131. if((hp->buckets[p].valid_archs & starpu_heteroprio_types_to_arch(a)) == 0)
  2132. continue;
  2133. const double arch_time = get_autoheteroprio_normalized_time(hp, p, a);
  2134. if(worstTime < arch_time)
  2135. {
  2136. second_worst_arch = worst_arch;
  2137. secondWorstTime = worstTime;
  2138. worst_arch = a;
  2139. worstTime = arch_time;
  2140. }
  2141. else if(secondWorstTime < arch_time)
  2142. {
  2143. second_worst_arch = a;
  2144. secondWorstTime = arch_time;
  2145. }
  2146. }
  2147. // Ensure that there is at least one arch that can execute priority
  2148. STARPU_ASSERT(worst_arch != -1);
  2149. const double worstArchTaskProportion = get_autoheteroprio_prio_arch_proportion(hp, p, worst_arch);
  2150. const double URT_worst = get_autoheteroprio_URT(hp, worst_arch, p);
  2151. double secondWorstArchTaskProportion, URT_secondWorst;
  2152. if(second_worst_arch == -1)
  2153. {
  2154. // If there's no second worst set values to worst possible values
  2155. secondWorstTime = AUTOHETEROPRIO_EXTREMELY_LONG_TIME;
  2156. secondWorstArchTaskProportion = 0.f;
  2157. URT_secondWorst = 0.f;
  2158. }
  2159. else
  2160. {
  2161. secondWorstTime = get_autoheteroprio_normalized_time(hp, p, second_worst_arch);
  2162. secondWorstArchTaskProportion = get_autoheteroprio_prio_arch_proportion(hp, p, second_worst_arch);
  2163. URT_secondWorst = get_autoheteroprio_URT(hp, second_worst_arch, p);
  2164. }
  2165. // Compute scores
  2166. for(a=0;a<STARPU_NB_TYPES;++a)
  2167. {
  2168. if(hp->buckets[p].valid_archs & starpu_heteroprio_types_to_arch(a))
  2169. {
  2170. double otherTime, otherArchTaskProportion, URT_other;
  2171. unsigned prio = prio_arch_index[a]++;
  2172. if(a == (unsigned) worst_arch)
  2173. {
  2174. // Compare the worst architecture to the second worst
  2175. otherTime = secondWorstTime;
  2176. URT_other = URT_secondWorst;
  2177. otherArchTaskProportion = secondWorstArchTaskProportion;
  2178. }
  2179. else
  2180. {
  2181. // Compare to the worst architecture
  2182. otherTime = worstTime;
  2183. URT_other = URT_worst;
  2184. otherArchTaskProportion = worstArchTaskProportion;
  2185. }
  2186. const double need_other = 1.0f - otherArchTaskProportion;
  2187. double NOD = get_autoheteroprio_NOD(hp, p);
  2188. double sum = get_autoheteroprio_successors_best_time_sum(hp, p);
  2189. double ownTime = get_autoheteroprio_normalized_time(hp, p, a);
  2190. double archDiff = otherTime - ownTime;
  2191. double archRelDiff = otherTime/ownTime;
  2192. double ownArchTaskProportion = get_autoheteroprio_prio_arch_proportion(hp, p, a);
  2193. double URT_own = get_autoheteroprio_URT(hp, a, p);
  2194. double need_own = 1.0f - get_autoheteroprio_arch_busy_proportion(hp, a);
  2195. double archNeedDiff = need_own-need_other;
  2196. double URT = (URT_own*need_own + URT_other*need_other);
  2197. prio_arch[a][prio].index = p;
  2198. if(hp->autoheteroprio_priority_ordering_policy == STARPU_HETEROPRIO_NOD_TIME_COMBINATION)
  2199. {
  2200. double relDiff = archRelDiff>1.0f?archRelDiff:1.0/archRelDiff;
  2201. double multiplier = exp(-hp->NTexpVal*(relDiff-1)*(relDiff-1));
  2202. prio_arch[a][prio].score = archDiff + hp->NTnodPond*multiplier*NOD;
  2203. }
  2204. else if(hp->autoheteroprio_priority_ordering_policy == STARPU_HETEROPRIO_BEST_NODS_SCORE || hp->autoheteroprio_priority_ordering_policy == STARPU_HETEROPRIO_BEST_NODS)
  2205. { // TODO, implement BEST_NODS
  2206. double multiplier = exp(-hp->BNexpVal*(archDiff)*(archDiff));
  2207. if(archDiff > 0.0f)
  2208. { // my arch is faster
  2209. multiplier = 1.0f;
  2210. }
  2211. multiplier = 2.0f*multiplier - 1.0f; // bad diff becomes -1, good or equal diff 1
  2212. prio_arch[a][prio].score = multiplier*NOD;
  2213. }
  2214. else if(hp->autoheteroprio_priority_ordering_policy == STARPU_HETEROPRIO_URT_PURE)
  2215. {
  2216. prio_arch[a][prio].score = URT;
  2217. }
  2218. else if(hp->autoheteroprio_priority_ordering_policy == STARPU_HETEROPRIO_URT)
  2219. {
  2220. prio_arch[a][prio].score = hp->URTurt * URT + archDiff;
  2221. }
  2222. else if(hp->autoheteroprio_priority_ordering_policy == STARPU_HETEROPRIO_URT_2)
  2223. {
  2224. prio_arch[a][prio].score = hp->URT2urt * URT + archDiff + hp->URT2prop * reLU(ownArchTaskProportion*otherArchTaskProportion*archNeedDiff);
  2225. }
  2226. else if(hp->autoheteroprio_priority_ordering_policy == STARPU_HETEROPRIO_URT_DOT_DIFF_PURE)
  2227. {
  2228. prio_arch[a][prio].score = URT*archDiff;
  2229. }
  2230. else if(hp->autoheteroprio_priority_ordering_policy == STARPU_HETEROPRIO_URT_DOT_DIFF_PURE_2)
  2231. {
  2232. prio_arch[a][prio].score = (1.0f + URT)*archDiff;
  2233. }
  2234. else if(hp->autoheteroprio_priority_ordering_policy == STARPU_HETEROPRIO_URT_DOT_REL_DIFF_PURE)
  2235. {
  2236. prio_arch[a][prio].score = URT*archRelDiff;
  2237. }
  2238. else if(hp->autoheteroprio_priority_ordering_policy == STARPU_HETEROPRIO_URT_DOT_REL_DIFF_PURE_2)
  2239. {
  2240. prio_arch[a][prio].score = (1.0f + URT)*archRelDiff;
  2241. }
  2242. else if(hp->autoheteroprio_priority_ordering_policy == STARPU_HETEROPRIO_URT_DOT_DIFF_2)
  2243. {
  2244. prio_arch[a][prio].score = (1.0f + URT)*archDiff + hp->and2pond * ownTime * archNeedDiff;
  2245. }
  2246. else if(hp->autoheteroprio_priority_ordering_policy == STARPU_HETEROPRIO_URT_DOT_DIFF_3)
  2247. {
  2248. prio_arch[a][prio].score = (1.0f + URT)*archDiff + hp->and3pond * ownTime * reLU(archNeedDiff);
  2249. }
  2250. else if(hp->autoheteroprio_priority_ordering_policy == STARPU_HETEROPRIO_URT_DOT_DIFF_4)
  2251. {
  2252. prio_arch[a][prio].score = (1.0f + URT)*archDiff - hp->and4pond * ownTime * reLU(-archNeedDiff);
  2253. }
  2254. else if(hp->autoheteroprio_priority_ordering_policy == STARPU_HETEROPRIO_URT_DOT_DIFF_5)
  2255. {
  2256. prio_arch[a][prio].score = (hp->and5xoffset + URT) * (hp->and5yoffset + archDiff);
  2257. }
  2258. else if(hp->autoheteroprio_priority_ordering_policy == STARPU_HETEROPRIO_URT_DOT_DIFF_6)
  2259. {
  2260. prio_arch[a][prio].score = (1.0f + URT)*log(1.0f + exp(archDiff));
  2261. }
  2262. else if(hp->autoheteroprio_priority_ordering_policy == STARPU_HETEROPRIO_URT_DOT_DIFF_7)
  2263. {
  2264. prio_arch[a][prio].score = rpg(URT)*(1+URT)*(1+archDiff)+(1-rpg(URT))*(-log(1+exp(-archDiff)));
  2265. }
  2266. else if(hp->autoheteroprio_priority_ordering_policy == STARPU_HETEROPRIO_URT_DOT_DIFF_8)
  2267. {
  2268. prio_arch[a][prio].score = (1/(1+exp(-URT))-0.5)*(1+URT)*(1+archDiff)+(1/(1+exp(-1/URT))-0.5)*(-exp(-archDiff));
  2269. }
  2270. else if(hp->autoheteroprio_priority_ordering_policy == STARPU_HETEROPRIO_URT_DOT_DIFF_9)
  2271. {
  2272. prio_arch[a][prio].score = log(hp->and9xoffset+URT)*atan(archDiff+hp->and9yoffset*URT);
  2273. }
  2274. else if(hp->autoheteroprio_priority_ordering_policy == STARPU_HETEROPRIO_URT_DOT_DIFF_10)
  2275. {
  2276. prio_arch[a][prio].score = (hp->and10xoffset+URT)*atan(archDiff) + hp->and10yoffset*URT;
  2277. }
  2278. else if(hp->autoheteroprio_priority_ordering_policy == STARPU_HETEROPRIO_URT_DOT_DIFF_11)
  2279. {
  2280. prio_arch[a][prio].score = (hp->and11xoffset+URT)*(archDiff+hp->and11yoffset*URT);
  2281. }
  2282. else if(hp->autoheteroprio_priority_ordering_policy == STARPU_HETEROPRIO_URTS_PER_SECONDS)
  2283. {
  2284. prio_arch[a][prio].score = URT / ownTime;
  2285. }
  2286. else if(hp->autoheteroprio_priority_ordering_policy == STARPU_HETEROPRIO_URTS_PER_SECONDS_2)
  2287. {
  2288. prio_arch[a][prio].score = (URT + archDiff) / ownTime;
  2289. }
  2290. else if(hp->autoheteroprio_priority_ordering_policy == STARPU_HETEROPRIO_URTS_PER_SECONDS_DIFF)
  2291. {
  2292. prio_arch[a][prio].score = URT / ownTime + archDiff;
  2293. }
  2294. else if(hp->autoheteroprio_priority_ordering_policy == STARPU_HETEROPRIO_URTS_TIME_RELEASED_DIFF)
  2295. {
  2296. prio_arch[a][prio].score = URT*(sum+archDiff)/ownTime;
  2297. }
  2298. else if(hp->autoheteroprio_priority_ordering_policy == STARPU_HETEROPRIO_URTS_TIME_COMBINATION)
  2299. {
  2300. double relDiff = archRelDiff>1.0f?archRelDiff:1.0/archRelDiff;
  2301. double multiplier = exp(-hp->ANTexpVal*(relDiff-1)*(relDiff-1));
  2302. prio_arch[a][prio].score = archDiff + hp->ANTnodPond*multiplier*URT;
  2303. }
  2304. else if(hp->autoheteroprio_priority_ordering_policy == STARPU_HETEROPRIO_NODS_PER_SECOND)
  2305. {
  2306. prio_arch[a][prio].score = NOD/ownTime;
  2307. }
  2308. else if(hp->autoheteroprio_priority_ordering_policy == STARPU_HETEROPRIO_NODS_TIME_RELEASED)
  2309. {
  2310. prio_arch[a][prio].score = NOD*sum/ownTime;
  2311. }
  2312. else if(hp->autoheteroprio_priority_ordering_policy == STARPU_HETEROPRIO_NODS_TIME_RELEASED_DIFF)
  2313. {
  2314. prio_arch[a][prio].score = NOD*(sum+archDiff)/ownTime;
  2315. }
  2316. else
  2317. {
  2318. _STARPU_MSG("[AUTOHETEROPRIO] Warning: unknown ordering policy.\n");
  2319. prio_arch[a][prio].score = 0;
  2320. }
  2321. if(!hp->freeze_data_gathering && hp->prio_average_time_arch_count[a][p] < AUTOHETEROPRIO_RELEVANT_SAMPLE_SIZE)
  2322. {
  2323. // if we dont have enough data on execution time, we push execution on it by increasing the score
  2324. prio_arch[a][prio].score += 99999999.;
  2325. }
  2326. }
  2327. }
  2328. }
  2329. for(a=0;a<STARPU_NB_TYPES;++a)
  2330. {
  2331. qsort(&prio_arch[a][0], hp->found_codelet_names_on_arch[a], sizeof(struct prio_score), compare_prio_scores);
  2332. }
  2333. starpu_heteroprio_clear_mapping_hp(hp);
  2334. for(a=0;a<STARPU_NB_TYPES;++a)
  2335. {
  2336. for(p=0;p<hp->found_codelet_names_on_arch[a];++p)
  2337. {
  2338. starpu_heteroprio_set_mapping_hp(hp, a, p, prio_arch[a][p].index);
  2339. }
  2340. }
  2341. /* // uncomment to print task names ordered by priority (TODO : use environment variable)
  2342. printf("priorities sorted:\n");
  2343. printf("CPU:\n");
  2344. for(p=0;p<hp->found_codelet_names_on_arch[STARPU_CPU_WORKER];++p)
  2345. {
  2346. printf("%d : %s bucket=%d (score = %f)\n", p, hp->found_codelet_names[prio_arch[STARPU_CPU_WORKER][p].index], prio_arch[STARPU_CPU_WORKER][p].index, prio_arch[STARPU_CPU_WORKER][p].score);
  2347. }
  2348. printf("GPU:\n");
  2349. for(p=0;p<hp->found_codelet_names_on_arch[STARPU_CUDA_WORKER];++p)
  2350. {
  2351. printf("%d : %s bucket=%d (score = %f)\n", p, hp->found_codelet_names[prio_arch[STARPU_CUDA_WORKER][p].index], prio_arch[STARPU_CUDA_WORKER][p].index, prio_arch[STARPU_CUDA_WORKER][p].score);
  2352. }
  2353. */
  2354. STARPU_PTHREAD_MUTEX_UNLOCK(&hp->auto_calibration_mutex);
  2355. }
  2356. // used to get the name of a codelet, considering a codelet grouping strategy
  2357. static const char *_heteroprio_get_codelet_name(enum autoheteroprio_codelet_grouping_strategy strategy, struct starpu_codelet *cl)
  2358. {
  2359. const char *name = NULL;
  2360. switch(strategy)
  2361. {
  2362. case BY_PERF_MODEL_OR_NAME:
  2363. name = _starpu_codelet_get_model_name(cl);
  2364. break;
  2365. case BY_NAME_ONLY:
  2366. name = _starpu_codelet_get_name(cl);
  2367. break;
  2368. }
  2369. return name ? name : AUTOHETEROPRIO_NO_NAME;
  2370. }
  2371. // used by get_task_auto_priority for knowing if a submitted codelet equals an other
  2372. static int are_same_codelets(struct _starpu_heteroprio_data *hp, const struct starpu_task *task, const char name[CODELET_MAX_NAME_LENGTH], unsigned valid_archs)
  2373. {
  2374. unsigned task_valid_archs = task->where >= 0 ? (unsigned) task->where : task->cl->where;
  2375. if(task_valid_archs != valid_archs)
  2376. {
  2377. // are not same codelet, because different architectures
  2378. return 0;
  2379. }
  2380. const char *task_name = _heteroprio_get_codelet_name(hp->codelet_grouping_strategy, task->cl);
  2381. return strncmp(name, task_name, CODELET_MAX_NAME_LENGTH) == 0;
  2382. }
  2383. static int get_task_auto_priority(struct _starpu_heteroprio_data *hp, const struct starpu_task *task)
  2384. {
  2385. STARPU_ASSERT(use_auto_mode);
  2386. STARPU_ASSERT(hp->use_auto_calibration);
  2387. STARPU_ASSERT(hp->found_codelet_names_length <= HETEROPRIO_MAX_PRIO);
  2388. if(task->cl->where == STARPU_NOWHERE)
  2389. {
  2390. return -1;
  2391. }
  2392. const char *name = _heteroprio_get_codelet_name(hp->codelet_grouping_strategy, task->cl);
  2393. starpu_worker_relax_on();
  2394. STARPU_PTHREAD_MUTEX_LOCK(&hp->auto_calibration_mutex);
  2395. starpu_worker_relax_off();
  2396. unsigned current_priority;
  2397. for(current_priority = 0;current_priority<hp->found_codelet_names_length;++current_priority)
  2398. {
  2399. if(are_same_codelets(hp, task, &hp->found_codelet_names[current_priority][0], hp->buckets[current_priority].valid_archs))
  2400. {
  2401. STARPU_PTHREAD_MUTEX_UNLOCK(&hp->auto_calibration_mutex);
  2402. return current_priority;
  2403. }
  2404. }
  2405. // codelet's name does not exist in found_codelet_names, add it
  2406. STARPU_ASSERT(hp->found_codelet_names_length < HETEROPRIO_MAX_PRIO);
  2407. const unsigned found_codelet_names_length = hp->found_codelet_names_length;
  2408. if(!task->cl->model)
  2409. { // The codelet does not have a perf model
  2410. _STARPU_MSG("[HETEROPRIO] Warning: codelet %s does not have a perfmodel. This may negatively impact heteroprio's auto prioritizing.\n", name);
  2411. }
  2412. unsigned archs[STARPU_NB_TYPES] = {0};
  2413. unsigned arch;
  2414. for(arch=0;arch<STARPU_NARCH;++arch)
  2415. {
  2416. archs[arch] = starpu_worker_type_can_execute_task(arch, task);
  2417. }
  2418. starpu_autoheteroprio_add_task(hp, name, archs);
  2419. STARPU_PTHREAD_MUTEX_UNLOCK(&hp->auto_calibration_mutex);
  2420. return found_codelet_names_length;
  2421. }
  2422. // checks that auto-heteroprio arrays are correctly set (for debugging purposes)
  2423. static void check_auto_heteroprio_mapping(struct _starpu_heteroprio_data *hp)
  2424. {
  2425. // may be useful
  2426. (void) hp;
  2427. }
  2428. static double get_job_NOD(struct _starpu_heteroprio_data *hp, struct _starpu_job *job)
  2429. {
  2430. STARPU_ASSERT(!hp->freeze_data_gathering);
  2431. STARPU_ASSERT(_starpu_graph_record == 1);
  2432. double NOD = 0.f;
  2433. //STARPU_PTHREAD_MUTEX_LOCK(&job->sync_mutex);
  2434. /*if(!job->tag)
  2435. {
  2436. STARPU_PTHREAD_MUTEX_UNLOCK(&job->sync_mutex);
  2437. return 0;
  2438. }*/
  2439. //STARPU_PTHREAD_MUTEX_UNLOCK(&job->sync_mutex);
  2440. _starpu_graph_wrlock();
  2441. struct _starpu_graph_node *node = job->graph_node;
  2442. if(!node)
  2443. {
  2444. // No information because the graph isn't available
  2445. _starpu_graph_wrunlock();
  2446. return 0.f;
  2447. }
  2448. unsigned n;
  2449. for(n=0;n<node->n_outgoing;++n)
  2450. {
  2451. struct _starpu_graph_node *successor = node->outgoing[n]; // there is a node->outgoing_slot, but this ordering array doesnt seem useful here
  2452. if(successor)
  2453. { // successor may be NULL
  2454. NOD += 1.f/(double)successor->n_incoming;
  2455. }
  2456. }
  2457. _starpu_graph_wrunlock();
  2458. return NOD;
  2459. }
  2460. // get job's NRT (Normalized Released Time)
  2461. static double get_job_NRT(struct _starpu_heteroprio_data *hp, struct _starpu_job *job, unsigned arch)
  2462. {
  2463. STARPU_ASSERT(!hp->freeze_data_gathering);
  2464. STARPU_ASSERT(_starpu_graph_record == 1);
  2465. double NOD = 0.f;
  2466. //STARPU_PTHREAD_MUTEX_LOCK(&job->sync_mutex);
  2467. /*if(!job->tag)
  2468. {
  2469. STARPU_PTHREAD_MUTEX_UNLOCK(&job->sync_mutex);
  2470. return 0;
  2471. }*/
  2472. //STARPU_PTHREAD_MUTEX_UNLOCK(&job->sync_mutex);
  2473. _starpu_graph_wrlock();
  2474. struct _starpu_graph_node *node = job->graph_node;
  2475. if(!node)
  2476. {
  2477. // No information because the graph isn't available
  2478. _starpu_graph_wrunlock();
  2479. return 0.f;
  2480. }
  2481. unsigned n;
  2482. for(n=0;n<node->n_outgoing;++n)
  2483. {
  2484. struct _starpu_graph_node *successor = node->outgoing[n]; // there is a node->outgoing_slot, but this ordering array doesnt seem useful here
  2485. if(successor)
  2486. {
  2487. // successor may be NULL
  2488. struct _starpu_job *successor_job = successor->job;
  2489. STARPU_PTHREAD_MUTEX_LOCK(&successor_job->sync_mutex);
  2490. const struct starpu_task *successor_task = successor_job->task;
  2491. STARPU_PTHREAD_MUTEX_UNLOCK(&successor_job->sync_mutex);
  2492. if(successor_task->cl)
  2493. {
  2494. // if a codelet is associated to the task, we can count it in the NOD
  2495. int successor_prio = get_task_auto_priority(hp, successor_task);
  2496. double successor_arch_time;
  2497. if(successor_prio == -1)
  2498. {
  2499. successor_arch_time = 0.f;
  2500. }
  2501. else
  2502. {
  2503. successor_arch_time = get_autoheteroprio_prio_arch_proportion(hp, successor_prio, arch) * get_autoheteroprio_normalized_time(hp, successor_prio, arch);
  2504. }
  2505. NOD += successor_arch_time/(double)successor->n_incoming;
  2506. }
  2507. }
  2508. }
  2509. _starpu_graph_wrunlock();
  2510. return NOD;
  2511. }
  2512. static void register_arch_times(struct _starpu_heteroprio_data *hp, unsigned arch, double busy_time, double free_time)
  2513. {
  2514. STARPU_ASSERT(!hp->freeze_data_gathering);
  2515. double summed_busy_time = hp->average_arch_busy_time[arch] + busy_time;
  2516. double summed_free_time = hp->average_arch_free_time[arch] + free_time;
  2517. double max_time = STARPU_MAX(summed_busy_time, summed_free_time);
  2518. double scale_to_apply = 1.0f;
  2519. if(max_time > AUTOHETEROPRIO_MAX_WORKER_PROFILING_TIME)
  2520. {
  2521. scale_to_apply = AUTOHETEROPRIO_MAX_WORKER_PROFILING_TIME/max_time;
  2522. }
  2523. hp->average_arch_busy_time[arch] = summed_busy_time*scale_to_apply;
  2524. hp->average_arch_free_time[arch] = summed_free_time*scale_to_apply;
  2525. }
  2526. // gets the lowest expected time between each architectures
  2527. static double get_best_autoheteroprio_estimated_time(struct _starpu_heteroprio_data *hp, unsigned priority)
  2528. {
  2529. double time = 999999999999999.f;
  2530. unsigned arch;
  2531. for(arch=0;arch<STARPU_NARCH;++arch)
  2532. {
  2533. if(arch_can_execute_prio(hp, arch, priority))
  2534. {
  2535. time = STARPU_MIN(time, get_autoheteroprio_estimated_time(hp, priority, arch));
  2536. }
  2537. }
  2538. return time;
  2539. }
  2540. static double get_job_best_time(struct _starpu_heteroprio_data *hp, struct _starpu_job *job)
  2541. {
  2542. int task_priority = get_task_auto_priority(hp, job->task);
  2543. double time;
  2544. if(task_priority == -1)
  2545. {
  2546. time = AUTOHETEROPRIO_DEFAULT_TASK_TIME;
  2547. }
  2548. else
  2549. {
  2550. time = get_best_autoheteroprio_estimated_time(hp, task_priority);
  2551. }
  2552. return time;
  2553. }
  2554. static double get_job_successors_best_time_sum(struct _starpu_heteroprio_data *hp, struct _starpu_job *job)
  2555. {
  2556. STARPU_ASSERT(!hp->freeze_data_gathering);
  2557. STARPU_ASSERT(_starpu_graph_record == 1);
  2558. double sum = 0.f;
  2559. _starpu_graph_wrlock();
  2560. struct _starpu_graph_node *node = job->graph_node;
  2561. if(!node)
  2562. {
  2563. // No information because the graph isn't available
  2564. _starpu_graph_wrunlock();
  2565. return 0.f;
  2566. }
  2567. unsigned n;
  2568. for(n=0;n<node->n_outgoing;++n)
  2569. {
  2570. struct _starpu_graph_node *successor = node->outgoing[n]; // there is a node->outgoing_slot, but this ordering array doesnt seem useful here
  2571. if(successor && successor->job && successor->job->task->cl)
  2572. {
  2573. // successor may be NULL
  2574. sum += get_job_best_time(hp, successor->job);
  2575. }
  2576. }
  2577. _starpu_graph_wrunlock();
  2578. return sum;
  2579. }
  2580. static void add_NOD_to_data(struct _starpu_heteroprio_data *hp, unsigned task_priority, double NOD)
  2581. {
  2582. STARPU_ASSERT(!hp->freeze_data_gathering);
  2583. if(hp->prio_average_NOD_count[task_priority] < AUTOHETEROPRIO_RELEVANT_TASK_LIFE)
  2584. {
  2585. ++hp->prio_average_NOD_count[task_priority];
  2586. }
  2587. const unsigned count = hp->prio_average_NOD_count[task_priority];
  2588. hp->prio_average_NOD[task_priority] = hp->prio_average_NOD[task_priority] * (double)(count - 1) / (double)count
  2589. + NOD / (double)count;
  2590. }
  2591. static void add_URTs_to_data(struct _starpu_heteroprio_data *hp, unsigned task_priority, double archs_URTs[STARPU_NARCH])
  2592. {
  2593. STARPU_ASSERT(!hp->freeze_data_gathering);
  2594. if(hp->prio_average_URT_count[task_priority] < AUTOHETEROPRIO_RELEVANT_TASK_LIFE)
  2595. {
  2596. ++hp->prio_average_URT_count[task_priority];
  2597. }
  2598. const unsigned count = hp->prio_average_URT_count[task_priority];
  2599. unsigned arch;
  2600. for(arch=0;arch<STARPU_NARCH;++arch)
  2601. {
  2602. hp->prio_average_URT[arch][task_priority] = hp->prio_average_URT[arch][task_priority] * (double)(count - 1) / (double)count
  2603. + archs_URTs[arch] / (double)count;
  2604. }
  2605. }
  2606. static void register_execution_time(struct _starpu_heteroprio_data *hp, unsigned arch, unsigned task_priority, double time)
  2607. {
  2608. STARPU_ASSERT(!hp->freeze_data_gathering);
  2609. if(hp->prio_average_time_arch_count[arch][task_priority] < AUTOHETEROPRIO_RELEVANT_TASK_LIFE)
  2610. {
  2611. ++hp->prio_average_time_arch_count[arch][task_priority];
  2612. }
  2613. const unsigned count = hp->prio_average_time_arch_count[arch][task_priority];
  2614. hp->prio_average_time_arch[arch][task_priority] = hp->prio_average_time_arch[arch][task_priority] * (double)(count - 1) / (double)count
  2615. + time / (double)count;
  2616. hp->prio_arch_has_time_info[arch][task_priority] = 1;
  2617. }
  2618. static inline unsigned get_total_submitted_task_num(struct _starpu_heteroprio_data *hp)
  2619. {
  2620. unsigned total = 0;
  2621. unsigned idx_prio;
  2622. for(idx_prio = 0; idx_prio < HETEROPRIO_MAX_PRIO; ++idx_prio)
  2623. {
  2624. total += hp->prio_overall_proportion_count[idx_prio];
  2625. }
  2626. return total;
  2627. }
  2628. static inline double get_sum_task_proportions(struct _starpu_heteroprio_data *hp)
  2629. {
  2630. double total = 0.f;
  2631. unsigned idx_prio;
  2632. for(idx_prio = 0; idx_prio < HETEROPRIO_MAX_PRIO; ++idx_prio)
  2633. {
  2634. total += hp->prio_overall_proportion[idx_prio];
  2635. }
  2636. return total;
  2637. }
  2638. // noralizes tasks proportions so that their sum equals 1
  2639. static inline void normalize_task_proportions(struct _starpu_heteroprio_data *hp)
  2640. {
  2641. const double total_task_proportions = get_sum_task_proportions(hp);
  2642. STARPU_ASSERT(total_task_proportions > 0);
  2643. unsigned idx_prio;
  2644. for(idx_prio = 0; idx_prio < HETEROPRIO_MAX_PRIO; ++idx_prio)
  2645. {
  2646. hp->prio_overall_proportion[idx_prio] /= total_task_proportions;
  2647. }
  2648. }
  2649. static void add_submitted_task_to_data(struct _starpu_heteroprio_data *hp, unsigned task_priority)
  2650. {
  2651. STARPU_ASSERT(!hp->freeze_data_gathering);
  2652. if(hp->prio_overall_proportion_count[task_priority] < AUTOHETEROPRIO_RELEVANT_TASK_LIFE)
  2653. {
  2654. ++hp->prio_overall_proportion_count[task_priority];
  2655. }
  2656. const unsigned count = get_total_submitted_task_num(hp);
  2657. STARPU_ASSERT(count > 0);
  2658. hp->prio_overall_proportion[task_priority] += 1.f/(double)count;
  2659. // take back task proportions to a valid value (sum = 1)
  2660. normalize_task_proportions(hp);
  2661. }
  2662. // gets the sum of a task's architecture proportions
  2663. static inline double get_sum_task_arch_proportions(struct _starpu_heteroprio_data *hp, unsigned task_priority)
  2664. {
  2665. double total = 0.f;
  2666. unsigned arch;
  2667. for(arch=0;arch<STARPU_NB_TYPES;++arch)
  2668. {
  2669. total += hp->prio_arch_proportion[arch][task_priority];
  2670. }
  2671. return total;
  2672. }
  2673. // noralizes tasks execution proportions so that the sum of proportions of a task on each arch equals 1
  2674. // EXAMPLE : task A : %CPU = 0.75, %GPU = 0.25
  2675. static inline void normalize_task_arch_proportions(struct _starpu_heteroprio_data *hp, unsigned task_priority)
  2676. {
  2677. const double total_task_proportions = get_sum_task_arch_proportions(hp, task_priority);
  2678. STARPU_ASSERT(total_task_proportions > 0);
  2679. unsigned arch;
  2680. for(arch=0;arch<STARPU_NB_TYPES;++arch)
  2681. {
  2682. hp->prio_arch_proportion[arch][task_priority] /= total_task_proportions;
  2683. }
  2684. }
  2685. static void register_task_arch_execution(struct _starpu_heteroprio_data *hp, unsigned task_priority, unsigned arch)
  2686. {
  2687. STARPU_ASSERT(!hp->freeze_data_gathering);
  2688. if(hp->prio_arch_proportion_count[task_priority] < AUTOHETEROPRIO_RELEVANT_TASK_LIFE)
  2689. {
  2690. ++hp->prio_arch_proportion_count[task_priority];
  2691. }
  2692. unsigned count = hp->prio_arch_proportion_count[task_priority];
  2693. STARPU_ASSERT(count > 0);
  2694. if(count >= 2)
  2695. {
  2696. // to have correct proportions and not divide by zero
  2697. count -=1;
  2698. }
  2699. hp->prio_arch_proportion[arch][task_priority] += 1.f/(double)count;
  2700. // take back task proportions to a valid value (sum = 1)
  2701. normalize_task_arch_proportions(hp, task_priority);
  2702. }
  2703. static void add_successors_best_time_sum_to_data(struct _starpu_heteroprio_data *hp, unsigned task_priority, double sum)
  2704. {
  2705. STARPU_ASSERT(!hp->freeze_data_gathering);
  2706. if(hp->prio_average_successors_best_time_sum_count[task_priority] < AUTOHETEROPRIO_RELEVANT_TASK_LIFE)
  2707. {
  2708. ++hp->prio_average_successors_best_time_sum_count[task_priority];
  2709. }
  2710. const unsigned count = hp->prio_average_successors_best_time_sum_count[task_priority];
  2711. hp->prio_average_successors_best_time_sum[task_priority] = hp->prio_average_successors_best_time_sum[task_priority] * (double)(count - 1) / (double)count
  2712. + sum / (double)count;
  2713. }
  2714. static void add_best_time_to_data(struct _starpu_heteroprio_data *hp, unsigned task_priority, double sum)
  2715. {
  2716. STARPU_ASSERT(!hp->freeze_data_gathering);
  2717. if(hp->prio_average_best_count[task_priority] < AUTOHETEROPRIO_RELEVANT_TASK_LIFE)
  2718. {
  2719. ++hp->prio_average_best_count[task_priority];
  2720. }
  2721. const unsigned count = hp->prio_average_best_count[task_priority];
  2722. hp->prio_average_best[task_priority] = hp->prio_average_best[task_priority] * (double)(count - 1) / (double)count
  2723. + sum / (double)count;
  2724. }
  2725. static void autoheteroprio_update_slowdown_data(struct _starpu_heteroprio_data *hp)
  2726. {
  2727. unsigned p, arch;
  2728. for(p=0;p<hp->found_codelet_names_length;++p)
  2729. {
  2730. unsigned valid_archs[STARPU_NB_TYPES] = {0};
  2731. double arch_times[STARPU_NB_TYPES] = {0.f};
  2732. for(arch = 0; arch < STARPU_NB_TYPES; ++arch)
  2733. {
  2734. valid_archs[arch] = arch_can_execute_prio(hp, arch, p);
  2735. if(valid_archs[arch])
  2736. {
  2737. double arch_time = get_autoheteroprio_estimated_time(hp, p, arch);
  2738. STARPU_ASSERT(arch_time > 0.f);
  2739. arch_times[arch] = arch_time;
  2740. }
  2741. }
  2742. // Assert that at least one architecture can execute priority
  2743. for(arch = 0; arch < STARPU_NB_TYPES && !valid_archs[arch]; ++arch)
  2744. ;
  2745. STARPU_ASSERT(arch < STARPU_NB_TYPES);
  2746. arch = 0;
  2747. while(!valid_archs[arch])
  2748. ++arch;
  2749. unsigned fastest_arch = arch;
  2750. double best_time = arch_times[arch];
  2751. ++arch;
  2752. for(; arch < STARPU_NB_TYPES; ++arch)
  2753. {
  2754. if(valid_archs[arch] && arch_times[arch] < best_time)
  2755. {
  2756. fastest_arch = arch;
  2757. best_time = arch_times[arch];
  2758. }
  2759. }
  2760. starpu_heteroprio_set_faster_arch_hp(hp, fastest_arch, p);
  2761. for(arch = 0; arch < STARPU_NB_TYPES; ++arch)
  2762. {
  2763. if(valid_archs[arch] && arch != fastest_arch)
  2764. starpu_heteroprio_set_arch_slow_factor_hp(hp, arch, p, arch_times[arch]/best_time);
  2765. }
  2766. }
  2767. check_heteroprio_mapping(hp);
  2768. }
  2769. /* Push a new task (simply store it and update counters) */
  2770. static int push_task_heteroprio_policy(struct starpu_task *task)
  2771. {
  2772. unsigned sched_ctx_id = task->sched_ctx;
  2773. struct _starpu_heteroprio_data *hp = (struct _starpu_heteroprio_data*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  2774. unsigned computed_best_mem_node = 0;
  2775. unsigned best_node_now[PUSH_NB_AUTO] = {0};
  2776. if(hp->use_locality)
  2777. {
  2778. #ifdef LAHETEROPRIO_PRINT_STAT
  2779. lastats.push_to_use[starpu_worker_get_id()+1][hp->pushStrategyToUse] += 1;
  2780. #endif
  2781. //unsigned best_node_now[PUSH_NB_AUTO] = {0};
  2782. if(hp->pushStrategySet == PUSH_AUTO)
  2783. {
  2784. unsigned idx_strategy;
  2785. for(idx_strategy = 0 ; idx_strategy < PUSH_NB_AUTO ; ++idx_strategy)
  2786. {
  2787. best_node_now[idx_strategy] = get_best_mem_node(task, hp, idx_strategy);
  2788. }
  2789. }
  2790. computed_best_mem_node = (hp->pushStrategySet == PUSH_AUTO && hp->pushStrategyToUse < PUSH_NB_AUTO ?
  2791. best_node_now[hp->pushStrategyToUse]
  2792. : get_best_mem_node(task, hp, hp->pushStrategyToUse));
  2793. STARPU_ASSERT_MSG(hp->map_wgroup_has_been_called, "starpu_laheteroprio_map_wgroup_memory_nodes \
  2794. has not been called while you are using the heteroprio in LA mode. To fix this, you can either turn LA mode off by setting \
  2795. the HETEROPRIO_USE_LA variable to 0, or calling starpu_laheteroprio_map_wgroup_memory_nodes after starpu_laheteroprio_set_nb_prios.\n");
  2796. }
  2797. const unsigned best_mem_node = computed_best_mem_node;
  2798. /* One worker at a time uses heteroprio */
  2799. starpu_worker_relax_on();
  2800. STARPU_PTHREAD_MUTEX_LOCK(&hp->policy_mutex);
  2801. starpu_worker_relax_off();
  2802. /* Get taks priority (ID) */
  2803. int task_priority;
  2804. if(hp->use_auto_calibration)
  2805. {
  2806. task_priority = get_task_auto_priority(hp, task);
  2807. // TODO iterate worker only on first pushed task or before if possible (doesnt seem to work in initialization)
  2808. struct starpu_worker_collection *workers = starpu_sched_ctx_get_worker_collection(sched_ctx_id);
  2809. struct starpu_sched_ctx_iterator it;
  2810. workers->init_iterator(workers, &it);
  2811. while(workers->has_next(workers, &it))
  2812. {
  2813. unsigned workerid = workers->get_next(workers, &it);
  2814. unsigned worker_type = starpu_worker_get_type(workerid);
  2815. hp->has_worker_of_arch_type[worker_type] = 1; // update has_worker_of_arch_type here because it does not work in initialization
  2816. }
  2817. if(!hp->freeze_data_gathering)
  2818. {
  2819. if(hp->priority_last_ordering >= hp->priority_ordering_interval)
  2820. {
  2821. hp->priority_last_ordering = 0;
  2822. }
  2823. else
  2824. {
  2825. ++hp->priority_last_ordering;
  2826. }
  2827. }
  2828. if(hp->priority_last_ordering == 0)
  2829. {
  2830. // first pushed task OR at least "priority_ordering_interval" tasks have been pushed
  2831. order_priorities(hp);
  2832. if(hp->autoheteroprio_print_prio_after_ordering)
  2833. {
  2834. print_priorities(hp);
  2835. }
  2836. autoheteroprio_update_slowdown_data(hp);
  2837. ++hp->priority_last_ordering;
  2838. }
  2839. if(!hp->freeze_data_gathering)
  2840. {
  2841. struct _starpu_job *job = _starpu_get_job_associated_to_task(task);
  2842. if(task_priority != -1)
  2843. {
  2844. // register that the task has been submitted
  2845. add_submitted_task_to_data(hp, task_priority);
  2846. double NOD = get_job_NOD(hp, job);
  2847. add_NOD_to_data(hp, task_priority, NOD);
  2848. double archs_NRTs[STARPU_NARCH];
  2849. unsigned arch;
  2850. for(arch=0;arch<STARPU_NARCH;++arch)
  2851. {
  2852. archs_NRTs[arch] = get_job_NRT(hp, job, arch);
  2853. }
  2854. add_URTs_to_data(hp, task_priority, archs_NRTs);
  2855. double sum = get_job_successors_best_time_sum(hp, job);
  2856. add_successors_best_time_sum_to_data(hp, task_priority, sum);
  2857. double best_time = get_job_best_time(hp, job);
  2858. add_best_time_to_data(hp, task_priority, best_time);
  2859. }
  2860. autoheteroprio_update_slowdown_data(hp);
  2861. if(hp->autoheteroprio_print_data_on_update)
  2862. {
  2863. unsigned arch;
  2864. char is_arch_used[STARPU_NB_TYPES];
  2865. for(arch = 0; arch < STARPU_NB_TYPES; ++arch)
  2866. {
  2867. if(hp->average_arch_busy_time[arch] + hp->average_arch_free_time[arch] > 0)
  2868. is_arch_used[arch] = 1;
  2869. else
  2870. is_arch_used[arch] = 0;
  2871. }
  2872. fprintf(stderr, "Updated values :\n");
  2873. fprintf(stderr, "Busy proportion :\n\t");
  2874. for(arch = 0; arch < STARPU_NB_TYPES; ++arch)
  2875. {
  2876. if(is_arch_used[arch])
  2877. fprintf(stderr, "%s : %f, ",
  2878. starpu_worker_get_type_as_string(arch),
  2879. get_autoheteroprio_arch_busy_proportion(hp, arch));
  2880. }
  2881. fprintf(stderr, "\n");
  2882. unsigned idx_prio;
  2883. fprintf(stderr, "Assumed values for heuristic computation :\n");
  2884. for(idx_prio = 0; idx_prio < hp->found_codelet_names_length; ++idx_prio)
  2885. {
  2886. fprintf(stderr, "task %s :\n\tNOD = %f",
  2887. &hp->found_codelet_names[idx_prio][0],
  2888. get_autoheteroprio_NOD(hp, idx_prio));
  2889. for(arch = 0; arch < STARPU_NB_TYPES; ++arch)
  2890. {
  2891. if(is_arch_used[arch])
  2892. fprintf(stderr, ", URT_%s = %f",
  2893. starpu_worker_get_type_as_string(arch),
  2894. get_autoheteroprio_URT(hp, arch, idx_prio));
  2895. }
  2896. fprintf(stderr, "\n\testimated time : ");
  2897. for(arch = 0; arch < STARPU_NB_TYPES; ++arch)
  2898. {
  2899. if(is_arch_used[arch])
  2900. fprintf(stderr, "%s : %f, ",
  2901. starpu_worker_get_type_as_string(arch),
  2902. get_autoheteroprio_estimated_time(hp, idx_prio, arch));
  2903. }
  2904. fprintf(stderr, "\n\tnormalized time : ");
  2905. for(arch = 0; arch < STARPU_NB_TYPES; ++arch)
  2906. {
  2907. if(is_arch_used[arch])
  2908. fprintf(stderr, "%s : %f, ",
  2909. starpu_worker_get_type_as_string(arch),
  2910. get_autoheteroprio_normalized_time(hp, idx_prio, arch));
  2911. }
  2912. fprintf(stderr, "\n\tbestsum=%f, proportion=%f",
  2913. get_autoheteroprio_successors_best_time_sum(hp, idx_prio),
  2914. get_autoheteroprio_prio_proportion(hp, idx_prio));
  2915. for(arch = 0; arch < STARPU_NB_TYPES; ++arch)
  2916. {
  2917. if(is_arch_used[arch])
  2918. fprintf(stderr, ", prop%s=%f",
  2919. starpu_worker_get_type_as_string(arch),
  2920. get_autoheteroprio_prio_arch_proportion(hp, idx_prio, arch));
  2921. }
  2922. fprintf(stderr, "\n");
  2923. }
  2924. }
  2925. }
  2926. }
  2927. else
  2928. {
  2929. task_priority = task->priority;
  2930. }
  2931. /* Retrieve the correct bucket */
  2932. STARPU_ASSERT(task_priority >= 0);
  2933. STARPU_ASSERT(task_priority < HETEROPRIO_MAX_PRIO);
  2934. struct _heteroprio_bucket* bucket = &hp->buckets[task_priority];
  2935. /* Ensure that any worker that check that list can compute the task */
  2936. STARPU_ASSERT_MSG(bucket->valid_archs, "The bucket %d does not have any archs\n", task_priority);
  2937. STARPU_ASSERT(((bucket->valid_archs ^ task->where) & bucket->valid_archs) == 0);
  2938. if(hp->use_locality)
  2939. {
  2940. /* save the task */
  2941. starpu_task_list_push_front(&bucket->tasks_queue[best_mem_node], task);
  2942. if(hp->pushStrategySet == PUSH_AUTO)
  2943. {
  2944. laqueue_push(&bucket->auto_mn[best_mem_node], best_node_now);
  2945. }
  2946. #ifdef LAHETEROPRIO_PRINT_STAT
  2947. if( starpu_worker_get_id() != -1)
  2948. {
  2949. lastats.nb_tasks_per_wgroup[best_mem_node][task_priority] += 1;
  2950. lastats.nb_tasks_per_worker[starpu_worker_get_id()][task_priority] += 1;
  2951. }
  2952. #endif // LAHETEROPRIO_PRINT_STAT
  2953. bucket->tasks_queue_ntasks += 1;
  2954. #ifdef LAHETEROPRIO_PRINT_STAT
  2955. lastats.nb_tasks += 1;
  2956. #endif // LAHETEROPRIO_PRINT_STAT
  2957. }
  2958. else
  2959. {
  2960. /* save the task */
  2961. starpu_task_list_push_front(&bucket->tasks_queue[0],task);
  2962. /* Increase the total number of tasks */
  2963. bucket->tasks_queue_ntasks += 1;
  2964. }
  2965. /* Inc counters */
  2966. unsigned arch_index;
  2967. for(arch_index = 0; arch_index < STARPU_NB_TYPES; ++arch_index)
  2968. {
  2969. /* We test the archs on the bucket and not on task->where since it is restrictive */
  2970. if(bucket->valid_archs & starpu_heteroprio_types_to_arch(arch_index))
  2971. {
  2972. hp->nb_remaining_tasks_per_arch_index[arch_index] += 1;
  2973. }
  2974. }
  2975. hp->total_tasks_in_buckets += 1;
  2976. starpu_push_task_end(task);
  2977. /*if there are no tasks_queue block */
  2978. /* wake people waiting for a task */
  2979. struct starpu_worker_collection *workers = starpu_sched_ctx_get_worker_collection(sched_ctx_id);
  2980. struct starpu_sched_ctx_iterator it;
  2981. #ifndef STARPU_NON_BLOCKING_DRIVERS
  2982. char dowake[STARPU_NMAXWORKERS] = { 0 };
  2983. #endif
  2984. workers->init_iterator(workers, &it);
  2985. while(workers->has_next(workers, &it))
  2986. {
  2987. unsigned worker = workers->get_next(workers, &it);
  2988. #ifdef STARPU_NON_BLOCKING_DRIVERS
  2989. if (!starpu_bitmap_get(&hp->waiters, worker))
  2990. /* This worker is not waiting for a task */
  2991. continue;
  2992. #endif
  2993. if (starpu_worker_can_execute_task_first_impl(worker, task, NULL))
  2994. {
  2995. /* It can execute this one, tell him! */
  2996. #ifdef STARPU_NON_BLOCKING_DRIVERS
  2997. starpu_bitmap_unset(&hp->waiters, worker);
  2998. /* We really woke at least somebody, no need to wake somebody else */
  2999. break;
  3000. #else
  3001. dowake[worker] = 1;
  3002. #endif
  3003. }
  3004. }
  3005. /* Let the task free */
  3006. STARPU_PTHREAD_MUTEX_UNLOCK(&hp->policy_mutex);
  3007. #ifndef STARPU_NON_BLOCKING_DRIVERS
  3008. /* Now that we have a list of potential workers, try to wake one */
  3009. workers->init_iterator(workers, &it);
  3010. while(workers->has_next(workers, &it))
  3011. {
  3012. unsigned worker = workers->get_next(workers, &it);
  3013. if (dowake[worker])
  3014. if (starpu_wake_worker_relax_light(worker))
  3015. break; // wake up a single worker
  3016. }
  3017. #endif
  3018. return 0;
  3019. }
  3020. static struct starpu_task *pop_task_heteroprio_policy(unsigned sched_ctx_id)
  3021. {
  3022. const unsigned workerid = starpu_worker_get_id_check();
  3023. struct _starpu_heteroprio_data *hp = (struct _starpu_heteroprio_data*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  3024. struct _heteroprio_worker_wrapper* worker = &hp->workers_heteroprio[workerid];
  3025. struct starpu_task* task = NULL;
  3026. #ifdef STARPU_NON_BLOCKING_DRIVERS
  3027. /* If no tasks available, no tasks in worker queue or some arch worker queue just return NULL */
  3028. if (!STARPU_RUNNING_ON_VALGRIND
  3029. && (hp->total_tasks_in_buckets == 0 || hp->nb_remaining_tasks_per_arch_index[worker->arch_index] == 0)
  3030. && (hp->use_locality || (worker->tasks_queue.ntasks == 0 && hp->nb_prefetched_tasks_per_arch_index[worker->arch_index] == 0)))
  3031. {
  3032. return NULL;
  3033. }
  3034. if (!STARPU_RUNNING_ON_VALGRIND && starpu_bitmap_get(&hp->waiters, workerid))
  3035. {
  3036. /* Nobody woke us, avoid bothering the mutex */
  3037. return NULL;
  3038. }
  3039. #endif
  3040. starpu_worker_relax_on();
  3041. STARPU_PTHREAD_MUTEX_LOCK(&hp->policy_mutex);
  3042. starpu_worker_relax_off();
  3043. // if(hp->use_locality)
  3044. // {
  3045. // used only with use_locality==1
  3046. #ifdef LAHETEROPRIO_PRINT_STAT
  3047. unsigned src_mem_node = (unsigned)-1;
  3048. #endif
  3049. unsigned best_node_previous[PUSH_NB_AUTO] = {0};
  3050. // }
  3051. // else
  3052. // {
  3053. // used only with use_locality==0
  3054. /* keep track of the new added task to perfom real prefetch on node */
  3055. unsigned nb_added_tasks = 0;
  3056. // }
  3057. if (hp->use_locality)
  3058. {
  3059. const unsigned wgroupid = hp->workers_laheteroprio_wgroup_index[workerid];
  3060. if (hp->nb_remaining_tasks_per_arch_index[worker->arch_index] != 0)
  3061. {
  3062. const struct starpu_laheteroprio_access_item *wgroup_access_order = hp->wgroup_pop_access_orders[wgroupid];
  3063. const unsigned wgroup_access_order_size = hp->wgroup_pop_access_orders_size[wgroupid];
  3064. unsigned idx_access_item;
  3065. for (idx_access_item = 0; task == NULL && idx_access_item < wgroup_access_order_size; ++idx_access_item)
  3066. {
  3067. const unsigned current_wgroupid = wgroup_access_order[idx_access_item].wgroup_idx;
  3068. /*Retrieve the bucket using the mapping */
  3069. struct _heteroprio_bucket *bucket = &hp->buckets[hp->prio_mapping_per_arch_index[worker->arch_index][wgroup_access_order[idx_access_item].prio_idx]];
  3070. /*Ensure we can compute task from this bucket */
  3071. STARPU_ASSERT(bucket->valid_archs &worker->arch_type);
  3072. /*Take one task if possible */
  3073. if (!starpu_task_list_empty(&bucket->tasks_queue[current_wgroupid]))
  3074. {
  3075. if ((bucket->factor_base_arch_index == 0 ||
  3076. worker->arch_index == bucket->factor_base_arch_index ||
  3077. (((float) bucket->tasks_queue_ntasks) / ((float) hp->nb_workers_per_arch_index[bucket->factor_base_arch_index])) >= bucket->slow_factors_per_index[worker->arch_index]))
  3078. {
  3079. task = starpu_task_list_pop_front(&bucket->tasks_queue[current_wgroupid]);
  3080. if(!starpu_worker_can_execute_task(workerid, task, 0))
  3081. {
  3082. // Put the task back because worker can't execute it (e.g. codelet.can_execute)
  3083. starpu_task_list_push_front(&bucket->tasks_queue[0], task);
  3084. break;
  3085. }
  3086. if (hp->pushStrategySet == PUSH_AUTO)
  3087. {
  3088. memcpy(best_node_previous, laqueue_pop(&bucket->auto_mn[current_wgroupid]), sizeof(unsigned) *PUSH_NB_AUTO);
  3089. }
  3090. /*Save the task */
  3091. STARPU_AYU_ADDTOTASKQUEUE(starpu_task_get_job_id(task), workerid);
  3092. /*Update general counter */
  3093. hp->total_tasks_in_buckets -= 1;
  3094. bucket->tasks_queue_ntasks -= 1;
  3095. unsigned arch_index;
  3096. for (arch_index = 0; arch_index < STARPU_NB_TYPES; ++arch_index)
  3097. {
  3098. /*We test the archs on the bucket and not on task->where since it is restrictive */
  3099. if (bucket->valid_archs &starpu_heteroprio_types_to_arch(arch_index))
  3100. {
  3101. hp->nb_remaining_tasks_per_arch_index[arch_index] -= 1;
  3102. }
  3103. }
  3104. #ifdef LAHETEROPRIO_PRINT_STAT
  3105. if (current_wgroupid != wgroupid)
  3106. {
  3107. lastats.task_stolen_per_worker[workerid][wgroup_access_order[idx_access_item].prio_idx] += 1;
  3108. lastats.task_stolen_in_wgroup[current_wgroupid][wgroup_access_order[idx_access_item].prio_idx] += 1;
  3109. }
  3110. src_mem_node = current_wgroupid;
  3111. #endif
  3112. break;
  3113. }
  3114. #ifdef LAHETEROPRIO_PRINT_STAT
  3115. else
  3116. {
  3117. lastats.task_skipt_due_to_factor_per_worker[workerid][wgroup_access_order[idx_access_item].prio_idx] += 1;
  3118. }
  3119. #endif
  3120. }
  3121. #ifdef LAHETEROPRIO_PRINT_STAT
  3122. else
  3123. {
  3124. if (current_wgroupid == wgroupid)
  3125. {
  3126. lastats.task_list_empty_per_worker[workerid][wgroup_access_order[idx_access_item].prio_idx] += 1;
  3127. }
  3128. }
  3129. #endif
  3130. }
  3131. }
  3132. }
  3133. else
  3134. {
  3135. // !hp->use_locality
  3136. /* Check that some tasks are available for the current worker arch */
  3137. if( hp->nb_remaining_tasks_per_arch_index[worker->arch_index] != 0 )
  3138. {
  3139. /* Ideally we would like to fill the prefetch array */
  3140. unsigned nb_tasks_to_prefetch = (STARPU_HETEROPRIO_MAX_PREFETCH-worker->tasks_queue.ntasks);
  3141. /* But there are maybe less tasks than that! */
  3142. if(nb_tasks_to_prefetch > hp->nb_remaining_tasks_per_arch_index[worker->arch_index])
  3143. {
  3144. nb_tasks_to_prefetch = hp->nb_remaining_tasks_per_arch_index[worker->arch_index];
  3145. }
  3146. /* But in case there are less tasks than worker we take the minimum */
  3147. if(hp->nb_remaining_tasks_per_arch_index[worker->arch_index] < starpu_sched_ctx_get_nworkers(sched_ctx_id))
  3148. {
  3149. if(worker->tasks_queue.ntasks == 0)
  3150. nb_tasks_to_prefetch = 1;
  3151. else
  3152. nb_tasks_to_prefetch = 0;
  3153. }
  3154. unsigned idx_prio, arch_index;
  3155. /* We iterate until we found all the tasks we need */
  3156. for(idx_prio = 0; nb_tasks_to_prefetch && idx_prio < hp->nb_prio_per_arch_index[worker->arch_index]; ++idx_prio)
  3157. {
  3158. /* Retrieve the bucket using the mapping */
  3159. struct _heteroprio_bucket* bucket = &hp->buckets[hp->prio_mapping_per_arch_index[worker->arch_index][idx_prio]];
  3160. /* Ensure we can compute task from this bucket */
  3161. STARPU_ASSERT(bucket->valid_archs & worker->arch_type);
  3162. /* Take nb_tasks_to_prefetch tasks if possible */
  3163. while(!starpu_task_list_empty(&bucket->tasks_queue[0]) && nb_tasks_to_prefetch &&
  3164. (bucket->factor_base_arch_index == 0 ||
  3165. worker->arch_index == bucket->factor_base_arch_index ||
  3166. (((float)bucket->tasks_queue_ntasks)/((float)hp->nb_workers_per_arch_index[bucket->factor_base_arch_index])) >= bucket->slow_factors_per_index[worker->arch_index]
  3167. ))
  3168. {
  3169. task = starpu_task_list_pop_front(&bucket->tasks_queue[0]);
  3170. if(!starpu_worker_can_execute_task(workerid, task, 0))
  3171. {
  3172. // Put the task back because worker can't execute it (e.g. codelet.can_execute)
  3173. starpu_task_list_push_front(&bucket->tasks_queue[0], task);
  3174. break;
  3175. }
  3176. /* Save the task */
  3177. STARPU_AYU_ADDTOTASKQUEUE(starpu_task_get_job_id(task), workerid);
  3178. _starpu_prio_deque_push_front_task(&worker->tasks_queue, task);
  3179. /* Update general counter */
  3180. hp->nb_prefetched_tasks_per_arch_index[worker->arch_index] += 1;
  3181. hp->total_tasks_in_buckets -= 1;
  3182. bucket->tasks_queue_ntasks -= 1;
  3183. for(arch_index = 0; arch_index < STARPU_NB_TYPES; ++arch_index)
  3184. {
  3185. /* We test the archs on the bucket and not on task->where since it is restrictive */
  3186. if(bucket->valid_archs & starpu_heteroprio_types_to_arch(arch_index))
  3187. {
  3188. hp->nb_remaining_tasks_per_arch_index[arch_index] -= 1;
  3189. }
  3190. }
  3191. /* Decrease the number of tasks to found */
  3192. nb_tasks_to_prefetch -= 1;
  3193. nb_added_tasks += 1;
  3194. // TODO starpu_prefetch_task_input_for(task, workerid);
  3195. }
  3196. }
  3197. }
  3198. task = NULL;
  3199. /* The worker has some tasks in its queue */
  3200. if(worker->tasks_queue.ntasks)
  3201. {
  3202. int skipped;
  3203. task = _starpu_prio_deque_pop_task_for_worker(&worker->tasks_queue, workerid, &skipped);
  3204. hp->nb_prefetched_tasks_per_arch_index[worker->arch_index] -= 1;
  3205. }
  3206. /* Otherwise look if we can steal some work */
  3207. else if(hp->nb_prefetched_tasks_per_arch_index[worker->arch_index])
  3208. {
  3209. /* If HETEROPRIO_MAX_PREFETCH==1 it should not be possible to steal work */
  3210. STARPU_ASSERT(STARPU_HETEROPRIO_MAX_PREFETCH != 1);
  3211. struct starpu_worker_collection *workers = starpu_sched_ctx_get_worker_collection(sched_ctx_id);
  3212. struct starpu_sched_ctx_iterator it;
  3213. workers->init_iterator(workers, &it);
  3214. unsigned victim;
  3215. unsigned current_worker;
  3216. /* Start stealing from just after ourself */
  3217. while(workers->has_next(workers, &it))
  3218. {
  3219. current_worker = workers->get_next(workers, &it);
  3220. if(current_worker == workerid)
  3221. break;
  3222. }
  3223. /* circular loop */
  3224. while (1)
  3225. {
  3226. if (!workers->has_next(workers, &it))
  3227. {
  3228. /* End of the list, restart from the beginning */
  3229. workers->init_iterator(workers, &it);
  3230. }
  3231. while(workers->has_next(workers, &it))
  3232. {
  3233. victim = workers->get_next(workers, &it);
  3234. /* When getting on ourself again, we're done trying to find work */
  3235. if(victim == workerid)
  3236. goto done;
  3237. /* If it is the same arch and there is a task to steal */
  3238. if(hp->workers_heteroprio[victim].arch_index == worker->arch_index
  3239. && hp->workers_heteroprio[victim].tasks_queue.ntasks)
  3240. {
  3241. /* ensure the worker is not currently prefetching its data */
  3242. starpu_worker_lock(victim);
  3243. if(hp->workers_heteroprio[victim].arch_index == worker->arch_index
  3244. && hp->workers_heteroprio[victim].tasks_queue.ntasks)
  3245. {
  3246. int skipped;
  3247. /* steal the last added task */
  3248. task = _starpu_prio_deque_pop_task_for_worker(&hp->workers_heteroprio[victim].tasks_queue, workerid, &skipped);
  3249. /* we steal a task update global counter */
  3250. hp->nb_prefetched_tasks_per_arch_index[hp->workers_heteroprio[victim].arch_index] -= 1;
  3251. starpu_worker_unlock(victim);
  3252. goto done;
  3253. }
  3254. starpu_worker_unlock(victim);
  3255. }
  3256. }
  3257. }
  3258. done: ;
  3259. }
  3260. }
  3261. if (!task)
  3262. {
  3263. /* Tell pushers that we are waiting for tasks_queue for us */
  3264. starpu_bitmap_set(&hp->waiters, workerid);
  3265. }
  3266. STARPU_PTHREAD_MUTEX_UNLOCK(&hp->policy_mutex);
  3267. if(task &&_starpu_get_nsched_ctxs() > 1)
  3268. {
  3269. starpu_worker_relax_on();
  3270. _starpu_sched_ctx_lock_write(sched_ctx_id);
  3271. starpu_worker_relax_off();
  3272. if (_starpu_sched_ctx_worker_is_master_for_child_ctx(sched_ctx_id, workerid, task))
  3273. task = NULL;
  3274. _starpu_sched_ctx_unlock_write(sched_ctx_id);
  3275. if(hp->use_locality)
  3276. {
  3277. #ifdef LAHETEROPRIO_PRINT_STAT
  3278. {
  3279. const unsigned best_node_now = get_best_mem_node(task, hp, hp->pushStrategyToUse);
  3280. if (best_node_now != src_mem_node)
  3281. {
  3282. lastats.pop_redirect[workerid][src_mem_node] += 1;
  3283. }
  3284. }
  3285. #endif
  3286. if (hp->pushStrategySet == PUSH_AUTO)
  3287. {
  3288. unsigned best_node_now[PUSH_NB_AUTO] = { 0 };
  3289. unsigned idx_strategy;
  3290. for (idx_strategy = 0; idx_strategy < PUSH_NB_AUTO; ++idx_strategy)
  3291. {
  3292. best_node_now[idx_strategy] = get_best_mem_node(task, hp, idx_strategy);
  3293. }
  3294. STARPU_PTHREAD_MUTEX_LOCK(&hp->push_history_mutex);
  3295. unsigned idx_best_strategy = 0;
  3296. for (idx_strategy = 0; idx_strategy < PUSH_NB_AUTO; ++idx_strategy)
  3297. {
  3298. if (best_node_now[idx_strategy] == best_node_previous[idx_strategy])
  3299. {
  3300. hp->pushStrategyHistory[idx_strategy] += 1;
  3301. }
  3302. if (hp->pushStrategyHistory[idx_strategy] >=
  3303. hp->pushStrategyHistory[idx_best_strategy])
  3304. {
  3305. idx_best_strategy = idx_strategy;
  3306. }
  3307. }
  3308. hp->pushStrategyToUse = idx_best_strategy;
  3309. STARPU_PTHREAD_MUTEX_UNLOCK(&hp->push_history_mutex);
  3310. }
  3311. }
  3312. }
  3313. if(!hp->use_locality)
  3314. {
  3315. /* if we have task (task) me way have some in the queue (worker->tasks_queue_size) that was freshly addeed (nb_added_tasks) */
  3316. if(task && worker->tasks_queue.ntasks && nb_added_tasks && starpu_get_prefetch_flag())
  3317. {
  3318. /* TODO berenger: iterate in the other sense */
  3319. struct starpu_task *task_to_prefetch = NULL;
  3320. for (task_to_prefetch = starpu_task_prio_list_begin(&worker->tasks_queue.list);
  3321. (task_to_prefetch != starpu_task_prio_list_end(&worker->tasks_queue.list) &&
  3322. nb_added_tasks && hp->nb_remaining_tasks_per_arch_index[worker->arch_index] != 0);
  3323. task_to_prefetch = starpu_task_prio_list_next(&worker->tasks_queue.list, task_to_prefetch))
  3324. {
  3325. /* prefetch from closest to end task */
  3326. if (!task_to_prefetch->prefetched) /* FIXME: it seems we are prefetching several times?? */
  3327. {
  3328. starpu_prefetch_task_input_for(task_to_prefetch, workerid);
  3329. }
  3330. nb_added_tasks -= 1;
  3331. }
  3332. }
  3333. }
  3334. if(!hp->freeze_data_gathering && hp->use_auto_calibration && task)
  3335. {
  3336. // register that the task has been executed on the arch type :
  3337. int prio = get_task_auto_priority(hp, task);
  3338. if(prio != -1)
  3339. {
  3340. register_task_arch_execution(hp, prio, heteroprio_get_worker_arch_type(worker));
  3341. // register as well how much time it should take :
  3342. struct starpu_perfmodel_arch *arch_perfmodel = starpu_worker_get_perf_archtype(workerid, sched_ctx_id);
  3343. // Here we do something unclean, we register starPU's expected time for the task as the true actual execution time
  3344. // TODO : register the actual execution time instead of expected times
  3345. double expected_time = starpu_task_expected_length(task, arch_perfmodel, 0);
  3346. if(expected_time != 0 && expected_time == expected_time)
  3347. {
  3348. // is not zero and is non NAN
  3349. register_execution_time(hp, heteroprio_get_worker_arch_type(worker), prio, expected_time);
  3350. }
  3351. }
  3352. }
  3353. return task;
  3354. }
  3355. struct starpu_sched_policy _starpu_sched_heteroprio_policy =
  3356. {
  3357. .init_sched = initialize_heteroprio_policy,
  3358. .deinit_sched = deinitialize_heteroprio_policy,
  3359. .add_workers = add_workers_heteroprio_policy,
  3360. .remove_workers = remove_workers_heteroprio_policy,
  3361. .push_task = push_task_heteroprio_policy,
  3362. .simulate_push_task = NULL,
  3363. .push_task_notify = NULL,
  3364. .pop_task = pop_task_heteroprio_policy,
  3365. .pre_exec_hook = NULL,
  3366. .post_exec_hook = NULL,
  3367. .pop_every_task = NULL,
  3368. .policy_name = "heteroprio",
  3369. .policy_description = "heteroprio",
  3370. .worker_type = STARPU_WORKER_LIST,
  3371. .prefetches = 1,
  3372. };