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.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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
  76. #ifndef C_MSVC
  77. __attribute__((visibility("hidden")))
  78. #endif
  79. CNAME(BLASLONG m, BLASLONG n, float alpha, bfloat16 *a, BLASLONG lda, bfloat16 *x, BLASLONG incx, float beta, float *y, BLASLONG incy, int threads)
  80. {
  81. blas_arg_t args;
  82. blas_queue_t queue[MAX_CPU_NUMBER];
  83. BLASLONG range[MAX_CPU_NUMBER + 1];
  84. #ifndef TRANSA
  85. BLASLONG width_for_split = m;
  86. #else
  87. BLASLONG width_for_split = n;
  88. #endif
  89. BLASLONG BLOCK_WIDTH = width_for_split/threads;
  90. int mode = BLAS_BFLOAT16 | BLAS_REAL;
  91. args.m = m;
  92. args.n = n;
  93. args.a = (void *)a;
  94. args.b = (void *)x;
  95. args.c = (void *)y;
  96. args.lda = lda;
  97. args.ldb = incx;
  98. args.ldc = incy;
  99. args.alpha = (void *)&alpha;
  100. args.beta = (void *)&beta;
  101. range[0] = 0;
  102. int thread_idx;
  103. for (thread_idx=0; thread_idx<threads; thread_idx++) {
  104. if (thread_idx != threads-1) {
  105. range[thread_idx + 1] = range[thread_idx] + BLOCK_WIDTH;
  106. } else {
  107. range[thread_idx + 1] = range[thread_idx] + width_for_split;
  108. }
  109. queue[thread_idx].mode = mode;
  110. queue[thread_idx].routine = sbgemv_kernel;
  111. queue[thread_idx].args = &args;
  112. #ifndef TRANSA
  113. queue[thread_idx].range_m = &range[thread_idx];
  114. queue[thread_idx].range_n = NULL;
  115. #else
  116. queue[thread_idx].range_m = NULL;
  117. queue[thread_idx].range_n = &range[thread_idx];
  118. #endif
  119. queue[thread_idx].sa = NULL;
  120. queue[thread_idx].sb = NULL;
  121. queue[thread_idx].next = &queue[thread_idx + 1];
  122. width_for_split -= BLOCK_WIDTH;
  123. }
  124. if (thread_idx) {
  125. queue[0].sa = NULL;
  126. queue[0].sb = NULL;
  127. queue[thread_idx - 1].next = NULL;
  128. exec_blas(thread_idx, queue);
  129. }
  130. return 0;
  131. }