spmv_opencl.cl 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 2008-2010 (see AUTHORS file)
  4. *
  5. * This program 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. * This program 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 spvm(unsigned nnz, unsigned nrow,
  17. __global float* nzval, __global unsigned* colind,
  18. __global unsigned* rowptr, unsigned firstentry,
  19. __global float *vecin, unsigned nx_in,
  20. __global float *vecout, unsigned nx_out)
  21. {
  22. unsigned row;
  23. for (row = 0; row < nrow; row++)
  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. }