/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipcub/checkouts/docs-5.7.0/hipcub/include/hipcub/backend/rocprim/iterator/discard_output_iterator.hpp Source File

/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipcub/checkouts/docs-5.7.0/hipcub/include/hipcub/backend/rocprim/iterator/discard_output_iterator.hpp Source File#

hipCUB: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipcub/checkouts/docs-5.7.0/hipcub/include/hipcub/backend/rocprim/iterator/discard_output_iterator.hpp Source File
discard_output_iterator.hpp
1 /******************************************************************************
2  * Copyright (c) 2010-2011, Duane Merrill. All rights reserved.
3  * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved.
4  * Modifications Copyright (c) 2020, Advanced Micro Devices, Inc. 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 
30 #ifndef HIPCUB_ROCPRIM_ITERATOR_DISCARD_OUTPUT_ITERATOR_HPP_
31 #define HIPCUB_ROCPRIM_ITERATOR_DISCARD_OUTPUT_ITERATOR_HPP_
32 
33 #include <iterator>
34 #include <iostream>
35 
36 #include "../../../config.hpp"
37 
38 BEGIN_HIPCUB_NAMESPACE
39 #if (THRUST_VERSION >= 100700)
40  // This iterator is compatible with Thrust API 1.7 and newer
41  #include <thrust/iterator/iterator_facade.h>
42  #include <thrust/iterator/iterator_traits.h>
43 #endif // THRUST_VERSION
44 
54 template <typename OffsetT = ptrdiff_t>
56 {
57 public:
58 
59  // Required iterator traits
61  typedef OffsetT difference_type;
62  typedef void value_type;
63  typedef void pointer;
64  typedef void reference;
65 
66 #if (THRUST_VERSION >= 100700)
67  // Use Thrust's iterator categories so we can use these iterators in Thrust 1.7 (or newer) methods
68  typedef typename thrust::detail::iterator_facade_category<
69  thrust::any_system_tag,
70  thrust::random_access_traversal_tag,
71  value_type,
72  reference
73  >::type iterator_category;
74 #else
75  typedef std::random_access_iterator_tag iterator_category;
76 #endif // THRUST_VERSION
77 
78 private:
79 
80  OffsetT offset;
81 
82 public:
83 
85  __host__ __device__ __forceinline__ DiscardOutputIterator(
86  OffsetT offset = 0)
87  :
88  offset(offset)
89  {}
90 
95  __host__ __device__ __forceinline__ self_type operator++(int)
96  {
97  self_type retval = *this;
98  offset++;
99  return retval;
100  }
101 
106  __host__ __device__ __forceinline__ self_type operator++()
107  {
108  offset++;
109  return *this;
110  }
111 
116  __host__ __device__ __forceinline__ self_type& operator*()
117  {
118  // return self reference, which can be assigned to anything
119  return *this;
120  }
121 
126  template <typename Distance>
127  __host__ __device__ __forceinline__ self_type operator+(Distance n) const
128  {
129  self_type retval(offset + n);
130  return retval;
131  }
132 
137  template <typename Distance>
138  __host__ __device__ __forceinline__ self_type& operator+=(Distance n)
139  {
140  offset += n;
141  return *this;
142  }
143 
148  template <typename Distance>
149  __host__ __device__ __forceinline__ self_type operator-(Distance n) const
150  {
151  self_type retval(offset - n);
152  return retval;
153  }
154 
159  template <typename Distance>
160  __host__ __device__ __forceinline__ self_type& operator-=(Distance n)
161  {
162  offset -= n;
163  return *this;
164  }
165 
170  __host__ __device__ __forceinline__ difference_type operator-(self_type other) const
171  {
172  return offset - other.offset;
173  }
174 
179  template <typename Distance>
180  __host__ __device__ __forceinline__ self_type& operator[](Distance)
181  {
182  // return self reference, which can be assigned to anything
183  return *this;
184  }
185 
187  __host__ __device__ __forceinline__ pointer operator->()
188  {
189  return;
190  }
191 
193  template<typename T>
194  __host__ __device__ __forceinline__ void operator=(T const&)
195  {}
196 
198  __host__ __device__ __forceinline__ operator void*() const { return NULL; }
199 
204  __host__ __device__ __forceinline__ bool operator==(const self_type& rhs)
205  {
206  return (offset == rhs.offset);
207  }
208 
213  __host__ __device__ __forceinline__ bool operator!=(const self_type& rhs)
214  {
215  return (offset != rhs.offset);
216  }
217 
222  friend std::ostream& operator<<(std::ostream& os, const self_type& itr)
223  {
224  os << "[" << itr.offset << "]";
225  return os;
226  }
227 };
228 
229 END_HIPCUB_NAMESPACE
230 
231 #endif // HIPCUB_ROCPRIM_ITERATOR_DISCARD_OUTPUT_ITERATOR_HPP_
A discard iterator.
Definition: discard_output_iterator.hpp:56
void reference
The type of a reference to an element the iterator can point to.
Definition: discard_output_iterator.hpp:64
__host__ __device__ __forceinline__ pointer operator->()
Structure dereference.
Definition: discard_output_iterator.hpp:187
void value_type
The type of the element the iterator can point to.
Definition: discard_output_iterator.hpp:62
std::random_access_iterator_tag iterator_category
The iterator category.
Definition: discard_output_iterator.hpp:75
void pointer
The type of a pointer to an element the iterator can point to.
Definition: discard_output_iterator.hpp:63
DiscardOutputIterator self_type
My own type.
Definition: discard_output_iterator.hpp:60
__host__ __device__ __forceinline__ void operator=(T const &)
Assignment to anything else (no-op)
Definition: discard_output_iterator.hpp:194
OffsetT difference_type
Type to express the result of subtracting one iterator from another.
Definition: discard_output_iterator.hpp:61
__host__ __device__ __forceinline__ DiscardOutputIterator(OffsetT offset=0)
Constructor.
Definition: discard_output_iterator.hpp:85