Lift
Library of parallel computing primitives for GPUs and multi-core CPUs
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
strided_iterator.h
Go to the documentation of this file.
1 /*
2  * Lift
3  *
4  * Copyright (c) 2014-2015, NVIDIA CORPORATION
5  * Copyright (c) 2015, Nuno Subtil <subtil@gmail.com>
6  * Copyright (c) 2015, Roche Molecular Systems Inc.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  * * Neither the name of the copyright holders nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #pragma once
33 
34 namespace lift {
35 
36 template <typename T, uint32 stride, typename IndexType = uint64>
38 {
39  typedef T* iterator;
40  typedef const T* const_iterator;
41  typedef typename thrust::iterator_traits<iterator>::value_type value_type;
42  typedef typename thrust::iterator_traits<iterator>::reference reference;
43  typedef typename thrust::iterator_traits<const_iterator>::reference const_reference;
44  typedef typename thrust::iterator_traits<iterator>::pointer pointer;
45  typedef typename thrust::iterator_traits<const_iterator>::pointer const_pointer;
46  typedef typename thrust::reverse_iterator<iterator> reverse_iterator;
47  typedef typename thrust::reverse_iterator<const_iterator> const_reverse_iterator;
48  typedef typename thrust::iterator_traits<iterator>::difference_type difference_type;
49  typedef IndexType size_type;
50 
52  strided_iterator() = default;
53 
56  : m_vec(base)
57  { }
58 
60  {
61  return elem * stride;
62  }
63 
65  {
66  return m_vec[offset(n)];
67  }
68 
70  {
71  return m_vec[offset(n)];
72  }
73 
75  {
76  return m_vec[offset(n)];
77  }
78 
80  {
81  return m_vec[offset(n)];
82  }
83 
84  T *m_vec;
85 };
86 
87 } // namespace lift
LIFT_HOST_DEVICE strided_iterator()=default
LIFT_HOST_DEVICE const_reference operator[](size_type n) const
thrust::iterator_traits< iterator >::value_type value_type
thrust::reverse_iterator< iterator > reverse_iterator
thrust::iterator_traits< iterator >::reference reference
thrust::iterator_traits< const_iterator >::pointer const_pointer
LIFT_HOST_DEVICE reference operator[](size_type n)
thrust::iterator_traits< iterator >::pointer pointer
LIFT_HOST_DEVICE reference at(size_type n)
LIFT_HOST_DEVICE size_type offset(size_type elem) const
LIFT_HOST_DEVICE strided_iterator(T *base)
#define LIFT_HOST_DEVICE
Definition: local_memory.h:40
LIFT_HOST_DEVICE const_reference at(size_type n) const
thrust::reverse_iterator< const_iterator > const_reverse_iterator
thrust::iterator_traits< const_iterator >::reference const_reference
thrust::iterator_traits< iterator >::difference_type difference_type