dw_factolu.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  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, 2016 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. free(remaining);
  459. }
  460. }
  461. void dw_callback_codelet_update_u22(void *argcb)
  462. {
  463. int ret;
  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. ANNOTATE_HAPPENS_AFTER(args->remaining);
  470. /* all worker already used the counter */
  471. free(args->remaining);
  472. /* we now reduce the LU22 part (recursion appears there) */
  473. cl_args *u11arg = malloc(sizeof(cl_args));
  474. struct starpu_task *task = starpu_task_create();
  475. task->callback_func = dw_callback_codelet_update_u11;
  476. task->callback_arg = u11arg;
  477. task->cl = &cl11;
  478. task->cl_arg = u11arg;
  479. task->cl_arg_size = sizeof(*u11arg);
  480. task->handles[0] = starpu_data_get_sub_data(args->dataA, 2, args->k + 1, args->k + 1);
  481. u11arg->dataA = args->dataA;
  482. u11arg->i = args->k + 1;
  483. u11arg->nblocks = args->nblocks;
  484. /* schedule the codelet */
  485. ret = starpu_task_submit(task);
  486. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  487. }
  488. free(args);
  489. }
  490. void dw_callback_codelet_update_u12_21(void *argcb)
  491. {
  492. int ret;
  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 = malloc(sizeof(unsigned));
  504. *remaining = (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. /* update that square matrix */
  511. cl_args *u22a = malloc(sizeof(cl_args));
  512. struct starpu_task *task22 = starpu_task_create();
  513. task22->callback_func = dw_callback_codelet_update_u22;
  514. task22->callback_arg = u22a;
  515. task22->cl = &cl22;
  516. task22->cl_arg = u22a;
  517. task22->cl_arg_size = sizeof(*u22a);
  518. u22a->k = i;
  519. u22a->i = slicex;
  520. u22a->j = slicey;
  521. u22a->dataA = args->dataA;
  522. u22a->nblocks = nblocks;
  523. u22a->remaining = remaining;
  524. task22->handles[0] = starpu_data_get_sub_data(args->dataA, 2, u22a->i, u22a->k);
  525. task22->handles[1] = starpu_data_get_sub_data(args->dataA, 2, u22a->k, u22a->j);
  526. task22->handles[2] = starpu_data_get_sub_data(args->dataA, 2, u22a->i, u22a->j);
  527. /* schedule that codelet */
  528. ret = starpu_task_submit(task22);
  529. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  530. }
  531. }
  532. free(remaining);
  533. }
  534. }
  535. /*
  536. * code to bootstrap the factorization
  537. */
  538. void dw_codelet_facto(starpu_data_handle_t dataA, unsigned nblocks)
  539. {
  540. int ret;
  541. cl_args *args = malloc(sizeof(cl_args));
  542. args->i = 0;
  543. args->nblocks = nblocks;
  544. args->dataA = dataA;
  545. start = starpu_timing_now();
  546. /* inject a new task with this codelet into the system */
  547. struct starpu_task *task = starpu_task_create();
  548. task->callback_func = dw_callback_codelet_update_u11;
  549. task->callback_arg = args;
  550. task->cl = &cl11;
  551. task->cl_arg = args;
  552. task->handles[0] = starpu_data_get_sub_data(dataA, 2, 0, 0);
  553. /* schedule the codelet */
  554. ret = starpu_task_submit(task);
  555. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  556. starpu_task_wait_for_all();
  557. end = starpu_timing_now();
  558. double timing = end - start;
  559. unsigned n = starpu_matrix_get_nx(dataA);
  560. double flop = (2.0f*n*n*n)/3.0f;
  561. PRINTF("# size\tms\tGFlops\n");
  562. PRINTF("%u\t%.0f\t%.1f\n", n, timing/1000, flop/timing/1000.0f);
  563. }
  564. void dw_codelet_facto_v2(starpu_data_handle_t dataA, unsigned nblocks)
  565. {
  566. advance_11 = calloc(nblocks, sizeof(*advance_11));
  567. STARPU_ASSERT(advance_11);
  568. advance_12_21 = calloc(nblocks*nblocks, sizeof(*advance_12_21));
  569. STARPU_ASSERT(advance_12_21);
  570. advance_22 = calloc(nblocks*nblocks*nblocks, sizeof(*advance_22));
  571. STARPU_ASSERT(advance_22);
  572. cl_args *args = malloc(sizeof(cl_args));
  573. args->i = 0;
  574. args->nblocks = nblocks;
  575. args->dataA = dataA;
  576. start = starpu_timing_now();
  577. /* inject a new task with this codelet into the system */
  578. struct starpu_task *task = starpu_task_create();
  579. task->callback_func = dw_callback_v2_codelet_update_u11;
  580. task->callback_arg = args;
  581. task->cl = &cl11;
  582. task->cl_arg = args;
  583. task->cl_arg_size = sizeof(*args);
  584. task->handles[0] = starpu_data_get_sub_data(dataA, 2, 0, 0);
  585. /* schedule the codelet */
  586. int ret = starpu_task_submit(task);
  587. if (STARPU_UNLIKELY(ret == -ENODEV))
  588. {
  589. FPRINTF(stderr, "No worker may execute this task\n");
  590. exit(0);
  591. }
  592. starpu_task_wait_for_all();
  593. end = starpu_timing_now();
  594. double timing = end - start;
  595. unsigned n = starpu_matrix_get_nx(dataA);
  596. double flop = (2.0f*n*n*n)/3.0f;
  597. PRINTF("# size\tms\tGFlops\n");
  598. PRINTF("%u\t%.0f\t%.1f\n", n, timing/1000, flop/timing/1000.0f);
  599. free(advance_11);
  600. free(advance_12_21);
  601. free(advance_22);
  602. }
  603. void initialize_system(float **A, float **B, unsigned dim, unsigned pinned)
  604. {
  605. int ret;
  606. ret = starpu_init(NULL);
  607. if (ret == -ENODEV)
  608. exit(77);
  609. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  610. #ifdef STARPU_ATLAS
  611. char * symbol_11 = "lu_model_11_atlas";
  612. char * symbol_12 = "lu_model_12_atlas";
  613. char * symbol_21 = "lu_model_21_atlas";
  614. char * symbol_22 = "lu_model_22_atlas";
  615. #elif defined(STARPU_GOTO)
  616. char * symbol_11 = "lu_model_11_goto";
  617. char * symbol_12 = "lu_model_12_goto";
  618. char * symbol_21 = "lu_model_21_goto";
  619. char * symbol_22 = "lu_model_22_goto";
  620. #else
  621. char * symbol_11 = "lu_model_11";
  622. char * symbol_12 = "lu_model_12";
  623. char * symbol_21 = "lu_model_21";
  624. char * symbol_22 = "lu_model_22";
  625. #endif
  626. initialize_lu_kernels_model(&model_11,symbol_11,task_11_cost,task_11_cost_cpu,task_11_cost_cuda);
  627. initialize_lu_kernels_model(&model_12,symbol_12,task_12_cost,task_12_cost_cpu,task_12_cost_cuda);
  628. initialize_lu_kernels_model(&model_21,symbol_21,task_21_cost,task_21_cost_cpu,task_21_cost_cuda);
  629. initialize_lu_kernels_model(&model_22,symbol_22,task_22_cost,task_22_cost_cpu,task_22_cost_cuda);
  630. starpu_cublas_init();
  631. if (pinned)
  632. {
  633. starpu_malloc((void **)A, (size_t)dim*dim*sizeof(float));
  634. starpu_malloc((void **)B, (size_t)dim*sizeof(float));
  635. }
  636. else
  637. {
  638. *A = malloc((size_t)dim*dim*sizeof(float));
  639. STARPU_ASSERT(*A);
  640. *B = malloc((size_t)dim*sizeof(float));
  641. STARPU_ASSERT(*B);
  642. }
  643. }
  644. void free_system(float *A, float *B, unsigned dim, unsigned pinned)
  645. {
  646. if (pinned)
  647. {
  648. starpu_free(A);
  649. starpu_free(B);
  650. }
  651. else
  652. {
  653. free(A);
  654. free(B);
  655. }
  656. }
  657. void dw_factoLU(float *matA, unsigned size,
  658. unsigned ld, unsigned nblocks,
  659. unsigned version, unsigned _no_prio)
  660. {
  661. #ifdef CHECK_RESULTS
  662. FPRINTF(stderr, "Checking results ...\n");
  663. float *Asaved;
  664. Asaved = malloc((size_t)ld*ld*sizeof(float));
  665. memcpy(Asaved, matA, (size_t)ld*ld*sizeof(float));
  666. #endif
  667. no_prio = _no_prio;
  668. starpu_data_handle_t dataA;
  669. /* monitor and partition the A matrix into blocks :
  670. * one block is now determined by 2 unsigned (i,j) */
  671. starpu_matrix_data_register(&dataA, STARPU_MAIN_RAM, (uintptr_t)matA, ld,
  672. size, size, sizeof(float));
  673. struct starpu_data_filter f =
  674. {
  675. .filter_func = starpu_matrix_filter_vertical_block,
  676. .nchildren = nblocks
  677. };
  678. struct starpu_data_filter f2 =
  679. {
  680. .filter_func = starpu_matrix_filter_block,
  681. .nchildren = nblocks
  682. };
  683. starpu_data_map_filters(dataA, 2, &f, &f2);
  684. switch (version)
  685. {
  686. case 1:
  687. dw_codelet_facto(dataA, nblocks);
  688. break;
  689. default:
  690. case 2:
  691. dw_codelet_facto_v2(dataA, nblocks);
  692. break;
  693. }
  694. /* gather all the data */
  695. starpu_data_unpartition(dataA, STARPU_MAIN_RAM);
  696. starpu_data_unregister(dataA);
  697. #ifdef CHECK_RESULTS
  698. compare_A_LU(Asaved, matA, size, ld);
  699. #endif
  700. }