CUB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups
device_scan.cuh
Go to the documentation of this file.
1 
2 /******************************************************************************
3  * Copyright (c) 2011, Duane Merrill. All rights reserved.
4  * Copyright (c) 2011-2014, NVIDIA CORPORATION. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the NVIDIA CORPORATION nor the
14  * names of its contributors may be used to endorse or promote products
15  * derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  ******************************************************************************/
29 
35 #pragma once
36 
37 #include <stdio.h>
38 #include <iterator>
39 
40 #include "dispatch/device_scan_dispatch.cuh"
41 #include "../util_namespace.cuh"
42 
44 CUB_NS_PREFIX
45 
47 namespace cub {
48 
49 
77 struct DeviceScan
78 {
79  /******************************************************************/
83 
129  template <
130  typename InputIterator,
131  typename OutputIterator>
132  CUB_RUNTIME_FUNCTION
133  static cudaError_t ExclusiveSum(
134  void *d_temp_storage,
135  size_t &temp_storage_bytes,
136  InputIterator d_in,
137  OutputIterator d_out,
138  int num_items,
139  cudaStream_t stream = 0,
140  bool debug_synchronous = false)
141  {
142  // Signed integer type for global offsets
143  typedef int Offset;
144 
145  // Scan data type
146  typedef typename std::iterator_traits<InputIterator>::value_type T;
147 
148  return DeviceScanDispatch<InputIterator, OutputIterator, Sum, T, Offset>::Dispatch(
149  d_temp_storage,
150  temp_storage_bytes,
151  d_in,
152  d_out,
153  Sum(),
154  T(),
155  num_items,
156  stream,
157  debug_synchronous);
158  }
159 
160 
215  template <
216  typename InputIterator,
217  typename OutputIterator,
218  typename ScanOp,
219  typename Identity>
220  CUB_RUNTIME_FUNCTION
221  static cudaError_t ExclusiveScan(
222  void *d_temp_storage,
223  size_t &temp_storage_bytes,
224  InputIterator d_in,
225  OutputIterator d_out,
226  ScanOp scan_op,
227  Identity identity,
228  int num_items,
229  cudaStream_t stream = 0,
230  bool debug_synchronous = false)
231  {
232  // Signed integer type for global offsets
233  typedef int Offset;
234 
235  return DeviceScanDispatch<InputIterator, OutputIterator, ScanOp, Identity, Offset>::Dispatch(
236  d_temp_storage,
237  temp_storage_bytes,
238  d_in,
239  d_out,
240  scan_op,
241  identity,
242  num_items,
243  stream,
244  debug_synchronous);
245  }
246 
247 
249  /******************************************************************/
253 
254 
296  template <
297  typename InputIterator,
298  typename OutputIterator>
299  CUB_RUNTIME_FUNCTION
300  static cudaError_t InclusiveSum(
301  void *d_temp_storage,
302  size_t &temp_storage_bytes,
303  InputIterator d_in,
304  OutputIterator d_out,
305  int num_items,
306  cudaStream_t stream = 0,
307  bool debug_synchronous = false)
308  {
309  // Signed integer type for global offsets
310  typedef int Offset;
311 
312  return DeviceScanDispatch<InputIterator, OutputIterator, Sum, NullType, Offset>::Dispatch(
313  d_temp_storage,
314  temp_storage_bytes,
315  d_in,
316  d_out,
317  Sum(),
318  NullType(),
319  num_items,
320  stream,
321  debug_synchronous);
322  }
323 
324 
378  template <
379  typename InputIterator,
380  typename OutputIterator,
381  typename ScanOp>
382  CUB_RUNTIME_FUNCTION
383  static cudaError_t InclusiveScan(
384  void *d_temp_storage,
385  size_t &temp_storage_bytes,
386  InputIterator d_in,
387  OutputIterator d_out,
388  ScanOp scan_op,
389  int num_items,
390  cudaStream_t stream = 0,
391  bool debug_synchronous = false)
392  {
393  // Signed integer type for global offsets
394  typedef int Offset;
395 
396  return DeviceScanDispatch<InputIterator, OutputIterator, ScanOp, NullType, Offset>::Dispatch(
397  d_temp_storage,
398  temp_storage_bytes,
399  d_in,
400  d_out,
401  scan_op,
402  NullType(),
403  num_items,
404  stream,
405  debug_synchronous);
406  }
407 
409 
410 };
411 
416 } // CUB namespace
417 CUB_NS_POSTFIX // Optional outer namespace(s)
418 
419