dw_factolu.c 20 KB

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