DataMap

template<typename ElemType, DataLocation Location>
class DataMap

A map to an existing memory allocation in either the Host or the Device, depending on the Location parameter.

In essence, this object wraps an existing memory allocation as a HighFM type, storing just a pointer to the data. The underlying container must be stored contiguously in memory. Naturally, any modifications to the location of the container in memory will invalidate this object.

Warning

The constructor DataMap(const DataMap&) will just duplicate the map without actually copying the data since there is no container associated with this object.

Template Parameters:
  • ElemType – Type of the elements in the container.

  • Location – The location of the container. Options: Host or Device.

Subclassed by HighFM::TriangularMap< ElemType, UpLo, Location >

Constructor

DataMap()

Creates an empty DataMap.

DataMap(ElemType *ptr, index_t size)

Creates a DataMap from an existing memory allocation. The container must be stored contiguously in memory and be in the same memory space.

Parameters:
  • ptr[in] pointer to the existing memory allocation.

  • size[in] size of the existing memory allocation.

DataMap(const DataMap &other)

Creates a DataMap from an existing DataMap.

Note

This will only copy the map, but not the data in the container.

Parameters:

other[in] another DataMap to use as the data source.

DataMap(DataMap &&other) noexcept

Creates a DataMap and then moves the content from an other DataMap, following the move semantics. The other datamap is left in an unspecified state afterwards.

Parameters:

other[in] another DataMap to use as the data source.

DataMap(const Array<ElemType, Location> &other)

Creates a DataMap from an existing Array.

Parameters:

other[in] another Array to use as the data source.

Assignment

DataMap &operator=(const DataMap &other)

Replaces the container’s content with the contents of an other DataMap. The size of the two containers must match.

Parameters:

other[in] another DataMap to use as the data source.

Throws:

LengthError – if `size() != other.size()`.

Returns:

*this.

DataMap &operator=(DataMap &&other) noexcept

Replaces the container’s content with the contents of an other DataMap, following the move semantics. The other datamap is left in an unspecified state afterwards.

Parameters:

other[in] another DataMap to use as the data source.

Returns:

*this.

template<DataLocation OtherLoc>
DataMap &operator=(const DataMap<ElemType, OtherLoc> &other)

Replaces the container’s content with the contents of an other DataMap. The size of the two containers must match.

Parameters:

other[in] another DataMap to use as the data source.

Throws:

LengthError – if `size() != other.size()`.

Returns:

*this.

template<DataLocation OtherLoc>
DataMap &operator=(const Array<ElemType, OtherLoc> &array)

Copies the content from an array to this container. The size of the two containers must match.

Parameters:

array[in] a Array to use as the data source.

Throws:

LengthError – if `size() != other.size()`.

Returns:

*this.

void fill(ElemType val)

Sets all elements in the DataMap to val.

Parameters:

val[in] value to replace the DataMap content with.

Element Access

ElemType *data() noexcept

Note

If empty() = true, data() returns a nullptr.

Returns:

A raw pointer to the beginning of the container.

ElemType *data() const noexcept

Note

If empty() = true, data() returns a nullptr.

Returns:

A raw pointer to the beginning of the container.

ElemType &operator[](index_t idx)

Accesses element at idx position.

Parameters:

idx[in] position of the element to return.

Returns:

A reference to the requested element.

ElemType operator[](index_t idx) const

Accesses element at idx position.

Parameters:

idx[in] position of the element to return.

Returns:

A const reference to the requested element.

Iterators

iterator begin() noexcept
Returns:

An iterator to the beginning of the container.

iterator end() noexcept
Returns:

An iterator to past-the-end element of the container.

const_iterator cbegin() const noexcept
Returns:

A const_iterator to the beginning of the container.

const_iterator cend() const noexcept
Returns:

A const_iterator to the past-the-end element of the container.

Capacity

bool is_empty() const noexcept
Returns:

true if the container is empty, false otherwise.

virtual index_t size() const noexcept
Returns:

The number of elements in the container.

index_t capacity() const noexcept
Returns:

The capacity of the currently allocated storage.

Modifiers

void map_to(ElemType *ptr, index_t size)

Replaces the managed container.

Parameters:
  • ptr[in] pointer to the new container

  • size[in] size of the new container

void map_to(const DataMap &other)

Replaces the managed container.

Parameters:

other[in] another DataMap to use as data source

void map_to(const Array<ElemType, Location> &array)

Replaces the managed container.

Parameters:

other[in] a Array to use as data source

void swap(DataMap &other) noexcept

Swaps the DataMap content with other.

Parameters:

other[inout] another DataMap to exchange content with.