Extended CUDA Library (ecuda)
2.0
|
A resizable matrix stored in device memory. More...
#include <matrix.hpp>
Public Types | |
typedef base_type::value_type | value_type |
cell data type More... | |
typedef Alloc | allocator_type |
allocator type More... | |
typedef base_type::size_type | size_type |
unsigned integral type More... | |
typedef base_type::difference_type | difference_type |
signed integral type More... | |
typedef base_type::reference | reference |
cell reference type More... | |
typedef base_type::const_reference | const_reference |
cell const reference type More... | |
typedef base_type::pointer | pointer |
cell pointer type More... | |
typedef make_const< pointer >::type | const_pointer |
cell const pointer type More... | |
typedef base_type::row_type | row_type |
matrix row container type More... | |
typedef base_type::column_type | column_type |
matrix column container type More... | |
typedef base_type::const_row_type | const_row_type |
matrix const row container type More... | |
typedef base_type::const_column_type | const_column_type |
matrix const column container type More... | |
typedef base_type::iterator | iterator |
iterator type More... | |
typedef base_type::const_iterator | const_iterator |
const iterator type More... | |
typedef base_type::reverse_iterator | reverse_iterator |
reverse iterator type More... | |
typedef base_type::const_reverse_iterator | const_reverse_iterator |
const reverse iterator type More... | |
typedef impl::matrix_kernel_argument < T, Alloc > | kernel_argument |
kernel argument type More... | |
typedef const impl::matrix_kernel_argument < T, Alloc > | const_kernel_argument |
const kernel argument type More... | |
Public Member Functions | |
__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 value value. More... | |
__HOST__ | matrix (const matrix &src) |
Copy constructor. More... | |
__HOST__ | matrix (const matrix &src, const allocator_type &alloc) |
Copy constructor. More... | |
__HOST__ matrix & | operator= (const matrix &other) |
__HOST__ __DEVICE__ iterator | begin () __NOEXCEPT__ |
Returns an iterator to the first element of the container. More... | |
__HOST__ __DEVICE__ iterator | end () __NOEXCEPT__ |
Returns an iterator to the element following the last element of the container. More... | |
__HOST__ __DEVICE__ const_iterator | begin () const __NOEXCEPT__ |
Returns an iterator to the first element of the container. More... | |
__HOST__ __DEVICE__ const_iterator | end () const __NOEXCEPT__ |
Returns an iterator to the element following the last element of the container. More... | |
__HOST__ __DEVICE__ reverse_iterator | rbegin () __NOEXCEPT__ |
Returns a reverse iterator to the first element of the reversed container. More... | |
__HOST__ __DEVICE__ reverse_iterator | rend () __NOEXCEPT__ |
Returns a reverse iterator to the element following the last element of the reversed container. More... | |
__HOST__ __DEVICE__ const_reverse_iterator | rbegin () const __NOEXCEPT__ |
Returns a reverse iterator to the first element of the reversed container. More... | |
__HOST__ __DEVICE__ const_reverse_iterator | rend () const __NOEXCEPT__ |
Returns a reverse iterator to the element following the last element of the reversed container. More... | |
__HOST__ __DEVICE__ size_type | size () const __NOEXCEPT__ |
Returns the number of elements in the container (numberRows*numberColumns). More... | |
__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 implementation limitations. More... | |
__HOST__ __DEVICE__ size_type | number_rows () const __NOEXCEPT__ |
Returns the number of rows in the container. More... | |
__HOST__ __DEVICE__ size_type | number_columns () const __NOEXCEPT__ |
Returns the number of columns in the container. More... | |
__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. More... | |
__HOST__ __DEVICE__ bool | empty () const __NOEXCEPT__ |
Checks if the container has no elements. More... | |
__HOST__ __DEVICE__ row_type | get_row (const size_type rowIndex) |
Gets a view object of a single row of the matrix. More... | |
__HOST__ __DEVICE__ const_row_type | get_row (const size_type rowIndex) const |
Gets a view object of a single row of the matrix. More... | |
__HOST__ __DEVICE__ column_type | get_column (const size_type columnIndex) |
Gets a view object of a single column of the matrix. More... | |
__HOST__ __DEVICE__ const_column_type | get_column (const size_type columnIndex) const |
Gets a view object of a single column of the matrix. More... | |
__DEVICE__ reference | at (size_type rowIndex, size_type columnIndex) |
Returns a reference to the element at specified row and column index, with bounds checking. More... | |
__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. More... | |
__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. More... | |
__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. More... | |
__HOST__ __DEVICE__ row_type | operator[] (const size_type rowIndex) |
operator[](rowIndex) alias for get_row(rowIndex) More... | |
__HOST__ __DEVICE__ const_row_type | operator[] (const size_type rowIndex) const |
operator[](rowIndex) alias for get_row(rowIndex) More... | |
__DEVICE__ reference | front () |
Returns a reference to the first element in the container. More... | |
__DEVICE__ reference | back () |
Returns a reference to the last element in the container. More... | |
__DEVICE__ const_reference | front () const |
Returns a reference to the first element in the container. More... | |
__DEVICE__ const_reference | back () const |
Returns a reference to the last element in the container. More... | |
__HOST__ __DEVICE__ pointer | data () __NOEXCEPT__ |
Returns pointer to the underlying array serving as element storage. More... | |
__HOST__ __DEVICE__ const_pointer | data () const __NOEXCEPT__ |
Returns pointer to the underlying array serving as element storage. More... | |
__HOST__ __DEVICE__ void | fill (const value_type &value) |
Assigns a given value to all elements in the container. More... | |
__HOST__ __DEVICE__ void | swap (matrix &other) |
Exchanges the contents of the container with those of the other. More... | |
__HOST__ allocator_type | get_allocator () const |
Returns the allocator associated with the container. More... | |
template<class Alloc2 > | |
__HOST__ __DEVICE__ bool | operator== (const matrix< value_type, Alloc2 > &other) const |
Checks if the contents of two matrices are equal. More... | |
template<class Alloc2 > | |
__HOST__ __DEVICE__ bool | operator!= (const matrix< value_type, Alloc2 > &other) const |
Checks if the contents of two matrices are not equal. More... | |
template<class Alloc2 > | |
__HOST__ __DEVICE__ bool | operator< (const matrix< value_type, Alloc2 > &other) const |
Compares the contents of two matrices lexicographically. More... | |
template<class Alloc2 > | |
__HOST__ __DEVICE__ bool | operator> (const matrix< value_type, Alloc2 > &other) const |
Compares the contents of two matrices lexicographically. More... | |
template<class Alloc2 > | |
__HOST__ __DEVICE__ bool | operator<= (const matrix< value_type, Alloc2 > &other) const |
Compares the contents of two matrices lexicographically. More... | |
template<class Alloc2 > | |
__HOST__ __DEVICE__ bool | operator>= (const matrix< value_type, Alloc2 > &other) const |
Compares the contents of two matrices lexicographically. More... | |
Friends | |
template<typename U , class Alloc2 , class Q > | |
class | matrix |
A resizable matrix stored in device memory.
A matrix is defined as a 2D structure of dimensions rows*columns. The default implementation uses pitched memory where a 2D block of video memory is allocated with width=columns and height=rows. Pitched memory is aligned in a device-dependent manner so that calls to individual elements can be threaded more efficiently (i.e. minimizing the number of read operations required to supply data to multiple threads). Consult the CUDA API documentation for a more verbose explanation.
Methods are prefaced with appropriate keywords to declare them as host and/or device capable. In general: operations requiring memory allocation/deallocation are host only, operations to access the values of specific elements are device only, and copy operations on ranges of data and accessors of general information can be performed on both the host and device.
Memory use can be conceptualized as:
As a result, it is highly desirable for threading to utilize a column-wise orientation. For example, a good kernel to perform an operation on the elements of a matrix might be:
This could be called from host code like:
Unfortunately, CUDA solutions are very problem specific, so there is no generally applicable example for specifying how thread blocks should be defined. The size of the matrix, hardware limitations, CUDA API limitations, etc. all play a part. For example, the above implementation won't work in earlier versions of CUDA since blockDim.y was limited to 512 (at the time of this writing it was 1024 in the newer versions of CUDA).
Just keep in mind that the column dimension lies in contiguous memory, and the row dimension is contiguous blocks of columns; thus, an implementation that aims to have concurrently running threads accessing column >>>> row will run much more efficiently.
Matrix iterators (via begin(),end(),rbegin(),rend()) and lexicographical comparisons traverse the matrix linearly in row-major fashion (i.e. each column of the first row is traversed, then each column of the next row, and so on...).
Definition at line 126 of file matrix.hpp.
typedef Alloc ecuda::matrix< T, Alloc, P >::allocator_type |
allocator type
Definition at line 134 of file matrix.hpp.
typedef base_type::column_type ecuda::matrix< T, Alloc, P >::column_type |
matrix column container type
Definition at line 143 of file matrix.hpp.
typedef base_type::const_column_type ecuda::matrix< T, Alloc, P >::const_column_type |
matrix const column container type
Definition at line 145 of file matrix.hpp.
typedef base_type::const_iterator ecuda::matrix< T, Alloc, P >::const_iterator |
const iterator type
Definition at line 148 of file matrix.hpp.
typedef const impl::matrix_kernel_argument<T,Alloc> ecuda::matrix< T, Alloc, P >::const_kernel_argument |
const kernel argument type
Definition at line 153 of file matrix.hpp.
typedef make_const<pointer>::type ecuda::matrix< T, Alloc, P >::const_pointer |
cell const pointer type
Definition at line 140 of file matrix.hpp.
typedef base_type::const_reference ecuda::matrix< T, Alloc, P >::const_reference |
cell const reference type
Definition at line 138 of file matrix.hpp.
typedef base_type::const_reverse_iterator ecuda::matrix< T, Alloc, P >::const_reverse_iterator |
const reverse iterator type
Definition at line 150 of file matrix.hpp.
typedef base_type::const_row_type ecuda::matrix< T, Alloc, P >::const_row_type |
matrix const row container type
Definition at line 144 of file matrix.hpp.
typedef base_type::difference_type ecuda::matrix< T, Alloc, P >::difference_type |
signed integral type
Definition at line 136 of file matrix.hpp.
typedef base_type::iterator ecuda::matrix< T, Alloc, P >::iterator |
iterator type
Definition at line 147 of file matrix.hpp.
typedef impl::matrix_kernel_argument<T,Alloc> ecuda::matrix< T, Alloc, P >::kernel_argument |
kernel argument type
Definition at line 152 of file matrix.hpp.
typedef base_type::pointer ecuda::matrix< T, Alloc, P >::pointer |
cell pointer type
Definition at line 139 of file matrix.hpp.
typedef base_type::reference ecuda::matrix< T, Alloc, P >::reference |
cell reference type
Definition at line 137 of file matrix.hpp.
typedef base_type::reverse_iterator ecuda::matrix< T, Alloc, P >::reverse_iterator |
reverse iterator type
Definition at line 149 of file matrix.hpp.
typedef base_type::row_type ecuda::matrix< T, Alloc, P >::row_type |
matrix row container type
Definition at line 142 of file matrix.hpp.
typedef base_type::size_type ecuda::matrix< T, Alloc, P >::size_type |
unsigned integral type
Definition at line 135 of file matrix.hpp.
typedef base_type::value_type ecuda::matrix< T, Alloc, P >::value_type |
cell data type
Definition at line 133 of file matrix.hpp.
|
inline |
Constructs a matrix with dimensions numberRows x numberColumns filled with copies of elements with value value.
numberRows | number of rows (default: 0) |
numberColumns | number of columns (default: 0) |
value | the value to initialize elements of the matrix with (default: T()) |
allocator | allocator to use for all memory allocations of this container (does not normally need to be specified, by default the internal ecuda pitched memory allocator) |
Definition at line 204 of file matrix.hpp.
|
inline |
Copy constructor.
Constructs the matrix with a copy of the contents of src.
src | Another matrix object of the same type, whose contents are copied. |
Definition at line 219 of file matrix.hpp.
|
inline |
Copy constructor.
Constructs the matrix with a copy of the contents of src.
src | Another matrix object of the same type, whose contents are copied. |
alloc | Allocator to use for all memory allocations of this container. |
Definition at line 237 of file matrix.hpp.
|
inline |
Returns a reference to the element at specified row and column index, with bounds checking.
If the row and column are not within the range of the container, the current kernel will exit and cudaGetLastError will return cudaErrorUnknown.
rowIndex | position of the row to return |
columnIndex | position of the column to return |
Definition at line 470 of file matrix.hpp.
|
inline |
Returns a constant reference to the element at specified row and column index, with bounds checking.
If the row and column are not within the range of the container, the current kernel will exit and cudaGetLastError will return cudaErrorUnknown.
rowIndex | position of the row to return |
columnIndex | position of the column to return |
Definition at line 496 of file matrix.hpp.
|
inline |
Returns a reference to the last element in the container.
This is effectively the element at position (numberRows-1,numberColumns-1). Calling back on an empty container is undefined.
Definition at line 564 of file matrix.hpp.
|
inline |
Returns a reference to the last element in the container.
This is effectively the element at position (numberRows-1,numberColumns-1). Calling back on an empty container is undefined.
Definition at line 582 of file matrix.hpp.
|
inline |
Returns an iterator to the first element of the container.
If the container is empty, the returned iterator will be equal to end().
Definition at line 278 of file matrix.hpp.
|
inline |
Returns an iterator to the first element of the container.
If the container is empty, the returned iterator will be equal to end().
Definition at line 296 of file matrix.hpp.
|
inline |
Returns pointer to the underlying array serving as element storage.
The pointer is such that range [data(),data()+size()) is always a valid range, even if the container is empty.
Definition at line 592 of file matrix.hpp.
|
inline |
Returns pointer to the underlying array serving as element storage.
The pointer is such that range [data(),data()+size()) is always a valid range, even if the container is empty.
Definition at line 602 of file matrix.hpp.
|
inline |
Checks if the container has no elements.
Definition at line 408 of file matrix.hpp.
|
inline |
Returns an iterator to the element following the last element of the container.
The element acts as a placeholder; attempting to access it results in undefined behaviour.
Definition at line 287 of file matrix.hpp.
|
inline |
Returns an iterator to the element following the last element of the container.
The element acts as a placeholder; attempting to access it results in undefined behaviour.
Definition at line 305 of file matrix.hpp.
|
inline |
Assigns a given value to all elements in the container.
value | the value to assign to the elements |
Definition at line 609 of file matrix.hpp.
|
inline |
Returns a reference to the first element in the container.
This is effectively the element at position (0,0). Calling front on an empty container is undefined.
Definition at line 555 of file matrix.hpp.
|
inline |
Returns a reference to the first element in the container.
This is effectively the element at position (0,0). Calling front on an empty container is undefined.
Definition at line 573 of file matrix.hpp.
|
inline |
Returns the allocator associated with the container.
Definition at line 628 of file matrix.hpp.
|
inline |
Gets a view object of a single column of the matrix.
The view object is guaranteed to perform no memory allocations or deallocation, and merely holds a pointer to the start of the row and provides methods to traverse, access, and alter the underlying data.
columnIndex | index of the column to isolate |
Definition at line 445 of file matrix.hpp.
|
inline |
Gets a view object of a single column of the matrix.
The view object is guaranteed to perform no memory allocations or deallocation, and merely holds a pointer to the start of the row and provides methods to traverse and access the underlying data. In addition, the constness of this matrix is enforced so the view will not allow any alterations to the underlying data.
columnIndex | index of the column to isolate |
Definition at line 458 of file matrix.hpp.
|
inline |
Gets a view object of a single row of the matrix.
The view object is guaranteed to perform no memory allocations or deallocation, and merely holds a pointer to the start of the row and provides methods to traverse, access, and alter the underlying data.
rowIndex | of the row to isolate |
Definition at line 420 of file matrix.hpp.
|
inline |
Gets a view object of a single row of the matrix.
The view object is guaranteed to perform no memory allocations or deallocation, and merely holds a pointer to the start of the row and provides methods to traverse and access the underlying data. In addition, the constness of this matrix is enforced so the view will not allow any alterations to the underlying data.
rowIndex | of the row to isolate |
Definition at line 433 of file matrix.hpp.
|
inline |
Returns the maximum number of elements the container is able to hold due to system or library implementation limitations.
Definition at line 365 of file matrix.hpp.
|
inline |
Returns the number of columns in the container.
Definition at line 379 of file matrix.hpp.
|
inline |
Returns the number of rows in the container.
Definition at line 372 of file matrix.hpp.
|
inline |
Checks if the contents of two matrices are not equal.
That is, whether number_rows() != other.number_rows(), number_columns() != other.number_columns(), or whether any element in the this matrix does not compare equal to the element in the other matrix at the same position.
other | container to compare contents with |
Definition at line 656 of file matrix.hpp.
|
inline |
Returns a reference to the element at specified location index. No bounds checking is performed.
This is identical to at() but no bounds checking is performed.
rowIndex | row of the element to return |
columnIndex | column of the element to return |
Definition at line 521 of file matrix.hpp.
|
inline |
Returns a reference to the element at specified location index. No bounds checking is performed.
This is identical to at() but no bounds checking is performed.
rowIndex | row of the element to return |
columnIndex | column of the element to return |
Definition at line 532 of file matrix.hpp.
|
inline |
Compares the contents of two matrices lexicographically.
The order that elements are compared corresponds to their linearized layout (i.e. each column of the first row is compared, then each column of the next row, and so on...).
other | container to compare contents with |
Definition at line 668 of file matrix.hpp.
|
inline |
Compares the contents of two matrices lexicographically.
The order that elements are compared corresponds to their linearized layout (i.e. each column of the first row is compared, then each column of the next row, and so on...).
other | container to compare contents with |
Definition at line 698 of file matrix.hpp.
|
inline |
Definition at line 245 of file matrix.hpp.
|
inline |
Checks if the contents of two matrices are equal.
That is, whether number_rows() == other.number_rows(), number_columns() == other.number_columns() and each element in the this matrix compares equal to the other matrix at the same position.
other | container to compare contents with |
Definition at line 640 of file matrix.hpp.
|
inline |
Compares the contents of two matrices lexicographically.
The order that elements are compared corresponds to their linearized layout (i.e. each column of the first row is compared, then each column of the next row, and so on...).
other | container to compare contents with |
Definition at line 683 of file matrix.hpp.
|
inline |
Compares the contents of two matrices lexicographically.
The order that elements are compared corresponds to their linearized layout (i.e. each column of the first row is compared, then each column of the next row, and so on...).
other | container to compare contents with |
Definition at line 710 of file matrix.hpp.
|
inline |
operator[](rowIndex) alias for get_row(rowIndex)
rowIndex | index of the row to isolate |
Definition at line 539 of file matrix.hpp.
|
inline |
operator[](rowIndex) alias for get_row(rowIndex)
rowIndex | index of the row to isolate |
Definition at line 546 of file matrix.hpp.
|
inline |
Returns a reverse iterator to the first element of the reversed container.
It corresponds to the last element of the non-reversed container.
Definition at line 314 of file matrix.hpp.
|
inline |
Returns a reverse iterator to the first element of the reversed container.
It corresponds to the last element of the non-reversed container.
Definition at line 333 of file matrix.hpp.
|
inline |
Returns a reverse iterator to the element following the last element of the reversed container.
It corresponds to the element preceding the first element of the non-reversed container. This element acts as a placeholder, attempting to access it results in undefined behaviour.
Definition at line 324 of file matrix.hpp.
|
inline |
Returns a reverse iterator to the element following the last element of the reversed container.
It corresponds to the element preceding the first element of the non-reversed container. This element acts as a placeholder, attempting to access it results in undefined behaviour.
Definition at line 343 of file matrix.hpp.
|
inline |
Resizes the container to have dimensions newNumberRows x newNumberColumns.
If the current size is greater in either or both dimensions, the existing elements are truncated.
newNumberRows | new number of rows |
newNumberColumns | new number of columns |
value | the value to initialize the new elements with (default constructed if not specified) |
Definition at line 390 of file matrix.hpp.
|
inline |
Returns the number of elements in the container (numberRows*numberColumns).
Definition at line 357 of file matrix.hpp.
|
inline |
Exchanges the contents of the container with those of the other.
Does not invoke any move, copy, or swap operations on individual elements. All iterators and references remain valid. The past-the-end iterator is invalidated.
Although this can be called from both the host and device, a call from the device only swaps the contents of the containers in the calling thread only.
other | container to exchange the contents with |
Definition at line 622 of file matrix.hpp.
|
friend |
Definition at line 158 of file matrix.hpp.