38 #ifndef ECUDA_MATRIX_HPP
39 #define ECUDA_MATRIX_HPP
57 template<
typename T,
class Alloc>
class matrix_kernel_argument;
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, P >
130 typedef model::device_contiguous_row_matrix< T, P > base_type;
158 template<
typename U,
class Alloc2,
class Q>
friend class matrix;
174 base_type::get_pointer() = unmanaged_cast(other.get_pointer());
175 allocator = other.allocator;
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() );
205 base_type(
pointer(), numberRows, numberColumns ),
247 allocator = other.allocator;
254 #ifdef ECUDA_CPP11_AVAILABLE
345 #ifdef ECUDA_CPP11_AVAILABLE
474 throw std::out_of_range(
EXCEPTION_MSG(
"ecuda::matrix::at() row and/or column index parameter is out of range") );
483 return base_type::at( rowIndex, columnIndex );
500 throw std::out_of_range(
EXCEPTION_MSG(
"ecuda::matrix::at() row and/or column index parameter is out of range") );
509 return base_type::at( rowIndex, columnIndex );
639 template<
class Alloc2>
655 template<
class Alloc2>
667 template<
class Alloc2>
682 template<
class Alloc2>
697 template<
class Alloc2>
709 template<
class Alloc2>
726 template<
typename T,
class Alloc>
727 class matrix_kernel_argument :
public matrix<T,Alloc,typename ecuda::add_pointer<T>::type>
731 typedef matrix<T,Alloc,typename ecuda::add_pointer<T>::type> base_type;
735 __HOST__ matrix_kernel_argument(
const matrix<T,Alloc,P>& src ) : base_type( src, ecuda::true_type() ) {}
737 __HOST__ __DEVICE__ matrix_kernel_argument(
const matrix_kernel_argument& src ) : base_type( src, ecuda::true_type() ) {}
740 __HOST__ matrix_kernel_argument& operator=(
const matrix<T,Alloc,P>& src )
742 base_type::shallow_assign( src );
746 #ifdef ECUDA_CPP11_AVAILABLE
747 matrix_kernel_argument( matrix_kernel_argument&& src ) : base_type(std::move(src)) {}
749 matrix_kernel_argument& operator=( matrix_kernel_argument&& src )
751 base_type::operator=(std::move(src));
782 template<
typename T,
class Alloc1,
class Alloc2>
787 for( size_type i = 0; i < nr; ++i ) {
814 template<
typename T,
class Alloc1,
class Alloc2>
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 );
829 for( size_type i = 0; i < numberRows; ++i ) {
832 stagingMemory.assign( row1.
begin()+offsetColumn1, row1.
begin()+(offsetColumn1+numberColumns) );
834 ecuda::copy( stagingMemory.begin(), stagingMemory.end(), row2.
begin()+offsetColumn2 );
838 template<
typename T,
class Alloc>
843 if( src.
empty() )
return;
844 std::vector< T, host_allocator<T> > stagingMemory( src.
number_columns() );
845 std::vector<T> hostMatrix( src.
size() );
848 typename std::vector< T, host_allocator<T> >::const_iterator srcElement = stagingMemory.begin();
base_type::iterator iterator
iterator type
__HOST__ __DEVICE__ OutputIterator copy(InputIterator first, InputIterator last, OutputIterator result)
Replacement for std::copy.
__HOST__ __DEVICE__ size_type number_rows() const __NOEXCEPT__
Returns the number of rows in the container.
__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...
A resizable matrix stored in device memory.
__HOST__ allocator_type get_allocator() const
Returns the allocator associated with the container.
__HOST__ __DEVICE__ reverse_iterator rbegin() __NOEXCEPT__
Returns a reverse iterator to the first element of the reversed container.
base_type::const_iterator const_iterator
const iterator type
__HOST__ matrix(const matrix &src)
Copy constructor.
__HOST__ __DEVICE__ const_row_type get_row(const size_type rowIndex) const
Gets a view object of a single row of the matrix.
base_type::value_type value_type
cell data type
__HOST__ __DEVICE__ bool empty() const __NOEXCEPT__
Checks if the container has no elements.
__HOST__ __DEVICE__ bool operator==(const matrix< value_type, Alloc2 > &other) const
Checks if the contents of two matrices are equal.
__HOST__ __DEVICE__ const_pointer data() const __NOEXCEPT__
Returns pointer to the underlying array serving as element storage.
__HOST__ void matrix_transpose(matrix< T, Alloc > &src)
__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.
__HOST__ __DEVICE__ bool operator>(const matrix< value_type, Alloc2 > &other) const
Compares the contents of two matrices lexicographically.
__HOST__ __DEVICE__ reverse_iterator rend() __NOEXCEPT__
Returns a reverse iterator to the element following the last element of the reversed container...
base_type::pointer pointer
cell pointer type
__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.
make_const< pointer >::type const_pointer
cell const pointer type
Alloc allocator_type
allocator type
__HOST__ __DEVICE__ const_column_type get_column(const size_type columnIndex) const
Gets a view object of a single column of the matrix.
base_type::const_row_type const_row_type
matrix const row container type
__HOST__ __DEVICE__ const_iterator end() const __NOEXCEPT__
Returns an iterator to the element following the last element of the container.
base_type::const_column_type const_column_type
matrix const column container type
__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...
__HOST__ __DEVICE__ void swap(matrix &other)
Exchanges the contents of the container with those of the other.
__HOST__ __DEVICE__ const_iterator begin() const __NOEXCEPT__
Returns an iterator to the first element of the container.
base_type::column_type column_type
matrix column container type
__HOST__ __DEVICE__ bool operator<(const matrix< value_type, Alloc2 > &other) const
Compares the contents of two matrices lexicographically.
base_type::size_type size_type
unsigned integral type
__HOST__ __DEVICE__ const_reverse_iterator rend() const __NOEXCEPT__
Returns a reverse iterator to the element following the last element of the reversed container...
__HOST__ __DEVICE__ size_type number_columns() const __NOEXCEPT__
Returns the number of columns in the container.
__HOST__ matrix & operator=(const matrix &other)
__HOST__ __DEVICE__ pointer data() __NOEXCEPT__
Returns pointer to the underlying array serving as element storage.
__HOST__ __DEVICE__ void swap(T &a, T &b) __NOEXCEPT__
__DEVICE__ const_reference front() const
Returns a reference to the first element in the container.
__HOST__ __DEVICE__ column_type get_column(const size_type columnIndex)
Gets a view object of a single column of the matrix.
__HOST__ __DEVICE__ const_reverse_iterator rbegin() const __NOEXCEPT__
Returns a reverse iterator to the first element of the reversed container.
base_type::difference_type difference_type
signed integral type
__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...
__HOST__ __DEVICE__ const_row_type operator[](const size_type rowIndex) const
operator[](rowIndex) alias for get_row(rowIndex)
__HOST__ __DEVICE__ void fill(const value_type &value)
Assigns a given value to all elements in the container.
__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...
__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.
__HOST__ __DEVICE__ iterator begin() __NOEXCEPT__
Returns an iterator to the first element of the container.
base_type::const_reference const_reference
cell const reference type
__DEVICE__ reference front()
Returns a reference to the first element in the container.
__HOST__ __DEVICE__ bool operator!=(const matrix< value_type, Alloc2 > &other) const
Checks if the contents of two matrices are not equal.
base_type::reverse_iterator reverse_iterator
reverse iterator type
__HOST__ __DEVICE__ const T & min(const T &a, const T &b)
__HOST__ __DEVICE__ bool operator>=(const matrix< value_type, Alloc2 > &other) const
Compares the contents of two matrices lexicographically.
base_type::const_reverse_iterator const_reverse_iterator
const reverse iterator type
__HOST__ __DEVICE__ iterator end() __NOEXCEPT__
Returns an iterator to the element following the last element of the container.
__HOST__ matrix(const matrix &src, const allocator_type &alloc)
Copy constructor.
__DEVICE__ reference at(size_type rowIndex, size_type columnIndex)
Returns a reference to the element at specified row and column index, with bounds checking...
__HOST__ __DEVICE__ bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2)
Replacement for std::equal.
__HOST__ __DEVICE__ row_type get_row(const size_type rowIndex)
Gets a view object of a single row of the matrix.
__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...
__HOST__ __DEVICE__ row_type operator[](const size_type rowIndex)
operator[](rowIndex) alias for get_row(rowIndex)
__HOST__ __DEVICE__ size_type size() const __NOEXCEPT__
Returns the number of elements in the container (numberRows*numberColumns).
__DEVICE__ const_reference back() const
Returns a reference to the last element in the container.
impl::matrix_kernel_argument< T, Alloc > kernel_argument
kernel argument type
__DEVICE__ void threadfence()
base_type::row_type row_type
matrix row container type
__HOST__ __DEVICE__ const T & max(const T &a, const T &b)
base_type::reference reference
cell reference type
__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
__DEVICE__ reference back()
Returns a reference to the last element in the container.
__HOST__ __DEVICE__ void fill(ForwardIterator first, ForwardIterator last, const T &val)