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.

sbgemv_thread.c 5.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*********************************************************************/
  2. /* Copyright 2009, 2010 The University of Texas at Austin. */
  3. /* All rights reserved. */
  4. /* */
  5. /* Redistribution and use in source and binary forms, with or */
  6. /* without modification, are permitted provided that the following */
  7. /* conditions are met: */
  8. /* */
  9. /* 1. Redistributions of source code must retain the above */
  10. /* copyright notice, this list of conditions and the following */
  11. /* disclaimer. */
  12. /* */
  13. /* 2. Redistributions in binary form must reproduce the above */
  14. /* copyright notice, this list of conditions and the following */
  15. /* disclaimer in the documentation and/or other materials */
  16. /* provided with the distribution. */
  17. /* */
  18. /* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */
  19. /* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */
  20. /* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
  21. /* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
  22. /* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */
  23. /* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */
  24. /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
  25. /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */
  26. /* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */
  27. /* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
  28. /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
  29. /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */
  30. /* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
  31. /* POSSIBILITY OF SUCH DAMAGE. */
  32. /* */
  33. /* The views and conclusions contained in the software and */
  34. /* documentation are those of the authors and should not be */
  35. /* interpreted as representing official policies, either expressed */
  36. /* or implied, of The University of Texas at Austin. */
  37. /*********************************************************************/
  38. #include <stdio.h>
  39. #include <stdlib.h>
  40. #include "common.h"
  41. #ifndef TRANSA
  42. #define SBGEMV SBGEMV_N
  43. #else
  44. #define SBGEMV SBGEMV_T
  45. #endif
  46. static int sbgemv_kernel(blas_arg_t *args, BLASLONG *range_m, BLASLONG *range_n, FLOAT *dummy1, FLOAT *dummy2, BLASLONG dummy3){
  47. bfloat16 *a, *x;
  48. float *y;
  49. BLASLONG lda, incx, incy;
  50. BLASLONG m_from, m_to, n_from, n_to;
  51. a = (bfloat16 *)args->a;
  52. x = (bfloat16 *)args->b;
  53. y = (float *)args->c;
  54. lda = args->lda;
  55. incx = args->ldb;
  56. incy = args->ldc;
  57. #ifndef TRANSA // N
  58. m_from = *(range_m + 0);
  59. m_to = *(range_m + 1);
  60. n_from = 0;
  61. n_to = args -> n;
  62. a += m_from;
  63. y += m_from * incy;
  64. #else // T
  65. m_from = 0;
  66. m_to = args->m;
  67. n_from = *(range_n + 0);
  68. n_to = *(range_n + 1);
  69. a += n_from * lda;
  70. y += n_from * incy;
  71. #endif
  72. SBGEMV(m_to - m_from, n_to - n_from, *((FLOAT *)(args->alpha)), a, lda, x, incx, *((FLOAT *)(args->beta)), y, incy);
  73. return 0;
  74. }
  75. int CNAME(BLASLONG m, BLASLONG n, float alpha, bfloat16 *a, BLASLONG lda, bfloat16 *x, BLASLONG incx, float beta, float *y, BLASLONG incy, int threads)
  76. {
  77. blas_arg_t args;
  78. blas_queue_t queue[MAX_CPU_NUMBER];
  79. BLASLONG range[MAX_CPU_NUMBER + 1];
  80. #ifndef TRANSA
  81. BLASLONG width_for_split = m;
  82. #else
  83. BLASLONG width_for_split = n;
  84. #endif
  85. BLASLONG BLOCK_WIDTH = width_for_split/threads;
  86. int mode = BLAS_BFLOAT16 | BLAS_REAL;
  87. args.m = m;
  88. args.n = n;
  89. args.a = (void *)a;
  90. args.b = (void *)x;
  91. args.c = (void *)y;
  92. args.lda = lda;
  93. args.ldb = incx;
  94. args.ldc = incy;
  95. args.alpha = (void *)&alpha;
  96. args.beta = (void *)&beta;
  97. range[0] = 0;
  98. int thread_idx;
  99. for (thread_idx=0; thread_idx<threads; thread_idx++) {
  100. if (thread_idx != threads-1) {
  101. range[thread_idx + 1] = range[thread_idx] + BLOCK_WIDTH;
  102. } else {
  103. range[thread_idx + 1] = range[thread_idx] + width_for_split;
  104. }
  105. queue[thread_idx].mode = mode;
  106. queue[thread_idx].routine = sbgemv_kernel;
  107. queue[thread_idx].args = &args;
  108. #ifndef TRANSA
  109. queue[thread_idx].range_m = &range[thread_idx];
  110. queue[thread_idx].range_n = NULL;
  111. #else
  112. queue[thread_idx].range_m = NULL;
  113. queue[thread_idx].range_n = &range[thread_idx];
  114. #endif
  115. queue[thread_idx].sa = NULL;
  116. queue[thread_idx].sb = NULL;
  117. queue[thread_idx].next = &queue[thread_idx + 1];
  118. width_for_split -= BLOCK_WIDTH;
  119. }
  120. if (thread_idx) {
  121. queue[0].sa = NULL;
  122. queue[0].sb = NULL;
  123. queue[thread_idx - 1].next = NULL;
  124. exec_blas(thread_idx, queue);
  125. }
  126. return 0;
  127. }