CUB  
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Static Public Methods | List of all members
cub::DeviceAdjacentDifference Struct Reference

Detailed description

DeviceAdjacentDifference provides device-wide, parallel operations for computing the differences of adjacent elements residing within device-accessible memory.

Overview
  • DeviceAdjacentDifference calculates the differences of adjacent elements in d_input. Because the binary operation could be noncommutative, there are two sets of methods. Methods named SubtractLeft subtract left element *(i - 1) of input sequence from current element *i. Methods named SubtractRight subtract current element *i from the right one *(i + 1):
int *d_values; // [1, 2, 3, 4]
//...
int *d_subtract_left_result <-- [ 1, 1, 1, 1 ]
int *d_subtract_right_result <-- [ -1, -1, -1, 4 ]
  • For SubtractLeft, if the left element is out of bounds, the iterator is assigned to *(result + (i - first)) without modification.
  • For SubtractRight, if the right element is out of bounds, the iterator is assigned to *(result + (i - first)) without modification.
Snippet
The code snippet below illustrates how to use DeviceAdjacentDifference to compute the left difference between adjacent elements.
#include <cub/cub.cuh>
// or equivalently <cub/device/device_adjacent_difference.cuh>
// Declare, allocate, and initialize device-accessible pointers
int num_items; // e.g., 8
int *d_values; // e.g., [1, 2, 1, 2, 1, 2, 1, 2]
//...
// Determine temporary device storage requirements
void *d_temp_storage = NULL;
size_t temp_storage_bytes = 0;
d_temp_storage, temp_storage_bytes, d_values, num_items);
// Allocate temporary storage
cudaMalloc(&d_temp_storage, temp_storage_bytes);
// Run operation
d_temp_storage, temp_storage_bytes, d_values, num_items);
// d_values <-- [1, 1, -1, 1, -1, 1, -1, 1]

Static Public Methods

template<typename InputIteratorT , typename OutputIteratorT , typename DifferenceOpT = cub::Difference>
static CUB_RUNTIME_FUNCTION
cudaError_t 
SubtractLeftCopy (void *d_temp_storage, std::size_t &temp_storage_bytes, InputIteratorT d_input, OutputIteratorT d_output, std::size_t num_items, DifferenceOpT difference_op={}, cudaStream_t stream=0, bool debug_synchronous=false)
 Subtracts the left element of each adjacent pair of elements residing within device-accessible memory. More...
 
template<typename RandomAccessIteratorT , typename DifferenceOpT = cub::Difference>
static CUB_RUNTIME_FUNCTION
cudaError_t 
SubtractLeft (void *d_temp_storage, std::size_t &temp_storage_bytes, RandomAccessIteratorT d_input, std::size_t num_items, DifferenceOpT difference_op={}, cudaStream_t stream=0, bool debug_synchronous=false)
 Subtracts the left element of each adjacent pair of elements residing within device-accessible memory. More...
 
template<typename InputIteratorT , typename OutputIteratorT , typename DifferenceOpT = cub::Difference>
static CUB_RUNTIME_FUNCTION
cudaError_t 
SubtractRightCopy (void *d_temp_storage, std::size_t &temp_storage_bytes, InputIteratorT d_input, OutputIteratorT d_output, std::size_t num_items, DifferenceOpT difference_op={}, cudaStream_t stream=0, bool debug_synchronous=false)
 Subtracts the right element of each adjacent pair of elements residing within device-accessible memory. More...
 
template<typename RandomAccessIteratorT , typename DifferenceOpT = cub::Difference>
static CUB_RUNTIME_FUNCTION
cudaError_t 
SubtractRight (void *d_temp_storage, std::size_t &temp_storage_bytes, RandomAccessIteratorT d_input, std::size_t num_items, DifferenceOpT difference_op={}, cudaStream_t stream=0, bool debug_synchronous=false)
 Subtracts the right element of each adjacent pair of elements residing within device-accessible memory. More...
 

The documentation for this struct was generated from the following file: