00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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); }
00058 static inline __device__ __host__ int pow(int x, int y) { return (int)powf((float)x,(float)y); }
00059 };
00060
00061 #ifdef HAVE_KOKKOS_CUDA_FLOAT
00062 template<>
00063 struct ScalarTraits<float>
00064 {
00065 typedef float magnitudeType;
00066 typedef float halfPrecision;
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 }
00116
00117 #endif // _TEUCHOS_SCALARTRAITS_CUDA_HPP_