OpenMPCD
Utilities.hpp
Go to the documentation of this file.
1 /**
2  * @file
3  * Defines various CUDA device code utilities.
4  */
5 
6 #ifndef OPENMPCD_CUDA_DEVICECODE_UTILITIES_HPP
7 #define OPENMPCD_CUDA_DEVICECODE_UTILITIES_HPP
8 
10 
11 #include <boost/core/enable_if.hpp>
12 #include <boost/type_traits/is_floating_point.hpp>
13 #include <boost/type_traits/is_integral.hpp>
14 
15 namespace OpenMPCD
16 {
17 namespace CUDA
18 {
19 namespace DeviceCode
20 {
21  /**
22  * Atomically adds increment to target.
23  * @param[in] target The address of the value to increment.
24  * @param[in] increment The value to add to target.
25  */
27  void atomicAdd(double* const target, const double increment);
28 
29  /**
30  * Atomically adds increment to target.
31  * @param[in] target The address of the value to increment.
32  * @param[in] increment The value to add to target.
33  */
35  void atomicAdd(float* const target, const float increment);
36 
37 
38  /**
39  * The power function.
40  *
41  * @tparam B The type of the `base` argument, which must be an integral
42  * type.
43  *
44  * @param[in] base The base.
45  * @param[in] exponent The exponent.
46  */
47  template<typename B>
49  typename boost::enable_if<boost::is_integral<B>, double>::type
50  pow(const B base, const double exponent)
51  {
52  return ::pow(static_cast<double>(base), exponent);
53  }
54 
55  /**
56  * The power function.
57  *
58  * @param[in] base The base.
59  * @param[in] exponent The exponent.
60  */
62  double pow(const double base, const double exponent)
63  {
64  return ::pow(base, exponent);
65  }
66 } //namespace DeviceCode
67 } //namespace CUDA
68 } //namespace OpenMPCD
69 
70 #endif
OpenMPCD::CUDA::DeviceCode::pow
OPENMPCD_CUDA_HOST_AND_DEVICE boost::enable_if< boost::is_integral< B >, double >::type pow(const B base, const double exponent)
The power function.
Definition: Utilities.hpp:50
OPENMPCD_CUDA_DEVICE
#define OPENMPCD_CUDA_DEVICE
Denotes a function to be callable from a CUDA Device.
Definition: Macros.hpp:25
OPENMPCD_CUDA_HOST_AND_DEVICE
#define OPENMPCD_CUDA_HOST_AND_DEVICE
Denotes a function to be callable both from the Host and from a CUDA Device.
Definition: Macros.hpp:15
OpenMPCD::CUDA::DeviceCode::pow
OPENMPCD_CUDA_HOST_AND_DEVICE double pow(const double base, const double exponent)
The power function.
Definition: Utilities.hpp:62
Macros.hpp
OpenMPCD::CUDA::DeviceCode::atomicAdd
OPENMPCD_CUDA_DEVICE void atomicAdd(double *const target, const double increment)
Atomically adds increment to target.