dw_factolu.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2015 Université de Bordeaux
  4. * Copyright (C) 2010 Mehdi Juhoor <mjuhoor@gmail.com>
  5. * Copyright (C) 2010, 2011, 2012 CNRS
  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. .cuda_flags = {STARPU_CUDA_ASYNC},
  66. #endif
  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. .cuda_flags = {STARPU_CUDA_ASYNC},
  78. #endif
  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. .cuda_flags = {STARPU_CUDA_ASYNC},
  90. #endif
  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. int ret;
  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. /* 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. /* we are the only one that should launch that task */
  375. cl_args *u21a = malloc(sizeof(cl_args));
  376. struct starpu_task *task21 = starpu_task_create();
  377. task21->callback_func = dw_callback_v2_codelet_update_u21;
  378. task21->callback_arg = u21a;
  379. task21->cl = &cl21;
  380. task21->cl_arg = u21a;
  381. task21->cl_arg_size = sizeof(*u21a);
  382. u21a->i = i;
  383. u21a->k = slice;
  384. u21a->nblocks = args->nblocks;
  385. u21a->dataA = args->dataA;
  386. task21->handles[0] = starpu_data_get_sub_data(args->dataA, 2, u21a->i, u21a->i);
  387. task21->handles[1] = starpu_data_get_sub_data(args->dataA, 2, u21a->i, u21a->k);
  388. if (!no_prio && (slice == i +1))
  389. task21->priority = STARPU_MAX_PRIO;
  390. debug( "u11 %d start u21 %d %d\n", i, i, slice);
  391. ret = starpu_task_submit(task21);
  392. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  393. }
  394. }
  395. }
  396. }
  397. free(argcb);
  398. }
  399. /*
  400. * Callbacks
  401. */
  402. void dw_callback_codelet_update_u11(void *argcb)
  403. {
  404. int ret;
  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. /* update slice from u12 */
  424. cl_args *u12a = malloc(sizeof(cl_args));
  425. /* update slice from u21 */
  426. cl_args *u21a = malloc(sizeof(cl_args));
  427. struct starpu_task *task12 = starpu_task_create();
  428. task12->callback_func = dw_callback_codelet_update_u12_21;
  429. task12->callback_arg = u12a;
  430. task12->cl = &cl12;
  431. task12->cl_arg = u12a;
  432. task12->cl_arg_size = sizeof(*u12a);
  433. struct starpu_task *task21 = starpu_task_create();
  434. task21->callback_func = dw_callback_codelet_update_u12_21;
  435. task21->callback_arg = u21a;
  436. task21->cl = &cl21;
  437. task21->cl_arg = u21a;
  438. task21->cl_arg_size = sizeof(*u21a);
  439. u12a->i = args->i;
  440. u12a->k = slice;
  441. u12a->nblocks = args->nblocks;
  442. u12a->dataA = args->dataA;
  443. u12a->remaining = remaining;
  444. u21a->i = args->i;
  445. u21a->k = slice;
  446. u21a->nblocks = args->nblocks;
  447. u21a->dataA = args->dataA;
  448. u21a->remaining = remaining;
  449. task12->handles[0] = starpu_data_get_sub_data(args->dataA, 2, u12a->i, u12a->i);
  450. task12->handles[1] = starpu_data_get_sub_data(args->dataA, 2, u12a->k, u12a->i);
  451. task21->handles[0] = starpu_data_get_sub_data(args->dataA, 2, u21a->i, u21a->i);
  452. task21->handles[1] = starpu_data_get_sub_data(args->dataA, 2, u21a->i, u21a->k);
  453. ret = starpu_task_submit(task12);
  454. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  455. ret = starpu_task_submit(task21);
  456. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  457. }
  458. }
  459. }
  460. void dw_callback_codelet_update_u22(void *argcb)
  461. {
  462. int ret;
  463. cl_args *args = argcb;
  464. unsigned remaining = STARPU_ATOMIC_ADD(args->remaining, (-1));
  465. ANNOTATE_HAPPENS_BEFORE(args->remaining);
  466. if (remaining == 0)
  467. {
  468. ANNOTATE_HAPPENS_AFTER(args->remaining);
  469. /* all worker already used the counter */
  470. free(args->remaining);
  471. /* we now reduce the LU22 part (recursion appears there) */
  472. cl_args *u11arg = malloc(sizeof(cl_args));
  473. struct starpu_task *task = starpu_task_create();
  474. task->callback_func = dw_callback_codelet_update_u11;
  475. task->callback_arg = u11arg;
  476. task->cl = &cl11;
  477. task->cl_arg = u11arg;
  478. task->cl_arg_size = sizeof(*u11arg);
  479. task->handles[0] = starpu_data_get_sub_data(args->dataA, 2, args->k + 1, args->k + 1);
  480. u11arg->dataA = args->dataA;
  481. u11arg->i = args->k + 1;
  482. u11arg->nblocks = args->nblocks;
  483. /* schedule the codelet */
  484. ret = starpu_task_submit(task);
  485. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  486. }
  487. free(args);
  488. }
  489. void dw_callback_codelet_update_u12_21(void *argcb)
  490. {
  491. int ret;
  492. cl_args *args = argcb;
  493. unsigned remaining = STARPU_ATOMIC_ADD(args->remaining, -1);
  494. ANNOTATE_HAPPENS_BEFORE(args->remaining);
  495. if (remaining == 0)
  496. {
  497. ANNOTATE_HAPPENS_AFTER(args->remaining);
  498. /* now launch the update of LU22 */
  499. unsigned i = args->i;
  500. unsigned nblocks = args->nblocks;
  501. /* the number of tasks to be done */
  502. unsigned *remaining = malloc(sizeof(unsigned));
  503. *remaining = (nblocks - 1 - i)*(nblocks - 1 - i);
  504. unsigned slicey, slicex;
  505. for (slicey = i+1; slicey < nblocks; slicey++)
  506. {
  507. for (slicex = i+1; slicex < nblocks; slicex++)
  508. {
  509. /* update that square matrix */
  510. cl_args *u22a = malloc(sizeof(cl_args));
  511. struct starpu_task *task22 = starpu_task_create();
  512. task22->callback_func = dw_callback_codelet_update_u22;
  513. task22->callback_arg = u22a;
  514. task22->cl = &cl22;
  515. task22->cl_arg = u22a;
  516. task22->cl_arg_size = sizeof(*u22a);
  517. u22a->k = i;
  518. u22a->i = slicex;
  519. u22a->j = slicey;
  520. u22a->dataA = args->dataA;
  521. u22a->nblocks = nblocks;
  522. u22a->remaining = remaining;
  523. task22->handles[0] = starpu_data_get_sub_data(args->dataA, 2, u22a->i, u22a->k);
  524. task22->handles[1] = starpu_data_get_sub_data(args->dataA, 2, u22a->k, u22a->j);
  525. task22->handles[2] = starpu_data_get_sub_data(args->dataA, 2, u22a->i, u22a->j);
  526. /* schedule that codelet */
  527. ret = starpu_task_submit(task22);
  528. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  529. }
  530. }
  531. }
  532. }
  533. /*
  534. * code to bootstrap the factorization
  535. */
  536. void dw_codelet_facto(starpu_data_handle_t dataA, unsigned nblocks)
  537. {
  538. int ret;
  539. cl_args *args = malloc(sizeof(cl_args));
  540. args->i = 0;
  541. args->nblocks = nblocks;
  542. args->dataA = dataA;
  543. start = starpu_timing_now();
  544. /* inject a new task with this codelet into the system */
  545. struct starpu_task *task = starpu_task_create();
  546. task->callback_func = dw_callback_codelet_update_u11;
  547. task->callback_arg = args;
  548. task->cl = &cl11;
  549. task->cl_arg = args;
  550. task->handles[0] = starpu_data_get_sub_data(dataA, 2, 0, 0);
  551. /* schedule the codelet */
  552. ret = starpu_task_submit(task);
  553. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  554. starpu_task_wait_for_all();
  555. end = starpu_timing_now();
  556. double timing = end - start;
  557. unsigned n = starpu_matrix_get_nx(dataA);
  558. double flop = (2.0f*n*n*n)/3.0f;
  559. PRINTF("# size\tms\tGFlops\n");
  560. PRINTF("%u\t%.0f\t%.1f\n", n, timing/1000, flop/timing/1000.0f);
  561. }
  562. void dw_codelet_facto_v2(starpu_data_handle_t dataA, unsigned nblocks)
  563. {
  564. advance_11 = calloc(nblocks, sizeof(*advance_11));
  565. STARPU_ASSERT(advance_11);
  566. advance_12_21 = calloc(nblocks*nblocks, sizeof(*advance_12_21));
  567. STARPU_ASSERT(advance_12_21);
  568. advance_22 = calloc(nblocks*nblocks*nblocks, sizeof(*advance_22));
  569. STARPU_ASSERT(advance_22);
  570. cl_args *args = malloc(sizeof(cl_args));
  571. args->i = 0;
  572. args->nblocks = nblocks;
  573. args->dataA = dataA;
  574. start = starpu_timing_now();
  575. /* inject a new task with this codelet into the system */
  576. struct starpu_task *task = starpu_task_create();
  577. task->callback_func = dw_callback_v2_codelet_update_u11;
  578. task->callback_arg = args;
  579. task->cl = &cl11;
  580. task->cl_arg = args;
  581. task->cl_arg_size = sizeof(*args);
  582. task->handles[0] = starpu_data_get_sub_data(dataA, 2, 0, 0);
  583. /* schedule the codelet */
  584. int ret = starpu_task_submit(task);
  585. if (STARPU_UNLIKELY(ret == -ENODEV))
  586. {
  587. FPRINTF(stderr, "No worker may execute this task\n");
  588. exit(0);
  589. }
  590. starpu_task_wait_for_all();
  591. end = starpu_timing_now();
  592. double timing = end - start;
  593. unsigned n = starpu_matrix_get_nx(dataA);
  594. double flop = (2.0f*n*n*n)/3.0f;
  595. PRINTF("# size\tms\tGFlops\n");
  596. PRINTF("%u\t%.0f\t%.1f\n", n, timing/1000, flop/timing/1000.0f);
  597. free(advance_11);
  598. free(advance_12_21);
  599. free(advance_22);
  600. }
  601. void initialize_system(float **A, float **B, unsigned dim, unsigned pinned)
  602. {
  603. int ret;
  604. ret = starpu_init(NULL);
  605. if (ret == -ENODEV)
  606. exit(77);
  607. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  608. #ifdef STARPU_ATLAS
  609. char * symbol_11 = "lu_model_11_atlas";
  610. char * symbol_12 = "lu_model_12_atlas";
  611. char * symbol_21 = "lu_model_21_atlas";
  612. char * symbol_22 = "lu_model_22_atlas";
  613. #elif defined(STARPU_GOTO)
  614. char * symbol_11 = "lu_model_11_goto";
  615. char * symbol_12 = "lu_model_12_goto";
  616. char * symbol_21 = "lu_model_21_goto";
  617. char * symbol_22 = "lu_model_22_goto";
  618. #else
  619. char * symbol_11 = "lu_model_11";
  620. char * symbol_12 = "lu_model_12";
  621. char * symbol_21 = "lu_model_21";
  622. char * symbol_22 = "lu_model_22";
  623. #endif
  624. initialize_lu_kernels_model(&model_11,symbol_11,task_11_cost,task_11_cost_cpu,task_11_cost_cuda);
  625. initialize_lu_kernels_model(&model_12,symbol_12,task_12_cost,task_12_cost_cpu,task_12_cost_cuda);
  626. initialize_lu_kernels_model(&model_21,symbol_21,task_21_cost,task_21_cost_cpu,task_21_cost_cuda);
  627. initialize_lu_kernels_model(&model_22,symbol_22,task_22_cost,task_22_cost_cpu,task_22_cost_cuda);
  628. starpu_cublas_init();
  629. if (pinned)
  630. {
  631. starpu_malloc((void **)A, (size_t)dim*dim*sizeof(float));
  632. starpu_malloc((void **)B, (size_t)dim*sizeof(float));
  633. }
  634. else
  635. {
  636. *A = malloc((size_t)dim*dim*sizeof(float));
  637. STARPU_ASSERT(*A);
  638. *B = malloc((size_t)dim*sizeof(float));
  639. STARPU_ASSERT(*B);
  640. }
  641. }
  642. void free_system(float *A, float *B, unsigned dim, unsigned pinned)
  643. {
  644. if (pinned)
  645. {
  646. starpu_free(A);
  647. starpu_free(B);
  648. }
  649. else
  650. {
  651. free(A);
  652. free(B);
  653. }
  654. }
  655. void dw_factoLU(float *matA, unsigned size,
  656. unsigned ld, unsigned nblocks,
  657. unsigned version, unsigned _no_prio)
  658. {
  659. #ifdef CHECK_RESULTS
  660. FPRINTF(stderr, "Checking results ...\n");
  661. float *Asaved;
  662. Asaved = malloc((size_t)ld*ld*sizeof(float));
  663. memcpy(Asaved, matA, (size_t)ld*ld*sizeof(float));
  664. #endif
  665. no_prio = _no_prio;
  666. starpu_data_handle_t dataA;
  667. /* monitor and partition the A matrix into blocks :
  668. * one block is now determined by 2 unsigned (i,j) */
  669. starpu_matrix_data_register(&dataA, STARPU_MAIN_RAM, (uintptr_t)matA, ld,
  670. size, size, sizeof(float));
  671. struct starpu_data_filter f =
  672. {
  673. .filter_func = starpu_matrix_filter_vertical_block,
  674. .nchildren = nblocks
  675. };
  676. struct starpu_data_filter f2 =
  677. {
  678. .filter_func = starpu_matrix_filter_block,
  679. .nchildren = nblocks
  680. };
  681. starpu_data_map_filters(dataA, 2, &f, &f2);
  682. switch (version)
  683. {
  684. case 1:
  685. dw_codelet_facto(dataA, nblocks);
  686. break;
  687. default:
  688. case 2:
  689. dw_codelet_facto_v2(dataA, nblocks);
  690. break;
  691. }
  692. /* gather all the data */
  693. starpu_data_unpartition(dataA, STARPU_MAIN_RAM);
  694. starpu_data_unregister(dataA);
  695. #ifdef CHECK_RESULTS
  696. compare_A_LU(Asaved, matA, size, ld);
  697. #endif
  698. }