dw_factolu.c 21 KB

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