Compartilhar via


array_view Class

Represents an N-dimensional view over the data held in another container.

template <
   typename _Value_type,
   int _Rank = 1
>
class array_view : public _Array_view_base<_Rank, sizeof(_Value_type)/sizeof(int)>;

template <
   typename _Value_type,
   int _Rank
>
class array_view<const _Value_type, _Rank> : public _Array_view_base<_Rank, sizeof(_Value_type)/sizeof(int)>;

Parameters

  • _Value_type
    The data type of the elements in the array_view object.

  • _Rank
    The rank of the array_view object.

Members

Public Constructors

Name

Description

array_view::array_view Constructor

Initializes a new instance of the array_view class. There is no default constructor for array<T,N>. All constructors are restricted to run on the CPU only and cannot be executed on a Direct3D target.

array_view::~array_view Destructor

Destroys the array_view object.

Public Methods

Name

Description

array_view::copy_to Method

Copies the contents of the array_view object to the specified destination by calling copy(*this, dest).

array_view::data Method

Returns a pointer to the raw data of the array_view.

array_view::discard_data Method

Discards the current data underlying this view.

array_view::get_extent Method

Returns the extent object of the array_view object.

array_view::get_ref Method

Returns a reference to the indexed element.

array_view::get_source_accelerator_view Method

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

array_view::refresh Method

Notifies the array_view object that its bound memory has been modified outside the array_view interface. A call to this method renders all cached information stale.

array_view::reinterpret_as Method

Returns a one-dimensional array that contains all the elements in the array_view object.

array_view::section Method

Returns a subsection of the array_view object that's at the specified origin and, optionally, that has the specified extent.

array_view::synchronize Method

Synchronizes any modifications made to the array_view object back to its source data.

array_view::synchronize_async Method

Asynchronously synchronizes any modifications made to the array_view object back to its source data.

array_view::synchronize_to Method

Synchronizes any modifications made to the array_view object to the specified accelerator_view.

array_view::synchronize_to_async Method

Asynchronously synchronizes any modifications made to the array_view object to the specified accelerator_view.

array_view::view_as Method

Produces an array_view object of a different rank using this array_view object’s data.

Public Operators

Name

Description

array_view::operator() Operator

Returns the value of the element that is specified by the parameter or parameters.

array_view::operator[] Operator

Returns the element that is specified by the parameters.

array_view::operator= Operator

Copies the contents of the specified array_view object into this one.

Public Constants

Name

Description

array_view::rank Constant

Stores the rank of the array_view object.

Data Members

Name

Description

array_view::extent Data Member

Gets the extent object that defines the shape of the array_view object.

array_view::source_accelerator_view Data Member

Gets the accelerator_view where the data source of the array_view is located

array_view::value_type Data Member

The value type of the array_view and the bound array.

Remarks

The array_view class represents a view into the data that is contained in an array object or a subsection of an array object.

You can access the array_view object where the source data is located (locally) or on a different accelerator or a coherence domain (remotely). When you access the object remotely, views are copied and cached as necessary. Except for the effects of automatic caching, array_view objects have a performance profile similar to that of array objects. There is a small performance penalty when you access the data through views.

There are three remote usage scenarios:

  • A view to a system memory pointer is passed by means of a parallel_for_each call to an accelerator and accessed on the accelerator.

  • A view to an array located on an accelerator is passed by means of a parallel_for_each call to another accelerator and is accessed there.

  • A view to an array located on an accelerator is accessed on the CPU.

In any one of these scenarios, the referenced views are copied by the runtime to the remote location and, if modified by the calls to the array_view object, are copied back to the local location. The runtime might optimize the process of copying changes back, might copy only changed elements, or might copy unchanged portions also. Overlapping array_view objects on one data source are not guaranteed to maintain referential integrity in a remote location.

You must synchronize any multithreaded access to the same data source.

The runtime makes the following guarantees regarding the caching of data in array_view objects:

  • All well-synchronized accesses to an array object and an array_view object on it in program order obey a serial happens-before relationship.

  • All well-synchronized accesses to overlapping array_view objects on the same accelerator on a single array object are aliased through the array object. They induce a total occurs-before relationship which obeys program order. There is no caching. If the array_view objects are executing on different accelerators, the order of access is undefined, creating a race condition.

When you create an array_view object using a pointer in system memory, you must change the view array_view object only through the array_view pointer. Alternatively, you must call refresh() on one of the array_view objects that are attached to the system pointer, if the underlying native memory is changed directly, instead of through the array_view object.

Either action notifies the array_view object that the underlying native memory is changed and that any copies that are located on an accelerator are outdated. If you follow these guidelines, the pointer-based views are identical to those provided to views of data-parallel arrays.

Inheritance Hierarchy

_Array_view_shape

_Array_view_base

array_view

Requirements

Header: amp.h

Namespace: Concurrency

See Also

Reference

Concurrency Namespace (C++ AMP)