38 #ifndef ECUDA_CUBE_HPP
39 #define ECUDA_CUBE_HPP
61 template<
typename T,
class Alloc>
class cube_kernel_argument;
128 template<
typename T,
class Alloc=device_pitch_allocator<T>,
class P=shared_ptr<T> >
129 class cube :
private model::device_contiguous_row_matrix< T, P > {
132 typedef model::device_contiguous_row_matrix< T, P > base_type;
144 typedef model::device_sequence< value_type, striding_padded_ptr<value_type,typename ecuda::add_pointer<value_type>::type> >
row_type;
145 typedef model::device_sequence< value_type, striding_padded_ptr<value_type,typename ecuda::add_pointer<value_type>::type> >
column_type;
146 typedef model::device_contiguous_sequence<value_type >
depth_type;
147 typedef model::device_sequence< const value_type, striding_padded_ptr<const value_type,typename ecuda::add_pointer<const value_type>::type> >
const_row_type;
148 typedef model::device_sequence< const value_type, striding_padded_ptr<const value_type,typename ecuda::add_pointer<const value_type>::type> >
const_column_type;
156 typedef model::device_matrix< value_type, striding_padded_ptr<value_type,typename ecuda::add_pointer<value_type>::type> >
slice_xy_type;
157 typedef model::device_contiguous_row_matrix< value_type, typename ecuda::add_pointer<value_type>::type >
slice_xz_type;
158 typedef model::device_contiguous_row_matrix< value_type, typename ecuda::add_pointer<value_type>::type >
slice_yz_type;
159 typedef model::device_matrix< const value_type, striding_padded_ptr<const value_type,typename ecuda::add_pointer<const value_type>::type> >
const_slice_xy_type;
160 typedef model::device_contiguous_row_matrix< const value_type, typename ecuda::add_pointer<const value_type>::type >
const_slice_xz_type;
161 typedef model::device_contiguous_row_matrix< const value_type, typename ecuda::add_pointer<const value_type>::type >
const_slice_yz_type;
170 template<
typename U,
class Alloc2,
class Q>
friend class cube;
184 base_type::get_pointer() = other.get_pointer();
185 allocator = other.allocator;
186 numberRows = other.numberRows;
195 typedef typename ecuda::add_pointer<value_type>::type raw_pointer_type;
196 shared_ptr<value_type> sp( naked_cast<raw_pointer_type>(p) );
197 padded_ptr< value_type, shared_ptr<value_type> > pp( sp, p.get_pitch() );
216 const Alloc& allocator = Alloc()
217 ) : base_type(
pointer(), numberRows*numberColumns, numberDepths ), numberRows(numberRows), allocator(allocator)
232 numberRows( src.numberRows ),
250 numberRows( src.numberRows ),
266 #ifdef ECUDA_CPP11_AVAILABLE
267 __HOST__ cube(
cube&& src ) : base_type(std::move(src)), numberRows(std::move(src.numberRows)), allocator(std::move(src.allocator)) {}
277 base_type::operator=(std::move(src));
278 allocator = std::move(src.allocator);
279 numberRows = std::move(src.numberRows);
414 #ifdef ECUDA_CPP11_AVAILABLE
430 typedef typename make_unmanaged<typename base_type::pointer>::type unmanaged_pointer_type;
431 unmanaged_pointer_type ptr = unmanaged_cast( base_type::get_pointer() );
432 ptr.skip_bytes( columnIndex*ptr.get_pitch() );
434 typename row_type::pointer ptr2( ptr.get(),
number_columns()*ptr.get_pitch() );
447 typedef typename make_unmanaged<typename base_type::pointer>::type unmanaged_pointer_type;
448 unmanaged_pointer_type ptr = unmanaged_cast( base_type::get_pointer() );
451 typename column_type::pointer ptr2( ptr.get(), ptr.get_pitch() );
464 typedef typename make_unmanaged<typename base_type::pointer>::type unmanaged_pointer_type;
465 unmanaged_pointer_type ptr = unmanaged_cast( base_type::get_pointer() );
479 typedef typename make_unmanaged_const<typename base_type::pointer>::type unmanaged_pointer_type;
480 unmanaged_pointer_type ptr = unmanaged_cast( base_type::get_pointer() );
481 ptr.skip_bytes( columnIndex*ptr.get_pitch() );
483 typename const_row_type::pointer ptr2( ptr.get(),
number_columns()*ptr.get_pitch() );
496 typedef typename make_unmanaged_const<typename base_type::pointer>::type unmanaged_pointer_type;
497 unmanaged_pointer_type ptr = unmanaged_cast( base_type::get_pointer() );
500 typename const_column_type::pointer ptr2( ptr.get(), ptr.get_pitch() );
513 typedef typename make_unmanaged_const<typename base_type::pointer>::type unmanaged_pointer_type;
514 unmanaged_pointer_type ptr = unmanaged_cast( base_type::get_pointer() );
527 typedef typename make_unmanaged<typename base_type::pointer>::type unmanaged_pointer_type;
528 unmanaged_pointer_type ptr = unmanaged_cast( base_type::get_pointer() );
541 typedef typename make_unmanaged<typename base_type::pointer>::type unmanaged_pointer_type;
542 unmanaged_pointer_type ptr = unmanaged_cast( base_type::get_pointer() );
544 typename slice_xy_type::pointer ptr2( ptr.get(), ptr.get_pitch() );
556 typedef typename make_unmanaged<typename base_type::pointer>::type unmanaged_pointer_type;
557 unmanaged_pointer_type ptr = unmanaged_cast( base_type::get_pointer() );
558 typename slice_xz_type::pointer ptr2( ptr.get(), ptr.get_pitch()*
number_columns() );
571 typedef typename make_unmanaged_const<typename base_type::pointer>::type unmanaged_pointer_type;
572 unmanaged_pointer_type ptr = unmanaged_cast( base_type::get_pointer() );
585 typedef typename make_unmanaged_const<typename base_type::pointer>::type unmanaged_pointer_type;
586 unmanaged_pointer_type ptr = unmanaged_cast( base_type::get_pointer() );
588 typename const_slice_xy_type::pointer ptr2( ptr.get(), ptr.get_pitch() );
600 typedef typename make_unmanaged_const<typename base_type::pointer>::type unmanaged_pointer_type;
601 unmanaged_pointer_type ptr = unmanaged_cast( base_type::get_pointer() );
602 typename const_slice_xz_type::pointer ptr2( ptr.get(), ptr.get_pitch()*
number_columns() );
622 throw std::out_of_range(
EXCEPTION_MSG(
"ecuda::cube::at() row, column and/or depth index parameter is out of range") );
631 return base_type::at( rowIndex*
number_columns()+columnIndex, depthIndex );
649 throw std::out_of_range(
EXCEPTION_MSG(
"ecuda::cube::at() row, column and/or depth index parameter is out of range") );
658 return base_type::at( rowIndex*
number_columns()+columnIndex, depthIndex );
712 cube newCube( newNumberRows, newNumberColumns, newNumberDepths, value,
get_allocator() );
721 numberRows = newNumberRows;
745 template<
typename T,
class Alloc=device_pitch_allocator<T> >
746 class cube_kernel_argument :
public cube<T,Alloc,typename ecuda::add_pointer<T>::type>
750 typedef cube<T,Alloc,typename ecuda::add_pointer<T>::type> base_type;
754 __HOST__ cube_kernel_argument(
const cube<T,Alloc,P>& src ) : base_type( src, ecuda::true_type() ) {}
756 __HOST__ __DEVICE__ cube_kernel_argument(
const cube_kernel_argument& src ) : base_type( src, ecuda::true_type() ) {}
759 __HOST__ cube_kernel_argument& operator=(
const cube<T,Alloc,P>& src )
761 base_type::shallow_assign( src );
765 #ifdef ECUDA_CPP11_AVAILABLE
766 cube_kernel_argument( cube_kernel_argument&& src ) : base_type(std::move(src)) {}
768 cube_kernel_argument& operator=( cube_kernel_argument&& src )
770 base_type::operator=(std::move(src));
base_type::iterator iterator
iterator type
base_type::value_type value_type
cell data type
__HOST__ __DEVICE__ reverse_iterator rend() __NOEXCEPT__
Returns a reverse iterator to the element following the last element of the reversed container...
__HOST__ allocator_type get_allocator() const
Returns the allocator associated with the container.
__HOST__ cube(const cube &src, const allocator_type &alloc)
Copy constructor.
__HOST__ __DEVICE__ OutputIterator copy(InputIterator first, InputIterator last, OutputIterator result)
Replacement for std::copy.
base_type::pointer pointer
cell pointer type
__HOST__ __DEVICE__ const_slice_yz_type get_yz(const size_type rowIndex) const
Gets a view of the matrix of elements at a single row.
__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__ const_pointer data() const __NOEXCEPT__
Returns pointer to the underlying 2D memory serving as element storage.
__DEVICE__ reference operator()(const size_type rowIndex, const size_type columnIndex, const size_type depthIndex)
Returns a reference to the element at specified location index. No bounds checking is performed...
const impl::cube_kernel_argument< T, Alloc > const_kernel_argument
const kernel argument type
__HOST__ __DEVICE__ slice_yz_type operator[](const size_type rowIndex)
operator[](rowIndex) alias for get_yz(rowIndex)
__HOST__ __DEVICE__ reverse_iterator rbegin() __NOEXCEPT__
Returns a reverse iterator to the first element of the reversed container.
__HOST__ void resize(const size_type newNumberRows, const size_type newNumberColumns, const size_type newNumberDepths, const value_type &value=value_type())
Resizes the container to have dimensions newNumberRows x newNumberColumns x newNumberDepths.
__HOST__ __DEVICE__ slice_xy_type get_xy(const size_type depthIndex)
Gets a view of the matrix of elements at a single depth.
__HOST__ cube(const size_type numberRows=0, const size_type numberColumns=0, const size_type numberDepths=0, const value_type &value=value_type(), const Alloc &allocator=Alloc())
Constructs a cube with dimensions numberRows x numberColumns x numberDepths filled with copies of ele...
model::device_matrix< value_type, striding_padded_ptr< value_type, typename ecuda::add_pointer< value_type >::type > > slice_xy_type
xy section of a cube at a fixed depth
__HOST__ __DEVICE__ const_row_type get_row(const size_type columnIndex, const size_type depthIndex) const
Gets a view of the sequence of elements forming a single row.
model::device_matrix< const value_type, striding_padded_ptr< const value_type, typename ecuda::add_pointer< const value_type >::type > > const_slice_xy_type
xy section of a cube at a fixed depth
__HOST__ __DEVICE__ slice_xz_type get_xz(const size_type columnIndex)
Gets a view of the matrix of elements at a single column.
__HOST__ __DEVICE__ const_depth_type get_depth(const size_type rowIndex, const size_type columnIndex) const
Gets a view of the sequence of elements forming a single depth.
base_type::reference reference
cell reference type
__DEVICE__ const_reference at(size_type rowIndex, size_type columnIndex, size_type depthIndex) const
Returns a constant reference to the element at specified row, column, and depth index, with bounds checking.
model::device_contiguous_row_matrix< value_type, typename ecuda::add_pointer< value_type >::type > slice_xz_type
xz section of a cube at a fixed column
__HOST__ __DEVICE__ const_slice_xy_type get_xy(const size_type depthIndex) const
Gets a view of the matrix of elements at a single depth.
Alloc allocator_type
allocator type
__HOST__ __DEVICE__ pointer data() __NOEXCEPT__
Returns pointer to the underlying 2D memory serving as element storage.
base_type::const_reverse_iterator const_reverse_iterator
const reverse iterator type
__HOST__ __DEVICE__ slice_yz_type get_yz(const size_type rowIndex)
Gets a view of the matrix of elements at a single row.
__HOST__ __DEVICE__ size_type number_columns() const __NOEXCEPT__
Returns the number of columns in the container.
model::device_contiguous_sequence< const value_type > const_depth_type
cube const depth container type
__HOST__ __DEVICE__ const_iterator begin() const __NOEXCEPT__
Returns an iterator to the first element of the container.
__HOST__ __DEVICE__ iterator end() __NOEXCEPT__
Returns an iterator to the element following the last element of the container.
__HOST__ __DEVICE__ void swap(T &a, T &b) __NOEXCEPT__
A resizable cube stored in device memory.
base_type::const_iterator const_iterator
const iterator type
make_const< pointer >::type const_pointer
cell const pointer type
model::device_contiguous_row_matrix< const value_type, typename ecuda::add_pointer< const value_type >::type > const_slice_xz_type
const xz section of a cube at a fixed row
__HOST__ __DEVICE__ size_type number_depths() const __NOEXCEPT__
Returns the number of depths in the container.
__HOST__ __DEVICE__ const_iterator end() const __NOEXCEPT__
Returns an iterator to the element following the last element of the container.
__DEVICE__ reference at(size_type rowIndex, size_type columnIndex, size_type depthIndex)
Returns a reference to the element at specified row, column, and depth index, with bounds checking...
__HOST__ __DEVICE__ const_reverse_iterator rbegin() const __NOEXCEPT__
Returns a reverse iterator to the first element of the reversed container.
model::device_sequence< value_type, striding_padded_ptr< value_type, typename ecuda::add_pointer< value_type >::type > > row_type
cube row container type
__HOST__ cube(const cube &src)
Copy constructor.
__HOST__ __DEVICE__ const_slice_yz_type operator[](const size_type rowIndex) const
operator[](rowIndex) alias for get_yz(rowIndex)
__HOST__ __DEVICE__ void fill(const value_type &value)
Assigns a given value to all elements in the container.
__HOST__ __DEVICE__ depth_type get_depth(const size_type rowIndex, const size_type columnIndex)
Gets a view of the sequence of elements forming a single depth.
__HOST__ __DEVICE__ size_type number_rows() const __NOEXCEPT__
Returns the number of rows in the container.
base_type::const_reference const_reference
cell const reference type
__HOST__ __DEVICE__ size_type size() const __NOEXCEPT__
Returns the number of elements in the container.
model::device_sequence< value_type, striding_padded_ptr< value_type, typename ecuda::add_pointer< value_type >::type > > column_type
cube column container type
__HOST__ __DEVICE__ const T & min(const T &a, const T &b)
__DEVICE__ const_reference operator()(const size_type rowIndex, const size_type columnIndex, const size_type depthIndex) const
Returns a reference to the element at specified location index. No bounds checking is performed...
__HOST__ __DEVICE__ row_type get_row(const size_type columnIndex, const size_type depthIndex)
Gets a view of the sequence of elements forming a single row.
__HOST__ __DEVICE__ const_slice_xz_type get_xz(const size_type columnIndex) const
Gets a view of the matrix of elements at a single column.
__HOST__ __DEVICE__ column_type get_column(const size_type rowIndex, const size_type depthIndex)
Gets a view of the sequence of elements forming a single column.
model::device_contiguous_row_matrix< const value_type, typename ecuda::add_pointer< const value_type >::type > const_slice_yz_type
const yz section of a cube at a fixed row
base_type::size_type size_type
unsigned integral type
__HOST__ __DEVICE__ bool empty() const __NOEXCEPT__
Checks if the container has no elements.
base_type::reverse_iterator reverse_iterator
reverse iterator type
model::device_contiguous_sequence< value_type > depth_type
cube depth container type
model::device_sequence< const value_type, striding_padded_ptr< const value_type, typename ecuda::add_pointer< const value_type >::type > > const_column_type
cube const column container type
__DEVICE__ void threadfence()
model::device_contiguous_row_matrix< value_type, typename ecuda::add_pointer< value_type >::type > slice_yz_type
yz section of a cube at a fixed row
__HOST__ cube & operator=(const cube &src)
impl::cube_kernel_argument< T, Alloc > kernel_argument
kernel argument type
__HOST__ __DEVICE__ iterator begin() __NOEXCEPT__
Returns an iterator to the first element of the container.
model::device_sequence< const value_type, striding_padded_ptr< const value_type, typename ecuda::add_pointer< const value_type >::type > > const_row_type
cube const row container type
__HOST__ __DEVICE__ const_column_type get_column(const size_type rowIndex, const size_type depthIndex) const
Gets a view of the sequence of elements forming a single column.
base_type::difference_type difference_type
signed integral type
__HOST__ __DEVICE__ void fill(ForwardIterator first, ForwardIterator last, const T &val)