Extended CUDA Library (ecuda)  2.0
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros
vector.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 // vector.hpp
32 //
33 // An STL-like structure that resides in video memory.
34 //
35 // Author: Scott D. Zuyderduyn, Ph.D. (scott.zuyderduyn@utoronto.ca)
36 //----------------------------------------------------------------------------
37 
38 #pragma once
39 #ifndef ECUDA_VECTOR_HPP
40 #define ECUDA_VECTOR_HPP
41 
42 #include <cstddef>
43 #include <iterator>
44 #include <limits>
45 #include <vector>
46 
47 #ifdef ECUDA_CPP11_AVAILABLE
48 #include <initializer_list>
49 #include <memory>
50 #include <utility>
51 #endif
52 
53 #include "global.hpp"
54 #include "algorithm.hpp"
55 #include "allocators.hpp"
56 #include "memory.hpp"
57 #include "type_traits.hpp"
58 
60 
61 namespace ecuda {
62 
64 namespace impl {
65 
66 template<typename T,class Alloc> class vector_kernel_argument; // forward declaration
67 
68 } // namespace impl
70 
95 template< typename T, class Alloc=device_allocator<T>, class P=shared_ptr<T> >
96 class vector : private model::device_contiguous_sequence< T, P > {
97 
98 private:
99  typedef model::device_contiguous_sequence< T, P > base_type;
100 
101 public:
102  typedef typename base_type::value_type value_type;
103  typedef Alloc allocator_type;
104  typedef typename base_type::size_type size_type;
105  typedef typename base_type::difference_type difference_type;
106  #ifdef ECUDA_CPP11_AVAILABLE
107  typedef typename base_type::reference reference;
108  typedef typename base_type::const_reference const_reference;
109  typedef typename std::allocator_traits<Alloc>::pointer pointer;
110  typedef typename std::allocator_traits<Alloc>::const_pointer const_pointer;
111  #else
112  typedef typename Alloc::reference reference;
113  typedef typename Alloc::const_reference const_reference;
114  typedef typename Alloc::pointer pointer;
115  typedef typename Alloc::const_pointer const_pointer;
116  #endif
117 
118  typedef typename base_type::iterator iterator;
119  typedef typename base_type::const_iterator const_iterator;
120  typedef typename base_type::reverse_iterator reverse_iterator;
121  typedef typename base_type::const_reverse_iterator const_reverse_iterator;
122 
123  typedef impl::vector_kernel_argument<T,Alloc> kernel_argument;
124  typedef const impl::vector_kernel_argument<T,Alloc> const_kernel_argument;
125 
126 private:
127  size_type n;
128  allocator_type allocator;
129 
130  template<typename U,class Alloc2,class Q> friend class vector;
131 
132 protected:
136  template<class Q>
137  __HOST__ __DEVICE__ vector( const vector<T,Alloc,Q>& src, ecuda::true_type ) : base_type(unmanaged_cast(src.get_pointer())), n(src.n), allocator(src.allocator) {}
138 
142  template<class Q>
143  __HOST__ __DEVICE__ vector& shallow_assign( const vector<T,Alloc,Q>& other )
144  {
145  base_type::get_pointer() = unmanaged_cast(other.get_pointer());
146  n = other.n;
147  allocator = other.allocator;
148  return *this;
149  }
150 
151 
152 private:
153  __HOST__ void growMemory( size_type minimum );
154 
155  __HOST__ void init( size_type len, const value_type& value, ecuda::true_type )
156  {
157  growMemory( len );
158  n = len;
159  if( len ) ecuda::fill( begin(), end(), value );
160  }
161 
162  template<class Iterator>
163  __HOST__ inline void init( Iterator first, Iterator last, ecuda::false_type )
164  {
165  const size_type len = ::ecuda::distance(first,last);
166  growMemory( len );
167  ecuda::copy( first, last, begin() );
168  n = len;
169  }
170 
171 public:
176  __HOST__ explicit vector( const allocator_type& allocator = allocator_type() ) : base_type(), n(0), allocator(allocator) {}
177 
184  __HOST__ explicit vector( size_type n, const value_type& value, const allocator_type& allocator = allocator_type() ) : base_type( shared_ptr<T>( allocator.allocate(n) ), n ), n(n), allocator(allocator)
185  {
186  init( n, value, ecuda::true_type() );
187  }
188 
193  __HOST__ explicit vector( size_type n ) : base_type( shared_ptr<T>( Alloc().allocate(n) ) ), n(n)
194  {
195  init( n, value_type(), ecuda::true_type() );
196  }
197 
203  template<class Iterator>
204  __HOST__ vector( Iterator first, Iterator last, const allocator_type& allocator = allocator_type() ) : base_type(), n(0), allocator(allocator)
205  {
206  typedef typename ecuda::is_integral<Iterator>::type _Integral;
207  init( first, last, _Integral() );
208  }
209 
217  __HOST__ vector( const vector& src ) :
218  base_type(),
219  n(src.n),
220  allocator(src.get_allocator())
221  //std::allocator_traits<allocator_type>::select_on_container_copy_construction(src.get_allocator())
222  {
223  if( size() != src.size() ) resize( src.size() );
224  ecuda::copy( src.begin(), src.end(), begin() );
225  }
226 
228  {
229  if( size() != src.size() ) resize( src.size() );
230  allocator = src.allocator;
231  ecuda::copy( src.begin(), src.end(), begin() );
232  return *this;
233  }
234 
235  #ifdef ECUDA_CPP11_AVAILABLE
236  __HOST__ __DEVICE__ vector( vector&& src ) : base_type(src), n(std::move(src.n)), allocator(std::move(src.allocator)) {}
244 
250  __HOST__ __DEVICE__ vector( vector&& src, const allocator_type& allocator ) : base_type(src), n(std::move(src.n)), allocator(allocator) {}
251 
257  __HOST__ vector( std::initializer_list<value_type> il, const allocator_type& allocator = allocator_type() ) : base_type(shared_ptr<T>(allocator.allocate(il.size()))), n(il.size()), allocator(allocator)
258  {
259  ecuda::copy( il.begin(), il.end(), begin() );
260  }
261 
262  __HOST__ vector& operator=( vector&& src )
263  {
264  base_type::operator=(std::move(src));
265  n = std::move(src.n);
266  return *this;
267  }
268  #endif
269 
277  __HOST__ __DEVICE__ inline iterator begin() __NOEXCEPT__ { return base_type::begin(); }
278 
286  __HOST__ __DEVICE__ inline iterator end() __NOEXCEPT__ { return base_type::begin()+size(); }
287 
295  __HOST__ __DEVICE__ inline const_iterator begin() const __NOEXCEPT__ { return base_type::begin(); }
296 
304  __HOST__ __DEVICE__ inline const_iterator end() const __NOEXCEPT__ { return base_type::begin()+size(); }
305 
314 
324 
333 
343 
344  #ifdef ECUDA_CPP11_AVAILABLE
345  __HOST__ __DEVICE__ inline const_iterator cbegin() const __NOEXCEPT__ { return base_type::cbegin(); }
346  __HOST__ __DEVICE__ inline const_iterator cend() const __NOEXCEPT__ { return base_type::cbegin()+size(); }
347  __HOST__ __DEVICE__ inline const_reverse_iterator crbegin() __NOEXCEPT__ { return base_type::crbegin(); }
348  __HOST__ __DEVICE__ inline const_reverse_iterator crend() __NOEXCEPT__ { return base_type::crbegin()+size(); }
349  #endif
350 
356  __HOST__ __DEVICE__ inline size_type size() const __NOEXCEPT__ { return n; }
357 
365 
375  __HOST__ void resize( size_type newSize, const value_type& value = value_type() )
376  {
377  if( size() == newSize ) return;
378  if( size() > newSize ) { n = newSize; return; }
379  growMemory( newSize ); // make sure enough device memory is allocated
380  std::vector< value_type, host_allocator<value_type> > v( newSize-n, value );
381  ecuda::copy( v.begin(), v.end(), begin() );
382  n = newSize;
383  }
384 
389  __HOST__ __DEVICE__ inline size_type capacity() const __NOEXCEPT__ { return base_type::size(); }
390 
396  __HOST__ __DEVICE__ inline bool empty() const __NOEXCEPT__ { return !n; }
397 
409  __HOST__ inline void reserve( size_type newCapacity ) { growMemory(newCapacity); }
410 
421  {
422  if( !(index < size()) ) {
423  #ifndef __CUDACC__
424  throw std::out_of_range( EXCEPTION_MSG("ecuda::vector::at() index parameter is out of range") );
425  #else
426  // this strategy is taken from:
427  // http://stackoverflow.com/questions/12521721/crashing-a-kernel-gracefully
429  //__threadfence();
430  asm("trap;");
431  #endif
432  }
433  return base_type::operator[](index);
434  }
435 
445  __DEVICE__ inline const_reference at( size_type index ) const
446  {
447  if( !(index < size()) ) {
448  #ifndef __CUDACC__
449  throw std::out_of_range( EXCEPTION_MSG("ecuda::vector::at() index parameter is out of range") );
450  #else
451  // this strategy is taken from:
452  // http://stackoverflow.com/questions/12521721/crashing-a-kernel-gracefully
454  //__threadfence();
455  asm("trap;");
456  #endif
457  }
458  return base_type::operator[](index);
459  }
460 
467  __DEVICE__ inline reference operator[]( const size_type index ) { return base_type::operator[](index); }
468 
475  __DEVICE__ inline const_reference operator[]( const size_type index ) const { return base_type::operator[](index); }
476 
485  __DEVICE__ inline reference operator()( const size_type index ) { return base_type::operator[](index); }
486 
495  __DEVICE__ inline const_reference operator()( const size_type index ) const { return base_type::operator[](index); }
496 
504  __DEVICE__ inline reference front() { return operator[](0); }
505 
513  __DEVICE__ inline reference back() { return operator[]( size()-1 ); }
514 
522  __DEVICE__ inline const_reference front() const { return operator[](0); }
523 
531  __DEVICE__ inline const_reference back() const { return operator[]( size()-1 ); }
532 
541  __HOST__ __DEVICE__ inline pointer data() __NOEXCEPT__ { return base_type::get_pointer(); }
542 
551  __HOST__ __DEVICE__ inline const_pointer data() const __NOEXCEPT__ { return base_type::get_pointer(); }
552 
558  __HOST__ void assign( size_type newSize, const value_type& value = value_type() )
559  {
560  growMemory(newSize); // make sure enough device memory is allocated
561  ecuda::fill( begin(), end(), value );
562  n = newSize;
563  }
564 
569  template<class Iterator>
570  __HOST__ void assign( Iterator first, Iterator last )
571  {
572  typename std::iterator_traits<Iterator>::difference_type len = ::ecuda::distance(first,last);
573  growMemory( len ); // make sure enough device memory is allocated
574  ecuda::copy( first, last, begin() );
575  n = len;
576  }
577 
578  #ifdef ECUDA_CPP11_AVAILABLE
579  __HOST__ inline void assign( std::initializer_list<value_type> il )
587  {
588  assign( il.begin(), il.end() );
589  //host_array_proxy<const value_type> proxy( il.begin(), il.size() );
590  //assign( proxy.begin(), proxy.end() );
591  }
592  #endif
593 
598  __HOST__ void push_back( const value_type& value )
599  {
600  growMemory(n+1);
601  ecuda::copy( &value, (&value)+1, begin()+n );
602  ++n;
603  }
604 
614  __HOST__ __DEVICE__ inline void pop_back() { /*if( n )*/ --n; } // NOTE: if called from device the host instance doesn't change
615 
629  {
630  std::vector< value_type, host_allocator<value_type> > v( ::ecuda::distance(position,end())+1 ); // allocate staging memory
631  v.front() = value; // put new element at front of staging
632  ::ecuda::copy( position, end(), v.begin()+1 ); // copy trailing elements to staging
633  const size_type index = ::ecuda::distance(begin(),position); // get index of insert position
634  growMemory(size()+1); // make sure enough device memory is allocated
635  // reacquire iterator just in case new memory was allocated
636  const_iterator newPosition = begin()+index;
637  ::ecuda::copy( v.begin(), v.end(), newPosition );
638  ++n;
639  return newPosition;
640  }
641 
656  {
657  std::vector< value_type, host_allocator<value_type> > v( ::ecuda::distance(position,end())+count, value ); // allocate staging memory
658  ::ecuda::copy( position, end(), v.begin()+count ); // copy trailing elements to staging
659  const size_type index = ::ecuda::distance(begin(),position); // get index of insert position
660  growMemory(size()+count); // make sure enough device memory is allocated
661  // require iterator just in case new memory was allocated
662  const_iterator newPosition = begin()+index;
663  ::ecuda::copy( v.begin(), v.end(), newPosition );
664  n += count;
665  return newPosition;
666  }
667 
679  template<class InputIterator>
680  __HOST__ void insert( const_iterator position, InputIterator first, InputIterator last )
681  {
682  const std::vector< value_type, host_allocator<value_type> > v( first, last ); // allocate staging memory and put new content there
683  const size_type len = v.size(); // number of new elements
684  v.resize( v.size()+::ecuda::distance(position,end()) ); // make room for trailing elements
685  ::ecuda::copy( position, end(), v.begin()+len ); // copy trailing elements to staging
686  const size_type index = ::ecuda::distance(begin(),position); // get index of insert position
687  growMemory(size()+len); // make sure enough device memory is allocated
688  // require iterator just in case new memory was allocated
689  const_iterator newPosition = begin()+index;
690  ::ecuda::copy( v.begin(), v.end(), newPosition );
691  n += len;
692  }
693 
694  #ifdef ECUDA_CPP11_AVAILABLE
695  __HOST__ inline void insert( const_iterator position, std::initializer_list<value_type> il )
709  {
710  return insert( position, il.begin(), il.end() );
711  }
712  #endif
713 
727  {
728  vector<value_type> v( position+1, end() ); // copy trailing elements to another device vector
729  ecuda::copy( v.begin(), v.end(), position ); // overwrite erase position
730  --n;
731  return begin()+ecuda::distance(begin(),position);
732  }
733 
748  {
749  vector<value_type> v( last, end() ); // copy trailing elements to another device vector
750  ecuda::copy( v.begin(), v.end(), first ); // overwrite erased elements
751  n -= ecuda::distance(first,last);
752  return begin()+ecuda::distance(begin(),first);
753  }
754 
766  __HOST__ __DEVICE__ void swap( vector& other )
767  {
768  base_type::swap( other );
769  ecuda::swap( n, other.n );
770  }
771 
781  __HOST__ __DEVICE__ inline void clear() { n = 0; }
782 
787  __HOST__ inline allocator_type get_allocator() const { return allocator; }
788 
798  {
799  if( size() == capacity() ) return;
800  vector v( n );
801  ecuda::copy( begin(), end(), v.begin() );
802  swap( v );
803  }
804 
814  __HOST__ __DEVICE__ bool operator==( const vector& other ) const
815  {
816  if( size() != other.size() ) return false;
817  #ifdef __CUDA_ARCH__
818  const_iterator iter1 = begin();
819  const_iterator iter2 = other.begin();
820  for( ; iter1 != end(); ++iter1, ++iter2 ) if( !( *iter1 == *iter2 ) ) return false;
821  return true;
822  #else
823  return ecuda::equal( begin(), end(), other.begin(), other.end() );
824  #endif
825  }
826 
836  __HOST__ __DEVICE__ inline bool operator!=( const vector& other ) const { return !operator==(other); }
837 
844  __HOST__ __DEVICE__ inline bool operator<( const vector& other ) const
845  {
846  #ifdef __CUDA_ARCH__
847  return ecuda::lexicographical_compare( begin(), end(), other.begin(), other.end() );
848  #else
849  std::vector< value_type, host_allocator<value_type> > v1( size() ), v2( size() );
850  ecuda::copy( begin(), end(), v1.begin() );
851  ecuda::copy( other.begin(), other.end(), v2.begin() );
852  return std::lexicographical_compare( v1.begin(), v1.end(), v2.begin(), v2.end() );
853  #endif
854  }
855 
862  __HOST__ __DEVICE__ inline bool operator>( const vector& other ) const
863  {
864  #ifdef __CUDA_ARCH__
865  return ecuda::lexicographical_compare( other.begin(), other.end(), begin(), end() );
866  #else
867  std::vector< value_type, host_allocator<value_type> > v1( size() ), v2( size() );
868  ecuda::copy( begin(), end(), v1.begin() );
869  ecuda::copy( other.begin(), other.end(), v2.begin() );
870  return std::lexicographical_compare( v2.begin(), v2.end(), v1.begin(), v1.end() );
871  #endif
872  }
873 
880  __HOST__ __DEVICE__ inline bool operator<=( const vector& other ) const { return !operator>(other); }
881 
888  __HOST__ __DEVICE__ inline bool operator>=( const vector& other ) const { return !operator<(other); }
889 
890 };
891 
892 template<typename T,class Alloc,class P>
893 __HOST__ void vector<T,Alloc,P>::growMemory( size_type minimum )
894 {
895  if( base_type::size() >= minimum ) return; // no growth neccessary
896  size_type m2 = base_type::size();
897  if( !m2 ) m2 = 1; // in case no memory is currently allocated
898  while( m2 < minimum ) m2 <<= 1;
899  // allocate larger chunk
900  shared_ptr<value_type> newMemory( get_allocator().allocate( m2 ) );
901  model::device_contiguous_sequence< value_type, shared_ptr<value_type> > newSequence( newMemory, m2 );
902  ecuda::copy( begin(), end(), newSequence.begin() );
903  base_type::swap( newSequence );
904 }
905 
907 namespace impl {
908 
918 template<typename T,class Alloc>
919 class vector_kernel_argument : public vector<T,Alloc,typename ecuda::add_pointer<T>::type>
920 {
921 
922 private:
923  typedef vector<T,Alloc,typename ecuda::add_pointer<T>::type> base_type;
924 
925 public:
926  template<class P>
927  __HOST__ vector_kernel_argument( const vector<T,Alloc,P>& src ) : base_type( src, ecuda::true_type() ) {}
928  __HOST__ __DEVICE__ vector_kernel_argument( const vector_kernel_argument& src ) : base_type( src, ecuda::true_type() ) {}
929  template<class P>
930  __HOST__ vector_kernel_argument& operator=( const vector<T,Alloc,P>& src )
931  {
932  vector<T,Alloc>::shallow_assign( src );
933  return *this;
934  }
935 
936  #ifdef ECUDA_CPP11_AVAILABLE
937  vector_kernel_argument( vector_kernel_argument&& src ) : base_type(std::move(src)) {}
938 
939  vector_kernel_argument& operator=( vector_kernel_argument&& src )
940  {
941  base_type::operator=(std::move(src));
942  return *this;
943  }
944  #endif
945 
946 };
947 
948 } // namespace impl
950 
951 } // namespace ecuda
952 
953 #endif
A smart pointer that retains shared ownership of an object in device memory.
Definition: shared_ptr.hpp:122
__HOST__ __DEVICE__ OutputIterator copy(InputIterator first, InputIterator last, OutputIterator result)
Replacement for std::copy.
Definition: copy.hpp:801
__DEVICE__ const_reference operator()(const size_type index) const
Returns a reference to the element at specified location index. No bounds checking is performed...
Definition: vector.hpp:495
__HOST__ void shrink_to_fit()
Requests the removal of unused capacity.
Definition: vector.hpp:797
__HOST__ void insert(const_iterator position, InputIterator first, InputIterator last)
Inserts elements from range [first,last) before position.
Definition: vector.hpp:680
__HOST__ __DEVICE__ const_pointer data() const __NOEXCEPT__
Returns pointer to the underlying array serving as element storage.
Definition: vector.hpp:551
__HOST__ __DEVICE__ const_reverse_iterator rend() const __NOEXCEPT__
Returns a reverse iterator to the element following the last element of the reversed container...
Definition: vector.hpp:342
__DEVICE__ const_reference at(size_type index) const
Returns a reference to the element at specified location index, with bounds checking.
Definition: vector.hpp:445
__DEVICE__ const_reference front() const
Returns a reference to the first element in the container.
Definition: vector.hpp:522
friend class vector
Definition: vector.hpp:130
__HOST__ allocator_type get_allocator() const
Returns the allocator associated with the container.
Definition: vector.hpp:787
__HOST__ __DEVICE__ iterator end() __NOEXCEPT__
Returns an iterator to the element following the last element of the container.
Definition: vector.hpp:286
#define __CONSTEXPR__
Definition: global.hpp:141
__HOST__ __DEVICE__ void swap(vector &other)
Exchanges the contents of the container with those of the other.
Definition: vector.hpp:766
__HOST__ __DEVICE__ const_iterator end() const __NOEXCEPT__
Returns an iterator to the element following the last element of the container.
Definition: vector.hpp:304
Alloc allocator_type
allocator type
Definition: vector.hpp:103
const impl::vector_kernel_argument< T, Alloc > const_kernel_argument
const kernel argument type
Definition: vector.hpp:124
base_type::size_type size_type
unsigned integral type
Definition: vector.hpp:104
__HOST__ iterator erase(const_iterator first, const_iterator last)
Removes the elements in the range [first,last).
Definition: vector.hpp:747
__DEVICE__ reference front()
Returns a reference to the first element in the container.
Definition: vector.hpp:504
__HOST__ __DEVICE__ bool operator>(const vector &other) const
Compares the contents of two vectors lexicographically.
Definition: vector.hpp:862
base_type::difference_type difference_type
signed integral type
Definition: vector.hpp:105
#define __NOEXCEPT__
Definition: global.hpp:140
__HOST__ __DEVICE__ bool empty() const __NOEXCEPT__
Checks if the container has no elements.
Definition: vector.hpp:396
__HOST__ __DEVICE__ bool operator!=(const vector &other) const
Checks if the contents of two arrays are not equal.
Definition: vector.hpp:836
__HOST__ __DEVICE__ reverse_iterator rend() __NOEXCEPT__
Returns a reverse iterator to the element following the last element of the reversed container...
Definition: vector.hpp:323
__HOST__ vector(Iterator first, Iterator last, const allocator_type &allocator=allocator_type())
Constructs the container with the contents of the range [begin,end).
Definition: vector.hpp:204
#define __HOST__
Definition: global.hpp:150
__HOST__ void reserve(size_type newCapacity)
Increase the capacity of the container to a value that's greater or equal to newCapacity.
Definition: vector.hpp:409
__HOST__ vector & operator=(const vector &src)
Definition: vector.hpp:227
__HOST__ __DEVICE__ bool operator<(const vector &other) const
Compares the contents of two vectors lexicographically.
Definition: vector.hpp:844
__DEVICE__ reference operator[](const size_type index)
Returns a reference to the element at specified location index. No bounds checking is performed...
Definition: vector.hpp:467
__HOST__ __DEVICE__ void swap(T &a, T &b) __NOEXCEPT__
Definition: algorithm.hpp:54
__HOST__ void assign(Iterator first, Iterator last)
Replaces the contents of the container with copies of those in the range [first,last).
Definition: vector.hpp:570
impl::vector_kernel_argument< T, Alloc > kernel_argument
kernel argument type
Definition: vector.hpp:123
__HOST__ __DEVICE__ bool operator<=(const vector &other) const
Compares the contents of two vectors lexicographically.
Definition: vector.hpp:880
Alloc::pointer pointer
cell pointer type
Definition: vector.hpp:114
__DEVICE__ reference operator()(const size_type index)
Returns a reference to the element at specified location index. No bounds checking is performed...
Definition: vector.hpp:485
Alloc::const_reference const_reference
cell const reference type
Definition: vector.hpp:113
__HOST__ __DEVICE__ const_iterator begin() const __NOEXCEPT__
Returns an iterator to the first element of the container.
Definition: vector.hpp:295
__HOST__ __DEVICE__ void pop_back()
Removes the last element of the container.
Definition: vector.hpp:614
__HOST__ __DEVICE__ size_type size() const __NOEXCEPT__
Returns the number of elements in the container.
Definition: vector.hpp:356
__HOST__ __DEVICE__ __CONSTEXPR__ size_type max_size() const __NOEXCEPT__
Returns the maximum number of elements the container is able to hold due to system or library impleme...
Definition: vector.hpp:364
base_type::const_iterator const_iterator
const iterator type
Definition: vector.hpp:119
__HOST__ void push_back(const value_type &value)
Appends the given element value to the end of the container.
Definition: vector.hpp:598
__HOST__ __DEVICE__ pointer data() __NOEXCEPT__
Returns pointer to the underlying array serving as element storage.
Definition: vector.hpp:541
__HOST__ void resize(size_type newSize, const value_type &value=value_type())
Resizes the container to contain newSize elements.
Definition: vector.hpp:375
base_type::reverse_iterator reverse_iterator
reverse iterator type
Definition: vector.hpp:120
__DEVICE__ reference at(size_type index)
Returns a reference to the element at specified location index, with bounds checking.
Definition: vector.hpp:420
__HOST__ void assign(size_type newSize, const value_type &value=value_type())
Replaces the contents of the container.
Definition: vector.hpp:558
__DEVICE__ const_reference back() const
Returns a reference to the last element in the container.
Definition: vector.hpp:531
__HOST__ __DEVICE__ const_reverse_iterator rbegin() const __NOEXCEPT__
Returns a reverse iterator to the first element of the reversed container.
Definition: vector.hpp:332
base_type::const_reverse_iterator const_reverse_iterator
const reverse iterator type
Definition: vector.hpp:121
A resizable vector stored in device memory.
Definition: vector.hpp:96
__HOST__ __DEVICE__ bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2)
Replacement for std::equal.
Definition: equal.hpp:173
__HOST__ vector(size_type n, const value_type &value, const allocator_type &allocator=allocator_type())
Constructs the container with n copies of elements with value value.
Definition: vector.hpp:184
__HOST__ iterator insert(const_iterator position, const size_type count, const value_type &value)
Inserts count copies of the value before position.
Definition: vector.hpp:655
Alloc::const_pointer const_pointer
cell const pointer type
Definition: vector.hpp:115
__DEVICE__ void threadfence()
__HOST__ __DEVICE__ const T & max(const T &a, const T &b)
Definition: algorithm.hpp:51
#define EXCEPTION_MSG(x)
Definition: global.hpp:92
#define __DEVICE__
Definition: global.hpp:151
__HOST__ __DEVICE__ bool lexicographical_compare(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2)
__HOST__ __DEVICE__ iterator begin() __NOEXCEPT__
Returns an iterator to the first element of the container.
Definition: vector.hpp:277
__HOST__ vector(const vector &src)
Copy constructor.
Definition: vector.hpp:217
__DEVICE__ reference back()
Returns a reference to the last element in the container.
Definition: vector.hpp:513
base_type::value_type value_type
cell data type
Definition: vector.hpp:102
__HOST__ vector(size_type n)
Constructs the container with n default-inserted instances of T. No copies are made.
Definition: vector.hpp:193
__HOST__ iterator insert(const_iterator position, const value_type &value)
Inserts value before position.
Definition: vector.hpp:628
__HOST__ __DEVICE__ void clear()
Removes all elements from the container.
Definition: vector.hpp:781
__HOST__ __DEVICE__ bool operator>=(const vector &other) const
Compares the contents of two vectors lexicographically.
Definition: vector.hpp:888
ECUDA_SUPPRESS_HD_WARNINGS __HOST__ __DEVICE__ ecuda::iterator_traits< InputIterator >::difference_type count(InputIterator first, InputIterator last, const T &value)
Definition: count.hpp:92
__DEVICE__ const_reference operator[](const size_type index) const
Returns a reference to the element at specified location index. No bounds checking is performed...
Definition: vector.hpp:475
__HOST__ __DEVICE__ bool operator==(const vector &other) const
Checks if the contents of two vectors are equal.
Definition: vector.hpp:814
Alloc::reference reference
cell reference type
Definition: vector.hpp:112
base_type::iterator iterator
iterator type
Definition: vector.hpp:118
__HOST__ __DEVICE__ reverse_iterator rbegin() __NOEXCEPT__
Returns a reverse iterator to the first element of the reversed container.
Definition: vector.hpp:313
__HOST__ iterator erase(const_iterator position)
Removes the element at position.
Definition: vector.hpp:726
ECUDA_SUPPRESS_HD_WARNINGS __HOST__ __DEVICE__ std::iterator_traits< Iterator >::difference_type distance(const Iterator &first, const Iterator &last)
Definition: iterator.hpp:627
__HOST__ vector(const allocator_type &allocator=allocator_type())
Default constructor. Constructs empty container.
Definition: vector.hpp:176
__HOST__ __DEVICE__ size_type capacity() const __NOEXCEPT__
Returns the number of elements that the container has currently allocated space for.
Definition: vector.hpp:389
__HOST__ __DEVICE__ void fill(ForwardIterator first, ForwardIterator last, const T &val)
Definition: fill.hpp:156