stencil-kernels.c 22 KB

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