dw_factolu.c 21 KB

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