Extended CUDA Library (ecuda)  2.0
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros
matrix.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 // matrix.hpp
32 // An STL-like structure that resides in video memory.
33 //
34 // Author: Scott D. Zuyderduyn, Ph.D. (scott.zuyderduyn@utoronto.ca)
35 //----------------------------------------------------------------------------
36 
37 #pragma once
38 #ifndef ECUDA_MATRIX_HPP
39 #define ECUDA_MATRIX_HPP
40 
41 #include <vector>
42 
43 #include "global.hpp"
44 #include "algorithm.hpp"
45 #include "allocators.hpp"
46 #include "apiwrappers.hpp"
47 #include "memory.hpp"
48 #include "type_traits.hpp"
49 
51 
52 namespace ecuda {
53 
55 namespace impl {
56 
57 template<typename T,class Alloc> class matrix_kernel_argument; // forward declaration
58 
59 } // namespace impl
61 
125 template< typename T, class Alloc=device_pitch_allocator<T>, class P=shared_ptr<T> >
126 class matrix : private model::device_contiguous_row_matrix< T, /*padded_ptr< T,*/P/* >*/ >
127 {
128 
129 private:
130  typedef model::device_contiguous_row_matrix< T, /*padded_ptr< T,*/P/* >*/ > base_type;
131 
132 public:
133  typedef typename base_type::value_type value_type;
134  typedef Alloc allocator_type;
135  typedef typename base_type::size_type size_type;
136  typedef typename base_type::difference_type difference_type;
137  typedef typename base_type::reference reference;
138  typedef typename base_type::const_reference const_reference;
139  typedef typename base_type::pointer pointer;
140  typedef typename make_const<pointer>::type const_pointer;
141 
142  typedef typename base_type::row_type row_type;
143  typedef typename base_type::column_type column_type;
144  typedef typename base_type::const_row_type const_row_type;
145  typedef typename base_type::const_column_type const_column_type;
146 
147  typedef typename base_type::iterator iterator;
148  typedef typename base_type::const_iterator const_iterator;
149  typedef typename base_type::reverse_iterator reverse_iterator;
150  typedef typename base_type::const_reverse_iterator const_reverse_iterator;
151 
152  typedef impl::matrix_kernel_argument<T,Alloc> kernel_argument;
153  typedef const impl::matrix_kernel_argument<T,Alloc> const_kernel_argument;
154 
155 private:
156  allocator_type allocator;
157  //template<typename U,class Alloc2> class device_matrix;
158  template<typename U,class Alloc2,class Q> friend class matrix;
159 
160 protected:
161 
165  template<typename U>
166  __HOST__ __DEVICE__ matrix( const matrix<T,Alloc,U>& src, ecuda::true_type ) : base_type( unmanaged_cast(src.get_pointer()), src.number_rows(), src.number_columns() ), allocator(src.allocator) {}
167 
171  template<typename U>
172  __HOST__ __DEVICE__ matrix& shallow_assign( const matrix<T,Alloc,U>& other )
173  {
174  base_type::get_pointer() = unmanaged_cast(other.get_pointer());
175  allocator = other.allocator;
176  return *this;
177  }
178 
179 private:
180  __HOST__ void init()
181  {
182  if( number_rows() && number_columns() ) {
183  // TODO: this is unfortunate - have to get a padded_ptr from the allocator, unwrap it and
184  // give it to shared_ptr, and then rewrap it in a padded_ptr with the same attributes
185  // as the original - the device_contiguous_row_matrix second template parameter which
186  // enforces a padded_ptr of some type is the reason
187  typename Alloc::pointer p = get_allocator().allocate( number_columns(), number_rows() );
188  shared_ptr<value_type> sp( naked_cast<typename ecuda::add_pointer<value_type>::type>(p) );
189  padded_ptr< value_type, shared_ptr<value_type> > pp( sp, p.get_pitch() ); //, p.get_width(), sp );
190  base_type base( pp, number_rows(), number_columns() );
191  base_type::swap( base );
192  }
193  }
194 
195 public:
204  __HOST__ matrix( const size_type numberRows=0, const size_type numberColumns=0, const value_type& value = value_type(), const allocator_type& allocator = allocator_type() ) :
205  base_type( pointer(), numberRows, numberColumns ),
206  allocator(allocator)
207  {
208  init();
209  if( size() ) ecuda::fill( begin(), end(), value );
210  }
211 
219  __HOST__ matrix( const matrix& src ) :
220  base_type( pointer(), src.number_rows(), src.number_columns() ),
221  allocator(src.get_allocator())
222 // TODO: this is broken due to some complaints from stdlib about making an iterator to a void pointer
223 // allocator(std::allocator_traits<allocator_type>::select_on_container_copy_construction(src.get_allocator()))
224  {
225  init();
226  if( size() ) ecuda::copy( src.begin(), src.end(), begin() );
227  }
228 
237  __HOST__ matrix( const matrix& src, const allocator_type& alloc ) :
238  base_type( pointer(), src.number_rows(), src.number_columns() ),
239  allocator(alloc)
240  {
241  init();
242  if( size() ) ecuda::copy( src.begin(), src.end(), begin() );
243  }
244 
245  __HOST__ matrix& operator=( const matrix& other )
246  {
247  allocator = other.allocator;
248  if( number_rows() != other.number_rows() || number_columns() != other.number_columns() )
249  resize( other.number_rows(), other.number_columns() );
250  if( size() ) ecuda::copy( other.begin(), other.end(), begin() );
251  return *this;
252  }
253 
254  #ifdef ECUDA_CPP11_AVAILABLE
255  __HOST__ matrix( matrix&& src ) : base_type() { swap(src); }
263 
264  __HOST__ matrix& operator=( matrix&& src )
265  {
266  swap(src);
267  return *this;
268  }
269  #endif
270 
278  __HOST__ __DEVICE__ inline iterator begin() __NOEXCEPT__ { return base_type::begin(); }
279 
287  __HOST__ __DEVICE__ inline iterator end() __NOEXCEPT__ { return base_type::end(); }
288 
296  __HOST__ __DEVICE__ inline const_iterator begin() const __NOEXCEPT__ { return base_type::begin(); }
297 
305  __HOST__ __DEVICE__ inline const_iterator end() const __NOEXCEPT__ { return base_type::end(); }
306 
314  __HOST__ __DEVICE__ inline reverse_iterator rbegin() __NOEXCEPT__ { return base_type::rbegin(); }
315 
324  __HOST__ __DEVICE__ inline reverse_iterator rend() __NOEXCEPT__ { return base_type::rend(); }
325 
333  __HOST__ __DEVICE__ inline const_reverse_iterator rbegin() const __NOEXCEPT__ { return base_type::rbegin(); }
334 
343  __HOST__ __DEVICE__ inline const_reverse_iterator rend() const __NOEXCEPT__ { return base_type::rend(); }
344 
345  #ifdef ECUDA_CPP11_AVAILABLE
346  __HOST__ __DEVICE__ inline const_iterator cbegin() const __NOEXCEPT__ { return base_type::cbegin(); }
347  __HOST__ __DEVICE__ inline const_iterator cend() const __NOEXCEPT__ { return base_type::cend(); }
348  __HOST__ __DEVICE__ inline const_reverse_iterator crbegin() __NOEXCEPT__ { return base_type::crbegin(); }
349  __HOST__ __DEVICE__ inline const_reverse_iterator crend() __NOEXCEPT__ { return base_type::crend(); }
350  #endif
351 
357  __HOST__ __DEVICE__ inline size_type size() const __NOEXCEPT__ { return base_type::size(); }
358 
366 
372  __HOST__ __DEVICE__ inline size_type number_rows() const __NOEXCEPT__ { return base_type::number_rows(); }
373 
379  __HOST__ __DEVICE__ inline size_type number_columns() const __NOEXCEPT__ { return base_type::number_columns(); }
380 
390  __HOST__ void resize( const size_type newNumberRows, const size_type newNumberColumns, const value_type& value = value_type() )
391  {
392  if( number_rows() == newNumberRows && number_columns() == newNumberColumns ) return; // no resize needed
393  // create new model
394  matrix newMatrix( newNumberRows, newNumberColumns, value, get_allocator() );
395  for( size_type i = 0; i < std::min(number_rows(),newNumberRows); ++i ) {
396  const_row_type oldRow = get_row(i);
397  row_type newRow = newMatrix.get_row(i);
398  ecuda::copy( oldRow.begin(), oldRow.begin()+std::min(number_columns(),newNumberColumns), newRow.begin() );
399  }
400  swap( newMatrix );
401  }
402 
408  __HOST__ __DEVICE__ inline bool empty() const __NOEXCEPT__ { return !number_rows() || !number_columns(); }
409 
420  __HOST__ __DEVICE__ inline row_type get_row( const size_type rowIndex ) { return base_type::get_row(rowIndex); }
421 
433  __HOST__ __DEVICE__ inline const_row_type get_row( const size_type rowIndex ) const { return base_type::get_row(rowIndex); }
434 
445  __HOST__ __DEVICE__ inline column_type get_column( const size_type columnIndex ) { return base_type::get_column(columnIndex); }
446 
458  __HOST__ __DEVICE__ inline const_column_type get_column( const size_type columnIndex ) const { return base_type::get_column(columnIndex); }
459 
470  __DEVICE__ inline reference at( size_type rowIndex, size_type columnIndex )
471  {
472  if( rowIndex >= number_rows() || columnIndex >= number_columns() ) {
473  #ifndef __CUDACC__
474  throw std::out_of_range( EXCEPTION_MSG("ecuda::matrix::at() row and/or column index parameter is out of range") );
475  #else
476  // this strategy is taken from:
477  // http://stackoverflow.com/questions/12521721/crashing-a-kernel-gracefully
479  //__threadfence();
480  asm("trap;");
481  #endif
482  }
483  return base_type::at( rowIndex, columnIndex );
484  }
485 
496  __DEVICE__ inline const_reference at( size_type rowIndex, size_type columnIndex ) const
497  {
498  if( rowIndex >= number_rows() || columnIndex >= number_columns() ) {
499  #ifndef __CUDACC__
500  throw std::out_of_range( EXCEPTION_MSG("ecuda::matrix::at() row and/or column index parameter is out of range") );
501  #else
502  // this strategy is taken from:
503  // http://stackoverflow.com/questions/12521721/crashing-a-kernel-gracefully
505  //__threadfence();
506  asm("trap;");
507  #endif
508  }
509  return base_type::at( rowIndex, columnIndex );
510  }
511 
521  __DEVICE__ inline reference operator()( const size_type rowIndex, const size_type columnIndex ) { return base_type::at(rowIndex,columnIndex); }
522 
532  __DEVICE__ inline const_reference operator()( const size_type rowIndex, const size_type columnIndex ) const { return base_type::at(rowIndex,columnIndex); }
533 
539  __HOST__ __DEVICE__ inline row_type operator[]( const size_type rowIndex ) { return get_row(rowIndex); }
540 
546  __HOST__ __DEVICE__ inline const_row_type operator[]( const size_type rowIndex ) const { return get_row(rowIndex); }
547 
555  __DEVICE__ inline reference front() { return base_type::at(0,0); }
556 
564  __DEVICE__ inline reference back() { return base_type::at(number_rows()-1,number_columns()-1); }
565 
573  __DEVICE__ inline const_reference front() const { return base_type::at(0,0); }
574 
582  __DEVICE__ inline const_reference back() const { return base_type::at(number_rows()-1,number_columns()-1); }
583 
592  __HOST__ __DEVICE__ inline pointer data() __NOEXCEPT__ { return base_type::get_pointer(); }
593 
602  __HOST__ __DEVICE__ inline const_pointer data() const __NOEXCEPT__ { return base_type::get_pointer(); }
603 
609  __HOST__ __DEVICE__ inline void fill( const value_type& value ) { if( !empty() ) ecuda::fill( begin(), end(), value ); }
610 
622  __HOST__ __DEVICE__ inline void swap( matrix& other ) { base_type::swap( other ); }
623 
628  __HOST__ inline allocator_type get_allocator() const { return allocator; }
629 
639  template<class Alloc2>
640  __HOST__ __DEVICE__ inline bool operator==( const matrix<value_type,Alloc2>& other ) const
641  {
642  return ecuda::equal( begin(), end(), other.begin() );
643  }
644 
655  template<class Alloc2>
656  __HOST__ __DEVICE__ inline bool operator!=( const matrix<value_type,Alloc2>& other ) const { return !operator==(other); }
657 
667  template<class Alloc2>
668  __HOST__ __DEVICE__ inline bool operator<( const matrix<value_type,Alloc2>& other ) const
669  {
670  return ecuda::lexicographical_compare( begin(), end(), other.begin(), other.end() );
671  }
672 
682  template<class Alloc2>
683  __HOST__ __DEVICE__ inline bool operator>( const matrix<value_type,Alloc2>& other ) const
684  {
685  return ecuda::lexicographical_compare( other.begin(), other.end(), begin(), end() );
686  }
687 
697  template<class Alloc2>
698  __HOST__ __DEVICE__ inline bool operator<=( const matrix<value_type,Alloc2>& other ) const { return !operator>(other); }
699 
709  template<class Alloc2>
710  __HOST__ __DEVICE__ inline bool operator>=( const matrix<value_type,Alloc2>& other ) const { return !operator<(other); }
711 
712 };
713 
715 namespace impl {
716 
726 template< typename T, class Alloc> //=device_pitch_allocator<T> >
727 class matrix_kernel_argument : public matrix<T,Alloc,typename ecuda::add_pointer<T>::type>
728 {
729 
730 private:
731  typedef matrix<T,Alloc,typename ecuda::add_pointer<T>::type> base_type;
732 
733 public:
734  template<class P>
735  __HOST__ matrix_kernel_argument( const matrix<T,Alloc,P>& src ) : base_type( src, ecuda::true_type() ) {}
736 
737  __HOST__ __DEVICE__ matrix_kernel_argument( const matrix_kernel_argument& src ) : base_type( src, ecuda::true_type() ) {}
738 
739  template<class P>
740  __HOST__ matrix_kernel_argument& operator=( const matrix<T,Alloc,P>& src )
741  {
742  base_type::shallow_assign( src );
743  return *this;
744  }
745 
746  #ifdef ECUDA_CPP11_AVAILABLE
747  matrix_kernel_argument( matrix_kernel_argument&& src ) : base_type(std::move(src)) {}
748 
749  matrix_kernel_argument& operator=( matrix_kernel_argument&& src )
750  {
751  base_type::operator=(std::move(src));
752  return *this;
753  }
754  #endif
755 
756 };
757 
758 } // namespace impl
760 
782 template<typename T,class Alloc1,class Alloc2>
783 __HOST__ void matrix_copy( matrix<T,Alloc1>& dest, const matrix<T,Alloc2>& src, typename matrix<T,Alloc2>::size_type offsetRow=0, typename matrix<T,Alloc2>::size_type offsetColumn=0 ) {
784  typedef typename matrix<T,Alloc2>::size_type size_type;
785  const size_type nr = std::min( dest.number_rows() , src.number_rows()-offsetRow );
786  const size_type nc = std::min( dest.number_columns(), src.number_columns()-offsetColumn );
787  for( size_type i = 0; i < nr; ++i ) {
788  typename matrix<T,Alloc1>::row_type destRow = dest[i];
789  typename matrix<T,Alloc2>::const_row_type srcRow = src[i+offsetRow];
790  ::ecuda::copy( src.begin(), src.end(), dest.begin() );
791  }
792 }
793 
814 template<typename T,class Alloc1,class Alloc2>
816  matrix<T,Alloc1>& mat1,
817  matrix<T,Alloc2>& mat2,
818  typename matrix<T,Alloc1>::size_type numberRows=0, typename matrix<T,Alloc1>::size_type numberColumns=0,
819  typename matrix<T,Alloc1>::size_type offsetRow1=0, typename matrix<T,Alloc1>::size_type offsetColumn1=0,
820  typename matrix<T,Alloc2>::size_type offsetRow2=0, typename matrix<T,Alloc2>::size_type offsetColumn2=0
821 )
822 {
823  if( (offsetRow1+numberRows) > mat1.number_rows() ) throw std::out_of_range( EXCEPTION_MSG("ecuda::matrix_swap() specified row subset of mat1 is out of bounds") );
824  if( (offsetRow2+numberRows) > mat2.number_rows() ) throw std::out_of_range( EXCEPTION_MSG("ecuda::matrix_swap() specified row subset of mat2 is out of bounds" ) );
825  if( (offsetColumn1+numberColumns) > mat1.number_columns() ) throw std::out_of_range( EXCEPTION_MSG("ecuda::matrix_swap() specified column subset of mat1 is out of bounds") );
826  if( (offsetColumn2+numberColumns) > mat2.number_columns() ) throw std::out_of_range( EXCEPTION_MSG("ecuda::matrix_swap() specified column subset of mat2 is out of bounds") );
827  std::vector< T, host_allocator<T> > stagingMemory( numberColumns );
828  typedef typename matrix<T,Alloc1>::size_type size_type;
829  for( size_type i = 0; i < numberRows; ++i ) {
830  typename matrix<T,Alloc1>::row_type row1 = mat1[offsetRow1+i];
831  typename matrix<T,Alloc2>::row_type row2 = mat1[offsetRow2+i];
832  stagingMemory.assign( row1.begin()+offsetColumn1, row1.begin()+(offsetColumn1+numberColumns) );
833  ecuda::copy( row2.begin()+offsetColumn2, row2.begin()+(offsetColumn2+numberColumns), row1.begin()+offsetColumn1 );
834  ecuda::copy( stagingMemory.begin(), stagingMemory.end(), row2.begin()+offsetColumn2 );
835  }
836 }
837 
838 template<typename T,class Alloc>
840  matrix<T,Alloc>& src
841 )
842 {
843  if( src.empty() ) return;
844  std::vector< T, host_allocator<T> > stagingMemory( src.number_columns() ); // stage a single row
845  std::vector<T> hostMatrix( src.size() );
846  for( typename matrix<T,Alloc>::size_type i = 0; i < src.number_rows(); ++i ) {
847  ecuda::copy( src[i].begin(), src[i].end(), stagingMemory.begin() ); // copy row
848  typename std::vector< T, host_allocator<T> >::const_iterator srcElement = stagingMemory.begin();
849  for( std::size_t j = 0; j < src.number_columns(); ++j, ++srcElement ) hostMatrix[j*src.number_rows()+i] = *srcElement; // transpose
850  }
851  src.resize( src.number_columns(), src.number_rows() ); // resize destination matrix
852  ecuda::copy( hostMatrix.begin(), hostMatrix.end(), src.begin() );
853  //typename std::vector<T>::const_iterator srcRow = hostMatrix.begin();
854  //for( typename matrix<T,Alloc>::size_type i = 0; i < src.number_rows(); ++i, srcRow += src.number_columns() ) {
855  // ecuda::copy( srcRow, srcRow+src.number_columns(), src[i].begin() );
856  //}
857 }
858 
859 } // namespace ecuda
860 
861 #endif
base_type::iterator iterator
iterator type
Definition: matrix.hpp:147
__HOST__ __DEVICE__ OutputIterator copy(InputIterator first, InputIterator last, OutputIterator result)
Replacement for std::copy.
Definition: copy.hpp:801
__HOST__ __DEVICE__ size_type number_rows() const __NOEXCEPT__
Returns the number of rows in the container.
Definition: matrix.hpp:372
__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: matrix.hpp:365
A resizable matrix stored in device memory.
Definition: matrix.hpp:126
__HOST__ allocator_type get_allocator() const
Returns the allocator associated with the container.
Definition: matrix.hpp:628
__HOST__ __DEVICE__ reverse_iterator rbegin() __NOEXCEPT__
Returns a reverse iterator to the first element of the reversed container.
Definition: matrix.hpp:314
base_type::const_iterator const_iterator
const iterator type
Definition: matrix.hpp:148
__HOST__ matrix(const matrix &src)
Copy constructor.
Definition: matrix.hpp:219
__HOST__ __DEVICE__ const_row_type get_row(const size_type rowIndex) const
Gets a view object of a single row of the matrix.
Definition: matrix.hpp:433
base_type::value_type value_type
cell data type
Definition: matrix.hpp:133
__HOST__ __DEVICE__ bool empty() const __NOEXCEPT__
Checks if the container has no elements.
Definition: matrix.hpp:408
__HOST__ __DEVICE__ bool operator==(const matrix< value_type, Alloc2 > &other) const
Checks if the contents of two matrices are equal.
Definition: matrix.hpp:640
__HOST__ __DEVICE__ const_pointer data() const __NOEXCEPT__
Returns pointer to the underlying array serving as element storage.
Definition: matrix.hpp:602
__HOST__ void matrix_transpose(matrix< T, Alloc > &src)
Definition: matrix.hpp:839
__HOST__ void resize(const size_type newNumberRows, const size_type newNumberColumns, const value_type &value=value_type())
Resizes the container to have dimensions newNumberRows x newNumberColumns.
Definition: matrix.hpp:390
__HOST__ __DEVICE__ bool operator>(const matrix< value_type, Alloc2 > &other) const
Compares the contents of two matrices lexicographically.
Definition: matrix.hpp:683
#define __CONSTEXPR__
Definition: global.hpp:141
__HOST__ __DEVICE__ reverse_iterator rend() __NOEXCEPT__
Returns a reverse iterator to the element following the last element of the reversed container...
Definition: matrix.hpp:324
base_type::pointer pointer
cell pointer type
Definition: matrix.hpp:139
__HOST__ void matrix_copy(matrix< T, Alloc1 > &dest, const matrix< T, Alloc2 > &src, typename matrix< T, Alloc2 >::size_type offsetRow=0, typename matrix< T, Alloc2 >::size_type offsetColumn=0)
Copies some or all of a source matrix to a destination matrix.
Definition: matrix.hpp:783
make_const< pointer >::type const_pointer
cell const pointer type
Definition: matrix.hpp:140
Alloc allocator_type
allocator type
Definition: matrix.hpp:134
__HOST__ __DEVICE__ const_column_type get_column(const size_type columnIndex) const
Gets a view object of a single column of the matrix.
Definition: matrix.hpp:458
base_type::const_row_type const_row_type
matrix const row container type
Definition: matrix.hpp:144
__HOST__ __DEVICE__ const_iterator end() const __NOEXCEPT__
Returns an iterator to the element following the last element of the container.
Definition: matrix.hpp:305
base_type::const_column_type const_column_type
matrix const column container type
Definition: matrix.hpp:145
#define __NOEXCEPT__
Definition: global.hpp:140
__DEVICE__ reference operator()(const size_type rowIndex, const size_type columnIndex)
Returns a reference to the element at specified location index. No bounds checking is performed...
Definition: matrix.hpp:521
__HOST__ __DEVICE__ void swap(matrix &other)
Exchanges the contents of the container with those of the other.
Definition: matrix.hpp:622
__HOST__ __DEVICE__ const_iterator begin() const __NOEXCEPT__
Returns an iterator to the first element of the container.
Definition: matrix.hpp:296
base_type::column_type column_type
matrix column container type
Definition: matrix.hpp:143
__HOST__ __DEVICE__ bool operator<(const matrix< value_type, Alloc2 > &other) const
Compares the contents of two matrices lexicographically.
Definition: matrix.hpp:668
base_type::size_type size_type
unsigned integral type
Definition: matrix.hpp:135
__HOST__ __DEVICE__ const_reverse_iterator rend() const __NOEXCEPT__
Returns a reverse iterator to the element following the last element of the reversed container...
Definition: matrix.hpp:343
#define __HOST__
Definition: global.hpp:150
__HOST__ __DEVICE__ size_type number_columns() const __NOEXCEPT__
Returns the number of columns in the container.
Definition: matrix.hpp:379
__HOST__ matrix & operator=(const matrix &other)
Definition: matrix.hpp:245
__HOST__ __DEVICE__ pointer data() __NOEXCEPT__
Returns pointer to the underlying array serving as element storage.
Definition: matrix.hpp:592
__HOST__ __DEVICE__ void swap(T &a, T &b) __NOEXCEPT__
Definition: algorithm.hpp:54
__DEVICE__ const_reference front() const
Returns a reference to the first element in the container.
Definition: matrix.hpp:573
__HOST__ __DEVICE__ column_type get_column(const size_type columnIndex)
Gets a view object of a single column of the matrix.
Definition: matrix.hpp:445
__HOST__ __DEVICE__ const_reverse_iterator rbegin() const __NOEXCEPT__
Returns a reverse iterator to the first element of the reversed container.
Definition: matrix.hpp:333
base_type::difference_type difference_type
signed integral type
Definition: matrix.hpp:136
__DEVICE__ const_reference operator()(const size_type rowIndex, const size_type columnIndex) const
Returns a reference to the element at specified location index. No bounds checking is performed...
Definition: matrix.hpp:532
__HOST__ __DEVICE__ const_row_type operator[](const size_type rowIndex) const
operator[](rowIndex) alias for get_row(rowIndex)
Definition: matrix.hpp:546
__HOST__ __DEVICE__ void fill(const value_type &value)
Assigns a given value to all elements in the container.
Definition: matrix.hpp:609
__DEVICE__ const_reference at(size_type rowIndex, size_type columnIndex) const
Returns a constant reference to the element at specified row and column index, with bounds checking...
Definition: matrix.hpp:496
__HOST__ void matrix_swap(matrix< T, Alloc1 > &mat1, matrix< T, Alloc2 > &mat2, typename matrix< T, Alloc1 >::size_type numberRows=0, typename matrix< T, Alloc1 >::size_type numberColumns=0, typename matrix< T, Alloc1 >::size_type offsetRow1=0, typename matrix< T, Alloc1 >::size_type offsetColumn1=0, typename matrix< T, Alloc2 >::size_type offsetRow2=0, typename matrix< T, Alloc2 >::size_type offsetColumn2=0)
Swaps some or all of a source matrix with a destination matrix.
Definition: matrix.hpp:815
__HOST__ __DEVICE__ iterator begin() __NOEXCEPT__
Returns an iterator to the first element of the container.
Definition: matrix.hpp:278
base_type::const_reference const_reference
cell const reference type
Definition: matrix.hpp:138
__DEVICE__ reference front()
Returns a reference to the first element in the container.
Definition: matrix.hpp:555
__HOST__ __DEVICE__ bool operator!=(const matrix< value_type, Alloc2 > &other) const
Checks if the contents of two matrices are not equal.
Definition: matrix.hpp:656
base_type::reverse_iterator reverse_iterator
reverse iterator type
Definition: matrix.hpp:149
__HOST__ __DEVICE__ const T & min(const T &a, const T &b)
Definition: algorithm.hpp:48
__HOST__ __DEVICE__ bool operator>=(const matrix< value_type, Alloc2 > &other) const
Compares the contents of two matrices lexicographically.
Definition: matrix.hpp:710
base_type::const_reverse_iterator const_reverse_iterator
const reverse iterator type
Definition: matrix.hpp:150
__HOST__ __DEVICE__ iterator end() __NOEXCEPT__
Returns an iterator to the element following the last element of the container.
Definition: matrix.hpp:287
friend class matrix
Definition: matrix.hpp:158
__HOST__ matrix(const matrix &src, const allocator_type &alloc)
Copy constructor.
Definition: matrix.hpp:237
__DEVICE__ reference at(size_type rowIndex, size_type columnIndex)
Returns a reference to the element at specified row and column index, with bounds checking...
Definition: matrix.hpp:470
__HOST__ __DEVICE__ bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2)
Replacement for std::equal.
Definition: equal.hpp:173
__HOST__ __DEVICE__ row_type get_row(const size_type rowIndex)
Gets a view object of a single row of the matrix.
Definition: matrix.hpp:420
__HOST__ matrix(const size_type numberRows=0, const size_type numberColumns=0, const value_type &value=value_type(), const allocator_type &allocator=allocator_type())
Constructs a matrix with dimensions numberRows x numberColumns filled with copies of elements with va...
Definition: matrix.hpp:204
__HOST__ __DEVICE__ row_type operator[](const size_type rowIndex)
operator[](rowIndex) alias for get_row(rowIndex)
Definition: matrix.hpp:539
__HOST__ __DEVICE__ size_type size() const __NOEXCEPT__
Returns the number of elements in the container (numberRows*numberColumns).
Definition: matrix.hpp:357
__DEVICE__ const_reference back() const
Returns a reference to the last element in the container.
Definition: matrix.hpp:582
impl::matrix_kernel_argument< T, Alloc > kernel_argument
kernel argument type
Definition: matrix.hpp:152
__DEVICE__ void threadfence()
base_type::row_type row_type
matrix row container type
Definition: matrix.hpp:142
__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
base_type::reference reference
cell reference type
Definition: matrix.hpp:137
__HOST__ __DEVICE__ bool lexicographical_compare(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2)
const impl::matrix_kernel_argument< T, Alloc > const_kernel_argument
const kernel argument type
Definition: matrix.hpp:153
__DEVICE__ reference back()
Returns a reference to the last element in the container.
Definition: matrix.hpp:564
__HOST__ __DEVICE__ void fill(ForwardIterator first, ForwardIterator last, const T &val)
Definition: fill.hpp:156