dw_block_spmv_kernels.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010-2011, 2015 Université de Bordeaux
  4. * Copyright (C) 2010, 2011 CNRS
  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. /*
  18. * Standard GEMV kernel (on one matrix block of the sparse matrix)
  19. */
  20. #include "dw_block_spmv.h"
  21. /*
  22. * U22
  23. */
  24. #ifdef STARPU_USE_CUDA
  25. #include <starpu_cublas_v2.h>
  26. static const float p1 = 1.0;
  27. static const float m1 = -1.0;
  28. #endif
  29. static inline void common_block_spmv(void *descr[], int s, STARPU_ATTRIBUTE_UNUSED void *_args)
  30. {
  31. /* printf("22\n"); */
  32. float *block = (float *)STARPU_MATRIX_GET_PTR(descr[0]);
  33. float *in = (float *)STARPU_VECTOR_GET_PTR(descr[1]);
  34. float *out = (float *)STARPU_VECTOR_GET_PTR(descr[2]);
  35. unsigned dx = STARPU_MATRIX_GET_NX(descr[0]);
  36. unsigned dy = STARPU_MATRIX_GET_NY(descr[0]);
  37. unsigned ld = STARPU_MATRIX_GET_LD(descr[0]);
  38. switch (s)
  39. {
  40. case 0:
  41. cblas_sgemv(CblasRowMajor, CblasNoTrans, dx, dy, 1.0f, block, ld, in, 1, 1.0f, out, 1);
  42. break;
  43. #ifdef STARPU_USE_CUDA
  44. case 1:
  45. cublasStatus_t status = cublasSgemv (starpu_cublas_get_local_handle(),
  46. CUBLAS_OP_T, dx, dy, &p1, block, ld, in, 1, &p1, out, 1);
  47. if (status != CUBLAS_STATUS_SUCCESS)
  48. STARPU_CUBLAS_REPORT_ERROR(status);
  49. break;
  50. #endif
  51. default:
  52. STARPU_ABORT();
  53. break;
  54. }
  55. }
  56. void cpu_block_spmv(void *descr[], void *_args)
  57. {
  58. /* printf("CPU CODELET \n"); */
  59. common_block_spmv(descr, 0, _args);
  60. }
  61. #ifdef STARPU_USE_CUDA
  62. void cublas_block_spmv(void *descr[], void *_args)
  63. {
  64. /* printf("CUBLAS CODELET \n"); */
  65. common_block_spmv(descr, 1, _args);
  66. }
  67. #endif /* STARPU_USE_CUDA */