block_cuda.cu 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2012 Inria
  4. * Copyright (C) 2012,2015,2017 CNRS
  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 <starpu.h>
  18. #include "../test_interfaces.h"
  19. extern struct test_config block_config;
  20. static __global__ void block_cuda(int *block,
  21. int nx, int ny, int nz,
  22. unsigned ldy, unsigned ldz,
  23. float factor, int *err)
  24. {
  25. int i, j, k;
  26. int val = 0;
  27. for (k = 0; k < nz ;k++)
  28. {
  29. for (j = 0; j < ny ;j++)
  30. {
  31. for(i = 0; i < nx ;i++)
  32. {
  33. if (block[(k*ldz)+(j*ldy)+i] != factor * val)
  34. {
  35. *err = 1;
  36. return;
  37. }
  38. else
  39. {
  40. block[(k*ldz)+(j*ldy)+i] *= -1;
  41. val++;
  42. }
  43. }
  44. }
  45. }
  46. }
  47. extern "C" void test_block_cuda_func(void *buffers[], void *args)
  48. {
  49. cudaError_t error;
  50. int *ret;
  51. error = cudaMalloc(&ret, sizeof(int));
  52. if (error != cudaSuccess)
  53. STARPU_CUDA_REPORT_ERROR(error);
  54. error = cudaMemcpy(ret, &block_config.copy_failed, sizeof(int), cudaMemcpyHostToDevice);
  55. if (error != cudaSuccess)
  56. STARPU_CUDA_REPORT_ERROR(error);
  57. int nx = STARPU_BLOCK_GET_NX(buffers[0]);
  58. int ny = STARPU_BLOCK_GET_NY(buffers[0]);
  59. int nz = STARPU_BLOCK_GET_NZ(buffers[0]);
  60. unsigned ldy = STARPU_BLOCK_GET_LDY(buffers[0]);
  61. unsigned ldz = STARPU_BLOCK_GET_LDZ(buffers[0]);
  62. int *block = (int *) STARPU_BLOCK_GET_PTR(buffers[0]);
  63. int factor = *(int*) args;
  64. block_cuda<<<1,1, 0, starpu_cuda_get_local_stream()>>>
  65. (block, nx, ny, nz, ldy, ldz, factor, ret);
  66. error = cudaMemcpy(&block_config.copy_failed, ret, sizeof(int), cudaMemcpyDeviceToHost);
  67. if (error != cudaSuccess)
  68. STARPU_CUDA_REPORT_ERROR(error);
  69. cudaFree(ret);
  70. cudaStreamSynchronize(starpu_cuda_get_local_stream());
  71. }