Visual Servoing Platform  version 3.3.0 under development (2020-02-17)
vpMatrix_mul.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * BLAS subroutines.
33  *
34  *****************************************************************************/
35 
36 #include <visp3/core/vpConfig.h>
37 #include <visp3/core/vpMatrix.h>
38 
39 #ifndef DOXYGEN_SHOULD_SKIP_THIS
40 
41 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN)
42 # ifdef VISP_HAVE_MKL
43 #include <mkl.h>
44 
45 void vpMatrix::blas_dgemm(char trans_a, char trans_b, int M_, int N_, int K_, double alpha,
46  double *a_data, int lda_, double *b_data, int ldb_, double beta, double *c_data,
47  int ldc_)
48 {
49  MKL_INT M = (MKL_INT)M_, K = (MKL_INT)K_, N = (MKL_INT)N_;
50  MKL_INT lda = (MKL_INT)lda_, ldb = (MKL_INT)ldb_, ldc = (MKL_INT)ldc_;
51 
52  dgemm(&trans_a, &trans_b, &M, &N, &K, &alpha, a_data, &lda, b_data, &ldb, &beta, c_data, &ldc);
53 }
54 
55 void vpMatrix::blas_dgemv(char trans, int M_, int N_, double alpha, double *a_data, int lda_,
56  double *x_data, int incx_, double beta, double *y_data, int incy_)
57 {
58  MKL_INT M = (MKL_INT)M_, N = (MKL_INT)N_;
59  MKL_INT lda = (MKL_INT)lda_, incx = (MKL_INT)incx_, incy = (MKL_INT)incy_;
60 
61  dgemv(&trans, &M, &N, &alpha, a_data, &lda, x_data, &incx, &beta, y_data, &incy);
62 }
63 # else
64 typedef int integer;
65 
66 extern "C" void dgemm_(char *transa, char *transb, integer *M, integer *N, integer *K, double *alpha, double *a,
67  integer *lda, double *b, integer *ldb, double *beta, double *c, integer *ldc);
68 
69 extern "C" void dgemv_(char *trans, integer *M, integer *N, double *alpha, double *a, integer *lda, double *x,
70  integer *incx, double *beta, double *y, integer *incy);
71 
72 void vpMatrix::blas_dgemm(char trans_a, char trans_b, int M_, int N_, int K_, double alpha,
73  double *a_data, int lda_, double *b_data, int ldb_, double beta, double *c_data,
74  int ldc_)
75 {
76  integer M = (integer)M_, K = (integer)K_, N = (integer)N_;
77  integer lda = (integer)lda_, ldb = (integer)ldb_, ldc = (integer)ldc_;
78 
79  dgemm_(&trans_a, &trans_b, &M, &N, &K, &alpha, a_data, &lda, b_data, &ldb, &beta, c_data, &ldc);
80 }
81 
82 void vpMatrix::blas_dgemv(char trans, int M_, int N_, double alpha, double *a_data, int lda_,
83  double *x_data, int incx_, double beta, double *y_data, int incy_)
84 {
85  integer M = (integer)M_, N = (integer)N_;
86  integer lda = (integer)lda_, incx = (integer)incx_, incy = (integer)incy_;
87 
88  dgemv_(&trans, &M, &N, &alpha, a_data, &lda, x_data, &incx, &beta, y_data, &incy);
89 }
90 # endif
91 #else
92 // Work arround to avoid warning LNK4221: This object file does not define any
93 // previously undefined public symbols
94 void dummy_vpMatrix_blas() {};
95 #endif
96 
97 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS