Teuchos - Trilinos Tools Package Version of the Day
Teuchos_ScalarTraitsCUDA.hpp
Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 //
00004 //                    Teuchos: Common Tools Package
00005 //                 Copyright (2004) Sandia Corporation
00006 //
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 #ifndef _TEUCHOS_SCALARTRAITS_CUDA_HPP_
00043 #define _TEUCHOS_SCALARTRAITS_CUDA_HPP_
00044 
00049 #include "Teuchos_ScalarTraitsDecl.hpp"
00050 
00051 namespace Teuchos {
00052 
00053 template<>
00054 struct ScalarTraits<int>
00055 {
00056   typedef int magnitudeType;
00057   typedef int halfPrecision;
00058   typedef int doublePrecision;
00059   static const bool isComplex = false;
00060   static const bool isOrdinal = true;
00061   static const bool isComparable = true;
00062   static const bool hasMachineParameters = false;
00063   static inline __device__ __host__ magnitudeType magnitude(int a) { return (int)fabsf((float)a); }
00064   static inline __device__ __host__ int zero()  { return 0; }
00065   static inline __device__ __host__ int one()   { return 1; }
00066   static inline __device__ __host__ int conjugate(int x) { return x; }
00067   static inline __device__ __host__ int real(int x) { return x; }
00068   static inline __device__ __host__ int imag(int)   { return 0; }
00069   static inline __device__ __host__ bool isnaninf(int) { return false; }
00070   static inline __device__ __host__ int squareroot(int x) { return (int)sqrtf((float)x); }          // perhaps this cast should be replaced by an explicit call like __float2int_rn
00071   static inline __device__ __host__ int pow(int x, int y) { return (int)powf((float)x,(float)y); }  // perhaps this cast should be replaced by an explicit call like __float2int_rn
00072 };
00073 
00074 #ifdef HAVE_KOKKOS_CUDA_FLOAT
00075 template<>
00076 struct ScalarTraits<float>
00077 {
00078   typedef float magnitudeType;
00079   typedef float halfPrecision; // should become IEEE754-2008 binary16 or fp16 later, perhaps specified at configure according to architectural support
00080 #ifdef HAVE_KOKKOS_CUDA_DOUBLE
00081   typedef double doublePrecision;
00082 #else
00083   typedef float  doublePrecision;
00084 #endif
00085   static const bool isComplex = false;
00086   static const bool isOrdinal = false;
00087   static const bool isComparable = true;
00088   static const bool hasMachineParameters = false;
00089   static inline __device__ __host__ magnitudeType magnitude(float a) { return fabsf(a); }
00090   static inline __device__ __host__ float zero()  { return(0.0f); }
00091   static inline __device__ __host__ float one()   { return(1.0f); }    
00092   static inline __device__ __host__ float conjugate(float x)   { return(x); }    
00093   static inline __device__ __host__ float real(float x) { return x; }
00094   static inline __device__ __host__ float imag(float)   { return zero(); }
00095   static inline __device__ __host__ bool  isnaninf(float x) { return isnan(x) || isinf(x); }
00096   static inline __device__ __host__ float squareroot(float x) { return sqrtf(x); }
00097   static inline __device__ __host__ float pow(float x, float y) { return powf(x,y); }
00098 };
00099 #endif // HAVE_KOKKOS_CUDA_FLOAT
00100 
00101 #ifdef HAVE_KOKKOS_CUDA_DOUBLE
00102 template<>
00103 struct ScalarTraits<double>
00104 {
00105   typedef double magnitudeType;
00106 #ifdef HAVE_KOKKOS_CUDA_FLOAT
00107   typedef float  halfPrecision;
00108 #else
00109   typedef double halfPrecision;
00110 #endif
00111   typedef double doublePrecision;
00112   static const bool isComplex = false;
00113   static const bool isOrdinal = false;
00114   static const bool isComparable = true;
00115   static const bool hasMachineParameters = false;
00116   static inline __device__ __host__ magnitudeType magnitude(double a) { return abs(a); }
00117   static inline __device__ __host__ double zero()  { return(0.0); }
00118   static inline __device__ __host__ double one()   { return(1.0); }    
00119   static inline __device__ __host__ double conjugate(double x)   { return(x); }    
00120   static inline __device__ __host__ double real(double x) { return x; }
00121   static inline __device__ __host__ double imag(double)   { return zero(); }
00122   static inline __device__ __host__ bool  isnaninf(double x) { return isnan(x) || isinf(x); }
00123   static inline __device__ __host__ double squareroot(double x) { return sqrt(x); }
00124   static inline __device__ __host__ double pow(double x, double y) { return pow(x,y); }
00125 };
00126 #endif // HAVE_KOKKOS_CUDA_DOUBLE
00127 
00128 } // Teuchos namespace
00129 
00130 #endif // _TEUCHOS_SCALARTRAITS_CUDA_HPP_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines