PSCF v1.4.0

Functions that perform parallel reductions on a GPU. More...

Functions

cudaReal Pscf::Reduce::sum (DeviceArray< cudaReal > const &in)
 Return sum of elements of a real array.
cudaReal Pscf::Reduce::sum (DeviceArray< cudaReal > const &in, int begin, int end)
 Return sum of elements of a real array slice.
std::complex< cudaRealPscf::Reduce::sum (DeviceArray< cudaComplex > const &in)
 Return sum of all elements of a complex array.
std::complex< cudaRealPscf::Reduce::sum (DeviceArray< cudaComplex > const &in, int begin, int end)
 Return sum of elements of a complex array slice.
cudaReal Pscf::Reduce::sumSq (DeviceArray< cudaReal > const &in)
 Return sum of squares of elements of a real array.
std::complex< cudaRealPscf::Reduce::sumSq (DeviceArray< cudaComplex > const &in)
 Return sum of squares of elements of a complex array.
cudaReal Pscf::Reduce::sumSqAbs (DeviceArray< cudaComplex > const &in)
 Return sum of squared magnitudes of elements of a complex array.
cudaReal Pscf::Reduce::innerProduct (DeviceArray< cudaReal > const &a, DeviceArray< cudaReal > const &b)
 Return the inner product of two real arrays.
cudaReal Pscf::Reduce::max (DeviceArray< cudaReal > const &in)
 Return maximum of all real array elements.
cudaReal Pscf::Reduce::max (DeviceArray< cudaReal > const &in, int begin, int end)
 Return maximum of elements of a real array slice.
cudaReal Pscf::Reduce::maxAbs (DeviceArray< cudaReal > const &in)
 Get maximum absolute magnitude of real array elements.
cudaReal Pscf::Reduce::min (DeviceArray< cudaReal > const &in)
 Return minimum of all real array elements.
cudaReal Pscf::Reduce::min (DeviceArray< cudaReal > const &in, int begin, int end)
 Return minimum of elements of a real array slice.
cudaReal Pscf::Reduce::minAbs (DeviceArray< cudaReal > const &in)
 Return minimum absolute magnitude of real array elements.
void Pscf::Reduce::freeWorkSpace ()
 Free any private work space currently allocated for reductions.

Detailed Description

Functions that perform parallel reductions on a GPU.

A reduction is any operation that involves reducing all of the elements of one or more arrays to a single scalar result. Examples include taking the computation of the sum or the maximum of all elements of a single array, or of a Euclidean inner product of two real arrays.

A public function is provided for each reduction operation, which takes one or more DeviceArray containers as inputs and returns a single value. Each wrapper function is a standard C++ function that may be called on the host CPU. The implementation of each such wrapper function calls one of the device-wide algorithms defined in the CUB library that is distributed as part of the CUDA Core Compute library collection provided with the CUDA development kit.

Reduction functions that return a real number return a value of type cudaReal. Functions that return a complex number instead return a value of type std::complex<cudaReal>. Complex values are returned as std::complex<cudaReal> rather than cudaComplex to allow similar interfaces to be used by reduction functions declared here and by analogous functions defined in src/pscf/cpu/Reduced.h that take take standard Array containers as inputs and perform calculations on the CPU.

Function Documentation

◆ sum() [1/4]

cudaReal Pscf::Reduce::sum ( DeviceArray< cudaReal > const & in)

Return sum of elements of a real array.

Parameters
inreal input array
Returns
sum of elements

Definition at line 216 of file Reduce.cu.

References Pscf::DeviceArray< Data >::capacity(), Pscf::DeviceArray< Data >::cArray(), Pscf::DeviceArray< Data >::isAllocated(), sum(), and UTIL_CHECK.

◆ sum() [2/4]

cudaReal Pscf::Reduce::sum ( DeviceArray< cudaReal > const & in,
int begin,
int end )

Return sum of elements of a real array slice.

Parameters
inreal input array
beginindex of first element of slice
endindex one past last element
Returns
sum of elements

Definition at line 231 of file Reduce.cu.

References Pscf::DeviceArray< Data >::capacity(), Pscf::DeviceArray< Data >::cArray(), Pscf::DeviceArray< Data >::isAllocated(), sum(), and UTIL_CHECK.

◆ sum() [3/4]

std::complex< cudaReal > Pscf::Reduce::sum ( DeviceArray< cudaComplex > const & in)

Return sum of all elements of a complex array.

Parameters
incomplex input array
Returns
complex sum of elements

Definition at line 249 of file Reduce.cu.

References Pscf::DeviceArray< Data >::capacity(), Pscf::DeviceArray< Data >::cArray(), Pscf::DeviceArray< Data >::isAllocated(), sum(), and UTIL_CHECK.

◆ sum() [4/4]

std::complex< cudaReal > Pscf::Reduce::sum ( DeviceArray< cudaComplex > const & in,
int begin,
int end )

Return sum of elements of a complex array slice.

Parameters
inreal input array
beginindex of first element of slice
endindex one past last element of slice
Returns
sum of elements

Definition at line 264 of file Reduce.cu.

References Pscf::DeviceArray< Data >::capacity(), Pscf::DeviceArray< Data >::cArray(), Pscf::DeviceArray< Data >::isAllocated(), sum(), and UTIL_CHECK.

◆ sumSq() [1/2]

cudaReal Pscf::Reduce::sumSq ( DeviceArray< cudaReal > const & in)

Return sum of squares of elements of a real array.

This function returns the square of the Euclidean norm for a real array.

Parameters
inreal input array
Returns
sum of squares of elements

Definition at line 281 of file Reduce.cu.

References Pscf::DeviceArray< Data >::associate(), Pscf::DeviceArray< Data >::capacity(), Pscf::DeviceArray< Data >::dissociate(), Pscf::DeviceArray< Data >::isAllocated(), Pscf::VecOp::sqV(), sum(), and UTIL_CHECK.

◆ sumSq() [2/2]

std::complex< cudaReal > Pscf::Reduce::sumSq ( DeviceArray< cudaComplex > const & in)

Return sum of squares of elements of a complex array.

This function returns the complex sum of complex squares of elements. This is not the square of the Hilbert space norm.

Parameters
inreal input array
Returns
sum of complex squares of elements

Definition at line 304 of file Reduce.cu.

References Pscf::DeviceArray< Data >::associate(), Pscf::DeviceArray< Data >::capacity(), Pscf::DeviceArray< Data >::dissociate(), Pscf::DeviceArray< Data >::isAllocated(), Pscf::VecOp::sqV(), sum(), and UTIL_CHECK.

◆ sumSqAbs()

cudaReal Pscf::Reduce::sumSqAbs ( DeviceArray< cudaComplex > const & in)

Return sum of squared magnitudes of elements of a complex array.

This function returns the real sum of the squared absolute magnitude of all elements of a complex array. This is the square of the conventional Hilbert space norm.

Parameters
inreal input array
Returns
sum of squared absolute magnitude of elements

Definition at line 328 of file Reduce.cu.

References Pscf::DeviceArray< Data >::associate(), Pscf::DeviceArray< Data >::capacity(), Pscf::DeviceArray< Data >::dissociate(), Pscf::DeviceArray< Data >::isAllocated(), Pscf::VecOp::sqAbsV(), sum(), and UTIL_CHECK.

◆ innerProduct()

cudaReal Pscf::Reduce::innerProduct ( DeviceArray< cudaReal > const & a,
DeviceArray< cudaReal > const & b )

Return the inner product of two real arrays.

Parameters
afirst real input array
bsecond real input array
Returns
Euclidean inner product

Definition at line 352 of file Reduce.cu.

References Pscf::DeviceArray< Data >::associate(), Pscf::DeviceArray< Data >::capacity(), Pscf::DeviceArray< Data >::dissociate(), Pscf::DeviceArray< Data >::isAllocated(), Pscf::VecOp::mulVV(), sum(), and UTIL_CHECK.

◆ max() [1/2]

cudaReal Pscf::Reduce::max ( DeviceArray< cudaReal > const & in)

Return maximum of all real array elements.

Parameters
inreal input array
Returns
value of maximum element

Definition at line 381 of file Reduce.cu.

References Pscf::DeviceArray< Data >::capacity(), Pscf::DeviceArray< Data >::cArray(), Pscf::DeviceArray< Data >::isAllocated(), max(), and UTIL_CHECK.

◆ max() [2/2]

cudaReal Pscf::Reduce::max ( DeviceArray< cudaReal > const & in,
int begin,
int end )

Return maximum of elements of a real array slice.

Parameters
inreal input array
beginindex of first element of slice
endindex one past last element
Returns
value of maximum element

Definition at line 394 of file Reduce.cu.

References Pscf::DeviceArray< Data >::capacity(), Pscf::DeviceArray< Data >::cArray(), Pscf::DeviceArray< Data >::isAllocated(), max(), and UTIL_CHECK.

◆ maxAbs()

cudaReal Pscf::Reduce::maxAbs ( DeviceArray< cudaReal > const & in)

Get maximum absolute magnitude of real array elements.

Parameters
inreal input array
Returns
magnitude of element of maximum magnitude

Definition at line 410 of file Reduce.cu.

References Pscf::VecOp::absV(), Pscf::DeviceArray< Data >::associate(), Pscf::DeviceArray< Data >::capacity(), Pscf::DeviceArray< Data >::dissociate(), Pscf::DeviceArray< Data >::isAllocated(), max(), and UTIL_CHECK.

◆ min() [1/2]

cudaReal Pscf::Reduce::min ( DeviceArray< cudaReal > const & in)

Return minimum of all real array elements.

Parameters
inreal input array
Returns
value of minimum element

Definition at line 436 of file Reduce.cu.

References Pscf::DeviceArray< Data >::capacity(), Pscf::DeviceArray< Data >::cArray(), Pscf::DeviceArray< Data >::isAllocated(), min(), and UTIL_CHECK.

◆ min() [2/2]

cudaReal Pscf::Reduce::min ( DeviceArray< cudaReal > const & in,
int begin,
int end )

Return minimum of elements of a real array slice.

Parameters
inreal input array
beginindex of first element of slice
endindex one past last element
Returns
value of minimum element

Definition at line 449 of file Reduce.cu.

References Pscf::DeviceArray< Data >::capacity(), Pscf::DeviceArray< Data >::cArray(), Pscf::DeviceArray< Data >::isAllocated(), min(), and UTIL_CHECK.

◆ minAbs()

cudaReal Pscf::Reduce::minAbs ( DeviceArray< cudaReal > const & in)

Return minimum absolute magnitude of real array elements.

Parameters
inreal input array
Returns
magnitude of element of minimum magnitude

Definition at line 465 of file Reduce.cu.

References Pscf::VecOp::absV(), Pscf::DeviceArray< Data >::associate(), Pscf::DeviceArray< Data >::capacity(), Pscf::DeviceArray< Data >::dissociate(), Pscf::DeviceArray< Data >::isAllocated(), min(), and UTIL_CHECK.

◆ freeWorkSpace()

void Pscf::Reduce::freeWorkSpace ( )

Free any private work space currently allocated for reductions.

Definition at line 203 of file Reduce.cu.