stencil-kernels.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2015 Université de Bordeaux
  4. * Copyright (C) 2012, 2013, 2016 CNRS
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include "stencil.h"
  18. /* Computation Kernels */
  19. /*
  20. * There are three codeletets:
  21. *
  22. * - cl_update, which takes a block and the boundaries of its neighbours, loads
  23. * the boundaries into the block and perform some update loops:
  24. *
  25. * comp. buffer save. buffers comp. buffer save. buffers comp. buffer
  26. * | ... |
  27. * | | +------------------+ +------------------+
  28. * | #N+1 | | #N+1 bottom copy====>#N+1 bottom copy |
  29. * +-------------+ +------------------+ +------------------+
  30. * | #N top copy | | #N top copy | | |
  31. * +-------------+ +------------------+ | |
  32. * | #N |
  33. * ...
  34. * | | +----------------+ +----------------------+
  35. * | | | #N bottom copy | | block #N bottom copy |
  36. * ^ +------------------+ +----------------+ +----------------------+
  37. * | | #N-1 top copy <====#N-1 top copy | | block #N-1 |
  38. * | +------------------+ +----------------+ | |
  39. * Z ...
  40. *
  41. * - save_cl_top, which take a block and its top boundary, and saves the top of
  42. * the block into the boundary (to be given as bottom of the neighbour above
  43. * this block).
  44. *
  45. * comp. buffer save. buffers comp. buffer save. buffers comp. buffer
  46. * | ... |
  47. * | | +------------------+ +------------------+
  48. * | #N+1 | | #N+1 bottom copy | | #N+1 bottom copy |
  49. * +-------------+ +------------------+ +------------------+
  50. * | #N top copy | | #N top copy <==== |
  51. * +-------------+ +------------------+ |..................|
  52. * | #N |
  53. * ...
  54. * | | +----------------+ +----------------------+
  55. * | | | #N bottom copy | | block #N bottom copy |
  56. * ^ +------------------+ +----------------+ +----------------------+
  57. * | | #N-1 top copy | | #N-1 top copy | | block #N-1 |
  58. * | +------------------+ +----------------+ | |
  59. * Z ...
  60. *
  61. * - save_cl_bottom, same for the bottom
  62. * comp. buffer save. buffers comp. buffer save. buffers comp. buffer
  63. * | ... |
  64. * | | +------------------+ +------------------+
  65. * | #N+1 | | #N+1 bottom copy | | #N+1 bottom copy |
  66. * +-------------+ +------------------+ +------------------+
  67. * | #N top copy | | #N top copy | | |
  68. * +-------------+ +------------------+ | |
  69. * | #N |
  70. * ...
  71. * |..................| +----------------+ +----------------------+
  72. * | ====>#N bottom copy | | block #N bottom copy |
  73. * ^ +------------------+ +----------------+ +----------------------+
  74. * | | #N-1 top copy | | #N-1 top copy | | block #N-1 |
  75. * | +------------------+ +----------------+ | |
  76. * Z ...
  77. *
  78. * The idea is that the computation buffers thus don't have to move, only their
  79. * boundaries are copied to buffers that do move (be it CPU/GPU, GPU/GPU or via
  80. * MPI)
  81. *
  82. * For each of the buffers above, there are two (0/1) buffers to make new/old switch costless.
  83. */
  84. #if 0
  85. # define DEBUG(fmt, ...) fprintf(stderr,fmt,##__VA_ARGS__)
  86. #else
  87. # define DEBUG(fmt, ...) (void) 0
  88. #endif
  89. /* Record which GPU ran which block, for nice pictures */
  90. int who_runs_what_len;
  91. int *who_runs_what;
  92. int *who_runs_what_index;
  93. double *last_tick;
  94. /* Achieved iterations */
  95. static int achieved_iter;
  96. /* Record how many updates each worker performed */
  97. unsigned update_per_worker[STARPU_NMAXWORKERS];
  98. static void record_who_runs_what(struct block_description *block)
  99. {
  100. double now, now2, diff, delta = get_ticks() * 1000;
  101. int workerid = starpu_worker_get_id_check();
  102. now = starpu_timing_now();
  103. now2 = now - start;
  104. diff = now2 - last_tick[block->bz];
  105. while (diff >= delta)
  106. {
  107. last_tick[block->bz] += delta;
  108. diff = now2 - last_tick[block->bz];
  109. if (who_runs_what_index[block->bz] < who_runs_what_len)
  110. who_runs_what[block->bz + (who_runs_what_index[block->bz]++) * get_nbz()] = -1;
  111. }
  112. if (who_runs_what_index[block->bz] < who_runs_what_len)
  113. who_runs_what[block->bz + (who_runs_what_index[block->bz]++) * get_nbz()] = global_workerid(workerid);
  114. }
  115. static void check_load(struct starpu_block_interface *block, struct starpu_block_interface *boundary)
  116. {
  117. /* Sanity checks */
  118. STARPU_ASSERT(block->nx == boundary->nx);
  119. STARPU_ASSERT(block->ny == boundary->ny);
  120. STARPU_ASSERT(boundary->nz == K);
  121. /* NB: this is not fully garanteed ... but it's *very* likely and that
  122. * makes our life much simpler */
  123. STARPU_ASSERT(block->ldy == boundary->ldy);
  124. STARPU_ASSERT(block->ldz == boundary->ldz);
  125. }
  126. /*
  127. * Load a neighbour's boundary into block, CPU version
  128. */
  129. static void load_subblock_from_buffer_cpu(void *_block,
  130. void *_boundary,
  131. unsigned firstz)
  132. {
  133. struct starpu_block_interface *block = (struct starpu_block_interface *)_block;
  134. struct starpu_block_interface *boundary = (struct starpu_block_interface *)_boundary;
  135. check_load(block, boundary);
  136. /* We do a contiguous memory transfer */
  137. size_t boundary_size = K*block->ldz*block->elemsize;
  138. unsigned offset = firstz*block->ldz;
  139. TYPE *block_data = (TYPE *)block->ptr;
  140. TYPE *boundary_data = (TYPE *)boundary->ptr;
  141. memcpy(&block_data[offset], boundary_data, boundary_size);
  142. }
  143. /*
  144. * Load a neighbour's boundary into block, CUDA version
  145. */
  146. #ifdef STARPU_USE_CUDA
  147. static void load_subblock_from_buffer_cuda(void *_block,
  148. void *_boundary,
  149. unsigned firstz)
  150. {
  151. struct starpu_block_interface *block = (struct starpu_block_interface *)_block;
  152. struct starpu_block_interface *boundary = (struct starpu_block_interface *)_boundary;
  153. check_load(block, boundary);
  154. /* We do a contiguous memory transfer */
  155. size_t boundary_size = K*block->ldz*block->elemsize;
  156. unsigned offset = firstz*block->ldz;
  157. TYPE *block_data = (TYPE *)block->ptr;
  158. TYPE *boundary_data = (TYPE *)boundary->ptr;
  159. cudaMemcpyAsync(&block_data[offset], boundary_data, boundary_size, cudaMemcpyDeviceToDevice, starpu_cuda_get_local_stream());
  160. }
  161. /*
  162. * cl_update (CUDA version)
  163. */
  164. static void update_func_cuda(void *descr[], void *arg)
  165. {
  166. struct block_description *block = arg;
  167. int workerid = starpu_worker_get_id_check();
  168. DEBUG( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
  169. if (block->bz == 0)
  170. FPRINTF(stderr,"!!! DO update_func_cuda z %d CUDA%d !!!\n", block->bz, workerid);
  171. else
  172. DEBUG( "!!! DO update_func_cuda z %d CUDA%d !!!\n", block->bz, workerid);
  173. #if defined(STARPU_USE_MPI) && !defined(STARPU_SIMGRID)
  174. int rank = 0;
  175. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  176. DEBUG( "!!! RANK %d !!!\n", rank);
  177. #endif
  178. DEBUG( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
  179. unsigned block_size_z = get_block_size(block->bz);
  180. unsigned i;
  181. update_per_worker[workerid]++;
  182. record_who_runs_what(block);
  183. /*
  184. * Load neighbours' boundaries : TOP
  185. */
  186. /* The offset along the z axis is (block_size_z + K) */
  187. load_subblock_from_buffer_cuda(descr[0], descr[2], block_size_z+K);
  188. load_subblock_from_buffer_cuda(descr[1], descr[3], block_size_z+K);
  189. /*
  190. * Load neighbours' boundaries : BOTTOM
  191. */
  192. load_subblock_from_buffer_cuda(descr[0], descr[4], 0);
  193. load_subblock_from_buffer_cuda(descr[1], descr[5], 0);
  194. /*
  195. * Stencils ... do the actual work here :) TODO
  196. */
  197. for (i=1; i<=K; i++)
  198. {
  199. struct starpu_block_interface *oldb = descr[i%2], *newb = descr[(i+1)%2];
  200. TYPE *old = (void*) oldb->ptr, *newer = (void*) newb->ptr;
  201. /* Shadow data */
  202. cuda_shadow_host(block->bz, old, oldb->nx, oldb->ny, oldb->nz, oldb->ldy, oldb->ldz, i);
  203. /* And perform actual computation */
  204. #ifdef LIFE
  205. cuda_life_update_host(block->bz, old, newer, oldb->nx, oldb->ny, oldb->nz, oldb->ldy, oldb->ldz, i);
  206. #else
  207. cudaMemcpyAsync(newer, old, oldb->nx * oldb->ny * oldb->nz * sizeof(*newer), cudaMemcpyDeviceToDevice, starpu_cuda_get_local_stream());
  208. #endif /* LIFE */
  209. }
  210. if (block->bz == 0)
  211. starpu_top_update_data_integer(starpu_top_achieved_loop, ++achieved_iter);
  212. }
  213. #endif /* STARPU_USE_CUDA */
  214. /*
  215. * Load a neighbour's boundary into block, OpenCL version
  216. */
  217. #ifdef STARPU_USE_OPENCL
  218. static void load_subblock_from_buffer_opencl(struct starpu_block_interface *block,
  219. struct starpu_block_interface *boundary,
  220. unsigned firstz)
  221. {
  222. check_load(block, boundary);
  223. /* We do a contiguous memory transfer */
  224. size_t boundary_size = K*block->ldz*block->elemsize;
  225. unsigned offset = firstz*block->ldz;
  226. cl_mem block_data = (cl_mem)block->dev_handle;
  227. cl_mem boundary_data = (cl_mem)boundary->dev_handle;
  228. cl_event event;
  229. cl_command_queue cq;
  230. starpu_opencl_get_current_queue(&cq);
  231. cl_int ret = clEnqueueCopyBuffer(cq, boundary_data, block_data, 0, offset, boundary_size, 0, NULL, NULL);
  232. if (ret != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(ret);
  233. }
  234. /*
  235. * cl_update (OpenCL version)
  236. */
  237. static void update_func_opencl(void *descr[], void *arg)
  238. {
  239. struct block_description *block = arg;
  240. int workerid = starpu_worker_get_id_check();
  241. DEBUG( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
  242. if (block->bz == 0)
  243. FPRINTF(stderr,"!!! DO update_func_opencl z %d OPENCL%d !!!\n", block->bz, workerid);
  244. else
  245. DEBUG( "!!! DO update_func_opencl z %d OPENCL%d !!!\n", block->bz, workerid);
  246. #if defined(STARPU_USE_MPI) && !defined(STARPU_SIMGRID)
  247. int rank = 0;
  248. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  249. DEBUG( "!!! RANK %d !!!\n", rank);
  250. #endif
  251. DEBUG( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
  252. unsigned block_size_z = get_block_size(block->bz);
  253. unsigned i;
  254. update_per_worker[workerid]++;
  255. record_who_runs_what(block);
  256. cl_command_queue cq;
  257. starpu_opencl_get_current_queue(&cq);
  258. /*
  259. * Load neighbours' boundaries : TOP
  260. */
  261. /* The offset along the z axis is (block_size_z + K) */
  262. load_subblock_from_buffer_opencl(descr[0], descr[2], block_size_z+K);
  263. load_subblock_from_buffer_opencl(descr[1], descr[3], block_size_z+K);
  264. /*
  265. * Load neighbours' boundaries : BOTTOM
  266. */
  267. load_subblock_from_buffer_opencl(descr[0], descr[4], 0);
  268. load_subblock_from_buffer_opencl(descr[1], descr[5], 0);
  269. /*
  270. * Stencils ... do the actual work here :) TODO
  271. */
  272. for (i=1; i<=K; i++)
  273. {
  274. struct starpu_block_interface *oldb = descr[i%2], *newb = descr[(i+1)%2];
  275. TYPE *old = (void*) oldb->dev_handle, *newer = (void*) newb->dev_handle;
  276. /* Shadow data */
  277. opencl_shadow_host(block->bz, old, oldb->nx, oldb->ny, oldb->nz, oldb->ldy, oldb->ldz, i);
  278. /* And perform actual computation */
  279. #ifdef LIFE
  280. opencl_life_update_host(block->bz, old, newer, oldb->nx, oldb->ny, oldb->nz, oldb->ldy, oldb->ldz, i);
  281. #else
  282. cl_event event;
  283. cl_int ret = clEnqueueCopyBuffer(cq, old, newer, 0, 0, oldb->nx * oldb->ny * oldb->nz * sizeof(*newer), 0, NULL, &event);
  284. if (ret != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(ret);
  285. #endif /* LIFE */
  286. }
  287. if (block->bz == 0)
  288. starpu_top_update_data_integer(starpu_top_achieved_loop, ++achieved_iter);
  289. }
  290. #endif /* STARPU_USE_OPENCL */
  291. /*
  292. * cl_update (CPU version)
  293. */
  294. void update_func_cpu(void *descr[], void *arg)
  295. {
  296. struct block_description *block = (struct block_description *) arg;
  297. int workerid = starpu_worker_get_id_check();
  298. DEBUG( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
  299. if (block->bz == 0)
  300. FPRINTF(stderr,"!!! DO update_func_cpu z %d CPU%d !!!\n", block->bz, workerid);
  301. else
  302. DEBUG( "!!! DO update_func_cpu z %d CPU%d !!!\n", block->bz, workerid);
  303. #if defined(STARPU_USE_MPI) && !defined(STARPU_SIMGRID)
  304. int rank = 0;
  305. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  306. DEBUG( "!!! RANK %d !!!\n", rank);
  307. #endif
  308. DEBUG( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
  309. unsigned block_size_z = get_block_size(block->bz);
  310. unsigned i;
  311. update_per_worker[workerid]++;
  312. record_who_runs_what(block);
  313. /*
  314. * Load neighbours' boundaries : TOP
  315. */
  316. /* The offset along the z axis is (block_size_z + K) */
  317. load_subblock_from_buffer_cpu(descr[0], descr[2], block_size_z+K);
  318. load_subblock_from_buffer_cpu(descr[1], descr[3], block_size_z+K);
  319. /*
  320. * Load neighbours' boundaries : BOTTOM
  321. */
  322. load_subblock_from_buffer_cpu(descr[0], descr[4], 0);
  323. load_subblock_from_buffer_cpu(descr[1], descr[5], 0);
  324. /*
  325. * Stencils ... do the actual work here :) TODO
  326. */
  327. for (i=1; i<=K; i++)
  328. {
  329. struct starpu_block_interface *oldb = (struct starpu_block_interface *) descr[i%2], *newb = (struct starpu_block_interface *) descr[(i+1)%2];
  330. TYPE *old = (TYPE*) oldb->ptr, *newer = (TYPE*) newb->ptr;
  331. /* Shadow data */
  332. unsigned ldy = oldb->ldy, ldz = oldb->ldz;
  333. unsigned nx = oldb->nx, ny = oldb->ny, nz = oldb->nz;
  334. unsigned x, y, z;
  335. unsigned stepx = 1;
  336. unsigned stepy = 1;
  337. unsigned stepz = 1;
  338. unsigned idx = 0;
  339. unsigned idy = 0;
  340. unsigned idz = 0;
  341. TYPE *ptr = old;
  342. # include "shadow.h"
  343. /* And perform actual computation */
  344. #ifdef LIFE
  345. life_update(block->bz, old, newer, oldb->nx, oldb->ny, oldb->nz, oldb->ldy, oldb->ldz, i);
  346. #else
  347. memcpy(newer, old, oldb->nx * oldb->ny * oldb->nz * sizeof(*newer));
  348. #endif /* LIFE */
  349. }
  350. if (block->bz == 0)
  351. starpu_top_update_data_integer(starpu_top_achieved_loop, ++achieved_iter);
  352. }
  353. /* Performance model and codelet structure */
  354. static struct starpu_perfmodel cl_update_model =
  355. {
  356. .type = STARPU_HISTORY_BASED,
  357. .symbol = "cl_update"
  358. };
  359. struct starpu_codelet cl_update =
  360. {
  361. .cpu_funcs = {update_func_cpu},
  362. #ifdef STARPU_USE_CUDA
  363. .cuda_funcs = {update_func_cuda},
  364. .cuda_flags = {STARPU_CUDA_ASYNC},
  365. #endif
  366. #ifdef STARPU_USE_OPENCL
  367. .opencl_funcs = {update_func_opencl},
  368. .opencl_flags = {STARPU_OPENCL_ASYNC},
  369. #endif
  370. .model = &cl_update_model,
  371. .nbuffers = 6,
  372. .modes = {STARPU_RW, STARPU_RW, STARPU_R, STARPU_R, STARPU_R, STARPU_R}
  373. };
  374. /*
  375. * Save the block internal boundaries to give them to our neighbours.
  376. */
  377. /* CPU version */
  378. static void load_subblock_into_buffer_cpu(void *_block,
  379. void *_boundary,
  380. unsigned firstz)
  381. {
  382. struct starpu_block_interface *block = (struct starpu_block_interface *)_block;
  383. struct starpu_block_interface *boundary = (struct starpu_block_interface *)_boundary;
  384. check_load(block, boundary);
  385. /* We do a contiguous memory transfer */
  386. size_t boundary_size = K*block->ldz*block->elemsize;
  387. unsigned offset = firstz*block->ldz;
  388. TYPE *block_data = (TYPE *)block->ptr;
  389. TYPE *boundary_data = (TYPE *)boundary->ptr;
  390. memcpy(boundary_data, &block_data[offset], boundary_size);
  391. }
  392. /* CUDA version */
  393. #ifdef STARPU_USE_CUDA
  394. static void load_subblock_into_buffer_cuda(void *_block,
  395. void *_boundary,
  396. unsigned firstz)
  397. {
  398. struct starpu_block_interface *block = (struct starpu_block_interface *)_block;
  399. struct starpu_block_interface *boundary = (struct starpu_block_interface *)_boundary;
  400. check_load(block, boundary);
  401. /* We do a contiguous memory transfer */
  402. size_t boundary_size = K*block->ldz*block->elemsize;
  403. unsigned offset = firstz*block->ldz;
  404. TYPE *block_data = (TYPE *)block->ptr;
  405. TYPE *boundary_data = (TYPE *)boundary->ptr;
  406. cudaMemcpyAsync(boundary_data, &block_data[offset], boundary_size, cudaMemcpyDeviceToDevice, starpu_cuda_get_local_stream());
  407. }
  408. #endif /* STARPU_USE_CUDA */
  409. /* OPENCL version */
  410. #ifdef STARPU_USE_OPENCL
  411. static void load_subblock_into_buffer_opencl(struct starpu_block_interface *block,
  412. struct starpu_block_interface *boundary,
  413. unsigned firstz)
  414. {
  415. check_load(block, boundary);
  416. /* We do a contiguous memory transfer */
  417. size_t boundary_size = K*block->ldz*block->elemsize;
  418. unsigned offset = firstz*block->ldz;
  419. cl_mem block_data = (cl_mem)block->dev_handle;
  420. cl_mem boundary_data = (cl_mem)boundary->dev_handle;
  421. cl_command_queue cq;
  422. starpu_opencl_get_current_queue(&cq);
  423. cl_event event;
  424. cl_int ret = clEnqueueCopyBuffer(cq, block_data, boundary_data, offset, 0, boundary_size, 0, NULL, NULL);
  425. if (ret != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(ret);
  426. }
  427. #endif /* STARPU_USE_OPENCL */
  428. /* Record how many top/bottom saves each worker performed */
  429. unsigned top_per_worker[STARPU_NMAXWORKERS];
  430. unsigned bottom_per_worker[STARPU_NMAXWORKERS];
  431. /* top save, CPU version */
  432. void dummy_func_top_cpu(void *descr[] STARPU_ATTRIBUTE_UNUSED, void *arg)
  433. {
  434. struct block_description *block = (struct block_description *) arg;
  435. int workerid = starpu_worker_get_id_check();
  436. top_per_worker[workerid]++;
  437. DEBUG( "DO SAVE Bottom block %d\n", block->bz);
  438. /* The offset along the z axis is (block_size_z + K)- K */
  439. unsigned block_size_z = get_block_size(block->bz);
  440. load_subblock_into_buffer_cpu(descr[0], descr[2], block_size_z);
  441. load_subblock_into_buffer_cpu(descr[1], descr[3], block_size_z);
  442. }
  443. /* bottom save, CPU version */
  444. void dummy_func_bottom_cpu(void *descr[] STARPU_ATTRIBUTE_UNUSED, void *arg)
  445. {
  446. struct block_description *block = (struct block_description *) arg;
  447. int workerid = starpu_worker_get_id_check();
  448. bottom_per_worker[workerid]++;
  449. DEBUG( "DO SAVE Top block %d\n", block->bz);
  450. load_subblock_into_buffer_cpu(descr[0], descr[2], K);
  451. load_subblock_into_buffer_cpu(descr[1], descr[3], K);
  452. }
  453. /* top save, CUDA version */
  454. #ifdef STARPU_USE_CUDA
  455. static void dummy_func_top_cuda(void *descr[] STARPU_ATTRIBUTE_UNUSED, void *arg)
  456. {
  457. struct block_description *block = (struct block_description *) arg;
  458. int workerid = starpu_worker_get_id_check();
  459. top_per_worker[workerid]++;
  460. DEBUG( "DO SAVE Top block %d\n", block->bz);
  461. /* The offset along the z axis is (block_size_z + K)- K */
  462. unsigned block_size_z = get_block_size(block->bz);
  463. load_subblock_into_buffer_cuda(descr[0], descr[2], block_size_z);
  464. load_subblock_into_buffer_cuda(descr[1], descr[3], block_size_z);
  465. }
  466. /* bottom save, CUDA version */
  467. static void dummy_func_bottom_cuda(void *descr[] STARPU_ATTRIBUTE_UNUSED, void *arg)
  468. {
  469. struct block_description *block = (struct block_description *) arg;
  470. int workerid = starpu_worker_get_id_check();
  471. bottom_per_worker[workerid]++;
  472. DEBUG( "DO SAVE Bottom block %d on CUDA\n", block->bz);
  473. load_subblock_into_buffer_cuda(descr[0], descr[2], K);
  474. load_subblock_into_buffer_cuda(descr[1], descr[3], K);
  475. }
  476. #endif /* STARPU_USE_CUDA */
  477. /* top save, OpenCL version */
  478. #ifdef STARPU_USE_OPENCL
  479. static void dummy_func_top_opencl(void *descr[] STARPU_ATTRIBUTE_UNUSED, void *arg)
  480. {
  481. struct block_description *block = (struct block_description *) arg;
  482. int workerid = starpu_worker_get_id_check();
  483. top_per_worker[workerid]++;
  484. DEBUG( "DO SAVE Top block %d\n", block->bz);
  485. /* The offset along the z axis is (block_size_z + K)- K */
  486. unsigned block_size_z = get_block_size(block->bz);
  487. load_subblock_into_buffer_opencl(descr[0], descr[2], block_size_z);
  488. load_subblock_into_buffer_opencl(descr[1], descr[3], block_size_z);
  489. }
  490. /* bottom save, OPENCL version */
  491. static void dummy_func_bottom_opencl(void *descr[] STARPU_ATTRIBUTE_UNUSED, void *arg)
  492. {
  493. struct block_description *block = (struct block_description *) arg;
  494. int workerid = starpu_worker_get_id_check();
  495. bottom_per_worker[workerid]++;
  496. DEBUG( "DO SAVE Bottom block %d on OPENCL\n", block->bz);
  497. load_subblock_into_buffer_opencl(descr[0], descr[2], K);
  498. load_subblock_into_buffer_opencl(descr[1], descr[3], K);
  499. }
  500. #endif /* STARPU_USE_OPENCL */
  501. /* Performance models and codelet for save */
  502. static struct starpu_perfmodel save_cl_bottom_model =
  503. {
  504. .type = STARPU_HISTORY_BASED,
  505. .symbol = "save_cl_bottom"
  506. };
  507. static struct starpu_perfmodel save_cl_top_model =
  508. {
  509. .type = STARPU_HISTORY_BASED,
  510. .symbol = "save_cl_top"
  511. };
  512. struct starpu_codelet save_cl_bottom =
  513. {
  514. .cpu_funcs = {dummy_func_bottom_cpu},
  515. #ifdef STARPU_USE_CUDA
  516. .cuda_funcs = {dummy_func_bottom_cuda},
  517. .cuda_flags = {STARPU_CUDA_ASYNC},
  518. #endif
  519. #ifdef STARPU_USE_OPENCL
  520. .opencl_funcs = {dummy_func_bottom_opencl},
  521. .opencl_flags = {STARPU_OPENCL_ASYNC},
  522. #endif
  523. .model = &save_cl_bottom_model,
  524. .nbuffers = 4,
  525. .modes = {STARPU_R, STARPU_R, STARPU_W, STARPU_W}
  526. };
  527. struct starpu_codelet save_cl_top =
  528. {
  529. .cpu_funcs = {dummy_func_top_cpu},
  530. #ifdef STARPU_USE_CUDA
  531. .cuda_funcs = {dummy_func_top_cuda},
  532. .cuda_flags = {STARPU_CUDA_ASYNC},
  533. #endif
  534. #ifdef STARPU_USE_OPENCL
  535. .opencl_funcs = {dummy_func_top_opencl},
  536. .opencl_flags = {STARPU_OPENCL_ASYNC},
  537. #endif
  538. .model = &save_cl_top_model,
  539. .nbuffers = 4,
  540. .modes = {STARPU_R, STARPU_R, STARPU_W, STARPU_W}
  541. };