spmv_opencl.cl 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010, 2012 Centre National de la Recherche Scientifique
  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. __kernel void spmv(int nnz, int nrow,
  17. __global float* nzval, __global unsigned* colind,
  18. __global unsigned* rowptr, int firstentry,
  19. __global float *vecin, int nx_in,
  20. __global float *vecout, int nx_out)
  21. {
  22. const int row = get_global_id(0);
  23. if (row < nrow)
  24. {
  25. float tmp = 0.0f;
  26. unsigned index;
  27. unsigned firstindex = rowptr[row] - firstentry;
  28. unsigned lastindex = rowptr[row+1] - firstentry;
  29. for (index = firstindex; index < lastindex; index++)
  30. {
  31. unsigned col;
  32. col = colind[index];
  33. tmp += nzval[index]*vecin[col];
  34. }
  35. vecout[row] = tmp;
  36. }
  37. }