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-2016, 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/dispatch_scan.cuh"
41 #include "../util_namespace.cuh"
42 
44 CUB_NS_PREFIX
45 
47 namespace cub {
48 
49 
77 struct DeviceScan
78 {
79  /******************************************************************/
83 
128  template <
129  typename InputIteratorT,
130  typename OutputIteratorT>
131  CUB_RUNTIME_FUNCTION
132  static cudaError_t ExclusiveSum(
133  void *d_temp_storage,
134  size_t &temp_storage_bytes,
135  InputIteratorT d_in,
136  OutputIteratorT d_out,
137  int num_items,
138  cudaStream_t stream = 0,
139  bool debug_synchronous = false)
140  {
141  // Signed integer type for global offsets
142  typedef int OffsetT;
143 
144  // Scan data type
145  typedef typename std::iterator_traits<InputIteratorT>::value_type T;
146 
147  return DispatchScan<InputIteratorT, OutputIteratorT, Sum, T, OffsetT>::Dispatch(
148  d_temp_storage,
149  temp_storage_bytes,
150  d_in,
151  d_out,
152  Sum(),
153  T(),
154  num_items,
155  stream,
156  debug_synchronous);
157  }
158 
159 
210  template <
211  typename InputIteratorT,
212  typename OutputIteratorT,
213  typename ScanOp,
214  typename Identity>
215  CUB_RUNTIME_FUNCTION
216  static cudaError_t ExclusiveScan(
217  void *d_temp_storage,
218  size_t &temp_storage_bytes,
219  InputIteratorT d_in,
220  OutputIteratorT d_out,
221  ScanOp scan_op,
222  Identity identity,
223  int num_items,
224  cudaStream_t stream = 0,
225  bool debug_synchronous = false)
226  {
227  // Signed integer type for global offsets
228  typedef int OffsetT;
229 
230  return DispatchScan<InputIteratorT, OutputIteratorT, ScanOp, Identity, OffsetT>::Dispatch(
231  d_temp_storage,
232  temp_storage_bytes,
233  d_in,
234  d_out,
235  scan_op,
236  identity,
237  num_items,
238  stream,
239  debug_synchronous);
240  }
241 
242 
244  /******************************************************************/
248 
249 
287  template <
288  typename InputIteratorT,
289  typename OutputIteratorT>
290  CUB_RUNTIME_FUNCTION
291  static cudaError_t InclusiveSum(
292  void* d_temp_storage,
293  size_t& temp_storage_bytes,
294  InputIteratorT d_in,
295  OutputIteratorT d_out,
296  int num_items,
297  cudaStream_t stream = 0,
298  bool debug_synchronous = false)
299  {
300  // Signed integer type for global offsets
301  typedef int OffsetT;
302 
303  return DispatchScan<InputIteratorT, OutputIteratorT, Sum, NullType, OffsetT>::Dispatch(
304  d_temp_storage,
305  temp_storage_bytes,
306  d_in,
307  d_out,
308  Sum(),
309  NullType(),
310  num_items,
311  stream,
312  debug_synchronous);
313  }
314 
315 
365  template <
366  typename InputIteratorT,
367  typename OutputIteratorT,
368  typename ScanOp>
369  CUB_RUNTIME_FUNCTION
370  static cudaError_t InclusiveScan(
371  void *d_temp_storage,
372  size_t &temp_storage_bytes,
373  InputIteratorT d_in,
374  OutputIteratorT d_out,
375  ScanOp scan_op,
376  int num_items,
377  cudaStream_t stream = 0,
378  bool debug_synchronous = false)
379  {
380  // Signed integer type for global offsets
381  typedef int OffsetT;
382 
383  return DispatchScan<InputIteratorT, OutputIteratorT, ScanOp, NullType, OffsetT>::Dispatch(
384  d_temp_storage,
385  temp_storage_bytes,
386  d_in,
387  d_out,
388  scan_op,
389  NullType(),
390  num_items,
391  stream,
392  debug_synchronous);
393  }
394 
396 
397 };
398 
403 } // CUB namespace
404 CUB_NS_POSTFIX // Optional outer namespace(s)
405 
406