HCC
HCC is a single-source, C/C++ compiler for heterogeneous computing. It's optimized with HSA (http://www.hsafoundation.com/).
|
The array_view<T,N> type represents a possibly cached view into the data held in an array<T,N>, or a section thereof. More...
#include <amp.h>
Public Types | |
typedef std::remove_const< T >::type | nc_T |
typedef Kalmar::_data_host< T > | acc_buffer_t |
typedef 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 (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 Concurrency::extent< N > &extent, Container &src) | |
Constructs an array_view which is bound to the data contained in the "src" container. More... | |
array_view (const Concurrency::extent< N > &ext, value_type *src) | |
Constructs an array_view which is bound to the data contained in the "src" container. More... | |
array_view (const Concurrency::extent< N > &ext) | |
Constructs an array_view which is not bound to a data source. 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, value_type *src) | |
Equivalent to construction using "array_view(extent<N>(e0 [, e1 [, e2 ]]), src)". More... | |
array_view (int e0, int e1, value_type *src) | |
array_view (int e0, int e1, int e2, value_type *src) | |
array_view (int e0) | |
Equivalent to construction using "array_view(extent<N>(e0 [, e1 [, e2 ]]))". More... | |
array_view (int e0, int e1) | |
array_view (int e0, int e1, int e2) | |
array_view (const array_view &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... | |
array_view & | operator= (const array_view &other) |
Assigns the contents of the array_view "other" to this array_view, using a shallow copy. 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 &dest) const |
Copies the contents of this array_view to the array_view given by "dest", as if by calling "copy(*this, dest)". More... | |
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... | |
void | discard_data () const |
Indicates to the runtime that it may discard the current logical contents of this array_view. More... | |
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< 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< T, N > | section (const Concurrency::index< N > &idx) const |
Equivalent to "section(idx, this->extent – idx)". | |
array_view< T, N > | section (const Concurrency::extent< N > &ext) const |
Equivalent to "section(index<N>(), ext)". | |
template<typename ElementType > | |
array_view< 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< 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... | |
template<int D0, int D1 = 0, int D2 = 0> | |
T & | operator[] (const tiled_index< D0, D1, D2 > &idx) const |
const acc_buffer_t & | internal () const |
int | get_offset () const |
Concurrency::index< N > | get_index_base () const |
T & | operator[] (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... | |
T & | operator() (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... | |
T & | operator() (int i0, int i1) const |
Equivalent to "array_view<T,N>::operator()(index<N>(i0 [, i1 [, i2 ]]))". More... | |
T & | operator() (int i0, int i1, int i2) const |
Equivalent to "array_view<T,N>::operator()(index<N>(i0 [, i1 [, i2 ]]))". More... | |
projection_helper< T, N >::result_type | operator[] (int i) const |
This overload is defined for array_view<T,N> where . More... | |
projection_helper< T, N >::result_type | operator() (int i0) const |
This overload is defined for array_view<T,N> where . More... | |
array_view< T, 1 > | section (int i0, int e0) const |
Equivalent to "section(index<N>(i0 [, i1 [, i2 ]]), extent<N>(e0 [, e1 [, e2 ]]))". More... | |
array_view< 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< 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) |
The array_view<T,N> type represents a possibly cached view into the data held in an array<T,N>, or a section thereof.
It also provides such views over native CPU data. It exposes an indexing interface congruent to that of array<T,N>.
|
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.
[in] | src | An array which contains the data that this array_view is bound to. |
|
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.
[in] | src | A template argument that must resolve to a linear container that supports .data() and .size() members (such as std::vector or std::array) |
[in] | extent | The extent of this array_view. |
|
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.
[in] | src | A 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] | ext | The extent of this array_view. |
References Concurrency::extent< N >::size().
|
inlineexplicit |
Constructs an array_view which is not bound to a data source.
The extent of the array_view is that given by the "extent" argument, and the origin of the array view is at zero. An array_view thus constructed represents uninitialized data and the underlying allocations are created lazily as the array_view is accessed on different locations (on an accelerator_view or on the CPU).
[in] | ext | The extent of this array_view. |
|
inline |
Equivalent to construction using "array_view(extent<N>(e0 [, e1 [, e2 ]]), src)".
[in] | e0,e1,e2 | The component values that will form the extent of this array_view. |
[in] | src | A template argument that must resolve to a contiguousi container that supports .data() and .size() members (such as std::vector or std::array) |
|
inline |
Equivalent to construction using "array_view(extent<N>(e0 [, e1 [, e2 ]]), src)".
[in] | e0,e1,e2 | The component values that will form the extent of this array_view. |
[in] | src | A 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. |
|
inlineexplicit |
Equivalent to construction using "array_view(extent<N>(e0 [, e1 [, e2 ]]))".
[in] | e0,e1,e2 | The component values that will form the extent of this array_view. |
|
inline |
Copy constructor.
Constructs an array_view from the supplied argument other. A shallow copy is performed.
[in] | other | An object of type array_view<T,N> or array_view<const T,N> from which to initialize this new array_view. |
|
inline |
Copies the data referred to by this array_view to the array given by "dest", as if by calling "copy(*this, dest)".
[in] | dest | An object of type array <T,N> to which to copy data from this array. |
References Concurrency::copy(), and Concurrency::array< T, N >::get_extent().
|
inline |
Copies the contents of this array_view to the array_view given by "dest", as if by calling "copy(*this, dest)".
[in] | dest | An object of type array_view<T,N> to which to copy data from this array. |
References Concurrency::copy().
|
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.
|
inline |
Indicates to the runtime that it may discard the current logical contents of this array_view.
This is an optimization hint to the runtime used to avoid copying the current contents of the view to a target accelerator_view, and its use is recommended if the existing content is not needed.
T& Concurrency::array_view< 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.
|
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.
|
inline |
Returns a reference to the element of this array_view that is at the location in N-dimensional space specified by "idx".
[in] | idx | An object of type index<N> that specifies the location of the element. |
|
inline |
Equivalent to "array_view<T,N>::operator()(index<N>(i0 [, i1 [, i2 ]]))".
[in] | i0,i1,i2 | The component values that will form the index into this array. |
|
inline |
Equivalent to "array_view<T,N>::operator()(index<N>(i0 [, i1 [, i2 ]]))".
[in] | i0,i1,i2 | The component values that will form the index into this array. |
|
inline |
This overload is defined for array_view<T,N> where .
This mode of indexing is equivalent to projecting on the most-significant dimension. It allows C-style indexing. For example:
[in] | i0 | An integer that is the index into the most-significant dimension of this array. |
|
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.
[in] | other | An object of type array_view<T,N> from which to copy into this array. |
References Concurrency::extent< N >::extent().
|
inline |
Returns a reference to the element of this array_view that is at the location in N-dimensional space specified by "idx".
[in] | idx | An object of type index<N> that specifies the location of the element. |
|
inline |
This overload is defined for array_view<T,N> where .
This mode of indexing is equivalent to projecting on the most-significant dimension. It allows C-style indexing. For example:
[in] | i0 | An integer that is the index into the most-significant dimension of this array. |
|
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.
|
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.
References Concurrency::extent< N >::size().
|
inline |
Returns a subsection of the source array view at the origin specified by "idx" and with the extent specified by "ext".
Example:
[in] | idx | Provides the offset/origin of the resulting section. |
[in] | ext | Provides the extent of the resulting section. |
Referenced by Concurrency::array< T, N >::section().
|
inline |
Equivalent to "section(index<N>(i0 [, i1 [, i2 ]]), extent<N>(e0 [, e1 [, e2 ]]))".
[in] | i0,i1,i2 | The component values that will form the origin of the section |
[in] | e0,e1,e2 | The component values that will form the extent of the section |
|
inline |
Equivalent to "section(index<N>(i0 [, i1 [, i2 ]]), extent<N>(e0 [, e1 [, e2 ]]))".
[in] | i0,i1,i2 | The component values that will form the origin of the section |
[in] | e0,e1,e2 | The component values that will form the extent of the section |
|
inline |
Equivalent to "section(index<N>(i0 [, i1 [, i2 ]]), extent<N>(e0 [, e1 [, e2 ]]))".
[in] | i0,i1,i2 | The component values that will form the origin of the section |
[in] | e0,e1,e2 | The component values that will form the extent of the section |
|
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.
[in] | type | An argument of type "access_type" which specifies the type of access on the data source that the array_view is synchronized for. |
|
inline |
An asynchronous version of synchronize, which returns a completion future object.
When the future is ready, the synchronization operation is complete.
|
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.
For writable array_view objects, callers of this functional can optionally specify the type of access desired on the specified target accelerator_view "av", 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 "av" only for reading. On the other hand, specifying an access_type of "access_type_read_write" synchronizes the data to "av" both for reading and writing; i.e. any modifications to the data on "av" are legal after synchronizing the array_view with write access and before subsequently accessing the array_view on a location other than "av".
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 "av", which is unnecessary if the contents are intended to be immediately overwritten without reading.
[in] | av | The target accelerator_view that "this" array_view is synchronized for access on. |
[in] | type | An argument of type "access_type" which specifies the type of access on the data source that the array_view is synchronized for. |
completion_future Concurrency::array_view< 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.
[in] | av | The target accelerator_view that "this" array_view is synchronized for access on. |
[in] | type | An argument of type "access_type" which specifies the type of access on the data source that the array_view is synchronized for. |
|
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).
References Concurrency::copy(), Concurrency::tiled_index< D0, D1, D2 >::global, and Concurrency::extent< N >::size().