|
Kokkos Core Kernels Package
Version of the Day
|
00001 /* 00002 //@HEADER 00003 // ************************************************************************ 00004 // 00005 // Kokkos: Manycore Performance-Portable Multidimensional Arrays 00006 // Copyright (2012) Sandia Corporation 00007 // 00008 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 00009 // the U.S. Government retains certain rights in this software. 00010 // 00011 // Redistribution and use in source and binary forms, with or without 00012 // modification, are permitted provided that the following conditions are 00013 // met: 00014 // 00015 // 1. Redistributions of source code must retain the above copyright 00016 // notice, this list of conditions and the following disclaimer. 00017 // 00018 // 2. Redistributions in binary form must reproduce the above copyright 00019 // notice, this list of conditions and the following disclaimer in the 00020 // documentation and/or other materials provided with the distribution. 00021 // 00022 // 3. Neither the name of the Corporation nor the names of the 00023 // contributors may be used to endorse or promote products derived from 00024 // this software without specific prior written permission. 00025 // 00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00037 // 00038 // Questions? Contact H. Carter Edwards (hcedwar@sandia.gov) 00039 // 00040 // ************************************************************************ 00041 //@HEADER 00042 */ 00043 00044 #ifndef KOKKOS_INNERPRODUCTSPACETRAITS_HPP 00045 #define KOKKOS_INNERPRODUCTSPACETRAITS_HPP 00046 00052 00053 #include "Kokkos_ArithTraits.hpp" 00054 00055 namespace Kokkos { 00056 namespace Details { 00057 00144 template<class T> 00145 class InnerProductSpaceTraits { 00146 public: 00148 typedef T val_type; 00149 00151 typedef typename ArithTraits<T>::mag_type mag_type; 00152 00154 typedef T dot_type; 00155 00157 static KOKKOS_FORCEINLINE_FUNCTION mag_type norm (const T& x) { 00158 return ArithTraits<T>::abs (x); 00159 } 00161 static KOKKOS_FORCEINLINE_FUNCTION dot_type dot (const T& x, const T& y) { 00162 return x * y; 00163 } 00164 }; 00165 00166 00167 // CUDA does not support long double in device functions. 00168 template<> 00169 struct InnerProductSpaceTraits<long double> 00170 { 00171 typedef long double val_type; 00172 typedef ArithTraits<val_type>::mag_type mag_type; 00173 typedef val_type dot_type; 00174 00175 static mag_type norm (const val_type& x) { 00176 return ArithTraits<val_type>::abs (x); 00177 } 00178 static dot_type dot (const val_type& x, const val_type& y) { 00179 return x * y; 00180 } 00181 }; 00182 00183 00184 // CUDA does not support std::complex<T> in device functions. 00185 template<class T> 00186 struct InnerProductSpaceTraits<std::complex<T> > 00187 { 00188 typedef std::complex<T> val_type; 00189 typedef typename ArithTraits<val_type>::mag_type mag_type; 00190 typedef val_type dot_type; 00191 00192 static mag_type norm (const val_type& x) { 00193 return ArithTraits<val_type>::abs (x); 00194 } 00195 static dot_type dot (const val_type& x, const val_type& y) { 00196 return x * y; 00197 } 00198 }; 00199 00200 00201 // dd_real and qd_real are floating-point types provided by the QD 00202 // library of David Bailey (LBNL): 00203 // 00204 // http://crd-legacy.lbl.gov/~dhbailey/mpdist/ 00205 // 00206 // dd_real uses two doubles (128 bits), and qd_real uses four doubles 00207 // (256 bits). 00208 // 00209 // Kokkos does <i>not</i> currently support these types in device 00210 // functions. It should be possible to use Kokkos' support for 00211 // aggregate types to implement device function support for dd_real 00212 // and qd_real, but we have not done this yet (as of 07 Jan 2014). 00213 // Hence, the class methods of the ArithTraits specializations for 00214 // dd_real and qd_real are not marked as device functions. 00215 #ifdef HAVE_KOKKOS_QD 00216 template<> 00217 struct InnerProductSpaceTraits<dd_real> 00218 { 00219 typedef dd_real val_type; 00220 typedef ArithTraits<val_type>::mag_type mag_type; 00221 typedef val_type dot_type; 00222 00223 static mag_type norm (const val_type& x) { 00224 return ArithTraits<val_type>::abs (x); 00225 } 00226 static dot_type dot (const val_type& x, const val_type& y) { 00227 return x * y; 00228 } 00229 }; 00230 00231 template<> 00232 struct InnerProductSpaceTraits<qd_real> 00233 { 00234 typedef qd_real val_type; 00235 typedef ArithTraits<val_type>::mag_type mag_type; 00236 typedef val_type dot_type; 00237 00238 static mag_type norm (const val_type& x) { 00239 return ArithTraits<val_type>::abs (x); 00240 } 00241 static dot_type dot (const val_type& x, const val_type& y) { 00242 return x * y; 00243 } 00244 }; 00245 #endif // HAVE_KOKKOS_QD 00246 00247 } // namespace Details 00248 } // namespace Kokkos 00249 00250 #endif // KOKKOS_INNERPRODUCTSPACETRAITS_HPP
1.7.6.1