dw_factolu.c 21 KB

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