dw_factolu.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2008-2015,2017,2018 Université de Bordeaux
  4. * Copyright (C) 2012,2013 Inria
  5. * Copyright (C) 2010 Mehdi Juhoor
  6. * Copyright (C) 2010-2013,2015-2017 CNRS
  7. * Copyright (C) 2013 Thibaut Lambert
  8. *
  9. * StarPU is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU Lesser General Public License as published by
  11. * the Free Software Foundation; either version 2.1 of the License, or (at
  12. * your option) any later version.
  13. *
  14. * StarPU is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  17. *
  18. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  19. */
  20. /*
  21. * This implements an LU factorization.
  22. * The task graph is submitted through continuation: the rest of the graph is
  23. * submitted as appropriate in the tasks' callback.
  24. */
  25. #include "dw_factolu.h"
  26. #ifdef STARPU_HAVE_HELGRIND_H
  27. #include <valgrind/helgrind.h>
  28. #endif
  29. #ifndef ANNOTATE_HAPPENS_BEFORE
  30. #define ANNOTATE_HAPPENS_BEFORE(obj) ((void)0)
  31. #endif
  32. #ifndef ANNOTATE_HAPPENS_AFTER
  33. #define ANNOTATE_HAPPENS_AFTER(obj) ((void)0)
  34. #endif
  35. #if 0
  36. #define debug(fmt, ...) fprintf(stderr, fmt, ## __VA_ARGS__)
  37. #else
  38. #define debug(fmt, ...)
  39. #endif
  40. struct starpu_perfmodel model_11;
  41. struct starpu_perfmodel model_12;
  42. struct starpu_perfmodel model_21;
  43. struct starpu_perfmodel model_22;
  44. static unsigned *advance_11; /* size nblocks, whether the 11 task is done */
  45. static unsigned *advance_12_21; /* size nblocks*nblocks */
  46. static unsigned *advance_22; /* array of nblocks *nblocks*nblocks */
  47. static double start;
  48. static double end;
  49. static unsigned no_prio = 0;
  50. static struct starpu_codelet cl11 =
  51. {
  52. .cpu_funcs = {dw_cpu_codelet_update_u11},
  53. .cpu_funcs_name = {"dw_cpu_codelet_update_u11"},
  54. #ifdef STARPU_USE_CUDA
  55. .cuda_funcs = {dw_cublas_codelet_update_u11},
  56. #endif
  57. .nbuffers = 1,
  58. .modes = {STARPU_RW},
  59. .model = &model_11
  60. };
  61. static struct starpu_codelet cl12 =
  62. {
  63. .cpu_funcs = {dw_cpu_codelet_update_u12},
  64. .cpu_funcs_name = {"dw_cpu_codelet_update_u12"},
  65. #ifdef STARPU_USE_CUDA
  66. .cuda_funcs = {dw_cublas_codelet_update_u12},
  67. #endif
  68. .cuda_flags = {STARPU_CUDA_ASYNC},
  69. .nbuffers = 2,
  70. .modes = {STARPU_R, STARPU_RW},
  71. .model = &model_12
  72. };
  73. static struct starpu_codelet cl21 =
  74. {
  75. .cpu_funcs = {dw_cpu_codelet_update_u21},
  76. .cpu_funcs_name = {"dw_cpu_codelet_update_u21"},
  77. #ifdef STARPU_USE_CUDA
  78. .cuda_funcs = {dw_cublas_codelet_update_u21},
  79. #endif
  80. .cuda_flags = {STARPU_CUDA_ASYNC},
  81. .nbuffers = 2,
  82. .modes = {STARPU_R, STARPU_RW},
  83. .model = &model_21
  84. };
  85. static struct starpu_codelet cl22 =
  86. {
  87. .cpu_funcs = {dw_cpu_codelet_update_u22},
  88. .cpu_funcs_name = {"dw_cpu_codelet_update_u22"},
  89. #ifdef STARPU_USE_CUDA
  90. .cuda_funcs = {dw_cublas_codelet_update_u22},
  91. #endif
  92. .cuda_flags = {STARPU_CUDA_ASYNC},
  93. .nbuffers = 3,
  94. .modes = {STARPU_R, STARPU_R, STARPU_RW},
  95. .model = &model_22
  96. };
  97. #define STARTED 0x01
  98. #define DONE 0x11
  99. /*
  100. * Upgraded Callbacks : break the pipeline design !
  101. */
  102. void dw_callback_v2_codelet_update_u22(void *argcb)
  103. {
  104. int ret;
  105. cl_args *args = argcb;
  106. unsigned k = args->k;
  107. unsigned i = args->i;
  108. unsigned j = args->j;
  109. unsigned nblocks = args->nblocks;
  110. debug("u22 %d %d %d\n", k, i, j);
  111. /* we did task 22k,i,j */
  112. advance_22[k*nblocks*nblocks + i + j*nblocks] = DONE;
  113. if ( (i == j) && (i == k+1))
  114. {
  115. /* we now reduce the LU22 part (recursion appears there) */
  116. cl_args *u11arg = malloc(sizeof(cl_args));
  117. struct starpu_task *task = starpu_task_create();
  118. task->callback_func = dw_callback_v2_codelet_update_u11;
  119. task->callback_arg = u11arg;
  120. task->cl = &cl11;
  121. task->cl_arg = u11arg;
  122. task->cl_arg_size = sizeof(*u11arg);
  123. task->handles[0] = starpu_data_get_sub_data(args->dataA, 2, k+1, k+1);
  124. u11arg->dataA = args->dataA;
  125. u11arg->i = k + 1;
  126. u11arg->nblocks = args->nblocks;
  127. /* schedule the codelet */
  128. if (!no_prio)
  129. task->priority = STARPU_MAX_PRIO;
  130. debug( "u22 %d %d %d start u11 %d\n", k, i, j, k + 1);
  131. ret = starpu_task_submit(task);
  132. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  133. }
  134. /* 11k+1 + 22k,k+1,j => 21 k+1,j */
  135. if ( i == k + 1 && j > k + 1)
  136. {
  137. uint8_t dep;
  138. /* 11 k+1*/
  139. dep = advance_11[(k+1)];
  140. if (dep & DONE)
  141. {
  142. /* try to push the task */
  143. uint8_t u = STARPU_ATOMIC_OR(&advance_12_21[(k+1) + j*nblocks], STARTED);
  144. if ((u & STARTED) == 0)
  145. {
  146. /* we are the only one that should launch that task */
  147. cl_args *u21a = malloc(sizeof(cl_args));
  148. struct starpu_task *task21 = starpu_task_create();
  149. task21->callback_func = dw_callback_v2_codelet_update_u21;
  150. task21->callback_arg = u21a;
  151. task21->cl = &cl21;
  152. task21->cl_arg = u21a;
  153. task21->cl_arg_size = sizeof(*u21a);
  154. u21a->i = k+1;
  155. u21a->k = j;
  156. u21a->nblocks = args->nblocks;
  157. u21a->dataA = args->dataA;
  158. task21->handles[0] = starpu_data_get_sub_data(args->dataA, 2, u21a->i, u21a->i);
  159. task21->handles[1] = starpu_data_get_sub_data(args->dataA, 2, u21a->i, u21a->k);
  160. debug( "u22 %d %d %d start u21 %d %d\n", k, i, j, k+1, j);
  161. ret = starpu_task_submit(task21);
  162. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  163. }
  164. }
  165. }
  166. /* 11k + 22k-1,i,k => 12 k,i */
  167. if (j == k + 1 && i > k + 1)
  168. {
  169. uint8_t dep;
  170. /* 11 k+1*/
  171. dep = advance_11[(k+1)];
  172. if (dep & DONE)
  173. {
  174. /* try to push the task */
  175. uint8_t u = STARPU_ATOMIC_OR(&advance_12_21[(k+1)*nblocks + i], STARTED);
  176. if ((u & STARTED) == 0)
  177. {
  178. /* we are the only one that should launch that task */
  179. cl_args *u12a = malloc(sizeof(cl_args));
  180. struct starpu_task *task12 = starpu_task_create();
  181. task12->callback_func = dw_callback_v2_codelet_update_u12;
  182. task12->callback_arg = u12a;
  183. task12->cl = &cl12;
  184. task12->cl_arg = u12a;
  185. task12->cl_arg_size = sizeof(*u12a);
  186. u12a->i = k+1;
  187. u12a->k = i;
  188. u12a->nblocks = args->nblocks;
  189. u12a->dataA = args->dataA;
  190. task12->handles[0] = starpu_data_get_sub_data(args->dataA, 2, u12a->i, u12a->i);
  191. task12->handles[1] = starpu_data_get_sub_data(args->dataA, 2, u12a->k, u12a->i);
  192. debug( "u22 %d %d %d start u12 %d %d\n", k, i, j, k+1, i);
  193. ret = starpu_task_submit(task12);
  194. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  195. }
  196. }
  197. }
  198. free(args);
  199. }
  200. void dw_callback_v2_codelet_update_u12(void *argcb)
  201. {
  202. int ret;
  203. cl_args *args = argcb;
  204. /* now launch the update of LU22 */
  205. unsigned i = args->i;
  206. unsigned k = args->k;
  207. unsigned nblocks = args->nblocks;
  208. debug( "u12 %d %d\n", i, k);
  209. /* we did task 21i,k */
  210. advance_12_21[i*nblocks + k] = DONE;
  211. unsigned slicey;
  212. for (slicey = i+1; slicey < nblocks; slicey++)
  213. {
  214. /* can we launch 22 i,args->k,slicey ? */
  215. /* deps : 21 args->k, slicey */
  216. uint8_t dep;
  217. dep = advance_12_21[i + slicey*nblocks];
  218. if (dep & DONE)
  219. {
  220. /* perhaps we may schedule the 22 i,args->k,slicey task */
  221. uint8_t u = STARPU_ATOMIC_OR(&advance_22[i*nblocks*nblocks + slicey*nblocks + k], STARTED);
  222. if ((u & STARTED) == 0)
  223. {
  224. /* update that square matrix */
  225. cl_args *u22a = malloc(sizeof(cl_args));
  226. struct starpu_task *task22 = starpu_task_create();
  227. task22->callback_func = dw_callback_v2_codelet_update_u22;
  228. task22->callback_arg = u22a;
  229. task22->cl = &cl22;
  230. task22->cl_arg = u22a;
  231. task22->cl_arg_size = sizeof(*u22a);
  232. u22a->k = i;
  233. u22a->i = k;
  234. u22a->j = slicey;
  235. u22a->dataA = args->dataA;
  236. u22a->nblocks = nblocks;
  237. task22->handles[0] = starpu_data_get_sub_data(args->dataA, 2, u22a->i, u22a->k);
  238. task22->handles[1] = starpu_data_get_sub_data(args->dataA, 2, u22a->k, u22a->j);
  239. task22->handles[2] = starpu_data_get_sub_data(args->dataA, 2, u22a->i, u22a->j);
  240. /* schedule that codelet */
  241. if (!no_prio && (slicey == i+1))
  242. task22->priority = STARPU_MAX_PRIO;
  243. debug( "u12 %d %d start u22 %d %d %d\n", i, k, i, k, slicey);
  244. ret = starpu_task_submit(task22);
  245. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  246. }
  247. }
  248. }
  249. free(argcb);
  250. }
  251. void dw_callback_v2_codelet_update_u21(void *argcb)
  252. {
  253. int ret;
  254. cl_args *args = argcb;
  255. /* now launch the update of LU22 */
  256. unsigned i = args->i;
  257. unsigned k = args->k;
  258. unsigned nblocks = args->nblocks;
  259. /* we did task 21i,k */
  260. advance_12_21[i + k*nblocks] = DONE;
  261. debug("u21 %d %d\n", i, k);
  262. unsigned slicex;
  263. for (slicex = i+1; slicex < nblocks; slicex++)
  264. {
  265. /* can we launch 22 i,slicex,k ? */
  266. /* deps : 12 slicex k */
  267. uint8_t dep;
  268. dep = advance_12_21[i*nblocks + slicex];
  269. if (dep & DONE)
  270. {
  271. /* perhaps we may schedule the 22 i,args->k,slicey task */
  272. uint8_t u = STARPU_ATOMIC_OR(&advance_22[i*nblocks*nblocks + k*nblocks + slicex], STARTED);
  273. if ((u & STARTED) == 0)
  274. {
  275. /* update that square matrix */
  276. cl_args *u22a = malloc(sizeof(cl_args));
  277. struct starpu_task *task22 = starpu_task_create();
  278. task22->callback_func = dw_callback_v2_codelet_update_u22;
  279. task22->callback_arg = u22a;
  280. task22->cl = &cl22;
  281. task22->cl_arg = u22a;
  282. task22->cl_arg_size = sizeof(*u22a);
  283. u22a->k = i;
  284. u22a->i = slicex;
  285. u22a->j = k;
  286. u22a->dataA = args->dataA;
  287. u22a->nblocks = nblocks;
  288. task22->handles[0] = starpu_data_get_sub_data(args->dataA, 2, u22a->i, u22a->k);
  289. task22->handles[1] = starpu_data_get_sub_data(args->dataA, 2, u22a->k, u22a->j);
  290. task22->handles[2] = starpu_data_get_sub_data(args->dataA, 2, u22a->i, u22a->j);
  291. /* schedule that codelet */
  292. if (!no_prio && (slicex == i+1))
  293. task22->priority = STARPU_MAX_PRIO;
  294. debug( "u21 %d %d start u22 %d %d %d\n", i, k, i, slicex, k);
  295. ret = starpu_task_submit(task22);
  296. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  297. }
  298. }
  299. }
  300. free(argcb);
  301. }
  302. void dw_callback_v2_codelet_update_u11(void *argcb)
  303. {
  304. /* in case there remains work, go on */
  305. cl_args *args = argcb;
  306. unsigned nblocks = args->nblocks;
  307. unsigned i = args->i;
  308. debug("u11 %d\n", i);
  309. /* we did task 11k */
  310. advance_11[i] = DONE;
  311. if (i == nblocks - 1)
  312. {
  313. /* we are done */
  314. free(argcb);
  315. return;
  316. }
  317. else
  318. {
  319. /* put new tasks */
  320. unsigned slice;
  321. for (slice = i + 1; slice < nblocks; slice++)
  322. {
  323. /* can we launch 12i,slice ? */
  324. uint8_t deps12;
  325. if (i == 0)
  326. {
  327. deps12 = DONE;
  328. }
  329. else
  330. {
  331. deps12 = advance_22[(i-1)*nblocks*nblocks + slice + i*nblocks];
  332. }
  333. if (deps12 & DONE)
  334. {
  335. /* we may perhaps launch the task 12i,slice */
  336. uint8_t u = STARPU_ATOMIC_OR(&advance_12_21[i*nblocks + slice], STARTED);
  337. if ((u & STARTED) == 0)
  338. {
  339. int ret;
  340. /* we are the only one that should launch that task */
  341. cl_args *u12a = malloc(sizeof(cl_args));
  342. struct starpu_task *task12 = starpu_task_create();
  343. task12->callback_func = dw_callback_v2_codelet_update_u12;
  344. task12->callback_arg = u12a;
  345. task12->cl = &cl12;
  346. task12->cl_arg = u12a;
  347. task12->cl_arg_size = sizeof(*u12a);
  348. u12a->i = i;
  349. u12a->k = slice;
  350. u12a->nblocks = args->nblocks;
  351. u12a->dataA = args->dataA;
  352. task12->handles[0] = starpu_data_get_sub_data(args->dataA, 2, u12a->i, u12a->i);
  353. task12->handles[1] = starpu_data_get_sub_data(args->dataA, 2, u12a->k, u12a->i);
  354. if (!no_prio && (slice == i +1))
  355. task12->priority = STARPU_MAX_PRIO;
  356. debug( "u11 %d start u12 %d %d\n", i, i, slice);
  357. ret = starpu_task_submit(task12);
  358. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  359. }
  360. }
  361. /* can we launch 21i,slice ? */
  362. if (i == 0)
  363. {
  364. deps12 = DONE;
  365. }
  366. else
  367. {
  368. deps12 = advance_22[(i-1)*nblocks*nblocks + slice*nblocks + i];
  369. }
  370. if (deps12 & DONE)
  371. {
  372. /* we may perhaps launch the task 12i,slice */
  373. uint8_t u = STARPU_ATOMIC_OR(&advance_12_21[i + slice*nblocks], STARTED);
  374. if ((u & STARTED) == 0)
  375. {
  376. int ret;
  377. /* we are the only one that should launch that task */
  378. cl_args *u21a = malloc(sizeof(cl_args));
  379. struct starpu_task *task21 = starpu_task_create();
  380. task21->callback_func = dw_callback_v2_codelet_update_u21;
  381. task21->callback_arg = u21a;
  382. task21->cl = &cl21;
  383. task21->cl_arg = u21a;
  384. task21->cl_arg_size = sizeof(*u21a);
  385. u21a->i = i;
  386. u21a->k = slice;
  387. u21a->nblocks = args->nblocks;
  388. u21a->dataA = args->dataA;
  389. task21->handles[0] = starpu_data_get_sub_data(args->dataA, 2, u21a->i, u21a->i);
  390. task21->handles[1] = starpu_data_get_sub_data(args->dataA, 2, u21a->i, u21a->k);
  391. if (!no_prio && (slice == i +1))
  392. task21->priority = STARPU_MAX_PRIO;
  393. debug( "u11 %d start u21 %d %d\n", i, i, slice);
  394. ret = starpu_task_submit(task21);
  395. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  396. }
  397. }
  398. }
  399. }
  400. free(argcb);
  401. }
  402. /*
  403. * Callbacks
  404. */
  405. void dw_callback_codelet_update_u11(void *argcb)
  406. {
  407. /* in case there remains work, go on */
  408. cl_args *args = argcb;
  409. if (args->i == args->nblocks - 1)
  410. {
  411. /* we are done */
  412. free(argcb);
  413. return;
  414. }
  415. else
  416. {
  417. /* put new tasks */
  418. unsigned nslices;
  419. nslices = args->nblocks - 1 - args->i;
  420. unsigned *remaining = malloc(sizeof(unsigned));
  421. *remaining = 2*nslices;
  422. unsigned slice;
  423. for (slice = args->i + 1; slice < args->nblocks; slice++)
  424. {
  425. int ret;
  426. /* update slice from u12 */
  427. cl_args *u12a = malloc(sizeof(cl_args));
  428. /* update slice from u21 */
  429. cl_args *u21a = malloc(sizeof(cl_args));
  430. struct starpu_task *task12 = starpu_task_create();
  431. task12->callback_func = dw_callback_codelet_update_u12_21;
  432. task12->callback_arg = u12a;
  433. task12->cl = &cl12;
  434. task12->cl_arg = u12a;
  435. task12->cl_arg_size = sizeof(*u12a);
  436. struct starpu_task *task21 = starpu_task_create();
  437. task21->callback_func = dw_callback_codelet_update_u12_21;
  438. task21->callback_arg = u21a;
  439. task21->cl = &cl21;
  440. task21->cl_arg = u21a;
  441. task21->cl_arg_size = sizeof(*u21a);
  442. u12a->i = args->i;
  443. u12a->k = slice;
  444. u12a->nblocks = args->nblocks;
  445. u12a->dataA = args->dataA;
  446. u12a->remaining = remaining;
  447. u21a->i = args->i;
  448. u21a->k = slice;
  449. u21a->nblocks = args->nblocks;
  450. u21a->dataA = args->dataA;
  451. u21a->remaining = remaining;
  452. task12->handles[0] = starpu_data_get_sub_data(args->dataA, 2, u12a->i, u12a->i);
  453. task12->handles[1] = starpu_data_get_sub_data(args->dataA, 2, u12a->k, u12a->i);
  454. task21->handles[0] = starpu_data_get_sub_data(args->dataA, 2, u21a->i, u21a->i);
  455. task21->handles[1] = starpu_data_get_sub_data(args->dataA, 2, u21a->i, u21a->k);
  456. ret = starpu_task_submit(task12);
  457. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  458. ret = starpu_task_submit(task21);
  459. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  460. }
  461. free(remaining);
  462. }
  463. }
  464. void dw_callback_codelet_update_u22(void *argcb)
  465. {
  466. cl_args *args = argcb;
  467. unsigned remaining = STARPU_ATOMIC_ADD(args->remaining, (-1));
  468. ANNOTATE_HAPPENS_BEFORE(args->remaining);
  469. if (remaining == 0)
  470. {
  471. int ret;
  472. ANNOTATE_HAPPENS_AFTER(args->remaining);
  473. /* all worker already used the counter */
  474. free(args->remaining);
  475. /* we now reduce the LU22 part (recursion appears there) */
  476. cl_args *u11arg = malloc(sizeof(cl_args));
  477. struct starpu_task *task = starpu_task_create();
  478. task->callback_func = dw_callback_codelet_update_u11;
  479. task->callback_arg = u11arg;
  480. task->cl = &cl11;
  481. task->cl_arg = u11arg;
  482. task->cl_arg_size = sizeof(*u11arg);
  483. task->handles[0] = starpu_data_get_sub_data(args->dataA, 2, args->k + 1, args->k + 1);
  484. u11arg->dataA = args->dataA;
  485. u11arg->i = args->k + 1;
  486. u11arg->nblocks = args->nblocks;
  487. /* schedule the codelet */
  488. ret = starpu_task_submit(task);
  489. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  490. }
  491. free(args);
  492. }
  493. void dw_callback_codelet_update_u12_21(void *argcb)
  494. {
  495. cl_args *args = argcb;
  496. unsigned remaining = STARPU_ATOMIC_ADD(args->remaining, -1);
  497. ANNOTATE_HAPPENS_BEFORE(args->remaining);
  498. if (remaining == 0)
  499. {
  500. ANNOTATE_HAPPENS_AFTER(args->remaining);
  501. /* now launch the update of LU22 */
  502. unsigned i = args->i;
  503. unsigned nblocks = args->nblocks;
  504. /* the number of tasks to be done */
  505. unsigned *remaining_tasks = malloc(sizeof(unsigned));
  506. *remaining_tasks = (nblocks - 1 - i)*(nblocks - 1 - i);
  507. unsigned slicey, slicex;
  508. for (slicey = i+1; slicey < nblocks; slicey++)
  509. {
  510. for (slicex = i+1; slicex < nblocks; slicex++)
  511. {
  512. int ret;
  513. /* update that square matrix */
  514. cl_args *u22a = malloc(sizeof(cl_args));
  515. struct starpu_task *task22 = starpu_task_create();
  516. task22->callback_func = dw_callback_codelet_update_u22;
  517. task22->callback_arg = u22a;
  518. task22->cl = &cl22;
  519. task22->cl_arg = u22a;
  520. task22->cl_arg_size = sizeof(*u22a);
  521. u22a->k = i;
  522. u22a->i = slicex;
  523. u22a->j = slicey;
  524. u22a->dataA = args->dataA;
  525. u22a->nblocks = nblocks;
  526. u22a->remaining = remaining_tasks;
  527. task22->handles[0] = starpu_data_get_sub_data(args->dataA, 2, u22a->i, u22a->k);
  528. task22->handles[1] = starpu_data_get_sub_data(args->dataA, 2, u22a->k, u22a->j);
  529. task22->handles[2] = starpu_data_get_sub_data(args->dataA, 2, u22a->i, u22a->j);
  530. /* schedule that codelet */
  531. ret = starpu_task_submit(task22);
  532. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  533. }
  534. }
  535. free(remaining_tasks);
  536. }
  537. }
  538. /*
  539. * code to bootstrap the factorization
  540. */
  541. void dw_codelet_facto(starpu_data_handle_t dataA, unsigned nblocks)
  542. {
  543. int ret;
  544. cl_args *args = malloc(sizeof(cl_args));
  545. args->i = 0;
  546. args->nblocks = nblocks;
  547. args->dataA = dataA;
  548. start = starpu_timing_now();
  549. /* inject a new task with this codelet into the system */
  550. struct starpu_task *task = starpu_task_create();
  551. task->callback_func = dw_callback_codelet_update_u11;
  552. task->callback_arg = args;
  553. task->cl = &cl11;
  554. task->cl_arg = args;
  555. task->handles[0] = starpu_data_get_sub_data(dataA, 2, 0, 0);
  556. /* schedule the codelet */
  557. ret = starpu_task_submit(task);
  558. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  559. starpu_task_wait_for_all();
  560. end = starpu_timing_now();
  561. double timing = end - start;
  562. unsigned n = starpu_matrix_get_nx(dataA);
  563. double flop = (2.0f*n*n*n)/3.0f;
  564. PRINTF("# size\tms\tGFlops\n");
  565. PRINTF("%u\t%.0f\t%.1f\n", n, timing/1000, flop/timing/1000.0f);
  566. }
  567. void dw_codelet_facto_v2(starpu_data_handle_t dataA, unsigned nblocks)
  568. {
  569. advance_11 = calloc(nblocks, sizeof(*advance_11));
  570. STARPU_ASSERT(advance_11);
  571. advance_12_21 = calloc(nblocks*nblocks, sizeof(*advance_12_21));
  572. STARPU_ASSERT(advance_12_21);
  573. advance_22 = calloc(nblocks*nblocks*nblocks, sizeof(*advance_22));
  574. STARPU_ASSERT(advance_22);
  575. cl_args *args = malloc(sizeof(cl_args));
  576. args->i = 0;
  577. args->nblocks = nblocks;
  578. args->dataA = dataA;
  579. start = starpu_timing_now();
  580. /* inject a new task with this codelet into the system */
  581. struct starpu_task *task = starpu_task_create();
  582. task->callback_func = dw_callback_v2_codelet_update_u11;
  583. task->callback_arg = args;
  584. task->cl = &cl11;
  585. task->cl_arg = args;
  586. task->cl_arg_size = sizeof(*args);
  587. task->handles[0] = starpu_data_get_sub_data(dataA, 2, 0, 0);
  588. /* schedule the codelet */
  589. int ret = starpu_task_submit(task);
  590. if (STARPU_UNLIKELY(ret == -ENODEV))
  591. {
  592. FPRINTF(stderr, "No worker may execute this task\n");
  593. exit(0);
  594. }
  595. starpu_task_wait_for_all();
  596. end = starpu_timing_now();
  597. double timing = end - start;
  598. unsigned n = starpu_matrix_get_nx(dataA);
  599. double flop = (2.0f*n*n*n)/3.0f;
  600. PRINTF("# size\tms\tGFlops\n");
  601. PRINTF("%u\t%.0f\t%.1f\n", n, timing/1000, flop/timing/1000.0f);
  602. free(advance_11);
  603. free(advance_12_21);
  604. free(advance_22);
  605. }
  606. void initialize_system(float **A, float **B, unsigned dim, unsigned pinned)
  607. {
  608. int ret;
  609. ret = starpu_init(NULL);
  610. if (ret == -ENODEV)
  611. exit(77);
  612. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  613. #ifdef STARPU_ATLAS
  614. char * symbol_11 = "lu_model_11_atlas";
  615. char * symbol_12 = "lu_model_12_atlas";
  616. char * symbol_21 = "lu_model_21_atlas";
  617. char * symbol_22 = "lu_model_22_atlas";
  618. #elif defined(STARPU_GOTO)
  619. char * symbol_11 = "lu_model_11_goto";
  620. char * symbol_12 = "lu_model_12_goto";
  621. char * symbol_21 = "lu_model_21_goto";
  622. char * symbol_22 = "lu_model_22_goto";
  623. #elif defined(STARPU_OPENBLAS)
  624. char * symbol_11 = "lu_model_11_openblas";
  625. char * symbol_12 = "lu_model_12_openblas";
  626. char * symbol_21 = "lu_model_21_openblas";
  627. char * symbol_22 = "lu_model_22_openblas";
  628. #else
  629. char * symbol_11 = "lu_model_11";
  630. char * symbol_12 = "lu_model_12";
  631. char * symbol_21 = "lu_model_21";
  632. char * symbol_22 = "lu_model_22";
  633. #endif
  634. initialize_lu_kernels_model(&model_11,symbol_11,task_11_cost,task_11_cost_cpu,task_11_cost_cuda);
  635. initialize_lu_kernels_model(&model_12,symbol_12,task_12_cost,task_12_cost_cpu,task_12_cost_cuda);
  636. initialize_lu_kernels_model(&model_21,symbol_21,task_21_cost,task_21_cost_cpu,task_21_cost_cuda);
  637. initialize_lu_kernels_model(&model_22,symbol_22,task_22_cost,task_22_cost_cpu,task_22_cost_cuda);
  638. starpu_cublas_init();
  639. if (pinned)
  640. {
  641. starpu_malloc((void **)A, (size_t)dim*dim*sizeof(float));
  642. starpu_malloc((void **)B, (size_t)dim*sizeof(float));
  643. }
  644. else
  645. {
  646. *A = malloc((size_t)dim*dim*sizeof(float));
  647. STARPU_ASSERT(*A);
  648. *B = malloc((size_t)dim*sizeof(float));
  649. STARPU_ASSERT(*B);
  650. }
  651. }
  652. void free_system(float *A, float *B, unsigned pinned)
  653. {
  654. if (pinned)
  655. {
  656. starpu_free(A);
  657. starpu_free(B);
  658. }
  659. else
  660. {
  661. free(A);
  662. free(B);
  663. }
  664. }
  665. void dw_factoLU(float *matA, unsigned size,
  666. unsigned ld, unsigned nblocks,
  667. unsigned version, unsigned _no_prio)
  668. {
  669. #ifdef CHECK_RESULTS
  670. FPRINTF(stderr, "Checking results ...\n");
  671. float *Asaved;
  672. Asaved = malloc((size_t)ld*ld*sizeof(float));
  673. memcpy(Asaved, matA, (size_t)ld*ld*sizeof(float));
  674. #endif
  675. no_prio = _no_prio;
  676. starpu_data_handle_t dataA;
  677. /* monitor and partition the A matrix into blocks :
  678. * one block is now determined by 2 unsigned (i,j) */
  679. starpu_matrix_data_register(&dataA, STARPU_MAIN_RAM, (uintptr_t)matA, ld,
  680. size, size, sizeof(float));
  681. struct starpu_data_filter f =
  682. {
  683. .filter_func = starpu_matrix_filter_vertical_block,
  684. .nchildren = nblocks
  685. };
  686. struct starpu_data_filter f2 =
  687. {
  688. .filter_func = starpu_matrix_filter_block,
  689. .nchildren = nblocks
  690. };
  691. starpu_data_map_filters(dataA, 2, &f, &f2);
  692. switch (version)
  693. {
  694. case 1:
  695. dw_codelet_facto(dataA, nblocks);
  696. break;
  697. default:
  698. case 2:
  699. dw_codelet_facto_v2(dataA, nblocks);
  700. break;
  701. }
  702. /* gather all the data */
  703. starpu_data_unpartition(dataA, STARPU_MAIN_RAM);
  704. starpu_data_unregister(dataA);
  705. #ifdef CHECK_RESULTS
  706. compare_A_LU(Asaved, matA, size, ld);
  707. #endif
  708. }