dw_factolu.c 22 KB

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