OpenMPCD
Average.hpp
Go to the documentation of this file.
1 /**
2  * @file
3  * Defines CUDA Device functions for averaging.
4  */
5 
6 #ifndef OPENMPCD_CUDA_DEVICECODE_AVERAGE_HPP
7 #define OPENMPCD_CUDA_DEVICECODE_AVERAGE_HPP
8 
9 namespace OpenMPCD
10 {
11 namespace CUDA
12 {
13 namespace DeviceCode
14 {
15 
16 /**
17  * Kernel to compute the arithmetic mean of the given values.
18  *
19  * Each value will enter the average with equal weight.
20  *
21  * @tparam T The type of values.
22  *
23  * @param[in] values
24  * The values to take the average of, stored on the CUDA Device.
25  * In total, `values` must hold at least
26  * `numberOfValues * sizeof(T)` bytes.
27  * @param[in] numberOfValues
28  * The number of values to treat.
29  * @param[out] output
30  * The CUDA Device pointer to save the result to.
31  */
32 template<typename T>
33  __global__ void arithmeticMean_kernel(
34  const T* const values,
35  const std::size_t numberOfValues,
36  T* const output);
37 
38 /**
39  * Computes, on the CUDA Device, the arithmetic mean of the given values.
40  *
41  * Each value will enter the average with equal weight.
42  *
43  * @throw OpenMPCD::NULLPointerException
44  * Throws if `values` is `nullptr`.
45  * @throw OpenMPCD::InvalidArgumentException
46  * Throws if `numberOfValues == 0`.
47  * @throw OpenMPCD::NULLPointerException
48  * Throws if `output` is `nullptr`.
49  * @throw OpenMPCD::InvalidArgumentException
50  * If OPENMPCD_DEBUG is defined,
51  * throws if `values` is not a Device pointer.
52  * @throw OpenMPCD::InvalidArgumentException
53  * If OPENMPCD_DEBUG is defined,
54  * throws if `output` is not a Device pointer.
55  *
56  * @tparam T The type of values.
57  *
58  * @param[in] values
59  * The values to take the average of, stored on the CUDA Device.
60  * In total, `values` must hold at least
61  * `numberOfValues * sizeof(T)` bytes.
62  * @param[in] numberOfValues
63  * The number of values to treat.
64  * @param[out] output
65  * The CUDA Device pointer to save the result to.
66  */
67 template<typename T>
68  void arithmeticMean(
69  const T* const values,
70  const std::size_t numberOfValues,
71  T* const output);
72 
73 } //namespace DeviceCode
74 } //namespace CUDA
75 } //namespace OpenMPCD
76 
78 
79 #endif //OPENMPCD_CUDA_DEVICECODE_AVERAGE_HPP
Average.hpp
OpenMPCD::CUDA::DeviceCode::arithmeticMean_kernel
__global__ void arithmeticMean_kernel(const T *const values, const std::size_t numberOfValues, T *const output)
Kernel to compute the arithmetic mean of the given values.
Definition: ImplementationDetails/Average.hpp:22
OpenMPCD::CUDA::DeviceCode::arithmeticMean
void arithmeticMean(const T *const values, const std::size_t numberOfValues, T *const output)
Computes, on the CUDA Device, the arithmetic mean of the given values.
Definition: ImplementationDetails/Average.hpp:33