stencil-kernels.c 22 KB

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