32 #ifndef VSMC_MATH_CBLAS_HPP 33 #define VSMC_MATH_CBLAS_HPP 39 #if VSMC_USE_MKL_CBLAS 40 #include <mkl_cblas.h> 42 #define VSMC_BLAS_INT MKL_INT 44 #elif VSMC_USE_ACCELERATE 45 #include <Accelerate/Accelerate.h> 51 #define VSMC_BLAS_INT int 60 using ::CblasRowMajor;
61 using ::CblasColMajor;
65 using ::CblasConjTrans;
98 #else // VSMC_USE_CBLAS 100 #ifndef VSMC_BLAS_NAME 101 #ifdef VSMC_BLAS_NAME_NO_UNDERSCORE 102 #define VSMC_BLAS_NAME(x) x 104 #define VSMC_BLAS_NAME(x) x##_ 108 #ifndef VSMC_BLAS_INT 109 #define VSMC_BLAS_INT int 114 void VSMC_BLAS_NAME(sgemv)(
const char *trans,
const VSMC_BLAS_INT *m,
119 void VSMC_BLAS_NAME(dgemv)(
const char *trans,
const VSMC_BLAS_INT *m,
120 const VSMC_BLAS_INT *n,
const double *alpha,
const double *a,
124 void VSMC_BLAS_NAME(stpmv)(
const char *uplo,
const char *trans,
125 const char *diag,
const VSMC_BLAS_INT *n,
const float *ap,
float *x,
128 void VSMC_BLAS_NAME(dtpmv)(
const char *uplo,
const char *trans,
129 const char *diag,
const VSMC_BLAS_INT *n,
const double *ap,
double *x,
132 void VSMC_BLAS_NAME(ssyr)(
const char *uplo,
const VSMC_BLAS_INT *n,
133 const float *alpha,
const float *x,
const VSMC_BLAS_INT *incx,
float *a,
136 void VSMC_BLAS_NAME(dsyr)(
const char *uplo,
const VSMC_BLAS_INT *n,
137 const double *alpha,
const double *x,
const VSMC_BLAS_INT *incx,
double *a,
140 void VSMC_BLAS_NAME(strmm)(
const char *side,
const char *uplo,
141 const char *transa,
const char *diag,
const VSMC_BLAS_INT *m,
145 void VSMC_BLAS_NAME(dtrmm)(
const char *side,
const char *uplo,
146 const char *transa,
const char *diag,
const VSMC_BLAS_INT *m,
147 const VSMC_BLAS_INT *n,
const double *alpha,
const double *a,
150 void VSMC_BLAS_NAME(ssyrk)(
const char *uplo,
const char *trans,
152 const float *a,
const VSMC_BLAS_INT *lda,
const float *beta,
float *c,
155 void VSMC_BLAS_NAME(dsyrk)(
const char *uplo,
const char *trans,
157 const double *a,
const VSMC_BLAS_INT *lda,
const double *beta,
double *c,
168 enum CBLAS_LAYOUT { CblasRowMajor = 101, CblasColMajor = 102 };
170 using CBLAS_ORDER = CBLAS_LAYOUT;
172 enum CBLAS_TRANSPOSE {
178 enum CBLAS_UPLO { CblasUpper = 121, CblasLower = 122 };
180 enum CBLAS_DIAG { CblasNonUnit = 131, CblasUnit = 132 };
182 enum CBLAS_SIDE { CblasLeft = 141, CblasRight = 142 };
184 inline char cblas_trans(
const CBLAS_LAYOUT layout,
const CBLAS_TRANSPOSE trans)
186 if (layout == CblasColMajor) {
187 if (trans == CblasNoTrans)
189 else if (trans == CblasTrans)
191 else if (trans == CblasConjTrans)
194 if (layout == CblasRowMajor) {
195 if (trans == CblasNoTrans)
197 else if (trans == CblasTrans)
199 else if (trans == CblasConjTrans)
205 inline char cblas_uplo(
const CBLAS_LAYOUT layout,
const CBLAS_UPLO uplo)
207 if (layout == CblasColMajor) {
208 if (uplo == CblasUpper)
210 if (uplo == CblasLower)
213 if (layout == CblasRowMajor) {
214 if (uplo == CblasUpper)
216 if (uplo == CblasLower)
222 inline char cblas_diag(
const CBLAS_DIAG diag)
224 if (diag == CblasUnit)
226 if (diag == CblasNonUnit)
231 inline char cblas_side(
const CBLAS_LAYOUT layout,
const CBLAS_SIDE side)
233 if (layout == CblasColMajor) {
234 if (side == CblasLeft)
236 if (side == CblasRight)
239 if (layout == CblasRowMajor) {
240 if (side == CblasLeft)
242 if (side == CblasRight)
248 inline float cblas_sdot(
const VSMC_BLAS_INT n,
const float *x,
258 inline double cblas_ddot(
const VSMC_BLAS_INT n,
const double *x,
268 inline void cblas_sgemv(
const CBLAS_LAYOUT layout,
const CBLAS_TRANSPOSE trans,
274 const char transf = cblas_trans(layout, trans);
275 VSMC_BLAS_NAME(sgemv)
276 (&transf, &m, &n, &alpha, a, &lda, x, &incx, &beta, y, &incy);
279 inline void cblas_dgemv(
const CBLAS_LAYOUT layout,
const CBLAS_TRANSPOSE trans,
285 const char transf = cblas_trans(layout, trans);
286 VSMC_BLAS_NAME(dgemv)
287 (&transf, &m, &n, &alpha, a, &lda, x, &incx, &beta, y, &incy);
290 inline void cblas_stpmv(
const CBLAS_LAYOUT layout,
const CBLAS_UPLO uplo,
291 const CBLAS_TRANSPOSE trans,
const CBLAS_DIAG diag,
const VSMC_BLAS_INT n,
294 const char uplof = cblas_uplo(layout, uplo);
295 const char transf = cblas_trans(layout, trans);
296 const char diagf = cblas_diag(diag);
297 VSMC_BLAS_NAME(stpmv)(&uplof, &transf, &diagf, &n, ap, x, &incx);
300 inline void cblas_dtpmv(CBLAS_LAYOUT layout,
const CBLAS_UPLO uplo,
301 const CBLAS_TRANSPOSE trans,
const CBLAS_DIAG diag,
const VSMC_BLAS_INT n,
304 const char uplof = cblas_uplo(layout, uplo);
305 const char transf = cblas_trans(layout, trans);
306 const char diagf = cblas_diag(diag);
307 VSMC_BLAS_NAME(dtpmv)(&uplof, &transf, &diagf, &n, ap, x, &incx);
310 inline void cblas_ssyr(
const CBLAS_LAYOUT layout,
const CBLAS_UPLO uplo,
314 const char uplof = cblas_uplo(layout, uplo);
315 VSMC_BLAS_NAME(ssyr)(&uplof, &n, &alpha, x, &incx, a, &lda);
318 inline void cblas_dsyr(
const CBLAS_LAYOUT layout,
const CBLAS_UPLO uplo,
322 const char uplof = cblas_uplo(layout, uplo);
323 VSMC_BLAS_NAME(dsyr)(&uplof, &n, &alpha, x, &incx, a, &lda);
326 inline void cblas_strmm(
const CBLAS_LAYOUT layout,
const CBLAS_SIDE side,
327 const CBLAS_UPLO uplo,
const CBLAS_TRANSPOSE trans,
const CBLAS_DIAG diag,
331 const char sidef = cblas_side(layout, side);
332 const char uplof = cblas_uplo(layout, uplo);
333 const char transf = cblas_trans(CblasColMajor, trans);
334 const char diagf = cblas_diag(diag);
335 VSMC_BLAS_NAME(strmm)
336 (&sidef, &uplof, &transf, &diagf, &m, &n, &alpha, a, &lda, b, &ldb);
339 inline void cblas_dtrmm(
const CBLAS_LAYOUT layout,
const CBLAS_SIDE side,
340 const CBLAS_UPLO uplo,
const CBLAS_TRANSPOSE trans,
const CBLAS_DIAG diag,
345 const char sidef = cblas_side(layout, side);
346 const char uplof = cblas_uplo(layout, uplo);
347 const char transf = cblas_trans(CblasColMajor, trans);
348 const char diagf = cblas_diag(diag);
349 VSMC_BLAS_NAME(dtrmm)
350 (&sidef, &uplof, &transf, &diagf, &m, &n, &alpha, a, &lda, b, &ldb);
353 inline void cblas_ssyrk(
const CBLAS_LAYOUT layout,
const CBLAS_UPLO uplo,
358 const char uplof = cblas_uplo(layout, uplo);
359 const char transf = cblas_trans(layout, trans);
360 VSMC_BLAS_NAME(ssyrk)
361 (&uplof, &transf, &n, &k, &alpha, a, &lda, &beta, c, &ldc);
364 inline void cblas_dsyrk(
const CBLAS_LAYOUT layout,
const CBLAS_UPLO uplo,
366 const double alpha,
const double *a,
const VSMC_BLAS_INT lda,
369 const char uplof = cblas_uplo(layout, uplo);
370 const char transf = cblas_trans(layout, trans);
371 VSMC_BLAS_NAME(dsyrk)
372 (&uplof, &transf, &n, &k, &alpha, a, &lda, &beta, c, &ldc);
379 #endif // VSMC_USE_CBLAS 381 #endif // VSMC_MATH_CBLAS_HPP