xgemm.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  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], "-y") == 0)
  355. {
  356. char *argptr;
  357. ydim = strtol(argv[++i], &argptr, 10);
  358. if (ydim == 0)
  359. {
  360. fprintf(stderr, "the Y dimension cannot be 0!\n");
  361. exit(EXIT_FAILURE);
  362. }
  363. }
  364. else if (strcmp(argv[i], "-z") == 0)
  365. {
  366. char *argptr;
  367. zdim = strtol(argv[++i], &argptr, 10);
  368. if (zdim == 0)
  369. {
  370. fprintf(stderr, "the Z dimension cannot be 0!\n");
  371. exit(EXIT_FAILURE);
  372. }
  373. }
  374. else if (strcmp(argv[i], "-size") == 0)
  375. {
  376. char *argptr;
  377. xdim = ydim = zdim = strtol(argv[++i], &argptr, 10);
  378. if (xdim == 0)
  379. {
  380. fprintf(stderr, "the size cannot be 0!\n");
  381. exit(EXIT_FAILURE);
  382. }
  383. }
  384. else if (strcmp(argv[i], "-iter") == 0)
  385. {
  386. char *argptr;
  387. niter = strtol(argv[++i], &argptr, 10);
  388. if (niter == 0)
  389. {
  390. fprintf(stderr, "the number of iterations cannot be 0!\n");
  391. exit(EXIT_FAILURE);
  392. }
  393. }
  394. else if (strcmp(argv[i], "-nsleeps") == 0)
  395. {
  396. char *argptr;
  397. nsleeps = strtol(argv[++i], &argptr, 10);
  398. }
  399. else if (strcmp(argv[i], "-bound") == 0)
  400. {
  401. bound = 1;
  402. }
  403. else if (strcmp(argv[i], "-hostname") == 0)
  404. {
  405. print_hostname = 1;
  406. }
  407. else if (strcmp(argv[i], "-check") == 0)
  408. {
  409. check = 1;
  410. }
  411. else if (strcmp(argv[i], "-spmd") == 0)
  412. {
  413. cl_gemm0.type = STARPU_SPMD;
  414. }
  415. else if (strcmp(argv[i], "-help") == 0 || strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0)
  416. {
  417. fprintf(stderr,"Usage: %s [-3d] [-nblocks n] [-nblocksx x] [-nblocksy y] [-nblocksz z] [-x x] [-y y] [-xy n] [-z z] [-size size] [-iter iter] [-bound] [-check] [-spmd] [-hostname] [-nsleeps nsleeps]\n", argv[0]);
  418. if (tiled)
  419. 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);
  420. else
  421. 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);
  422. exit(EXIT_SUCCESS);
  423. }
  424. else
  425. {
  426. fprintf(stderr,"Unrecognized option %s\n", argv[i]);
  427. exit(EXIT_FAILURE);
  428. }
  429. }
  430. }
  431. int main(int argc, char **argv)
  432. {
  433. double start, end;
  434. int ret;
  435. parse_args(argc, argv);
  436. #ifdef STARPU_QUICK_CHECK
  437. niter /= 10;
  438. #endif
  439. starpu_fxt_autostart_profiling(0);
  440. ret = starpu_init(NULL);
  441. if (ret == -ENODEV)
  442. return 77;
  443. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  444. starpu_cublas_init();
  445. init_problem_data();
  446. partition_mult_data();
  447. PRINTF("# ");
  448. if (print_hostname)
  449. PRINTF("node\t");
  450. PRINTF("x\ty\tz\tms\tGFlops");
  451. if (bound)
  452. PRINTF("\tTms\tTGFlops\tTims\tTiGFlops");
  453. PRINTF("\n");
  454. unsigned sleeps;
  455. for (sleeps = 0; sleeps < nsleeps; sleeps++)
  456. {
  457. if (bound)
  458. starpu_bound_start(0, 0);
  459. starpu_fxt_start_profiling();
  460. start = starpu_timing_now();
  461. unsigned x, y, z, iter;
  462. for (iter = 0; iter < niter; iter++)
  463. {
  464. if (tiled)
  465. {
  466. for (x = 0; x < nslicesx; x++)
  467. for (y = 0; y < nslicesy; y++)
  468. {
  469. starpu_data_handle_t Ctile = starpu_data_get_sub_data(C_handle, 2, x, y);
  470. for (z = 0; z < nslicesz; z++)
  471. {
  472. struct starpu_task *task = starpu_task_create();
  473. if (z == 0)
  474. task->cl = &cl_gemm0;
  475. else
  476. task->cl = &cl_gemm;
  477. task->handles[0] = starpu_data_get_sub_data(A_handle, 2, z, y);
  478. task->handles[1] = starpu_data_get_sub_data(B_handle, 2, x, z);
  479. task->handles[2] = Ctile;
  480. task->flops = 2ULL * (xdim/nslicesx) * (ydim/nslicesy) * (zdim/nslicesz);
  481. ret = starpu_task_submit(task);
  482. if (ret == -ENODEV)
  483. {
  484. check = 0;
  485. ret = 77;
  486. goto enodev;
  487. }
  488. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  489. }
  490. starpu_data_wont_use(Ctile);
  491. }
  492. }
  493. else
  494. {
  495. for (x = 0; x < nslicesx; x++)
  496. for (y = 0; y < nslicesy; y++)
  497. {
  498. struct starpu_task *task = starpu_task_create();
  499. task->cl = &cl_gemm0;
  500. task->handles[0] = starpu_data_get_sub_data(A_handle, 1, y);
  501. task->handles[1] = starpu_data_get_sub_data(B_handle, 1, x);
  502. task->handles[2] = starpu_data_get_sub_data(C_handle, 2, x, y);
  503. task->flops = 2ULL * (xdim/nslicesx) * (ydim/nslicesy) * zdim;
  504. ret = starpu_task_submit(task);
  505. if (ret == -ENODEV)
  506. {
  507. check = 0;
  508. ret = 77;
  509. goto enodev;
  510. }
  511. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  512. starpu_data_wont_use(starpu_data_get_sub_data(C_handle, 2, x, y));
  513. }
  514. }
  515. starpu_task_wait_for_all();
  516. }
  517. end = starpu_timing_now();
  518. starpu_fxt_stop_profiling();
  519. if (bound)
  520. starpu_bound_stop();
  521. double timing = end - start;
  522. double min, min_int;
  523. double flops = 2.0*((unsigned long long)niter)*((unsigned long long)xdim)
  524. *((unsigned long long)ydim)*((unsigned long long)zdim);
  525. if (bound)
  526. starpu_bound_compute(&min, &min_int, 1);
  527. if (print_hostname)
  528. {
  529. char hostname[255];
  530. gethostname(hostname, 255);
  531. PRINTF("%s\t", hostname);
  532. }
  533. PRINTF("%u\t%u\t%u\t%.0f\t%.1f", xdim, ydim, zdim, timing/niter/1000.0, flops/timing/1000.0);
  534. if (bound)
  535. PRINTF("\t%.0f\t%.1f\t%.0f\t%.1f", min, flops/min/1000000.0, min_int, flops/min_int/1000000.0);
  536. PRINTF("\n");
  537. if (sleeps < nsleeps-1)
  538. {
  539. sleep(10);
  540. }
  541. }
  542. enodev:
  543. starpu_data_unpartition(C_handle, STARPU_MAIN_RAM);
  544. starpu_data_unpartition(B_handle, STARPU_MAIN_RAM);
  545. starpu_data_unpartition(A_handle, STARPU_MAIN_RAM);
  546. starpu_data_unregister(A_handle);
  547. starpu_data_unregister(B_handle);
  548. starpu_data_unregister(C_handle);
  549. #ifdef STARPU_HAVE_BLAS
  550. #ifndef STARPU_SIMGRID
  551. if (check)
  552. ret = check_output();
  553. #endif
  554. #endif
  555. starpu_free_flags(A, zdim*ydim*sizeof(TYPE), STARPU_MALLOC_PINNED|STARPU_MALLOC_SIMULATION_FOLDED);
  556. starpu_free_flags(B, xdim*zdim*sizeof(TYPE), STARPU_MALLOC_PINNED|STARPU_MALLOC_SIMULATION_FOLDED);
  557. starpu_free_flags(C, xdim*ydim*sizeof(TYPE), STARPU_MALLOC_PINNED|STARPU_MALLOC_SIMULATION_FOLDED);
  558. starpu_cublas_shutdown();
  559. starpu_shutdown();
  560. return ret;
  561. }