|
Teuchos - Trilinos Tools Package 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 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 // @HEADER 00028 00029 #ifndef _TEUCHOS_SCALARTRAITS_CUDA_HPP_ 00030 #define _TEUCHOS_SCALARTRAITS_CUDA_HPP_ 00031 00036 #include "Teuchos_ScalarTraitsDecl.hpp" 00037 00038 namespace Teuchos { 00039 00040 template<> 00041 struct ScalarTraits<int> 00042 { 00043 typedef int magnitudeType; 00044 typedef int halfPrecision; 00045 typedef int doublePrecision; 00046 static const bool isComplex = false; 00047 static const bool isOrdinal = true; 00048 static const bool isComparable = true; 00049 static const bool hasMachineParameters = false; 00050 static inline __device__ __host__ magnitudeType magnitude(int a) { return (int)fabsf((float)a); } 00051 static inline __device__ __host__ int zero() { return 0; } 00052 static inline __device__ __host__ int one() { return 1; } 00053 static inline __device__ __host__ int conjugate(int x) { return x; } 00054 static inline __device__ __host__ int real(int x) { return x; } 00055 static inline __device__ __host__ int imag(int) { return 0; } 00056 static inline __device__ __host__ bool isnaninf(int) { return false; } 00057 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 00058 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 00059 }; 00060 00061 #ifdef HAVE_KOKKOS_CUDA_FLOAT 00062 template<> 00063 struct ScalarTraits<float> 00064 { 00065 typedef float magnitudeType; 00066 typedef float halfPrecision; // should become IEEE754-2008 binary16 or fp16 later, perhaps specified at configure according to architectural support 00067 #ifdef HAVE_KOKKOS_CUDA_DOUBLE 00068 typedef double doublePrecision; 00069 #else 00070 typedef float doublePrecision; 00071 #endif 00072 static const bool isComplex = false; 00073 static const bool isOrdinal = false; 00074 static const bool isComparable = true; 00075 static const bool hasMachineParameters = false; 00076 static inline __device__ __host__ magnitudeType magnitude(float a) { return fabsf(a); } 00077 static inline __device__ __host__ float zero() { return(0.0f); } 00078 static inline __device__ __host__ float one() { return(1.0f); } 00079 static inline __device__ __host__ float conjugate(float x) { return(x); } 00080 static inline __device__ __host__ float real(float x) { return x; } 00081 static inline __device__ __host__ float imag(float) { return zero(); } 00082 static inline __device__ __host__ bool isnaninf(float x) { return isnan(x) || isinf(x); } 00083 static inline __device__ __host__ float squareroot(float x) { return sqrtf(x); } 00084 static inline __device__ __host__ float pow(float x, float y) { return powf(x,y); } 00085 }; 00086 #endif // HAVE_KOKKOS_CUDA_FLOAT 00087 00088 #ifdef HAVE_KOKKOS_CUDA_DOUBLE 00089 template<> 00090 struct ScalarTraits<double> 00091 { 00092 typedef double magnitudeType; 00093 #ifdef HAVE_KOKKOS_CUDA_FLOAT 00094 typedef float halfPrecision; 00095 #else 00096 typedef double halfPrecision; 00097 #endif 00098 typedef double doublePrecision; 00099 static const bool isComplex = false; 00100 static const bool isOrdinal = false; 00101 static const bool isComparable = true; 00102 static const bool hasMachineParameters = false; 00103 static inline __device__ __host__ magnitudeType magnitude(double a) { return abs(a); } 00104 static inline __device__ __host__ double zero() { return(0.0); } 00105 static inline __device__ __host__ double one() { return(1.0); } 00106 static inline __device__ __host__ double conjugate(double x) { return(x); } 00107 static inline __device__ __host__ double real(double x) { return x; } 00108 static inline __device__ __host__ double imag(double) { return zero(); } 00109 static inline __device__ __host__ bool isnaninf(double x) { return isnan(x) || isinf(x); } 00110 static inline __device__ __host__ double squareroot(double x) { return sqrt(x); } 00111 static inline __device__ __host__ double pow(double x, double y) { return pow(x,y); } 00112 }; 00113 #endif // HAVE_KOKKOS_CUDA_DOUBLE 00114 00115 } // Teuchos namespace 00116 00117 #endif // _TEUCHOS_SCALARTRAITS_CUDA_HPP_
1.7.4