fmultiple_cuda.cu 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2015-2020 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. /* dumb CUDA kernel to check the matrix values and scale it up */
  17. #include <starpu.h>
  18. static __global__ void _fmultiple_check_scale_cuda(int *val, int nx, int ny, unsigned ld, int start, int factor)
  19. {
  20. int i, j;
  21. for(j=0; j<ny ; j++)
  22. {
  23. for(i=0; i<nx ; i++)
  24. {
  25. if (val[(j*ld)+i] != start + factor*(i+100*j))
  26. asm("trap;");
  27. val[(j*ld)+i] *= 2;
  28. }
  29. }
  30. }
  31. extern "C" void fmultiple_check_scale_cuda(void *buffers[], void *cl_arg)
  32. {
  33. int start, factor;
  34. int nx = (int)STARPU_MATRIX_GET_NX(buffers[0]);
  35. int ny = (int)STARPU_MATRIX_GET_NY(buffers[0]);
  36. unsigned ld = STARPU_MATRIX_GET_LD(buffers[0]);
  37. int *val = (int *)STARPU_MATRIX_GET_PTR(buffers[0]);
  38. starpu_codelet_unpack_args(cl_arg, &start, &factor);
  39. /* TODO: use more vals and threads in vals */
  40. _fmultiple_check_scale_cuda<<<1,1, 0, starpu_cuda_get_local_stream()>>>(val, nx, ny, ld, start, factor);
  41. cudaError_t status = cudaGetLastError();
  42. if (status != cudaSuccess) STARPU_CUDA_REPORT_ERROR(status);
  43. }
  44. static __global__ void _fmultiple_check_cuda(int *val, int nx, int ny, unsigned ld, int start, int factor)
  45. {
  46. int i, j;
  47. for(j=0; j<ny ; j++)
  48. {
  49. for(i=0; i<nx ; i++)
  50. {
  51. if (val[(j*ld)+i] != start + factor*(i+100*j))
  52. asm("trap;");
  53. }
  54. }
  55. }
  56. extern "C" void fmultiple_check_cuda(void *buffers[], void *cl_arg)
  57. {
  58. int start, factor;
  59. int nx = (int)STARPU_MATRIX_GET_NX(buffers[0]);
  60. int ny = (int)STARPU_MATRIX_GET_NY(buffers[0]);
  61. unsigned ld = STARPU_MATRIX_GET_LD(buffers[0]);
  62. int *val = (int *)STARPU_MATRIX_GET_PTR(buffers[0]);
  63. starpu_codelet_unpack_args(cl_arg, &start, &factor);
  64. /* TODO: use more vals and threads in vals */
  65. _fmultiple_check_cuda<<<1,1, 0, starpu_cuda_get_local_stream()>>>(val, nx, ny, ld, start, factor);
  66. cudaError_t status = cudaGetLastError();
  67. if (status != cudaSuccess) STARPU_CUDA_REPORT_ERROR(status);
  68. }