stencil-kernels.c 23 KB

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