|
Teuchos Package Browser (Single Doxygen Collection)
Version of the Day
|
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 template<> 00075 struct ScalarTraits<long int> 00076 { 00077 typedef long int magnitudeType; 00078 typedef long int halfPrecision; 00079 typedef long int doublePrecision; 00080 static const bool isComplex = false; 00081 static const bool isOrdinal = true; 00082 static const bool isComparable = true; 00083 static const bool hasMachineParameters = false; 00084 // Not defined: eps(), sfmin(), base(), prec(), t(), rnd(), emin(), rmin(), emax(), rmax() 00085 static inline __device__ __host__ magnitudeType magnitude(long int a) { return (long int)fabsf((float)a); } 00086 static inline __device__ __host__ long int zero() { return 0; } 00087 static inline __device__ __host__ long int one() { return 1; } 00088 static inline __device__ __host__ long int conjugate(long int x) { return x; } 00089 static inline __device__ __host__ long int real(long int x) { return x; } 00090 static inline __device__ __host__ long int imag(long int) { return 0; } 00091 static inline __device__ __host__ bool isnaninf(int) { return false; } 00092 static inline __device__ __host__ long int squareroot(long int x) { return (long int)sqrtf((float)x); } // perhaps this cast should be replaced by an explicit call like __float2int_rn 00093 static inline __device__ __host__ long int pow(long int x, long int y) { return (long int)powf((float)x,(float)y); } // perhaps this cast should be replaced by an explicit call like __float2int_rn 00094 }; 00095 00096 #ifdef HAVE_KOKKOSCLASSIC_CUDA_FLOAT 00097 template<> 00098 struct ScalarTraits<float> 00099 { 00100 typedef float magnitudeType; 00101 typedef float halfPrecision; // should become IEEE754-2008 binary16 or fp16 later, perhaps specified at configure according to architectural support 00102 #ifdef HAVE_KOKKOSCLASSIC_CUDA_DOUBLE 00103 typedef double doublePrecision; 00104 #else 00105 typedef float doublePrecision; 00106 #endif 00107 static const bool isComplex = false; 00108 static const bool isOrdinal = false; 00109 static const bool isComparable = true; 00110 static const bool hasMachineParameters = false; 00111 static inline __device__ __host__ magnitudeType magnitude(float a) { return fabsf(a); } 00112 static inline __device__ __host__ float zero() { return(0.0f); } 00113 static inline __device__ __host__ float one() { return(1.0f); } 00114 static inline __device__ __host__ float conjugate(float x) { return(x); } 00115 static inline __device__ __host__ float real(float x) { return x; } 00116 static inline __device__ __host__ float imag(float) { return zero(); } 00117 static inline __device__ __host__ bool isnaninf(float x) { return isnan(x) || isinf(x); } 00118 static inline __device__ __host__ float squareroot(float x) { return sqrtf(x); } 00119 static inline __device__ __host__ float pow(float x, float y) { return powf(x,y); } 00120 }; 00121 #endif // HAVE_KOKKOSCLASSIC_CUDA_FLOAT 00122 00123 #ifdef HAVE_KOKKOSCLASSIC_CUDA_DOUBLE 00124 template<> 00125 struct ScalarTraits<double> 00126 { 00127 typedef double magnitudeType; 00128 #ifdef HAVE_KOKKOSCLASSIC_CUDA_FLOAT 00129 typedef float halfPrecision; 00130 #else 00131 typedef double halfPrecision; 00132 #endif 00133 typedef double doublePrecision; 00134 static const bool isComplex = false; 00135 static const bool isOrdinal = false; 00136 static const bool isComparable = true; 00137 static const bool hasMachineParameters = false; 00138 static inline __device__ __host__ magnitudeType magnitude(double a) { return abs(a); } 00139 static inline __device__ __host__ double zero() { return(0.0); } 00140 static inline __device__ __host__ double one() { return(1.0); } 00141 static inline __device__ __host__ double conjugate(double x) { return(x); } 00142 static inline __device__ __host__ double real(double x) { return x; } 00143 static inline __device__ __host__ double imag(double) { return zero(); } 00144 static inline __device__ __host__ bool isnaninf(double x) { return isnan(x) || isinf(x); } 00145 static inline __device__ __host__ double squareroot(double x) { return sqrt(x); } 00146 static inline __device__ __host__ double pow(double x, double y) { return pow(x,y); } 00147 }; 00148 #endif // HAVE_KOKKOSCLASSIC_CUDA_DOUBLE 00149 00150 } // Teuchos namespace 00151 00152 #endif // _TEUCHOS_SCALARTRAITS_CUDA_HPP_
1.7.6.1