Extended CUDA Library (ecuda)  2.0
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros
device_contiguous_sequence.hpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2014-2016, Scott Zuyderduyn
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7 
8 1. Redistributions of source code must retain the above copyright notice, this
9  list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright notice,
11  this list of conditions and the following disclaimer in the documentation
12  and/or other materials provided with the distribution.
13 
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 
25 The views and conclusions contained in the software and documentation are those
26 of the authors and should not be interpreted as representing official policies,
27 either expressed or implied, of the FreeBSD Project.
28 */
29 
30 //----------------------------------------------------------------------------
31 // model/device_contiguous_sequence.hpp
32 //
33 // Lowest-level representation of a contiguous sequence in device memory.
34 //
35 // Author: Scott D. Zuyderduyn, Ph.D. (scott.zuyderduyn@utoronto.ca)
36 //----------------------------------------------------------------------------
37 
38 #pragma once
39 #ifndef ECUDA_MODEL_DEVICE_CONTIGUOUS_SEQUENCE_HPP
40 #define ECUDA_MODEL_DEVICE_CONTIGUOUS_SEQUENCE_HPP
41 
42 #include "../global.hpp"
43 #include "../memory.hpp"
44 #include "../iterator.hpp"
45 
46 #include "device_sequence.hpp"
47 
48 namespace ecuda {
49 
51 namespace model {
52 
60 template<typename T,class P=typename ecuda::add_pointer<T>::type>
61 class device_contiguous_sequence : public device_sequence<T,P>
62 {
63 private:
64  typedef device_sequence<T,P> base_type;
65 
66 public:
67  typedef typename base_type::value_type value_type;
68  typedef typename base_type::pointer pointer;
69  typedef typename base_type::reference reference;
70  typedef typename base_type::const_reference const_reference;
71  typedef typename base_type::size_type size_type;
72  typedef typename base_type::difference_type difference_type;
73 
74  typedef device_contiguous_iterator<value_type> iterator;
75  typedef device_contiguous_iterator<const value_type> const_iterator;
76  typedef reverse_device_iterator<iterator> reverse_iterator;
77  typedef reverse_device_iterator<const_iterator> const_reverse_iterator;
78 
79 public:
80  __HOST__ __DEVICE__ device_contiguous_sequence( pointer ptr = pointer(), size_type length = 0 ) : base_type(ptr,length) {}
81  __HOST__ __DEVICE__ device_contiguous_sequence( const device_contiguous_sequence& src ) : base_type(src) {}
82  template<typename U,class PointerType2> __HOST__ __DEVICE__ device_contiguous_sequence( const device_contiguous_sequence<U,PointerType2>& src ) : base_type(src) {}
83  __HOST__ device_contiguous_sequence& operator=( const device_contiguous_sequence& src )
84  {
85  base_type::operator=(src);
86  return *this;
87  }
88  #ifdef ECUDA_CPP11_AVAILABLE
89  __HOST__ device_contiguous_sequence( device_contiguous_sequence&& src ) : base_type(src) {}
90  __HOST__ device_contiguous_sequence& operator=( device_contiguous_sequence&& src )
91  {
92  base_type::operator=(src);
93  return *this;
94  }
95  #endif
96 
97  __HOST__ __DEVICE__ inline iterator begin() { return iterator( unmanaged_cast(base_type::get_pointer()) ); }
98  __HOST__ __DEVICE__ inline iterator end() { return iterator( unmanaged_cast(base_type::get_pointer()) + base_type::size() ); }
99  __HOST__ __DEVICE__ inline const_iterator begin() const { return const_iterator( unmanaged_cast(base_type::get_pointer()) ); }
100  __HOST__ __DEVICE__ inline const_iterator end() const { return const_iterator( unmanaged_cast(base_type::get_pointer()) + base_type::size() ); }
101  #ifdef ECUDA_CPP11_AVAILABLE
102  __HOST__ __DEVICE__ inline const_iterator cbegin() const { return const_iterator( unmanaged_cast(base_type::get_pointer()) ); }
103  __HOST__ __DEVICE__ inline const_iterator cend() const { return const_iterator( unmanaged_cast(base_type::get_pointer()) + base_type::size() ); }
104  #endif
105 
106  __HOST__ __DEVICE__ inline reverse_iterator rbegin() { return reverse_iterator(end()); }
107  __HOST__ __DEVICE__ inline reverse_iterator rend() { return reverse_iterator(begin()); }
108  __HOST__ __DEVICE__ inline const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
109  __HOST__ __DEVICE__ inline const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
110  #ifdef ECUDA_CPP11_AVAILABLE
111  __HOST__ __DEVICE__ inline const_reverse_iterator crbegin() const { return const_reverse_iterator(end()); }
112  __HOST__ __DEVICE__ inline const_reverse_iterator crend() const { return const_reverse_iterator(begin()); }
113  #endif
114 
115 };
116 
117 } // namespace model
119 
120 } // namespace ecuda
121 
122 #endif
#define __HOST__
Definition: global.hpp:150
#define __DEVICE__
Definition: global.hpp:151