You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

gemv_t_vector.c 6.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /***************************************************************************
  2. Copyright (c) 2013, The OpenBLAS Project
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are
  6. met:
  7. 1. Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. 2. Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in
  11. the documentation and/or other materials provided with the
  12. distribution.
  13. 3. Neither the name of the OpenBLAS project nor the names of
  14. its contributors may be used to endorse or promote products
  15. derived from this software without specific prior written permission.
  16. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  17. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBLAS PROJECT OR CONTRIBUTORS BE
  20. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  22. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  23. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  24. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  25. USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. *****************************************************************************/
  27. #include "common.h"
  28. #if !defined(DOUBLE)
  29. #define VSETVL(n) RISCV_RVV(vsetvl_e32m2)(n)
  30. #define FLOAT_V_T vfloat32m2_t
  31. #define FLOAT_V_T_M1 vfloat32m1_t
  32. #define VLEV_FLOAT RISCV_RVV(vle32_v_f32m2)
  33. #define VLSEV_FLOAT RISCV_RVV(vlse32_v_f32m2)
  34. #ifdef RISCV_0p10_INTRINSICS
  35. #define VFREDSUM_FLOAT(va, vb, gvl) vfredusum_vs_f32m2_f32m1(v_res, va, vb, gvl)
  36. #else
  37. #define VFREDSUM_FLOAT RISCV_RVV(vfredusum_vs_f32m2_f32m1)
  38. #endif
  39. #define VFMACCVV_FLOAT RISCV_RVV(vfmacc_vv_f32m2)
  40. #define VFMVVF_FLOAT RISCV_RVV(vfmv_v_f_f32m2)
  41. #define VFMVVF_FLOAT_M1 RISCV_RVV(vfmv_v_f_f32m1)
  42. #define VFMULVV_FLOAT RISCV_RVV(vfmul_vv_f32m2)
  43. #define xint_t int
  44. #else
  45. #define VSETVL(n) RISCV_RVV(vsetvl_e64m2)(n)
  46. #define FLOAT_V_T vfloat64m2_t
  47. #define FLOAT_V_T_M1 vfloat64m1_t
  48. #define VLEV_FLOAT RISCV_RVV(vle64_v_f64m2)
  49. #define VLSEV_FLOAT RISCV_RVV(vlse64_v_f64m2)
  50. #ifdef RISCV_0p10_INTRINSICS
  51. #define VFREDSUM_FLOAT(va, vb, gvl) vfredusum_vs_f64m2_f64m1(v_res, va, vb, gvl)
  52. #else
  53. #define VFREDSUM_FLOAT RISCV_RVV(vfredusum_vs_f64m2_f64m1)
  54. #endif
  55. #define VFMACCVV_FLOAT RISCV_RVV(vfmacc_vv_f64m2)
  56. #define VFMVVF_FLOAT RISCV_RVV(vfmv_v_f_f64m2)
  57. #define VFMVVF_FLOAT_M1 RISCV_RVV(vfmv_v_f_f64m1)
  58. #define VFMULVV_FLOAT RISCV_RVV(vfmul_vv_f64m2)
  59. #define xint_t long long
  60. #endif
  61. int CNAME(BLASLONG m, BLASLONG n, BLASLONG dummy1, FLOAT alpha, FLOAT *a, BLASLONG lda, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y, FLOAT *buffer)
  62. {
  63. BLASLONG i = 0, j = 0, k = 0;
  64. BLASLONG ix = 0, iy = 0;
  65. FLOAT *a_ptr = a;
  66. FLOAT temp;
  67. FLOAT_V_T va, vr, vx;
  68. unsigned int gvl = 0;
  69. FLOAT_V_T_M1 v_res;
  70. if(inc_x == 1){
  71. for(i = 0; i < n; i++){
  72. v_res = VFMVVF_FLOAT_M1(0, 1);
  73. gvl = VSETVL(m);
  74. j = 0;
  75. vr = VFMVVF_FLOAT(0, gvl);
  76. for(k = 0; k < m/gvl; k++){
  77. va = VLEV_FLOAT(&a_ptr[j], gvl);
  78. vx = VLEV_FLOAT(&x[j], gvl);
  79. vr = VFMULVV_FLOAT(va, vx, gvl); // could vfmacc here and reduce outside loop
  80. v_res = VFREDSUM_FLOAT(vr, v_res, gvl); // but that reordering diverges far enough from scalar path to make tests fail
  81. j += gvl;
  82. }
  83. if(j < m){
  84. gvl = VSETVL(m-j);
  85. va = VLEV_FLOAT(&a_ptr[j], gvl);
  86. vx = VLEV_FLOAT(&x[j], gvl);
  87. vr = VFMULVV_FLOAT(va, vx, gvl);
  88. v_res = VFREDSUM_FLOAT(vr, v_res, gvl);
  89. }
  90. temp = (FLOAT)EXTRACT_FLOAT(v_res);
  91. y[iy] += alpha * temp;
  92. iy += inc_y;
  93. a_ptr += lda;
  94. }
  95. }else{
  96. BLASLONG stride_x = inc_x * sizeof(FLOAT);
  97. for(i = 0; i < n; i++){
  98. v_res = VFMVVF_FLOAT_M1(0, 1);
  99. gvl = VSETVL(m);
  100. j = 0;
  101. ix = 0;
  102. vr = VFMVVF_FLOAT(0, gvl);
  103. for(k = 0; k < m/gvl; k++){
  104. va = VLEV_FLOAT(&a_ptr[j], gvl);
  105. vx = VLSEV_FLOAT(&x[ix], stride_x, gvl);
  106. vr = VFMULVV_FLOAT(va, vx, gvl);
  107. v_res = VFREDSUM_FLOAT(vr, v_res, gvl);
  108. j += gvl;
  109. ix += inc_x * gvl;
  110. }
  111. if(j < m){
  112. gvl = VSETVL(m-j);
  113. va = VLEV_FLOAT(&a_ptr[j], gvl);
  114. vx = VLSEV_FLOAT(&x[ix], stride_x, gvl);
  115. vr = VFMULVV_FLOAT(va, vx, gvl);
  116. v_res = VFREDSUM_FLOAT(vr, v_res, gvl);
  117. }
  118. temp = (FLOAT)EXTRACT_FLOAT(v_res);
  119. y[iy] += alpha * temp;
  120. iy += inc_y;
  121. a_ptr += lda;
  122. }
  123. }
  124. return(0);
  125. }