xgemm.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. * Copyright (C) 2010 Mehdi Juhoor
  5. * Copyright (C) 2017 Erwan Leria
  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. /*
  19. * Simple parallel GEMM implementation: partition the output matrix in the two
  20. * dimensions, and the input matrices in the corresponding dimension, and
  21. * perform the output computations in parallel.
  22. */
  23. #ifndef TYPE
  24. #error "Do not compile xgemm.c directly, compile sgemm.c or dgemm.c"
  25. #endif
  26. #include <limits.h>
  27. #include <string.h>
  28. #include <unistd.h>
  29. #include <math.h>
  30. #include <sys/types.h>
  31. #include <starpu.h>
  32. #include <starpu_fxt.h>
  33. #ifdef STARPU_HAVE_BLAS
  34. #include <common/blas.h>
  35. #endif
  36. #ifdef STARPU_USE_CUDA
  37. #include <cuda.h>
  38. #include <starpu_cublas_v2.h>
  39. static const TYPE p1 = 1.0;
  40. static const TYPE m1 = -1.0;
  41. static const TYPE v0 = 0.0;
  42. #endif
  43. static unsigned niter = 10;
  44. static unsigned nsleeps = 1;
  45. static unsigned nslicesx = 4;
  46. static unsigned nslicesy = 4;
  47. static unsigned nslicesz = 4;
  48. #if defined(STARPU_QUICK_CHECK) && !defined(STARPU_SIMGRID)
  49. static unsigned xdim = 256;
  50. static unsigned ydim = 256;
  51. static unsigned zdim = 64;
  52. #else
  53. static unsigned xdim = 960*4;
  54. static unsigned ydim = 960*4;
  55. static unsigned zdim = 960*4;
  56. #endif
  57. static unsigned check = 0;
  58. static unsigned bound = 0;
  59. static unsigned print_hostname = 0;
  60. static unsigned tiled = 0;
  61. static TYPE *A, *B, *C;
  62. static starpu_data_handle_t A_handle, B_handle, C_handle;
  63. #define FPRINTF(ofile, fmt, ...) do { if (!getenv("STARPU_SSILENT")) {fprintf(ofile, fmt, ## __VA_ARGS__); }} while(0)
  64. #define PRINTF(fmt, ...) do { if (!getenv("STARPU_SSILENT")) {printf(fmt, ## __VA_ARGS__); fflush(stdout); }} while(0)
  65. #ifdef STARPU_HAVE_BLAS
  66. static int check_output(void)
  67. {
  68. /* compute C = C - AB */
  69. CPU_GEMM("N", "N", ydim, xdim, zdim, (TYPE)-1.0f, A, ydim, B, zdim, (TYPE)1.0f, C, ydim);
  70. /* make sure C = 0 */
  71. TYPE err;
  72. err = CPU_ASUM(xdim*ydim, C, 1);
  73. if (err < EPSILON*xdim*ydim*zdim)
  74. {
  75. FPRINTF(stderr, "Results are OK\n");
  76. return 0;
  77. }
  78. else
  79. {
  80. int max;
  81. max = CPU_IAMAX(xdim*ydim, C, 1);
  82. FPRINTF(stderr, "There were errors ... err = %f\n", err);
  83. FPRINTF(stderr, "Max error : %e\n", C[max]);
  84. return 1;
  85. }
  86. }
  87. #endif
  88. static void init_problem_data(void)
  89. {
  90. #ifndef STARPU_SIMGRID
  91. unsigned i,j;
  92. #endif
  93. starpu_malloc_flags((void **)&A, zdim*ydim*sizeof(TYPE), STARPU_MALLOC_PINNED|STARPU_MALLOC_SIMULATION_FOLDED);
  94. starpu_malloc_flags((void **)&B, xdim*zdim*sizeof(TYPE), STARPU_MALLOC_PINNED|STARPU_MALLOC_SIMULATION_FOLDED);
  95. starpu_malloc_flags((void **)&C, xdim*ydim*sizeof(TYPE), STARPU_MALLOC_PINNED|STARPU_MALLOC_SIMULATION_FOLDED);
  96. #ifndef STARPU_SIMGRID
  97. /* fill the A and B matrices */
  98. for (j=0; j < ydim; j++)
  99. {
  100. for (i=0; i < zdim; i++)
  101. {
  102. A[j+i*ydim] = (TYPE)(starpu_drand48());
  103. }
  104. }
  105. for (j=0; j < zdim; j++)
  106. {
  107. for (i=0; i < xdim; i++)
  108. {
  109. B[j+i*zdim] = (TYPE)(starpu_drand48());
  110. }
  111. }
  112. for (j=0; j < ydim; j++)
  113. {
  114. for (i=0; i < xdim; i++)
  115. {
  116. C[j+i*ydim] = (TYPE)(0);
  117. }
  118. }
  119. #endif
  120. }
  121. static void partition_mult_data(void)
  122. {
  123. unsigned x, y, z;
  124. starpu_matrix_data_register(&A_handle, STARPU_MAIN_RAM, (uintptr_t)A,
  125. ydim, ydim, zdim, sizeof(TYPE));
  126. starpu_matrix_data_register(&B_handle, STARPU_MAIN_RAM, (uintptr_t)B,
  127. zdim, zdim, xdim, sizeof(TYPE));
  128. starpu_matrix_data_register(&C_handle, STARPU_MAIN_RAM, (uintptr_t)C,
  129. ydim, ydim, xdim, sizeof(TYPE));
  130. struct starpu_data_filter vert;
  131. memset(&vert, 0, sizeof(vert));
  132. vert.filter_func = starpu_matrix_filter_vertical_block;
  133. vert.nchildren = nslicesx;
  134. struct starpu_data_filter horiz;
  135. memset(&horiz, 0, sizeof(horiz));
  136. horiz.filter_func = starpu_matrix_filter_block;
  137. horiz.nchildren = nslicesy;
  138. if (tiled)
  139. {
  140. struct starpu_data_filter vertA;
  141. memset(&vertA, 0, sizeof(vertA));
  142. vertA.filter_func = starpu_matrix_filter_vertical_block;
  143. vertA.nchildren = nslicesz;
  144. struct starpu_data_filter horizB;
  145. memset(&horizB, 0, sizeof(horizB));
  146. horizB.filter_func = starpu_matrix_filter_block;
  147. horizB.nchildren = nslicesz;
  148. starpu_data_map_filters(A_handle, 2, &vertA, &horiz);
  149. starpu_data_map_filters(B_handle, 2, &vert, &horizB);
  150. starpu_data_map_filters(C_handle, 2, &vert, &horiz);
  151. for (y = 0; y < nslicesy; y++)
  152. for (z = 0; z < nslicesz; z++)
  153. starpu_data_set_coordinates(starpu_data_get_sub_data(A_handle, 2, z, y), 2, z, y);
  154. for (x = 0; x < nslicesx; x++)
  155. for (z = 0; z < nslicesz; z++)
  156. starpu_data_set_coordinates(starpu_data_get_sub_data(B_handle, 2, x, z), 2, x, z);
  157. }
  158. else
  159. {
  160. starpu_data_partition(B_handle, &vert);
  161. starpu_data_partition(A_handle, &horiz);
  162. starpu_data_map_filters(C_handle, 2, &vert, &horiz);
  163. for (y = 0; y < nslicesy; y++)
  164. starpu_data_set_coordinates(starpu_data_get_sub_data(A_handle, 1, y), 2, 0, y);
  165. for (x = 0; x < nslicesx; x++)
  166. starpu_data_set_coordinates(starpu_data_get_sub_data(B_handle, 1, x), 2, x, 0);
  167. }
  168. for (x = 0; x < nslicesx; x++)
  169. for (y = 0; y < nslicesy; y++)
  170. starpu_data_set_coordinates(starpu_data_get_sub_data(C_handle, 2, x, y), 2, x, y);
  171. }
  172. #ifdef STARPU_USE_CUDA
  173. static void cublas_mult(void *descr[], void *arg, const TYPE *beta)
  174. {
  175. (void)arg;
  176. TYPE *subA = (TYPE *)STARPU_MATRIX_GET_PTR(descr[0]);
  177. TYPE *subB = (TYPE *)STARPU_MATRIX_GET_PTR(descr[1]);
  178. TYPE *subC = (TYPE *)STARPU_MATRIX_GET_PTR(descr[2]);
  179. unsigned nxC = STARPU_MATRIX_GET_NX(descr[2]);
  180. unsigned nyC = STARPU_MATRIX_GET_NY(descr[2]);
  181. unsigned nyA = STARPU_MATRIX_GET_NY(descr[0]);
  182. unsigned ldA = STARPU_MATRIX_GET_LD(descr[0]);
  183. unsigned ldB = STARPU_MATRIX_GET_LD(descr[1]);
  184. unsigned ldC = STARPU_MATRIX_GET_LD(descr[2]);
  185. cublasStatus_t status = CUBLAS_GEMM(starpu_cublas_get_local_handle(),
  186. CUBLAS_OP_N, CUBLAS_OP_N,
  187. nxC, nyC, nyA,
  188. &p1, subA, ldA, subB, ldB,
  189. beta, subC, ldC);
  190. if (status != CUBLAS_STATUS_SUCCESS)
  191. STARPU_CUBLAS_REPORT_ERROR(status);
  192. }
  193. static void cublas_gemm0(void *descr[], void *arg)
  194. {
  195. cublas_mult(descr, arg, &v0);
  196. }
  197. static void cublas_gemm(void *descr[], void *arg)
  198. {
  199. cublas_mult(descr, arg, &p1);
  200. }
  201. #endif
  202. #ifdef STARPU_HAVE_BLAS
  203. void cpu_mult(void *descr[], void *arg, TYPE beta)
  204. {
  205. (void)arg;
  206. TYPE *subA = (TYPE *)STARPU_MATRIX_GET_PTR(descr[0]);
  207. TYPE *subB = (TYPE *)STARPU_MATRIX_GET_PTR(descr[1]);
  208. TYPE *subC = (TYPE *)STARPU_MATRIX_GET_PTR(descr[2]);
  209. unsigned nxC = STARPU_MATRIX_GET_NX(descr[2]);
  210. unsigned nyC = STARPU_MATRIX_GET_NY(descr[2]);
  211. unsigned nyA = STARPU_MATRIX_GET_NY(descr[0]);
  212. unsigned ldA = STARPU_MATRIX_GET_LD(descr[0]);
  213. unsigned ldB = STARPU_MATRIX_GET_LD(descr[1]);
  214. unsigned ldC = STARPU_MATRIX_GET_LD(descr[2]);
  215. int worker_size = starpu_combined_worker_get_size();
  216. if (worker_size == 1)
  217. {
  218. /* Sequential CPU task */
  219. CPU_GEMM("N", "N", nxC, nyC, nyA, (TYPE)1.0, subA, ldA, subB, ldB, beta, subC, ldC);
  220. }
  221. else
  222. {
  223. /* Parallel CPU task */
  224. unsigned rank = starpu_combined_worker_get_rank();
  225. unsigned block_size = (nyC + worker_size - 1)/worker_size;
  226. unsigned new_nyC = STARPU_MIN(nyC, block_size*(rank+1)) - block_size*rank;
  227. STARPU_ASSERT(nyC == STARPU_MATRIX_GET_NY(descr[1]));
  228. TYPE *new_subB = &subB[block_size*rank];
  229. TYPE *new_subC = &subC[block_size*rank];
  230. CPU_GEMM("N", "N", nxC, new_nyC, nyA, (TYPE)1.0, subA, ldA, new_subB, ldB, beta, new_subC, ldC);
  231. }
  232. }
  233. void cpu_gemm0(void *descr[], void *arg)
  234. {
  235. cpu_mult(descr, arg, 0.);
  236. }
  237. void cpu_gemm(void *descr[], void *arg)
  238. {
  239. cpu_mult(descr, arg, 1.);
  240. }
  241. #endif
  242. static struct starpu_perfmodel starpu_gemm_model =
  243. {
  244. .type = STARPU_HISTORY_BASED,
  245. .symbol = STARPU_GEMM_STR(gemm)
  246. };
  247. static struct starpu_codelet cl_gemm0 =
  248. {
  249. #ifdef STARPU_HAVE_BLAS
  250. .type = STARPU_SEQ, /* changed to STARPU_SPMD if -spmd is passed */
  251. .max_parallelism = INT_MAX,
  252. .cpu_funcs = {cpu_gemm0},
  253. .cpu_funcs_name = {"cpu_gemm0"},
  254. #endif
  255. #ifdef STARPU_USE_CUDA
  256. .cuda_funcs = {cublas_gemm0},
  257. #elif defined(STARPU_SIMGRID)
  258. .cuda_funcs = {(void*)1},
  259. #endif
  260. .cuda_flags = {STARPU_CUDA_ASYNC},
  261. .nbuffers = 3,
  262. .modes = {STARPU_R, STARPU_R, STARPU_W},
  263. .model = &starpu_gemm_model
  264. };
  265. static struct starpu_codelet cl_gemm =
  266. {
  267. #ifdef STARPU_HAVE_BLAS
  268. .type = STARPU_SEQ, /* changed to STARPU_SPMD if -spmd is passed */
  269. .max_parallelism = INT_MAX,
  270. .cpu_funcs = {cpu_gemm},
  271. .cpu_funcs_name = {"cpu_gemm"},
  272. #endif
  273. #ifdef STARPU_USE_CUDA
  274. .cuda_funcs = {cublas_gemm},
  275. #elif defined(STARPU_SIMGRID)
  276. .cuda_funcs = {(void*)1},
  277. #endif
  278. .cuda_flags = {STARPU_CUDA_ASYNC},
  279. .nbuffers = 3,
  280. .modes = {STARPU_R, STARPU_R, STARPU_RW},
  281. .model = &starpu_gemm_model
  282. };
  283. static void parse_args(int argc, char **argv)
  284. {
  285. int i;
  286. for (i = 1; i < argc; i++)
  287. {
  288. if (strcmp(argv[i], "-3d") == 0)
  289. {
  290. tiled = 1;
  291. }
  292. else if (strcmp(argv[i], "-nblocks") == 0)
  293. {
  294. char *argptr;
  295. nslicesx = strtol(argv[++i], &argptr, 10);
  296. nslicesy = nslicesx;
  297. nslicesz = nslicesx;
  298. if (nslicesx == 0)
  299. {
  300. fprintf(stderr, "the number of blocks in X cannot be 0!\n");
  301. exit(EXIT_FAILURE);
  302. }
  303. }
  304. else if (strcmp(argv[i], "-nblocksx") == 0)
  305. {
  306. char *argptr;
  307. nslicesx = strtol(argv[++i], &argptr, 10);
  308. if (nslicesx == 0)
  309. {
  310. fprintf(stderr, "the number of blocks in X cannot be 0!\n");
  311. exit(EXIT_FAILURE);
  312. }
  313. }
  314. else if (strcmp(argv[i], "-nblocksy") == 0)
  315. {
  316. char *argptr;
  317. nslicesy = strtol(argv[++i], &argptr, 10);
  318. if (nslicesy == 0)
  319. {
  320. fprintf(stderr, "the number of blocks in Y cannot be 0!\n");
  321. exit(EXIT_FAILURE);
  322. }
  323. }
  324. else if (strcmp(argv[i], "-nblocksz") == 0)
  325. {
  326. char *argptr;
  327. nslicesz = strtol(argv[++i], &argptr, 10);
  328. if (nslicesz == 0)
  329. {
  330. fprintf(stderr, "the number of blocks in Z cannot be 0!\n");
  331. exit(EXIT_FAILURE);
  332. }
  333. }
  334. else if (strcmp(argv[i], "-x") == 0)
  335. {
  336. char *argptr;
  337. xdim = strtol(argv[++i], &argptr, 10);
  338. if (xdim == 0)
  339. {
  340. fprintf(stderr, "the X dimension cannot be 0!\n");
  341. exit(EXIT_FAILURE);
  342. }
  343. }
  344. else if (strcmp(argv[i], "-xy") == 0)
  345. {
  346. char *argptr;
  347. xdim = ydim = strtol(argv[++i], &argptr, 10);
  348. if (xdim == 0)
  349. {
  350. fprintf(stderr, "the XY dimensions cannot be 0!\n");
  351. exit(EXIT_FAILURE);
  352. }
  353. }
  354. else if (strcmp(argv[i], "-xyz") == 0)
  355. {
  356. char *argptr;
  357. xdim = ydim = zdim = strtol(argv[++i], &argptr, 10);
  358. }
  359. else if (strcmp(argv[i], "-y") == 0)
  360. {
  361. char *argptr;
  362. ydim = strtol(argv[++i], &argptr, 10);
  363. if (ydim == 0)
  364. {
  365. fprintf(stderr, "the Y dimension cannot be 0!\n");
  366. exit(EXIT_FAILURE);
  367. }
  368. }
  369. else if (strcmp(argv[i], "-z") == 0)
  370. {
  371. char *argptr;
  372. zdim = strtol(argv[++i], &argptr, 10);
  373. if (zdim == 0)
  374. {
  375. fprintf(stderr, "the Z dimension cannot be 0!\n");
  376. exit(EXIT_FAILURE);
  377. }
  378. }
  379. else if (strcmp(argv[i], "-size") == 0)
  380. {
  381. char *argptr;
  382. xdim = ydim = zdim = strtol(argv[++i], &argptr, 10);
  383. if (xdim == 0)
  384. {
  385. fprintf(stderr, "the size cannot be 0!\n");
  386. exit(EXIT_FAILURE);
  387. }
  388. }
  389. else if (strcmp(argv[i], "-iter") == 0)
  390. {
  391. char *argptr;
  392. niter = strtol(argv[++i], &argptr, 10);
  393. if (niter == 0)
  394. {
  395. fprintf(stderr, "the number of iterations cannot be 0!\n");
  396. exit(EXIT_FAILURE);
  397. }
  398. }
  399. else if (strcmp(argv[i], "-nsleeps") == 0)
  400. {
  401. char *argptr;
  402. nsleeps = strtol(argv[++i], &argptr, 10);
  403. }
  404. else if (strcmp(argv[i], "-bound") == 0)
  405. {
  406. bound = 1;
  407. }
  408. else if (strcmp(argv[i], "-hostname") == 0)
  409. {
  410. print_hostname = 1;
  411. }
  412. else if (strcmp(argv[i], "-check") == 0)
  413. {
  414. check = 1;
  415. }
  416. else if (strcmp(argv[i], "-spmd") == 0)
  417. {
  418. cl_gemm0.type = STARPU_SPMD;
  419. }
  420. else if (strcmp(argv[i], "-help") == 0 || strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0)
  421. {
  422. fprintf(stderr,"Usage: %s [-3d] [-nblocks n] [-nblocksx x] [-nblocksy y] [-nblocksz z] [-x x] [-y y] [-xy n] [-z z] [-xyz n] [-size size] [-iter iter] [-bound] [-check] [-spmd] [-hostname] [-nsleeps nsleeps]\n", argv[0]);
  423. if (tiled)
  424. fprintf(stderr,"Currently selected: %ux%u * %ux%u and %ux%ux%u blocks (size %ux%u length %u), %u iterations, %u sleeps\n", zdim, ydim, xdim, zdim, nslicesx, nslicesy, nslicesz, xdim / nslicesx, ydim / nslicesy, zdim / nslicesz, niter, nsleeps);
  425. else
  426. fprintf(stderr,"Currently selected: %ux%u * %ux%u and %ux%u blocks (size %ux%u length %u), %u iterations, %u sleeps\n", zdim, ydim, xdim, zdim, nslicesx, nslicesy, xdim / nslicesx, ydim / nslicesy, zdim, niter, nsleeps);
  427. exit(EXIT_SUCCESS);
  428. }
  429. else
  430. {
  431. fprintf(stderr,"Unrecognized option %s\n", argv[i]);
  432. exit(EXIT_FAILURE);
  433. }
  434. }
  435. }
  436. int main(int argc, char **argv)
  437. {
  438. double start, end;
  439. int ret;
  440. parse_args(argc, argv);
  441. #ifdef STARPU_QUICK_CHECK
  442. niter /= 10;
  443. #endif
  444. starpu_fxt_autostart_profiling(0);
  445. ret = starpu_init(NULL);
  446. if (ret == -ENODEV)
  447. return 77;
  448. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  449. starpu_cublas_init();
  450. init_problem_data();
  451. partition_mult_data();
  452. PRINTF("# ");
  453. if (print_hostname)
  454. PRINTF("node\t");
  455. PRINTF("x\ty\tz\tms\tGFlops");
  456. if (bound)
  457. PRINTF("\tTms\tTGFlops\tTims\tTiGFlops");
  458. PRINTF("\n");
  459. unsigned sleeps;
  460. for (sleeps = 0; sleeps < nsleeps; sleeps++)
  461. {
  462. if (bound)
  463. starpu_bound_start(0, 0);
  464. starpu_fxt_start_profiling();
  465. start = starpu_timing_now();
  466. unsigned x, y, z, iter;
  467. for (iter = 0; iter < niter; iter++)
  468. {
  469. if (tiled)
  470. {
  471. for (x = 0; x < nslicesx; x++)
  472. for (y = 0; y < nslicesy; y++)
  473. {
  474. starpu_data_handle_t Ctile = starpu_data_get_sub_data(C_handle, 2, x, y);
  475. for (z = 0; z < nslicesz; z++)
  476. {
  477. struct starpu_task *task = starpu_task_create();
  478. if (z == 0)
  479. task->cl = &cl_gemm0;
  480. else
  481. task->cl = &cl_gemm;
  482. task->handles[0] = starpu_data_get_sub_data(A_handle, 2, z, y);
  483. task->handles[1] = starpu_data_get_sub_data(B_handle, 2, x, z);
  484. task->handles[2] = Ctile;
  485. task->flops = 2ULL * (xdim/nslicesx) * (ydim/nslicesy) * (zdim/nslicesz);
  486. ret = starpu_task_submit(task);
  487. if (ret == -ENODEV)
  488. {
  489. check = 0;
  490. ret = 77;
  491. goto enodev;
  492. }
  493. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  494. }
  495. starpu_data_wont_use(Ctile);
  496. }
  497. }
  498. else
  499. {
  500. for (x = 0; x < nslicesx; x++)
  501. for (y = 0; y < nslicesy; y++)
  502. {
  503. struct starpu_task *task = starpu_task_create();
  504. task->cl = &cl_gemm0;
  505. task->handles[0] = starpu_data_get_sub_data(A_handle, 1, y);
  506. task->handles[1] = starpu_data_get_sub_data(B_handle, 1, x);
  507. task->handles[2] = starpu_data_get_sub_data(C_handle, 2, x, y);
  508. task->flops = 2ULL * (xdim/nslicesx) * (ydim/nslicesy) * zdim;
  509. ret = starpu_task_submit(task);
  510. if (ret == -ENODEV)
  511. {
  512. check = 0;
  513. ret = 77;
  514. goto enodev;
  515. }
  516. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  517. starpu_data_wont_use(starpu_data_get_sub_data(C_handle, 2, x, y));
  518. }
  519. }
  520. starpu_task_wait_for_all();
  521. }
  522. end = starpu_timing_now();
  523. starpu_fxt_stop_profiling();
  524. if (bound)
  525. starpu_bound_stop();
  526. double timing = end - start;
  527. double min, min_int;
  528. double flops = 2.0*((unsigned long long)niter)*((unsigned long long)xdim)
  529. *((unsigned long long)ydim)*((unsigned long long)zdim);
  530. if (bound)
  531. starpu_bound_compute(&min, &min_int, 1);
  532. if (print_hostname)
  533. {
  534. char hostname[255];
  535. gethostname(hostname, 255);
  536. PRINTF("%s\t", hostname);
  537. }
  538. PRINTF("%u\t%u\t%u\t%.0f\t%.1f", xdim, ydim, zdim, timing/niter/1000.0, flops/timing/1000.0);
  539. if (bound)
  540. PRINTF("\t%.0f\t%.1f\t%.0f\t%.1f", min, flops/min/1000000.0, min_int, flops/min_int/1000000.0);
  541. PRINTF("\n");
  542. if (sleeps < nsleeps-1)
  543. {
  544. sleep(10);
  545. }
  546. }
  547. enodev:
  548. starpu_data_unpartition(C_handle, STARPU_MAIN_RAM);
  549. starpu_data_unpartition(B_handle, STARPU_MAIN_RAM);
  550. starpu_data_unpartition(A_handle, STARPU_MAIN_RAM);
  551. starpu_data_unregister(A_handle);
  552. starpu_data_unregister(B_handle);
  553. starpu_data_unregister(C_handle);
  554. #ifdef STARPU_HAVE_BLAS
  555. #ifndef STARPU_SIMGRID
  556. if (check)
  557. ret = check_output();
  558. #endif
  559. #endif
  560. starpu_free_flags(A, zdim*ydim*sizeof(TYPE), STARPU_MALLOC_PINNED|STARPU_MALLOC_SIMULATION_FOLDED);
  561. starpu_free_flags(B, xdim*zdim*sizeof(TYPE), STARPU_MALLOC_PINNED|STARPU_MALLOC_SIMULATION_FOLDED);
  562. starpu_free_flags(C, xdim*ydim*sizeof(TYPE), STARPU_MALLOC_PINNED|STARPU_MALLOC_SIMULATION_FOLDED);
  563. starpu_cublas_shutdown();
  564. starpu_shutdown();
  565. return ret;
  566. }