fmultiple_cuda.cu 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2015 Université Bordeaux
  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. }
  42. static __global__ void _fmultiple_check_cuda(int *val, int nx, int ny, unsigned ld, int start, int factor)
  43. {
  44. int i, j;
  45. for(j=0; j<ny ; j++)
  46. {
  47. for(i=0; i<nx ; i++)
  48. {
  49. if (val[(j*ld)+i] != start + factor*(i+100*j))
  50. asm("trap;");
  51. }
  52. }
  53. }
  54. extern "C" void fmultiple_check_cuda(void *buffers[], void *cl_arg)
  55. {
  56. int start, factor;
  57. int nx = (int)STARPU_MATRIX_GET_NX(buffers[0]);
  58. int ny = (int)STARPU_MATRIX_GET_NY(buffers[0]);
  59. unsigned ld = STARPU_MATRIX_GET_LD(buffers[0]);
  60. int *val = (int *)STARPU_MATRIX_GET_PTR(buffers[0]);
  61. starpu_codelet_unpack_args(cl_arg, &start, &factor);
  62. /* TODO: use more vals and threads in vals */
  63. _fmultiple_check_cuda<<<1,1, 0, starpu_cuda_get_local_stream()>>>(val, nx, ny, ld, start, factor);
  64. }