mirror of
https://github.com/OpenMathLib/OpenBLAS
synced 2026-05-31 00:45:48 +08:00
This adds all the relevant bits and pieces to add a `shgemv` path as well as a future `hgemm`/`hgemv` path in a similar model to `sb` and `b` interfaces. I've also fixed a few bits and pieces around `shgemm` which didn't build in a few situations.
222 lines
6.9 KiB
C
222 lines
6.9 KiB
C
/*********************************************************************/
|
|
/* Copyright 2025 The OpenBLAS Project. */
|
|
/* Copyright 2009, 2010 The University of Texas at Austin. */
|
|
/* All rights reserved. */
|
|
/* */
|
|
/* Redistribution and use in source and binary forms, with or */
|
|
/* without modification, are permitted provided that the following */
|
|
/* conditions are met: */
|
|
/* */
|
|
/* 1. Redistributions of source code must retain the above */
|
|
/* copyright notice, this list of conditions and the following */
|
|
/* disclaimer. */
|
|
/* */
|
|
/* 2. Redistributions in binary form must reproduce the above */
|
|
/* copyright notice, this list of conditions and the following */
|
|
/* disclaimer in the documentation and/or other materials */
|
|
/* provided with the distribution. */
|
|
/* */
|
|
/* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */
|
|
/* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */
|
|
/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
|
|
/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
|
|
/* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */
|
|
/* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */
|
|
/* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
|
|
/* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */
|
|
/* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */
|
|
/* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
|
|
/* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
|
|
/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */
|
|
/* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
|
|
/* POSSIBILITY OF SUCH DAMAGE. */
|
|
/* */
|
|
/* The views and conclusions contained in the software and */
|
|
/* documentation are those of the authors and should not be */
|
|
/* interpreted as representing official policies, either expressed */
|
|
/* or implied, of The University of Texas at Austin. */
|
|
/*********************************************************************/
|
|
|
|
#include <stdio.h>
|
|
#include "common.h"
|
|
#include "l1param.h"
|
|
#ifdef FUNCTION_PROFILE
|
|
#include "functable.h"
|
|
#endif
|
|
|
|
#ifdef BGEMM
|
|
#define GEMV_THREAD_N bgemv_thread_n
|
|
#define GEMV_THREAD_T bgemv_thread_t
|
|
#define ERROR_NAME "BGEMV "
|
|
#elif defined(HFLOAT16)
|
|
#define GEMV_THREAD_N shgemv_thread_n
|
|
#define GEMV_THREAD_T shgemv_thread_t
|
|
#define ERROR_NAME "SHGEMV "
|
|
#else
|
|
#define GEMV_THREAD_N sbgemv_thread_n
|
|
#define GEMV_THREAD_T sbgemv_thread_t
|
|
#define ERROR_NAME "SBGEMV "
|
|
#endif
|
|
|
|
#ifdef SMP
|
|
static int (*gemv_thread[])(BLASLONG, BLASLONG, FLOAT, IFLOAT *, BLASLONG, IFLOAT * , BLASLONG, FLOAT, FLOAT *, BLASLONG, int) = {
|
|
GEMV_THREAD_N, GEMV_THREAD_T,
|
|
};
|
|
#endif
|
|
|
|
#ifndef CBLAS
|
|
|
|
void NAME(char *TRANS, blasint *M, blasint *N, FLOAT *ALPHA, IFLOAT *a, blasint *LDA, IFLOAT *x, blasint *INCX, FLOAT *BETA, FLOAT *y, blasint *INCY)
|
|
{
|
|
char trans = *TRANS;
|
|
blasint m = *M;
|
|
blasint n = *N;
|
|
blasint lda = *LDA;
|
|
blasint incx = *INCX;
|
|
blasint incy = *INCY;
|
|
FLOAT alpha = *ALPHA;
|
|
FLOAT beta = *BETA;
|
|
#ifdef SMP
|
|
int nthreads;
|
|
#endif
|
|
|
|
int (*gemv[])(BLASLONG, BLASLONG, FLOAT, IFLOAT *, BLASLONG, IFLOAT * , BLASLONG, FLOAT, FLOAT *, BLASLONG) = {
|
|
GEMV_N, GEMV_T,
|
|
};
|
|
|
|
blasint info;
|
|
blasint lenx, leny;
|
|
blasint i;
|
|
|
|
PRINT_DEBUG_NAME;
|
|
|
|
TOUPPER(trans);
|
|
|
|
info = 0;
|
|
|
|
i = -1;
|
|
|
|
if (trans == 'N') {i = 0;}
|
|
if (trans == 'T') {i = 1;}
|
|
if (trans == 'R') {i = 0;}
|
|
if (trans == 'C') {i = 1;}
|
|
|
|
if (incy == 0) {info = 11;}
|
|
if (incx == 0) {info = 8;}
|
|
if (lda < MAX(1, m)) {info = 6;}
|
|
if (n < 0) {info = 3;}
|
|
if (m < 0) {info = 2;}
|
|
if (i < 0) {info = 1;}
|
|
|
|
trans = i;
|
|
|
|
if (info != 0) {
|
|
BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
|
|
return;
|
|
}
|
|
|
|
#else
|
|
|
|
void CNAME(enum CBLAS_ORDER order, enum CBLAS_TRANSPOSE TransA, blasint m, blasint n, FLOAT alpha, IFLOAT *a, blasint lda, IFLOAT *x, blasint incx, FLOAT beta, FLOAT *y, blasint incy)
|
|
{
|
|
blasint lenx, leny;
|
|
int trans;
|
|
blasint info, t;
|
|
#ifdef SMP
|
|
int nthreads;
|
|
#endif
|
|
|
|
int (*gemv[])(BLASLONG, BLASLONG, FLOAT, IFLOAT *, BLASLONG, IFLOAT * , BLASLONG, FLOAT, FLOAT *, BLASLONG) = {
|
|
GEMV_N, GEMV_T,
|
|
};
|
|
|
|
PRINT_DEBUG_CNAME;
|
|
|
|
trans = -1;
|
|
info = 0;
|
|
|
|
if (order == CblasColMajor) { // Column Major
|
|
if (TransA == CblasNoTrans || TransA == CblasConjNoTrans) {
|
|
trans = 0;
|
|
} else if (TransA == CblasTrans || TransA == CblasConjTrans) {
|
|
trans = 1;
|
|
}
|
|
} else { // Row Major
|
|
if (TransA == CblasNoTrans || TransA == CblasConjNoTrans) {
|
|
trans = 1;
|
|
} else if (TransA == CblasTrans || TransA == CblasConjTrans) {
|
|
trans = 0;
|
|
}
|
|
|
|
t = n;
|
|
n = m;
|
|
m = t;
|
|
}
|
|
|
|
info = -1;
|
|
|
|
if (incy == 0) {info = 11;}
|
|
if (incx == 0) {info = 8;}
|
|
if (lda < MAX(1, m)) {info = 6;}
|
|
if (n < 0) {info = 3;}
|
|
if (m < 0) {info = 2;}
|
|
if (trans < 0) {info = 1;}
|
|
|
|
if (info >= 0) {
|
|
BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
|
|
return;
|
|
}
|
|
|
|
#endif
|
|
|
|
if ((m==0) || (n==0)) return;
|
|
|
|
if (trans) {
|
|
lenx = m;
|
|
leny = n;
|
|
} else {
|
|
lenx = n;
|
|
leny = m;
|
|
}
|
|
|
|
#ifdef BGEMM
|
|
float alpha_float, beta_float;
|
|
SBF16TOS_K(1, &alpha, 1, &alpha_float, 1);
|
|
SBF16TOS_K(1, &beta, 1, &beta_float, 1);
|
|
#else
|
|
float alpha_float = alpha;
|
|
float beta_float = beta;
|
|
#endif
|
|
|
|
if (alpha_float == ZERO) {
|
|
if (beta_float != ONE) SCAL_K(leny, 0, 0, beta, y, blasabs(incy), NULL, 0, NULL, 0);
|
|
return;
|
|
}
|
|
|
|
IDEBUG_START;
|
|
FUNCTION_PROFILE_START();
|
|
|
|
if (incx < 0) {x -= (lenx - 1) * incx;}
|
|
if (incy < 0) {y -= (leny - 1) * incy;}
|
|
|
|
#ifdef SMP
|
|
if ( 1L * m * n < 115200L * GEMM_MULTITHREAD_THRESHOLD )
|
|
nthreads = 1;
|
|
else
|
|
nthreads = num_cpu_avail(2);
|
|
|
|
if (nthreads == 1) {
|
|
#endif
|
|
(gemv[(int)trans])(m, n, alpha, a, lda, x, incx, beta, y, incy);
|
|
#ifdef SMP
|
|
} else {
|
|
(gemv_thread[(int)trans])(m, n, alpha, a, lda, x, incx, beta, y, incy, nthreads);
|
|
}
|
|
#endif
|
|
|
|
FUNCTION_PROFILE_END(1, m * n + m + n, 2 * m * n);
|
|
IDEBUG_END;
|
|
|
|
return;
|
|
}
|