dw_factolu.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2012 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. unsigned *advance_11; /* size nblocks, whether the 11 task is done */
  26. unsigned *advance_12_21; /* size nblocks*nblocks */
  27. unsigned *advance_22; /* array of nblocks *nblocks*nblocks */
  28. struct timeval start;
  29. struct timeval end;
  30. static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
  31. static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
  32. static unsigned finished = 0;
  33. static unsigned no_prio = 0;
  34. static struct starpu_codelet cl11 =
  35. {
  36. .where = STARPU_CPU|STARPU_CUDA,
  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. .where = STARPU_CPU|STARPU_CUDA,
  48. .cpu_funcs = {dw_cpu_codelet_update_u12, NULL},
  49. #ifdef STARPU_USE_CUDA
  50. .cuda_funcs = {dw_cublas_codelet_update_u12, NULL},
  51. #endif
  52. .nbuffers = 2,
  53. .modes = {STARPU_R, STARPU_RW},
  54. .model = &model_12
  55. };
  56. static struct starpu_codelet cl21 =
  57. {
  58. .where = STARPU_CPU|STARPU_CUDA,
  59. .cpu_funcs = {dw_cpu_codelet_update_u21, NULL},
  60. #ifdef STARPU_USE_CUDA
  61. .cuda_funcs = {dw_cublas_codelet_update_u21, NULL},
  62. #endif
  63. .nbuffers = 2,
  64. .modes = {STARPU_R, STARPU_RW},
  65. .model = &model_21
  66. };
  67. static struct starpu_codelet cl22 =
  68. {
  69. .where = STARPU_CPU|STARPU_CUDA,
  70. .cpu_funcs = {dw_cpu_codelet_update_u22, NULL},
  71. #ifdef STARPU_USE_CUDA
  72. .cuda_funcs = {dw_cublas_codelet_update_u22, NULL},
  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 : wake the application up */
  291. pthread_mutex_lock(&mutex);
  292. finished = 1;
  293. pthread_cond_signal(&cond);
  294. pthread_mutex_unlock(&mutex);
  295. return;
  296. }
  297. else
  298. {
  299. /* put new tasks */
  300. unsigned slice;
  301. for (slice = i + 1; slice < nblocks; slice++)
  302. {
  303. /* can we launch 12i,slice ? */
  304. uint8_t deps12;
  305. if (i == 0)
  306. {
  307. deps12 = DONE;
  308. }
  309. else
  310. {
  311. deps12 = advance_22[(i-1)*nblocks*nblocks + slice + i*nblocks];
  312. }
  313. if (deps12 & DONE)
  314. {
  315. /* we may perhaps launch the task 12i,slice */
  316. uint8_t u = STARPU_ATOMIC_OR(&advance_12_21[i*nblocks + slice], STARTED);
  317. if ((u & STARTED) == 0)
  318. {
  319. /* we are the only one that should launch that task */
  320. cl_args *u12a = malloc(sizeof(cl_args));
  321. struct starpu_task *task12 = starpu_task_create();
  322. task12->callback_func = dw_callback_v2_codelet_update_u12;
  323. task12->callback_arg = u12a;
  324. task12->cl = &cl12;
  325. task12->cl_arg = u12a;
  326. u12a->i = i;
  327. u12a->k = slice;
  328. u12a->nblocks = args->nblocks;
  329. u12a->dataA = args->dataA;
  330. task12->handles[0] = starpu_data_get_sub_data(args->dataA, 2, u12a->i, u12a->i);
  331. task12->handles[1] = starpu_data_get_sub_data(args->dataA, 2, u12a->k, u12a->i);
  332. if (!no_prio && (slice == i +1))
  333. task12->priority = STARPU_MAX_PRIO;
  334. debug( "u11 %d start u12 %d %d\n", i, i, slice);
  335. ret = starpu_task_submit(task12);
  336. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  337. }
  338. }
  339. /* can we launch 21i,slice ? */
  340. if (i == 0)
  341. {
  342. deps12 = DONE;
  343. }
  344. else
  345. {
  346. deps12 = advance_22[(i-1)*nblocks*nblocks + slice*nblocks + i];
  347. }
  348. if (deps12 & DONE)
  349. {
  350. /* we may perhaps launch the task 12i,slice */
  351. uint8_t u = STARPU_ATOMIC_OR(&advance_12_21[i + slice*nblocks], STARTED);
  352. if ((u & STARTED) == 0)
  353. {
  354. /* we are the only one that should launch that task */
  355. cl_args *u21a = malloc(sizeof(cl_args));
  356. struct starpu_task *task21 = starpu_task_create();
  357. task21->callback_func = dw_callback_v2_codelet_update_u21;
  358. task21->callback_arg = u21a;
  359. task21->cl = &cl21;
  360. task21->cl_arg = u21a;
  361. u21a->i = i;
  362. u21a->k = slice;
  363. u21a->nblocks = args->nblocks;
  364. u21a->dataA = args->dataA;
  365. task21->handles[0] = starpu_data_get_sub_data(args->dataA, 2, u21a->i, u21a->i);
  366. task21->handles[1] = starpu_data_get_sub_data(args->dataA, 2, u21a->i, u21a->k);
  367. if (!no_prio && (slice == i +1))
  368. task21->priority = STARPU_MAX_PRIO;
  369. debug( "u11 %d start u21 %d %d\n", i, i, slice);
  370. ret = starpu_task_submit(task21);
  371. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  372. }
  373. }
  374. }
  375. }
  376. free(argcb);
  377. }
  378. /*
  379. * Callbacks
  380. */
  381. void dw_callback_codelet_update_u11(void *argcb)
  382. {
  383. int ret;
  384. /* in case there remains work, go on */
  385. cl_args *args = argcb;
  386. if (args->i == args->nblocks - 1)
  387. {
  388. /* we are done : wake the application up */
  389. pthread_mutex_lock(&mutex);
  390. finished = 1;
  391. pthread_cond_signal(&cond);
  392. pthread_mutex_unlock(&mutex);
  393. return;
  394. }
  395. else
  396. {
  397. /* put new tasks */
  398. unsigned nslices;
  399. nslices = args->nblocks - 1 - args->i;
  400. unsigned *remaining = malloc(sizeof(unsigned));
  401. *remaining = 2*nslices;
  402. unsigned slice;
  403. for (slice = args->i + 1; slice < args->nblocks; slice++)
  404. {
  405. /* update slice from u12 */
  406. cl_args *u12a = malloc(sizeof(cl_args));
  407. /* update slice from u21 */
  408. cl_args *u21a = malloc(sizeof(cl_args));
  409. struct starpu_task *task12 = starpu_task_create();
  410. task12->callback_func = dw_callback_codelet_update_u12_21;
  411. task12->callback_arg = u12a;
  412. task12->cl = &cl12;
  413. task12->cl_arg = u12a;
  414. struct starpu_task *task21 = starpu_task_create();
  415. task21->callback_func = dw_callback_codelet_update_u12_21;
  416. task21->callback_arg = u21a;
  417. task21->cl = &cl21;
  418. task21->cl_arg = u21a;
  419. u12a->i = args->i;
  420. u12a->k = slice;
  421. u12a->nblocks = args->nblocks;
  422. u12a->dataA = args->dataA;
  423. u12a->remaining = remaining;
  424. u21a->i = args->i;
  425. u21a->k = slice;
  426. u21a->nblocks = args->nblocks;
  427. u21a->dataA = args->dataA;
  428. u21a->remaining = remaining;
  429. task12->handles[0] = starpu_data_get_sub_data(args->dataA, 2, u12a->i, u12a->i);
  430. task12->handles[1] = starpu_data_get_sub_data(args->dataA, 2, u12a->k, u12a->i);
  431. task21->handles[0] = starpu_data_get_sub_data(args->dataA, 2, u21a->i, u21a->i);
  432. task21->handles[1] = starpu_data_get_sub_data(args->dataA, 2, u21a->i, u21a->k);
  433. ret = starpu_task_submit(task12);
  434. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  435. ret = starpu_task_submit(task21);
  436. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  437. }
  438. }
  439. }
  440. void dw_callback_codelet_update_u22(void *argcb)
  441. {
  442. int ret;
  443. cl_args *args = argcb;
  444. if (STARPU_ATOMIC_ADD(args->remaining, (-1)) == 0)
  445. {
  446. /* all worker already used the counter */
  447. free(args->remaining);
  448. /* we now reduce the LU22 part (recursion appears there) */
  449. cl_args *u11arg = malloc(sizeof(cl_args));
  450. struct starpu_task *task = starpu_task_create();
  451. task->callback_func = dw_callback_codelet_update_u11;
  452. task->callback_arg = u11arg;
  453. task->cl = &cl11;
  454. task->cl_arg = u11arg;
  455. task->handles[0] = starpu_data_get_sub_data(args->dataA, 2, args->k + 1, args->k + 1);
  456. u11arg->dataA = args->dataA;
  457. u11arg->i = args->k + 1;
  458. u11arg->nblocks = args->nblocks;
  459. /* schedule the codelet */
  460. ret = starpu_task_submit(task);
  461. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  462. }
  463. free(args);
  464. }
  465. void dw_callback_codelet_update_u12_21(void *argcb)
  466. {
  467. int ret;
  468. cl_args *args = argcb;
  469. if (STARPU_ATOMIC_ADD(args->remaining, -1) == 0)
  470. {
  471. /* now launch the update of LU22 */
  472. unsigned i = args->i;
  473. unsigned nblocks = args->nblocks;
  474. /* the number of tasks to be done */
  475. unsigned *remaining = malloc(sizeof(unsigned));
  476. *remaining = (nblocks - 1 - i)*(nblocks - 1 - i);
  477. unsigned slicey, slicex;
  478. for (slicey = i+1; slicey < nblocks; slicey++)
  479. {
  480. for (slicex = i+1; slicex < nblocks; slicex++)
  481. {
  482. /* update that square matrix */
  483. cl_args *u22a = malloc(sizeof(cl_args));
  484. struct starpu_task *task22 = starpu_task_create();
  485. task22->callback_func = dw_callback_codelet_update_u22;
  486. task22->callback_arg = u22a;
  487. task22->cl = &cl22;
  488. task22->cl_arg = u22a;
  489. u22a->k = i;
  490. u22a->i = slicex;
  491. u22a->j = slicey;
  492. u22a->dataA = args->dataA;
  493. u22a->nblocks = nblocks;
  494. u22a->remaining = remaining;
  495. task22->handles[0] = starpu_data_get_sub_data(args->dataA, 2, u22a->i, u22a->k);
  496. task22->handles[1] = starpu_data_get_sub_data(args->dataA, 2, u22a->k, u22a->j);
  497. task22->handles[2] = starpu_data_get_sub_data(args->dataA, 2, u22a->i, u22a->j);
  498. /* schedule that codelet */
  499. ret = starpu_task_submit(task22);
  500. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  501. }
  502. }
  503. }
  504. }
  505. /*
  506. * code to bootstrap the factorization
  507. */
  508. void dw_codelet_facto(starpu_data_handle_t dataA, unsigned nblocks)
  509. {
  510. int ret;
  511. cl_args *args = malloc(sizeof(cl_args));
  512. args->i = 0;
  513. args->nblocks = nblocks;
  514. args->dataA = dataA;
  515. gettimeofday(&start, NULL);
  516. /* inject a new task with this codelet into the system */
  517. struct starpu_task *task = starpu_task_create();
  518. task->callback_func = dw_callback_codelet_update_u11;
  519. task->callback_arg = args;
  520. task->cl = &cl11;
  521. task->cl_arg = args;
  522. task->handles[0] = starpu_data_get_sub_data(dataA, 2, 0, 0);
  523. /* schedule the codelet */
  524. ret = starpu_task_submit(task);
  525. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  526. /* stall the application until the end of computations */
  527. pthread_mutex_lock(&mutex);
  528. if (!finished)
  529. pthread_cond_wait(&cond, &mutex);
  530. pthread_mutex_unlock(&mutex);
  531. gettimeofday(&end, NULL);
  532. double timing = (double)((end.tv_sec - start.tv_sec)*1000000 + (end.tv_usec - start.tv_usec));
  533. FPRINTF(stderr, "Computation took (in ms)\n");
  534. FPRINTF(stdout, "%2.2f\n", timing/1000);
  535. unsigned n = starpu_matrix_get_nx(dataA);
  536. double flop = (2.0f*n*n*n)/3.0f;
  537. FPRINTF(stderr, "Synthetic GFlops : %2.2f\n", (flop/timing/1000.0f));
  538. }
  539. void dw_codelet_facto_v2(starpu_data_handle_t dataA, unsigned nblocks)
  540. {
  541. advance_11 = calloc(nblocks, sizeof(*advance_11));
  542. STARPU_ASSERT(advance_11);
  543. advance_12_21 = calloc(nblocks*nblocks, sizeof(*advance_12_21));
  544. STARPU_ASSERT(advance_12_21);
  545. advance_22 = calloc(nblocks*nblocks*nblocks, sizeof(*advance_22));
  546. STARPU_ASSERT(advance_22);
  547. cl_args *args = malloc(sizeof(cl_args));
  548. args->i = 0;
  549. args->nblocks = nblocks;
  550. args->dataA = dataA;
  551. gettimeofday(&start, NULL);
  552. /* inject a new task with this codelet into the system */
  553. struct starpu_task *task = starpu_task_create();
  554. task->callback_func = dw_callback_v2_codelet_update_u11;
  555. task->callback_arg = args;
  556. task->cl = &cl11;
  557. task->cl_arg = args;
  558. task->handles[0] = starpu_data_get_sub_data(dataA, 2, 0, 0);
  559. /* schedule the codelet */
  560. int ret = starpu_task_submit(task);
  561. if (STARPU_UNLIKELY(ret == -ENODEV))
  562. {
  563. FPRINTF(stderr, "No worker may execute this task\n");
  564. exit(0);
  565. }
  566. /* stall the application until the end of computations */
  567. pthread_mutex_lock(&mutex);
  568. if (!finished)
  569. pthread_cond_wait(&cond, &mutex);
  570. pthread_mutex_unlock(&mutex);
  571. gettimeofday(&end, NULL);
  572. double timing = (double)((end.tv_sec - start.tv_sec)*1000000 + (end.tv_usec - start.tv_usec));
  573. FPRINTF(stderr, "Computation took (in ms)\n");
  574. FPRINTF(stdout, "%2.2f\n", timing/1000);
  575. unsigned n = starpu_matrix_get_nx(dataA);
  576. double flop = (2.0f*n*n*n)/3.0f;
  577. FPRINTF(stderr, "Synthetic GFlops : %2.2f\n", (flop/timing/1000.0f));
  578. }
  579. void initialize_system(float **A, float **B, unsigned dim, unsigned pinned)
  580. {
  581. int ret;
  582. ret = starpu_init(NULL);
  583. if (ret == -ENODEV)
  584. exit(77);
  585. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  586. starpu_helper_cublas_init();
  587. if (pinned)
  588. {
  589. starpu_malloc((void **)A, (size_t)dim*dim*sizeof(float));
  590. starpu_malloc((void **)B, (size_t)dim*sizeof(float));
  591. }
  592. else
  593. {
  594. *A = malloc((size_t)dim*dim*sizeof(float));
  595. STARPU_ASSERT(*A);
  596. *B = malloc((size_t)dim*sizeof(float));
  597. STARPU_ASSERT(*B);
  598. }
  599. }
  600. void free_system(float *A, float *B, unsigned dim, unsigned pinned)
  601. {
  602. if (pinned)
  603. {
  604. starpu_free(A);
  605. starpu_free(B);
  606. }
  607. else
  608. {
  609. free(A);
  610. free(B);
  611. }
  612. }
  613. void dw_factoLU(float *matA, unsigned size,
  614. unsigned ld, unsigned nblocks,
  615. unsigned version, unsigned _no_prio)
  616. {
  617. #ifdef CHECK_RESULTS
  618. FPRINTF(stderr, "Checking results ...\n");
  619. float *Asaved;
  620. Asaved = malloc((size_t)ld*ld*sizeof(float));
  621. memcpy(Asaved, matA, (size_t)ld*ld*sizeof(float));
  622. #endif
  623. no_prio = _no_prio;
  624. starpu_data_handle_t dataA;
  625. /* monitor and partition the A matrix into blocks :
  626. * one block is now determined by 2 unsigned (i,j) */
  627. starpu_matrix_data_register(&dataA, 0, (uintptr_t)matA, ld,
  628. size, size, sizeof(float));
  629. struct starpu_data_filter f =
  630. {
  631. .filter_func = starpu_vertical_block_filter_func,
  632. .nchildren = nblocks
  633. };
  634. struct starpu_data_filter f2 =
  635. {
  636. .filter_func = starpu_block_filter_func,
  637. .nchildren = nblocks
  638. };
  639. starpu_data_map_filters(dataA, 2, &f, &f2);
  640. switch (version)
  641. {
  642. case 1:
  643. dw_codelet_facto(dataA, nblocks);
  644. break;
  645. default:
  646. case 2:
  647. dw_codelet_facto_v2(dataA, nblocks);
  648. break;
  649. }
  650. /* gather all the data */
  651. starpu_data_unpartition(dataA, 0);
  652. starpu_data_unregister(dataA);
  653. #ifdef CHECK_RESULTS
  654. compare_A_LU(Asaved, matA, size, ld);
  655. #endif
  656. }