dw_block_spmv_kernels.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2008-2011,2013-2015,2017 Université de Bordeaux
  4. * Copyright (C) 2010,2011,2015,2017 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, 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. {
  46. cublasStatus_t status = cublasSgemv (starpu_cublas_get_local_handle(),
  47. CUBLAS_OP_T, dx, dy, &p1, block, ld, in, 1, &p1, out, 1);
  48. if (status != CUBLAS_STATUS_SUCCESS)
  49. STARPU_CUBLAS_REPORT_ERROR(status);
  50. break;
  51. }
  52. #endif
  53. default:
  54. STARPU_ABORT();
  55. break;
  56. }
  57. }
  58. void cpu_block_spmv(void *descr[], void *_args)
  59. {
  60. /* printf("CPU CODELET \n"); */
  61. common_block_spmv(descr, 0, _args);
  62. }
  63. #ifdef STARPU_USE_CUDA
  64. void cublas_block_spmv(void *descr[], void *_args)
  65. {
  66. /* printf("CUBLAS CODELET \n"); */
  67. common_block_spmv(descr, 1, _args);
  68. }
  69. #endif /* STARPU_USE_CUDA */