shadow.cu 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. /* Perform replication of data on X and Y edges, to fold the domain on
  19. itself through mere replication of the source state. */
  20. extern "C" __global__ void
  21. 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
  35. cuda_shadow_host(int bz, TYPE *ptr, int nx, int ny, int nz, int ldy, int ldz, int i)
  36. {
  37. unsigned max_parallelism = 512;
  38. unsigned threads_per_dim_x = max_parallelism;
  39. while (threads_per_dim_x / 2 >= nx)
  40. threads_per_dim_x /= 2;
  41. unsigned threads_per_dim_y = max_parallelism / threads_per_dim_x;
  42. while (threads_per_dim_y / 2 >= ny)
  43. threads_per_dim_y /= 2;
  44. #if 0
  45. unsigned threads_per_dim_z = 4;
  46. dim3 dimBlock(threads_per_dim_x, threads_per_dim_y, threads_per_dim_z);
  47. dim3 dimGrid(nx / threads_per_dim_x, ny / threads_per_dim_y, nz / threads_per_dim_z);
  48. #else
  49. dim3 dimBlock(threads_per_dim_x, threads_per_dim_y);
  50. dim3 dimGrid((nx + threads_per_dim_x-1) / threads_per_dim_x, (ny + threads_per_dim_y-1) / threads_per_dim_y);
  51. #endif
  52. cuda_shadow <<<dimGrid, dimBlock, 0, starpu_cuda_get_local_stream()>>> (bz, ptr, nx, ny, nz, ldy, ldz, i);
  53. }