fmultiple_cuda.cu 2.4 KB

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