stencil-kernels.c 23 KB

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