tensor-0.1.0
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Enumerator Groups Pages
gemm.cc
1 // -*- mode: c++; fill-column: 80; c-basic-offset: 2; indent-tabs-mode: nil -*-
2 /*
3  Copyright (c) 2010 Juan Jose Garcia Ripoll
4 
5  Tensor is free software; you can redistribute it and/or modify it
6  under the terms of the GNU Library General Public License as published
7  by the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Library General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 
20 #ifndef TENSOR_GEMM_CC
21 #define TENSOR_GEMM_CC
22 
23 #ifdef TENSOR_USE_ESSL
24 #include <essl.h>
25 #endif
26 #include <tensor/tensor_blas.h>
27 
28 namespace blas {
29 
30  inline void gemm(char op1, char op2, integer m, integer n, integer k,
31  double alpha, const double *A, integer lda, const double *B,
32  integer ldb, double beta, double *C, integer ldc)
33  {
34 #ifdef TENSOR_USE_ESSL
35  dgemm(&op1, &op2, m, n, k, alpha, A, lda, B, ldb, beta, C, ldc);
36 #endif
37 #ifdef TENSOR_USE_ACML
38  dgemm(op1, op2, m, n, k, alpha, const_cast<double *>(A),
39  lda, const_cast<double*>(B), ldb, beta, C, ldc);
40 #endif
41 #if !defined(TENSOR_USE_ESSL) && !defined(TENSOR_USE_ACML)
42  cblas_dgemm(CblasColMajor, char_to_op(op1), char_to_op(op2),
43  m, n, k, alpha, A, lda, B, ldb, beta, C, ldc);
44 #endif
45  }
46 
47  inline void gemm(char op1, char op2, integer m, integer n, integer k,
48  const tensor::cdouble &alpha, const tensor::cdouble *A, integer lda,
49  const tensor::cdouble *B, integer ldb, const tensor::cdouble &beta,
50  tensor::cdouble *C, integer ldc)
51  {
52 #ifdef TENSOR_USE_ESSL
53  zgemm(&op1, &op2, m, n, k, alpha, A, lda, B, ldb, beta, C, ldc);
54 #endif
55 #ifdef TENSOR_USE_ACML
56  zgemm(op1, op2, m, n, k,
57  reinterpret_cast<doublecomplex *>(const_cast<tensor::cdouble *>(&alpha)),
58  reinterpret_cast<doublecomplex *>(const_cast<tensor::cdouble *>(A)),
59  lda,
60  reinterpret_cast<doublecomplex *>(const_cast<tensor::cdouble *>(B)),
61  ldb,
62  reinterpret_cast<doublecomplex *>(const_cast<tensor::cdouble *>(&beta)),
63  reinterpret_cast<doublecomplex *>(C), ldc);
64 #endif
65 #if !defined(TENSOR_USE_ESSL) && !defined(TENSOR_USE_ACML)
66  cblas_zgemm(CblasColMajor, char_to_op(op1), char_to_op(op2),
67  m, n, k, &alpha, A, lda, B, ldb, &beta, C, ldc);
68 #endif
69  }
70 
71 }
72 
73 #endif