DataMap¶
-
template<typename ElemType, DataLocation Location>
class DataMap¶ A map to an existing memory allocation in either the
Host
or theDevice
, depending on theLocation
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(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.
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. Theother
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
.
Element Access
-
ElemType *data() noexcept¶
Note
If
empty() = true
,data()
returns anullptr
.- Returns:
A raw pointer to the beginning of the container.
-
ElemType *data() const noexcept¶
Note
If
empty() = true
,data()
returns anullptr
.- Returns:
A raw pointer to the beginning of the container.
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 thepast-the-end
element of the container.
Capacity
-
bool is_empty() const noexcept¶
- Returns:
true
if the container is empty,false
otherwise.
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