shadow.cu 2.3 KB

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