dw_factolu.c 22 KB

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