dw_factolu.c 21 KB

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