shadow.cu 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012 CNRS
  4. * Copyright (C) 2010-2011,2014,2016 Université de Bordeaux
  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. #define _externC extern "C"
  18. #include "stencil.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 cuda_shadow( int bz, TYPE *ptr, int nx, int ny, int nz, int ldy, int ldz, int i)
  22. {
  23. unsigned idx = threadIdx.x + blockIdx.x * blockDim.x;
  24. unsigned idy = threadIdx.y + blockIdx.y * blockDim.y;
  25. //unsigned idz = threadIdx.z + blockIdx.z * blockDim.z;
  26. unsigned idz = 0;
  27. unsigned stepx = blockDim.x * gridDim.x;
  28. unsigned stepy = blockDim.y * gridDim.y;
  29. //unsigned stepz = blockDim.z * gridDim.z;
  30. unsigned stepz = 1;
  31. unsigned x, y, z;
  32. #include "shadow.h"
  33. }
  34. extern "C" void cuda_shadow_host(int bz, TYPE *ptr, int nx, int ny, int nz, int ldy, int ldz, int i)
  35. {
  36. unsigned max_parallelism = 512;
  37. unsigned threads_per_dim_x = max_parallelism;
  38. while (threads_per_dim_x / 2 >= nx)
  39. threads_per_dim_x /= 2;
  40. unsigned threads_per_dim_y = max_parallelism / threads_per_dim_x;
  41. while (threads_per_dim_y / 2 >= ny)
  42. threads_per_dim_y /= 2;
  43. #if 0
  44. unsigned threads_per_dim_z = 4;
  45. dim3 dimBlock(threads_per_dim_x, threads_per_dim_y, threads_per_dim_z);
  46. dim3 dimGrid(nx / threads_per_dim_x, ny / threads_per_dim_y, nz / threads_per_dim_z);
  47. #else
  48. dim3 dimBlock(threads_per_dim_x, threads_per_dim_y);
  49. dim3 dimGrid((nx + threads_per_dim_x-1) / threads_per_dim_x, (ny + threads_per_dim_y-1) / threads_per_dim_y);
  50. #endif
  51. cuda_shadow <<<dimGrid, dimBlock, 0, starpu_cuda_get_local_stream()>>> (bz, ptr, nx, ny, nz, ldy, ldz, i);
  52. }