shadow.cu 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010 Université de Bordeaux 1
  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. #define _externC extern "C"
  17. #include "stencil.h"
  18. #include <starpu_cuda.h>
  19. /* Perform replication of data on X and Y edges, to fold the domain on
  20. itself through mere replication of the source state. */
  21. extern "C" __global__ void
  22. cuda_shadow( int bz, TYPE *ptr, int nx, int ny, int nz, int ldy, int ldz, int i)
  23. {
  24. unsigned idx = threadIdx.x + blockIdx.x * blockDim.x;
  25. unsigned idy = threadIdx.y + blockIdx.y * blockDim.y;
  26. //unsigned idz = threadIdx.z + blockIdx.z * blockDim.z;
  27. unsigned idz = 0;
  28. unsigned stepx = blockDim.x * gridDim.x;
  29. unsigned stepy = blockDim.y * gridDim.y;
  30. //unsigned stepz = blockDim.z * gridDim.z;
  31. unsigned stepz = 1;
  32. unsigned x, y, z;
  33. #include "shadow.h"
  34. }
  35. extern "C" void
  36. cuda_shadow_host(int bz, TYPE *ptr, int nx, int ny, int nz, int ldy, int ldz, int i)
  37. {
  38. unsigned max_parallelism = 512;
  39. unsigned threads_per_dim_x = max_parallelism;
  40. while (threads_per_dim_x / 2 >= nx)
  41. threads_per_dim_x /= 2;
  42. unsigned threads_per_dim_y = max_parallelism / threads_per_dim_x;
  43. while (threads_per_dim_y / 2 >= ny)
  44. threads_per_dim_y /= 2;
  45. #if 0
  46. unsigned threads_per_dim_z = 4;
  47. dim3 dimBlock(threads_per_dim_x, threads_per_dim_y, threads_per_dim_z);
  48. dim3 dimGrid(nx / threads_per_dim_x, ny / threads_per_dim_y, nz / threads_per_dim_z);
  49. #else
  50. dim3 dimBlock(threads_per_dim_x, threads_per_dim_y);
  51. dim3 dimGrid((nx + threads_per_dim_x-1) / threads_per_dim_x, (ny + threads_per_dim_y-1) / threads_per_dim_y);
  52. #endif
  53. cuda_shadow <<<dimGrid, dimBlock, 0, starpu_cuda_get_local_stream()>>> (bz, ptr, nx, ny, nz, ldy, ldz, i);
  54. }