Kokkos Core Kernels Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Kokkos_InnerProductSpaceTraits.hpp
Go to the documentation of this file.
1 /*
2 //@HEADER
3 // ************************************************************************
4 //
5 // Kokkos: Manycore Performance-Portable Multidimensional Arrays
6 // Copyright (2012) 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 H. Carter Edwards (hcedwar@sandia.gov)
39 //
40 // ************************************************************************
41 //@HEADER
42 */
43 
44 #ifndef KOKKOS_INNERPRODUCTSPACETRAITS_HPP
45 #define KOKKOS_INNERPRODUCTSPACETRAITS_HPP
46 
52 
53 #include "Kokkos_ArithTraits.hpp"
54 
55 namespace Kokkos {
56 namespace Details {
57 
144 template<class T>
146 public:
148  typedef T val_type;
149 
152 
154  typedef T dot_type;
155 
157  static KOKKOS_FORCEINLINE_FUNCTION mag_type norm (const T& x) {
158  return ArithTraits<T>::abs (x);
159  }
161  static KOKKOS_FORCEINLINE_FUNCTION dot_type dot (const T& x, const T& y) {
162  return x * y;
163  }
164 };
165 
166 
167 // CUDA does not support long double in device functions.
168 template<>
169 struct InnerProductSpaceTraits<long double>
170 {
171  typedef long double val_type;
172  typedef ArithTraits<val_type>::mag_type mag_type;
173  typedef val_type dot_type;
174 
175  static mag_type norm (const val_type& x) {
176  return ArithTraits<val_type>::abs (x);
177  }
178  static dot_type dot (const val_type& x, const val_type& y) {
179  return x * y;
180  }
181 };
182 
183 
184 // CUDA does not support std::complex<T> in device functions.
185 template<class T>
186 struct InnerProductSpaceTraits<std::complex<T> >
187 {
188  typedef std::complex<T> val_type;
189  typedef typename ArithTraits<val_type>::mag_type mag_type;
190  typedef val_type dot_type;
191 
192  static mag_type norm (const val_type& x) {
193  return ArithTraits<val_type>::abs (x);
194  }
195  static dot_type dot (const val_type& x, const val_type& y) {
196  return x * y;
197  }
198 };
199 
200 
201 // dd_real and qd_real are floating-point types provided by the QD
202 // library of David Bailey (LBNL):
203 //
204 // http://crd-legacy.lbl.gov/~dhbailey/mpdist/
205 //
206 // dd_real uses two doubles (128 bits), and qd_real uses four doubles
207 // (256 bits).
208 //
209 // Kokkos does <i>not</i> currently support these types in device
210 // functions. It should be possible to use Kokkos' support for
211 // aggregate types to implement device function support for dd_real
212 // and qd_real, but we have not done this yet (as of 07 Jan 2014).
213 // Hence, the class methods of the ArithTraits specializations for
214 // dd_real and qd_real are not marked as device functions.
215 #ifdef HAVE_KOKKOS_QD
216 template<>
217 struct InnerProductSpaceTraits<dd_real>
218 {
219  typedef dd_real val_type;
220  typedef ArithTraits<val_type>::mag_type mag_type;
221  typedef val_type dot_type;
222 
223  static mag_type norm (const val_type& x) {
224  return ArithTraits<val_type>::abs (x);
225  }
226  static dot_type dot (const val_type& x, const val_type& y) {
227  return x * y;
228  }
229 };
230 
231 template<>
232 struct InnerProductSpaceTraits<qd_real>
233 {
234  typedef qd_real val_type;
235  typedef ArithTraits<val_type>::mag_type mag_type;
236  typedef val_type dot_type;
237 
238  static mag_type norm (const val_type& x) {
239  return ArithTraits<val_type>::abs (x);
240  }
241  static dot_type dot (const val_type& x, const val_type& y) {
242  return x * y;
243  }
244 };
245 #endif // HAVE_KOKKOS_QD
246 
247 } // namespace Details
248 } // namespace Kokkos
249 
250 #endif // KOKKOS_INNERPRODUCTSPACETRAITS_HPP
static KOKKOS_FORCEINLINE_FUNCTION mag_type abs(const T &x)
The absolute value (magnitude) of x.
ArithTraits< T >::mag_type mag_type
The type returned by norm(x) for a value x of type T.
T dot_type
The type returned by dot(x,y) for values x and y of type T.
static KOKKOS_FORCEINLINE_FUNCTION dot_type dot(const T &x, const T &y)
The "dot product" of two values x and y of type T.
Traits class for inner product space operations on type T.
static KOKKOS_FORCEINLINE_FUNCTION mag_type norm(const T &x)
The "norm" (absolute value or magnitude) of a value x of type T.
T mag_type
The type of the magnitude (absolute value) of T.
Declaration and definition of Kokkos::Details::ArithTraits.