Tpetra parallel linear algebra  Version of the Day
Tpetra_Details_libGemm.cpp
1 /*
2 //@HEADER
3 // ************************************************************************
4 //
5 // Kokkos: Node API and Parallel Node Kernels
6 // Copyright (2008) Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39 //
40 // ************************************************************************
41 //@HEADER
42 */
43 
45 #include "KokkosKernels_config.h"
46 #include <stdexcept>
47 
48 // TpetraCore_config.h (included in Tpetra_Details_libGemm.hpp)
49 // defines the TPETRACORE_F77_BLAS_MANGLE macro. First argument is
50 // the lower-case version of the BLAS function name, and second
51 // argument is the upper-case version of the same name. The macro
52 // handles mangling for calling the Fortran 77 function from C. We
53 // then make an extern "C" declaration here for each BLAS function
54 // that we want to use.
55 
56 #ifdef HAVE_TPETRA_INST_COMPLEX_FLOAT
57 
58 #define TPETRACORE_CGEMM TPETRACORE_F77_BLAS_MANGLE(cgemm,CGEMM)
59 
60 extern "C" void
61 TPETRACORE_CGEMM
62  (const char* transA, const char* transB,
63  const int* m, const int* n, const int* k,
64  const void* alpha, const void* a, const int* lda,
65  const void* b, const int* ldb,
66  const void* beta, void* c, const int* ldc);
67 
68 #endif // HAVE_TPETRA_INST_COMPLEX_FLOAT
69 
70 #define TPETRACORE_DGEMM TPETRACORE_F77_BLAS_MANGLE(dgemm,DGEMM)
71 
72 extern "C" void
73 TPETRACORE_DGEMM
74  (const char* transA, const char* transB,
75  const int* m, const int* n, const int* k,
76  const double* alpha, const double* a, const int* lda,
77  const double* b, const int* ldb,
78  const double* beta, double* c, const int* ldc);
79 
80 #define TPETRACORE_SGEMM TPETRACORE_F77_BLAS_MANGLE(sgemm,SGEMM)
81 
82 extern "C" void
83 TPETRACORE_SGEMM
84  (const char* transA, const char* transB,
85  const int* m, const int* n, const int* k,
86  const float* alpha, const float* a, const int* lda,
87  const float* b, const int* ldb,
88  const float* beta, float* c, const int* ldc);
89 
90 #ifdef HAVE_TPETRA_INST_COMPLEX_DOUBLE
91 
92 #define TPETRACORE_ZGEMM TPETRACORE_F77_BLAS_MANGLE(zgemm,ZGEMM)
93 
94 extern "C" void
95 TPETRACORE_ZGEMM
96  (const char* transA, const char* transB,
97  const int* m, const int* n, const int* k,
98  const void* alpha, const void* a, const int* lda,
99  const void* b, const int* ldb,
100  const void* beta, void* c, const int* ldc);
101 
102 #endif // HAVE_TPETRA_INST_COMPLEX_DOUBLE
103 
104 namespace Tpetra {
105 namespace Details {
106 namespace Blas {
107 namespace Lib {
108 namespace Impl {
109 
110 void
111 cgemm (const char transA,
112  const char transB,
113  const int m,
114  const int n,
115  const int k,
116  const ::Kokkos::complex<float>& alpha,
117  const ::Kokkos::complex<float> A[],
118  const int lda,
119  const ::Kokkos::complex<float> B[],
120  const int ldb,
121  const ::Kokkos::complex<float>& beta,
122  ::Kokkos::complex<float> C[],
123  const int ldc)
124 {
125 #ifdef HAVE_TPETRA_INST_COMPLEX_FLOAT
126  TPETRACORE_CGEMM (&transA, &transB, &m, &n, &k, &alpha, A, &lda, B, &ldb, &beta, C, &ldc);
127 #else
128  throw std::runtime_error ("Tpetra::Details::Blas::Lib::Impl::cgemm: "
129  "You must configure Tpetra with complex<float> support.");
130 #endif // HAVE_TPETRA_INST_COMPLEX_FLOAT
131 }
132 
133 void
134 dgemm (const char transA,
135  const char transB,
136  const int m,
137  const int n,
138  const int k,
139  const double alpha,
140  const double A[],
141  const int lda,
142  const double B[],
143  const int ldb,
144  const double beta,
145  double C[],
146  const int ldc)
147 {
148  TPETRACORE_DGEMM (&transA, &transB, &m, &n, &k, &alpha, A, &lda, B, &ldb, &beta, C, &ldc);
149 }
150 
151 void
152 sgemm (const char transA,
153  const char transB,
154  const int m,
155  const int n,
156  const int k,
157  const float alpha,
158  const float A[],
159  const int lda,
160  const float B[],
161  const int ldb,
162  const float beta,
163  float C[],
164  const int ldc)
165 {
166  TPETRACORE_SGEMM (&transA, &transB, &m, &n, &k, &alpha, A, &lda, B, &ldb, &beta, C, &ldc);
167 }
168 
169 void
170 zgemm (const char transA,
171  const char transB,
172  const int m,
173  const int n,
174  const int k,
175  const ::Kokkos::complex<double>& alpha,
176  const ::Kokkos::complex<double> A[],
177  const int lda,
178  const ::Kokkos::complex<double> B[],
179  const int ldb,
180  const ::Kokkos::complex<double>& beta,
181  ::Kokkos::complex<double> C[],
182  const int ldc)
183 {
184 #ifdef HAVE_TPETRA_INST_COMPLEX_DOUBLE
185  TPETRACORE_ZGEMM (&transA, &transB, &m, &n, &k, &alpha, A, &lda, B, &ldb, &beta, C, &ldc);
186 #else
187  throw std::runtime_error ("Tpetra::Details::Blas::Lib::Impl::zgemm: "
188  "You must configure Tpetra with complex<double> support.");
189 #endif // HAVE_TPETRA_INST_COMPLEX_DOUBLE
190 }
191 
192 } // namespace Impl
193 } // namespace Lib
194 } // namespace Blas
195 } // namespace Details
196 } // namespace Tpetra
Namespace Tpetra contains the class and methods constituting the Tpetra library.
Wrappers for the BLAS library&#39;s implementation of _GEMM; implementation detail of Tpetra::MultiVector...
Implementation details of Tpetra.