dw_factolu.c 21 KB

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