cheshirekow  v0.1.0
intrinsics.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Josh Bialkowski (jbialk@mit.edu)
3  *
4  * This file is part of mpblocks.
5  *
6  * mpblocks is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * mpblocks is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with mpblocks. If not, see <http://www.gnu.org/licenses/>.
18  */
27 #ifndef MPBLOCKS_DUBINS_CURVES_CUDA_INTRINSICS_H_
28 #define MPBLOCKS_DUBINS_CURVES_CUDA_INTRINSICS_H_
29 
30 #ifdef __CUDACC__
31  #ifdef __CUDA_ARCH__
32  #define WHICH_CUDA intr::DEVICE
33  #else
34  #define WHICH_CUDA intr::HOST
35  #endif
36 #else
37  #define WHICH_CUDA intr::NATIVE
38 #endif
39 
40 #include <cmath>
41 #include <cuda_runtime.h>
42 
43 namespace mpblocks {
44 namespace cudaNN {
45 // provides overloads for cuda intrinsics for generic programming
46 namespace intr {
47 
49 {
53 };
54 
55 // defeault template calls std functions
56 template<Trajectory>
57 struct Dispatch
58 {
59  __host__ static double sin( double x ){ return std::sin(x); }
60  __host__ static float sin( float x ){ return std::sin(x); }
61  __host__ static double cos( double x ){ return std::cos(x); }
62  __host__ static float cos( float x ){ return std::cos(x); }
63  __host__ static double acos( double x ){ return std::acos(x); }
64  __host__ static float acos( float x ){ return std::acos(x); }
65  __host__ static double atan2( double x, double y ){ return std::atan2(x,y); }
66  __host__ static float atan2( float x, double y ){ return std::atan2(x,y); }
67 };
68 
69 // specialization for device calls device functions
70 template <>
72 {
73  __device__ static double sin( double x ){ return ::sin(x); }
74  __device__ static float sin( float x ){ return __sinf(x); }
75  __device__ static double cos( double x ){ return ::cos(x); }
76  __device__ static float cos( float x ){ return __cosf(x); }
77  __device__ static double acos( double x ){ return ::acos(x); }
78  __device__ static float acos( float x ){ return ::acosf(x); }
79  __device__ static double atan2( double x, double y ){ return ::atan2(x,y); }
80  __device__ static float atan2( float x, double y ){ return ::atan2f(x,y); }
81 };
82 
83 
84 } // intrinsics
85 } // cudaNN
86 } // mpblocks
87 
88 #endif // INTRINSICS_H_
static __device__ float acos(float x)
Definition: intrinsics.h:78
static __device__ float sin(float x)
Definition: intrinsics.h:74
static __device__ float cos(float x)
Definition: intrinsics.h:76
static __device__ double atan2(double x, double y)
Definition: intrinsics.h:79
static __host__ float cos(float x)
Definition: intrinsics.h:62
static __host__ double cos(double x)
Definition: intrinsics.h:61
static __host__ double acos(double x)
Definition: intrinsics.h:63
static __device__ double sin(double x)
Definition: intrinsics.h:73
#define __device__
Definition: fakecuda.h:34
static __host__ double atan2(double x, double y)
Definition: intrinsics.h:65
static __device__ double cos(double x)
Definition: intrinsics.h:75
static __device__ float atan2(float x, double y)
Definition: intrinsics.h:80
static __device__ double acos(double x)
Definition: intrinsics.h:77
static __host__ float atan2(float x, double y)
Definition: intrinsics.h:66
#define __host__
Definition: fakecuda.h:37
static __host__ float sin(float x)
Definition: intrinsics.h:60
static __host__ double sin(double x)
Definition: intrinsics.h:59
static __host__ float acos(float x)
Definition: intrinsics.h:64