OpenMPCD
ImplementationDetails/Average.hpp
Go to the documentation of this file.
1 /**
2  * @file
3  * Holds implementation details for `OpenMPCD/CUDA/DeviceCode/Average.hpp`.
4  */
5 
6 #ifndef OPENMPCD_CUDA_DEVICECODE_IMPLEMENTATIONDETAILS_AVERAGE
7 #define OPENMPCD_CUDA_DEVICECODE_IMPLEMENTATIONDETAILS_AVERAGE
8 
10 
11 #include <thrust/execution_policy.h>
12 #include <thrust/reduce.h>
13 
14 namespace OpenMPCD
15 {
16 namespace CUDA
17 {
18 namespace DeviceCode
19 {
20 
21 template<typename T>
22  __global__ void arithmeticMean_kernel(
23  const T* const values,
24  const std::size_t numberOfValues,
25  T* const output)
26 {
27  const T result =
28  thrust::reduce(thrust::device, values, values + numberOfValues);
29  *output = result / numberOfValues;
30 }
31 
32 template<typename T>
34  const T* const values,
35  const std::size_t numberOfValues,
36  T* const output)
37 {
38  #ifdef OPENMPCD_DEBUG
39  if(!values)
41 
42  if(numberOfValues == 0)
43  OPENMPCD_THROW(InvalidArgumentException, "`numberOfValues`");
44 
45  if(!output)
47 
50 
53  #endif
54 
55  const T result =
56  thrust::reduce(thrust::device, values, values + numberOfValues) /
57  numberOfValues;
58 
60 }
61 
62 } //namespace DeviceCode
63 } //namespace CUDA
64 } //namespace OpenMPCD
65 
66 #endif //OPENMPCD_CUDA_DEVICECODE_IMPLEMENTATIONDETAILS_AVERAGE
OPENMPCD_THROW
#define OPENMPCD_THROW(ExceptionType, message)
Throws the given ExceptionType, passing the given message along with file and line number information...
Definition: Exceptions.hpp:22
OpenMPCD::CUDA::DeviceMemoryManager::isDeviceMemoryPointer
static bool isDeviceMemoryPointer(const void *const ptr)
Returns whether the given pointer is a pointer to CUDA Device memory.
Definition: DeviceMemoryManager.cpp:81
OpenMPCD::CUDA::DeviceMemoryManager::copyElementsFromHostToDevice
static void copyElementsFromHostToDevice(const T *const src, T *const dest, const std::size_t count)
Copies count elements of type T from the Host to the Device.
Definition: ImplementationDetails/DeviceMemoryManager.hpp:22
DeviceMemoryManager.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::NULLPointerException
NULL-pointer exception.
Definition: Exceptions.hpp:96
OpenMPCD::InvalidArgumentException
Invalid argument exception.
Definition: Exceptions.hpp:128
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