HCC
HCC is a single-source, C/C++ compiler for heterogeneous computing. It's optimized with HSA (http://www.hsafoundation.com/).
|
The partial specialization array_view<const T,N> represents a view over elements of type const T with rank N. More...
#include <hc.hpp>
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) __CPU__ __HC__ | |
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) __CPU__ __HC__ | |
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) __CPU__ __HC__ | |
Equivalent to construction using "array_view(extent<N>(e0 [, e1 [, e2 ]]), src)". More... | |
array_view (int e0, int e1, const value_type *src) __CPU__ __HC__ | |
array_view (int e0, int e1, int e2, const value_type *src) __CPU__ __HC__ | |
array_view (const array_view< nc_T, N > &other) __CPU__ __HC__ | |
Copy constructor. More... | |
array_view (const array_view &other) __CPU__ __HC__ | |
Copy constructor. More... | |
extent< N > | get_extent () const __CPU__ __HC__ |
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 __CPU__ __HC__ |
Returns a pointer to the first data element underlying this array_view. More... | |
T * | accelerator_pointer () const __CPU__ __HC__ |
Returns a pointer to the device memory 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 __CPU__ __HC__ |
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 index< N > &idx, const extent< N > &ext) const __CPU__ __HC__ |
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 index< N > &idx) const __CPU__ __HC__ |
Equivalent to "section(idx, this->extent – idx)". | |
array_view< const T, N > | section (const extent< N > &ext) const __CPU__ __HC__ |
Equivalent to "section(index<N>(), ext)". | |
template<typename ElementType > | |
array_view< const ElementType, N > | reinterpret_as () const __CPU__ __HC__ |
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 (extent< K > viewExtent) const __CPU__ __HC__ |
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 __CPU__ __HC__ |
int | get_offset () const __CPU__ __HC__ |
index< N > | get_index_base () const __CPU__ __HC__ |
array_view & | operator= (const array_view< T, N > &other) __CPU__ __HC__ |
Assigns the contents of the array_view "other" to this array_view, using a shallow copy. More... | |
array_view & | operator= (const array_view &other) __CPU__ __HC__ |
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 __CPU__ __HC__ |
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 __CPU__ __HC__ |
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 __CPU__ __HC__ |
Equivalent to "array_view<T,N>::operator()(index<N>(i0 [, i1 [, i2 ]]))". More... | |
const T & | operator() (int i0, int i1) const __CPU__ __HC__ |
Equivalent to "array_view<T,N>::operator()(index<N>(i0 [, i1 [, i2 ]]))". More... | |
const T & | operator() (int i0, int i1, int i2) const __CPU__ __HC__ |
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 __CPU__ __HC__ |
This overload is defined for array_view<T,N> where . More... | |
array_view< const T, 1 > | section (int i0, int e0) const __CPU__ __HC__ |
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 __CPU__ __HC__ |
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 __CPU__ __HC__ |
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 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 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.
|
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 hc::extent< N >::size().
|
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. |
|
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 |
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> from which to initialize this new array_view. |
|
inline |
Returns a pointer to the device memory underlying this 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 hc::copy().
|
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 hc::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.
const T& hc::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.
|
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 const 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 |
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 |
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 hc::extent< N >::extent().
|
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 hc::extent< N >::extent().
|
inline |
Returns a const 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 hc::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 hc::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.
|
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.
[in] | av | The target accelerator_view that "this" array_view is synchronized for access on. |
completion_future hc::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.
[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 hc::copy(), and hc::extent< N >::size().