dw_block_spmv_kernels.c 2.0 KB

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