HCC
HCC is a single-source, C/C++ compiler for heterogeneous computing. It's optimized with HSA (http://www.hsafoundation.com/).
Public Types | Public Member Functions | Static Public Attributes | Friends | List of all members
Concurrency::array_view< const T, N > Class Template Reference

The partial specialization array_view<const T,N> represents a view over elements of type const T with rank N. More...

#include <amp.h>

Collaboration diagram for Concurrency::array_view< const T, N >:
Collaboration graph

Public Types

typedef std::remove_const< T >::type nc_T
 
typedef Kalmar::_data_host< const T > acc_buffer_t
 
typedef const T value_type
 The element type of this array.
 

Public Member Functions

 array_view ()=delete
 There is no default constructor for array_view<T,N>.
 
 array_view (const array< T, N > &src)
 Constructs an array_view which is bound to the data contained in the "src" array. More...
 
template<typename Container , class = typename std::enable_if<__is_container<Container>::value>::type>
 array_view (const extent< N > &extent, const Container &src)
 Constructs an array_view which is bound to the data contained in the "src" container. More...
 
 array_view (const extent< N > &ext, const value_type *src)
 Constructs an array_view which is bound to the data contained in the "src" container. More...
 
template<typename Container , class = typename std::enable_if<__is_container<Container>::value>::type>
 array_view (int e0, Container &src)
 Equivalent to construction using "array_view(extent<N>(e0 [, e1 [, e2 ]]), src)". More...
 
template<typename Container , class = typename std::enable_if<__is_container<Container>::value>::type>
 array_view (int e0, int e1, Container &src)
 
template<typename Container , class = typename std::enable_if<__is_container<Container>::value>::type>
 array_view (int e0, int e1, int e2, Container &src)
 
 array_view (int e0, const value_type *src)
 Equivalent to construction using "array_view(extent<N>(e0 [, e1 [, e2 ]]), src)". More...
 
 array_view (int e0, int e1, const value_type *src)
 
 array_view (int e0, int e1, int e2, const value_type *src)
 
 array_view (const array_view &other)
 Copy constructor. More...
 
 array_view (const array_view< nc_T, N > &other)
 Copy constructor. More...
 
extent< N > get_extent () const
 Access the extent that defines the shape of this array_view.
 
accelerator_view get_source_accelerator_view () const
 Access the accelerator_view where the data source of the array_view is located. More...
 
void copy_to (array< T, N > &dest) const
 Copies the data referred to by this array_view to the array given by "dest", as if by calling "copy(*this, dest)". More...
 
void copy_to (const array_view< T, N > &dest) const
 Copies the contents of this array_view to the array_view given by "dest", as if by calling "copy(*this, dest)". More...
 
const T * data () const
 Returns a pointer to the first data element underlying this array_view. More...
 
void refresh () const
 Calling this member function informs the array_view that its bound memory has been modified outside the array_view interface. More...
 
void synchronize () const
 Calling this member function synchronizes any modifications made to the data underlying "this" array_view to its source data container. More...
 
completion_future synchronize_async () const
 An asynchronous version of synchronize, which returns a completion future object. More...
 
void synchronize_to (const accelerator_view &av) const
 Calling this member function synchronizes any modifications made to the data underlying "this" array_view to the specified accelerator_view "av". More...
 
completion_future synchronize_to_async (const accelerator_view &av) const
 An asynchronous version of synchronize_to, which returns a completion future object. More...
 
const T & get_ref (const index< N > &idx) const
 Returns a reference to the element of this array_view that is at the location in N-dimensional space specified by "idx". More...
 
array_view< const T, N > section (const Concurrency::index< N > &idx, const Concurrency::extent< N > &ext) const
 Returns a subsection of the source array view at the origin specified by "idx" and with the extent specified by "ext". More...
 
array_view< const T, N > section (const Concurrency::index< N > &idx) const
 Equivalent to "section(idx, this->extent – idx)".
 
array_view< const T, N > section (const Concurrency::extent< N > &ext) const
 Equivalent to "section(index<N>(), ext)".
 
template<typename ElementType >
array_view< const ElementType, N > reinterpret_as () const
 This member function is similar to "array<T,N>::reinterpret_as", although it only supports array_views of rank 1 (only those guarantee that all elements are laid out contiguously). More...
 
template<int K>
array_view< const T, K > view_as (Concurrency::extent< K > viewExtent) const
 This member function is similar to "array<T,N>::view_as", although it only supports array_views of rank 1 (only those guarantee that all elements are laid out contiguously). More...
 
const acc_buffer_t & internal () const
 
int get_offset () const
 
Concurrency::index< N > get_index_base () const
 
array_viewoperator= (const array_view< T, N > &other)
 Assigns the contents of the array_view "other" to this array_view, using a shallow copy. More...
 
array_viewoperator= (const array_view &other)
 Assigns the contents of the array_view "other" to this array_view, using a shallow copy. More...
 
const T & operator[] (const index< N > &idx) const
 Returns a const reference to the element of this array_view that is at the location in N-dimensional space specified by "idx". More...
 
const T & operator() (const index< N > &idx) const
 Returns a const reference to the element of this array_view that is at the location in N-dimensional space specified by "idx". More...
 
const T & operator() (int i0) const
 Equivalent to "array_view<T,N>::operator()(index<N>(i0 [, i1 [, i2 ]]))". More...
 
const T & operator() (int i0, int i1) const
 Equivalent to "array_view<T,N>::operator()(index<N>(i0 [, i1 [, i2 ]]))". More...
 
const T & operator() (int i0, int i1, int i2) const
 Equivalent to "array_view<T,N>::operator()(index<N>(i0 [, i1 [, i2 ]]))". More...
 
projection_helper< const T, N >::const_result_type operator[] (int i) const
 This overload is defined for array_view<T,N> where $N \ge 2$. More...
 
array_view< const T, 1 > section (int i0, int e0) const
 Equivalent to "section(index<N>(i0 [, i1 [, i2 ]]), extent<N>(e0 [, e1 [, e2 ]]))". More...
 
array_view< const T, 2 > section (int i0, int i1, int e0, int e1) const
 Equivalent to "section(index<N>(i0 [, i1 [, i2 ]]), extent<N>(e0 [, e1 [, e2 ]]))". More...
 
array_view< const T, 3 > section (int i0, int i1, int i2, int e0, int e1, int e2) const
 Equivalent to "section(index<N>(i0 [, i1 [, i2 ]]), extent<N>(e0 [, e1 [, e2 ]]))". More...
 

Static Public Attributes

static const int rank = N
 The rank of this array.
 

Friends

template<typename K , int Q>
struct projection_helper
 
template<typename K , int Q>
struct array_projection_helper
 
template<typename Q , int K>
class array
 
template<typename Q , int K>
class array_view
 
template<typename Q , int K>
bool is_flat (const array_view< Q, K > &) noexcept
 
template<typename Q , int K>
void copy (const array< Q, K > &, const array_view< Q, K > &)
 
template<typename InputIter , typename Q , int K>
void copy (InputIter, InputIter, const array_view< Q, K > &)
 
template<typename Q , int K>
void copy (const array_view< const Q, K > &, array< Q, K > &)
 
template<typename OutputIter , typename Q , int K>
void copy (const array_view< Q, K > &, OutputIter)
 
template<typename Q , int K>
void copy (const array_view< const Q, K > &src, const array_view< Q, K > &dest)
 

Detailed Description

template<typename T, int N>
class Concurrency::array_view< const T, N >

The partial specialization array_view<const T,N> represents a view over elements of type const T with rank N.

The elements are readonly. At the boundary of a call site (such as parallel_for_each), this form of array_view need only be copied to the target accelerator if it isn't already there. It will not be copied out.

Constructor & Destructor Documentation

template<typename T , int N>
Concurrency::array_view< const T, N >::array_view ( const array< T, N > &  src)
inline

Constructs an array_view which is bound to the data contained in the "src" array.

The extent of the array_view is that of the src array, and the origin of the array view is at zero.

Parameters
[in]srcAn array which contains the data that this array_view is bound to.
template<typename T , int N>
template<typename Container , class = typename std::enable_if<__is_container<Container>::value>::type>
Concurrency::array_view< const T, N >::array_view ( const extent< N > &  extent,
const Container &  src 
)
inline

Constructs an array_view which is bound to the data contained in the "src" container.

The extent of the array_view is that given by the "extent" argument, and the origin of the array view is at zero.

Parameters
[in]srcA template argument that must resolve to a linear container that supports .data() and .size() members (such as std::vector or std::array)
[in]extentThe extent of this array_view.
template<typename T , int N>
Concurrency::array_view< const T, N >::array_view ( const extent< N > &  ext,
const value_type src 
)
inline

Constructs an array_view which is bound to the data contained in the "src" container.

The extent of the array_view is that given by the "extent" argument, and the origin of the array view is at zero.

Parameters
[in]srcA pointer to the source data this array_view will bind to. If the number of elements pointed to is less than the size of extent, the behavior is undefined.
[in]extThe extent of this array_view.

References Concurrency::extent< N >::size().

template<typename T , int N>
template<typename Container , class = typename std::enable_if<__is_container<Container>::value>::type>
Concurrency::array_view< const T, N >::array_view ( int  e0,
Container &  src 
)
inline

Equivalent to construction using "array_view(extent<N>(e0 [, e1 [, e2 ]]), src)".

Parameters
[in]e0,e1,e2The component values that will form the extent of this array_view.
[in]srcA template argument that must resolve to a contiguousi container that supports .data() and .size() members (such as std::vector or std::array)
template<typename T , int N>
Concurrency::array_view< const T, N >::array_view ( int  e0,
const value_type src 
)
inline

Equivalent to construction using "array_view(extent<N>(e0 [, e1 [, e2 ]]), src)".

Parameters
[in]e0,e1,e2The component values that will form the extent of this array_view.
[in]srcA pointer to the source data this array_view will bind to. If the number of elements pointed to is less than the size of extent, the behavior is undefined.
template<typename T , int N>
Concurrency::array_view< const T, N >::array_view ( const array_view< const T, N > &  other)
inline

Copy constructor.

Constructs an array_view from the supplied argument other. A shallow copy is performed.

Parameters
[in]otherAn object of type array_view<T,N> or array_view<const T,N> from which to initialize this new array_view.
template<typename T , int N>
Concurrency::array_view< const T, N >::array_view ( const array_view< nc_T, N > &  other)
inline

Copy constructor.

Constructs an array_view from the supplied argument other. A shallow copy is performed.

Parameters
[in]otherAn object of type array_view<T,N> from which to initialize this new array_view.

Member Function Documentation

template<typename T , int N>
void Concurrency::array_view< const T, N >::copy_to ( array< T, N > &  dest) const
inline

Copies the data referred to by this array_view to the array given by "dest", as if by calling "copy(*this, dest)".

Parameters
[in]destAn object of type array <T,N> to which to copy data from this array.

References Concurrency::copy().

template<typename T , int N>
void Concurrency::array_view< const T, N >::copy_to ( const array_view< T, N > &  dest) const
inline

Copies the contents of this array_view to the array_view given by "dest", as if by calling "copy(*this, dest)".

Parameters
[in]destAn object of type array_view<T,N> to which to copy data from this array.

References Concurrency::copy().

template<typename T , int N>
const T* Concurrency::array_view< const T, N >::data ( ) const
inline

Returns a pointer to the first data element underlying this array_view.

This is only available on array_views of rank 1.

When the data source of the array_view is native CPU memory, the pointer returned by data() is valid for the lifetime of the data source.

When the data source underlying the array_view is an array, or the array view is created without a data source, the pointer returned by data() in CPU context is ephemeral and is invalidated when the original data source or any of its views are accessed on an accelerator_view through a parallel_for_each or a copy operation.

Returns
A const pointer to the first element in the linearized array.
template<typename T , int N>
const T& Concurrency::array_view< const T, N >::get_ref ( const index< N > &  idx) const

Returns a reference to the element of this array_view that is at the location in N-dimensional space specified by "idx".

Unlike the other indexing operators for accessing the array_view on the CPU, this method does not implicitly synchronize this array_view's contents to the CPU. After accessing the array_view on a remote location or performing a copy operation involving this array_view, users are responsible to explicitly synchronize the array_view to the CPU before calling this method. Failure to do so results in undefined behavior.

template<typename T , int N>
accelerator_view Concurrency::array_view< const T, N >::get_source_accelerator_view ( ) const
inline

Access the accelerator_view where the data source of the array_view is located.

When the data source of the array_view is native CPU memory, the method returns accelerator(accelerator::cpu_accelerator).default_view. When the data source underlying the array_view is an array, the method returns the accelerator_view where the source array is located.

template<typename T , int N>
const T& Concurrency::array_view< const T, N >::operator() ( const index< N > &  idx) const
inline

Returns a const reference to the element of this array_view that is at the location in N-dimensional space specified by "idx".

Parameters
[in]idxAn object of type index<N> that specifies the location of the element.
template<typename T , int N>
const T& Concurrency::array_view< const T, N >::operator() ( int  i0) const
inline

Equivalent to "array_view<T,N>::operator()(index<N>(i0 [, i1 [, i2 ]]))".

Parameters
[in]i0,i1,i2The component values that will form the index into this array.
template<typename T , int N>
const T& Concurrency::array_view< const T, N >::operator() ( int  i0,
int  i1 
) const
inline

Equivalent to "array_view<T,N>::operator()(index<N>(i0 [, i1 [, i2 ]]))".

Parameters
[in]i0,i1,i2The component values that will form the index into this array.
template<typename T , int N>
const T& Concurrency::array_view< const T, N >::operator() ( int  i0,
int  i1,
int  i2 
) const
inline

Equivalent to "array_view<T,N>::operator()(index<N>(i0 [, i1 [, i2 ]]))".

Parameters
[in]i0,i1,i2The component values that will form the index into this array.
template<typename T , int N>
array_view& Concurrency::array_view< const T, N >::operator= ( const array_view< T, N > &  other)
inline

Assigns the contents of the array_view "other" to this array_view, using a shallow copy.

Both array_views will refer to the same data.

Parameters
[in]otherAn object of type array_view<T,N> from which to copy into this array.
Returns
Returns *this.

References Concurrency::extent< N >::extent().

template<typename T , int N>
array_view& Concurrency::array_view< const T, N >::operator= ( const array_view< const T, N > &  other)
inline

Assigns the contents of the array_view "other" to this array_view, using a shallow copy.

Both array_views will refer to the same data.

Parameters
[in]otherAn object of type array_view<T,N> from which to copy into this array.
Returns
Returns *this.

References Concurrency::extent< N >::extent().

template<typename T , int N>
const T& Concurrency::array_view< const T, N >::operator[] ( const index< N > &  idx) const
inline

Returns a const reference to the element of this array_view that is at the location in N-dimensional space specified by "idx".

Parameters
[in]idxAn object of type index<N> that specifies the location of the element.
template<typename T , int N>
projection_helper<const T, N>::const_result_type Concurrency::array_view< const T, N >::operator[] ( int  i) const
inline

This overload is defined for array_view<T,N> where $N \ge 2$.

This mode of indexing is equivalent to projecting on the most-significant dimension. It allows C-style indexing. For example:

array<float,4> myArray(myExtents, ...);
myArray[index<4>(5,4,3,2)] = 7;
assert(myArray[5][4][3][2] == 7);
Parameters
[in]i0An integer that is the index into the most-significant dimension of this array.
Returns
Returns an array_view whose dimension is one lower than that of this array_view.
template<typename T , int N>
void Concurrency::array_view< const T, N >::refresh ( ) const
inline

Calling this member function informs the array_view that its bound memory has been modified outside the array_view interface.

This will render all cached information stale.

template<typename T , int N>
template<typename ElementType >
array_view<const ElementType, N> Concurrency::array_view< const T, N >::reinterpret_as ( ) const
inline

This member function is similar to "array<T,N>::reinterpret_as", although it only supports array_views of rank 1 (only those guarantee that all elements are laid out contiguously).

The size of the reinterpreted ElementType must evenly divide into the total size of this array_view.

Returns
Returns an array_view from this array_view<T,1> with the element type reinterpreted from T to ElementType.

References Concurrency::extent< N >::size().

template<typename T , int N>
array_view<const T, N> Concurrency::array_view< const T, N >::section ( const Concurrency::index< N > &  idx,
const Concurrency::extent< N > &  ext 
) const
inline

Returns a subsection of the source array view at the origin specified by "idx" and with the extent specified by "ext".

Example:

array<float,2> a(extent<2>(200,100));
array_view<float,2> v1(a); // v1.extent = <200,100>
array_view<float,2> v2 = v1.section(index<2>(15,25), extent<2>(40,50));
assert(v2(0,0) == v1(15,25));
Parameters
[in]idxProvides the offset/origin of the resulting section.
[in]extProvides the extent of the resulting section.
Returns
Returns a subsection of the source array at specified origin, and with the specified extent.

Referenced by Concurrency::array< T, N >::section().

template<typename T , int N>
array_view<const T, 1> Concurrency::array_view< const T, N >::section ( int  i0,
int  e0 
) const
inline

Equivalent to "section(index<N>(i0 [, i1 [, i2 ]]), extent<N>(e0 [, e1 [, e2 ]]))".

Parameters
[in]i0,i1,i2The component values that will form the origin of the section
[in]e0,e1,e2The component values that will form the extent of the section
template<typename T , int N>
array_view<const T, 2> Concurrency::array_view< const T, N >::section ( int  i0,
int  i1,
int  e0,
int  e1 
) const
inline

Equivalent to "section(index<N>(i0 [, i1 [, i2 ]]), extent<N>(e0 [, e1 [, e2 ]]))".

Parameters
[in]i0,i1,i2The component values that will form the origin of the section
[in]e0,e1,e2The component values that will form the extent of the section
template<typename T , int N>
array_view<const T, 3> Concurrency::array_view< const T, N >::section ( int  i0,
int  i1,
int  i2,
int  e0,
int  e1,
int  e2 
) const
inline

Equivalent to "section(index<N>(i0 [, i1 [, i2 ]]), extent<N>(e0 [, e1 [, e2 ]]))".

Parameters
[in]i0,i1,i2The component values that will form the origin of the section
[in]e0,e1,e2The component values that will form the extent of the section
template<typename T , int N>
void Concurrency::array_view< const T, N >::synchronize ( ) const
inline

Calling this member function synchronizes any modifications made to the data underlying "this" array_view to its source data container.

For example, for an array_view on system memory, if the data underlying the view are modified on a remote accelerator_view through a parallel_for_each invocation, calling synchronize ensures that the modifications are synchronized to the source data and will be visible through the system memory pointer which the array_view was created over.

For writable array_view objects, callers of this functional can optionally specify the type of access desired on the source data container through the "type" parameter. For example specifying a "access_type_read" (which is also the default value of the parameter) indicates that the data has been synchronized to its source location only for reading. On the other hand, specifying an access_type of "access_type_read_write" synchronizes the data to its source location both for reading and writing; i.e. any modifications to the source data directly through the source data container are legal after synchronizing the array_view with write access and before subsequently accessing the array_view on another remote location.

It is advisable to be precise about the access_type specified in the synchronize call; i.e. if only write access it required, specifying access_type_write may yield better performance that calling synchronize with "access_type_read_write" since the later may require any modifications made to the data on remote locations to be synchronized to the source location, which is unnecessary if the contents are intended to be overwritten without reading.

template<typename T , int N>
completion_future Concurrency::array_view< const T, N >::synchronize_async ( ) const
inline

An asynchronous version of synchronize, which returns a completion future object.

When the future is ready, the synchronization operation is complete.

Returns
An object of type completion_future that can be used to determine the status of the asynchronous operation or can be used to chain other operations to be executed after the completion of the asynchronous operation.
template<typename T , int N>
void Concurrency::array_view< const T, N >::synchronize_to ( const accelerator_view av) const
inline

Calling this member function synchronizes any modifications made to the data underlying "this" array_view to the specified accelerator_view "av".

For example, for an array_view on system memory, if the data underlying the view is modified on the CPU, and synchronize_to is called on "this" array_view, then the array_view contents are cached on the specified accelerator_view location.

Parameters
[in]avThe target accelerator_view that "this" array_view is synchronized for access on.
template<typename T , int N>
completion_future Concurrency::array_view< const T, N >::synchronize_to_async ( const accelerator_view av) const

An asynchronous version of synchronize_to, which returns a completion future object.

When the future is ready, the synchronization operation is complete.

Parameters
[in]avThe target accelerator_view that "this" array_view is synchronized for access on.
[in]typeAn argument of type "access_type" which specifies the type of access on the data source that the array_view is synchronized for.
Returns
An object of type completion_future that can be used to determine the status of the asynchronous operation or can be used to chain other operations to be executed after the completion of the asynchronous operation.
template<typename T , int N>
template<int K>
array_view<const T, K> Concurrency::array_view< const T, N >::view_as ( Concurrency::extent< K >  viewExtent) const
inline

This member function is similar to "array<T,N>::view_as", although it only supports array_views of rank 1 (only those guarantee that all elements are laid out contiguously).

Returns
Returns an array_view from this array_view<T,1> with the rank changed to K from 1.

References Concurrency::copy(), and Concurrency::extent< N >::size().


The documentation for this class was generated from the following file: