A helper class that is very similar to Memory<V, Size> but with dynamically allocated memory and thus dynamic size.
Example:
This code allocates a small array with 11 scalar entries and implements two equivalent loops that initialize the memory. The scalar loop writes each individual int. The vectorized loop writes int_v::Size values to memory per iteration. Since the size of 11 is not a multiple of int_v::Size (unless you use the scalar Vc implementation) the last write access of the vector loop would normally be out of bounds. But the Memory class automatically pads the memory such that the whole array can be accessed with correctly aligned memory addresses. (Note: the scalar loop can be auto-vectorized, except for the last three assignments.)
__restrict__
keyword. Therefore modifying memory of V::EntryType will require the compiler to assume aliasing. If you want to use the __restrict__
keyword you need to use a standard pointer to memory and do the vector address calculation and loads and stores manually.#include <Vc/Memory>
Inherits MemoryBase< V, Memory< V, Size1, Size2, InitPadding >, 2, Memory< V, Size2, 0, InitPadding > >, and MemoryBase< V, Memory< V, 0u, 0u, true >, 1, void >.
Public Member Functions | |
Memory (size_t size) | |
Allocate enough memory to access size values of type V::EntryType . | |
template<typename Parent, typename RM> | |
Memory (const MemoryBase< V, Parent, 1, RM > &rhs) | |
Copy the memory into a new memory area. | |
Memory (const Memory &rhs) | |
Overload of the above function. | |
~Memory () | |
Frees the memory which was allocated in the constructor. | |
void | swap (Memory &rhs) |
Swap the contents and size information of two Memory objects. | |
size_t | entriesCount () const |
size_t | vectorsCount () const |
template<typename Parent, typename RM> | |
Memory & | operator= (const MemoryBase< V, Parent, 1, RM > &rhs) |
Overwrite all entries with the values stored in rhs . | |
Memory & | operator= (const EntryType *rhs) |
Overwrite all entries with the values stored in the memory at rhs . | |
Memory & | operator= (const MemoryBase< V, Parent, 2, RM > &rhs) |
Copies the data from a different object. | |
Memory & | operator= (const V &v) |
Initialize all data with the given vector. | |
std::enable_if<!std::is_convertible< Flags, int >::value, vector_reference< Flags > >::type | vector (size_t i, Flags=Flags()) |
std::enable_if<!std::is_convertible< Flags, int >::value, const_vector_reference< Flags > >::type | vector (size_t i, Flags=Flags()) const |
Const overload of the above function. | |
std::enable_if< std::is_convertible< ShiftT, int >::value, vector_reference< decltype(std::declval< Flags >()|Unaligned)> >::type | vector (size_t i, ShiftT shift, Flags=Flags()) |
std::enable_if< std::is_convertible< ShiftT, int >::value, const_vector_reference< decltype(std::declval< Flags >()|Unaligned)> >::type | vector (size_t i, ShiftT shift, Flags=Flags()) const |
Const overload of the above function. | |
Memory & | operator= (const MemoryBase< V, Parent, 2, RM > &rhs) |
Copies the data from a different object. | |
Memory & | operator= (const V &v) |
Initialize all data with the given vector. | |
std::enable_if<!std::is_convertible< Flags, int >::value, vector_reference< Flags > >::type | vector (size_t i, Flags=Flags()) |
std::enable_if<!std::is_convertible< Flags, int >::value, const_vector_reference< Flags > >::type | vector (size_t i, Flags=Flags()) const |
Const overload of the above function. | |
std::enable_if< std::is_convertible< ShiftT, int >::value, vector_reference< decltype(std::declval< Flags >()|Unaligned)> >::type | vector (size_t i, ShiftT shift, Flags=Flags()) |
std::enable_if< std::is_convertible< ShiftT, int >::value, const_vector_reference< decltype(std::declval< Flags >()|Unaligned)> >::type | vector (size_t i, ShiftT shift, Flags=Flags()) const |
Const overload of the above function. | |
Memory & | operator= (const MemoryBase< V, Parent, 2, RM > &rhs) |
Copies the data from a different object. | |
Memory & | operator= (const V &v) |
Initialize all data with the given vector. | |
std::enable_if<!std::is_convertible< Flags, int >::value, vector_reference< Flags > >::type | vector (size_t i, Flags=Flags()) |
std::enable_if<!std::is_convertible< Flags, int >::value, const_vector_reference< Flags > >::type | vector (size_t i, Flags=Flags()) const |
Const overload of the above function. | |
std::enable_if< std::is_convertible< ShiftT, int >::value, vector_reference< decltype(std::declval< Flags >()|Unaligned)> >::type | vector (size_t i, ShiftT shift, Flags=Flags()) |
std::enable_if< std::is_convertible< ShiftT, int >::value, const_vector_reference< decltype(std::declval< Flags >()|Unaligned)> >::type | vector (size_t i, ShiftT shift, Flags=Flags()) const |
Const overload of the above function. | |
size_t | entriesCount () const |
size_t | vectorsCount () const |
MemoryVectorIterator< V, Flags > | begin (Flags flags=Flags()) |
Return a (vectorized) iterator to the start of this memory object. | |
MemoryVectorIterator< const V, Flags > | begin (Flags flags=Flags()) const |
const overload of the above | |
MemoryVectorIterator< V, Flags > | end (Flags flags=Flags()) |
Return a (vectorized) iterator to the end of this memory object. | |
MemoryVectorIterator< const V, Flags > | end (Flags flags=Flags()) const |
const overload of the above | |
vector_reference< Flags > | vectorAt (size_t i, Flags flags=Flags()) |
const_vector_reference< Flags > | vectorAt (size_t i, Flags flags=Flags()) const |
Const overload of the above function. | |
vector_reference< Flags > | firstVector (Flags f=Flags()) |
const_vector_reference< Flags > | firstVector (Flags f=Flags()) const |
Const overload of the above function. | |
vector_reference< Flags > | lastVector (Flags f=Flags()) |
const_vector_reference< Flags > | lastVector (Flags f=Flags()) const |
Const overload of the above function. | |
void | setZero () |
Zero the whole memory area. | |
Memory< V, Size1, Size2, InitPadding > & | operator+= (const MemoryBase< V, P2, Dimension, RM > &rhs) |
(Inefficient) shorthand to add up two arrays. | |
Memory< V, Size1, Size2, InitPadding > & | operator+= (EntryType rhs) |
(Inefficient) shorthand to add a value to an array. | |
Memory< V, Size1, Size2, InitPadding > & | operator-= (const MemoryBase< V, P2, Dimension, RM > &rhs) |
(Inefficient) shorthand to subtract two arrays. | |
Memory< V, Size1, Size2, InitPadding > & | operator-= (EntryType rhs) |
(Inefficient) shorthand to subtract a value from an array. | |
Memory< V, Size1, Size2, InitPadding > & | operator*= (const MemoryBase< V, P2, Dimension, RM > &rhs) |
(Inefficient) shorthand to multiply two arrays. | |
Memory< V, Size1, Size2, InitPadding > & | operator*= (EntryType rhs) |
(Inefficient) shorthand to multiply a value to an array. | |
Memory< V, Size1, Size2, InitPadding > & | operator/= (const MemoryBase< V, P2, Dimension, RM > &rhs) |
(Inefficient) shorthand to divide two arrays. | |
Memory< V, Size1, Size2, InitPadding > & | operator/= (EntryType rhs) |
(Inefficient) shorthand to divide an array with a value. | |
bool | operator== (const MemoryBase< V, P2, Dimension, RM > &rhs) const |
(Inefficient) shorthand compare equality of two arrays. | |
bool | operator!= (const MemoryBase< V, P2, Dimension, RM > &rhs) const |
(Inefficient) shorthand compare two arrays. | |
bool | operator< (const MemoryBase< V, P2, Dimension, RM > &rhs) const |
(Inefficient) shorthand compare two arrays. | |
bool | operator<= (const MemoryBase< V, P2, Dimension, RM > &rhs) const |
(Inefficient) shorthand compare two arrays. | |
bool | operator> (const MemoryBase< V, P2, Dimension, RM > &rhs) const |
(Inefficient) shorthand compare two arrays. | |
bool | operator>= (const MemoryBase< V, P2, Dimension, RM > &rhs) const |
(Inefficient) shorthand compare two arrays. | |
size_t | entriesCount () const |
size_t | vectorsCount () const |
MemoryVectorIterator< V, Flags > | begin (Flags flags=Flags()) |
Return a (vectorized) iterator to the start of this memory object. | |
MemoryVectorIterator< const V, Flags > | begin (Flags flags=Flags()) const |
const overload of the above | |
MemoryVectorIterator< V, Flags > | end (Flags flags=Flags()) |
Return a (vectorized) iterator to the end of this memory object. | |
MemoryVectorIterator< const V, Flags > | end (Flags flags=Flags()) const |
const overload of the above | |
vector_reference< Flags > | vectorAt (size_t i, Flags flags=Flags()) |
const_vector_reference< Flags > | vectorAt (size_t i, Flags flags=Flags()) const |
Const overload of the above function. | |
vector_reference< Flags > | firstVector (Flags f=Flags()) |
const_vector_reference< Flags > | firstVector (Flags f=Flags()) const |
Const overload of the above function. | |
vector_reference< Flags > | lastVector (Flags f=Flags()) |
const_vector_reference< Flags > | lastVector (Flags f=Flags()) const |
Const overload of the above function. | |
void | setZero () |
Zero the whole memory area. | |
Memory< V, Size1, Size2, InitPadding > & | operator+= (const MemoryBase< V, P2, Dimension, RM > &rhs) |
(Inefficient) shorthand to add up two arrays. | |
Memory< V, Size1, Size2, InitPadding > & | operator+= (EntryType rhs) |
(Inefficient) shorthand to add a value to an array. | |
Memory< V, Size1, Size2, InitPadding > & | operator-= (const MemoryBase< V, P2, Dimension, RM > &rhs) |
(Inefficient) shorthand to subtract two arrays. | |
Memory< V, Size1, Size2, InitPadding > & | operator-= (EntryType rhs) |
(Inefficient) shorthand to subtract a value from an array. | |
Memory< V, Size1, Size2, InitPadding > & | operator*= (const MemoryBase< V, P2, Dimension, RM > &rhs) |
(Inefficient) shorthand to multiply two arrays. | |
Memory< V, Size1, Size2, InitPadding > & | operator*= (EntryType rhs) |
(Inefficient) shorthand to multiply a value to an array. | |
Memory< V, Size1, Size2, InitPadding > & | operator/= (const MemoryBase< V, P2, Dimension, RM > &rhs) |
(Inefficient) shorthand to divide two arrays. | |
Memory< V, Size1, Size2, InitPadding > & | operator/= (EntryType rhs) |
(Inefficient) shorthand to divide an array with a value. | |
bool | operator== (const MemoryBase< V, P2, Dimension, RM > &rhs) const |
(Inefficient) shorthand compare equality of two arrays. | |
bool | operator!= (const MemoryBase< V, P2, Dimension, RM > &rhs) const |
(Inefficient) shorthand compare two arrays. | |
bool | operator< (const MemoryBase< V, P2, Dimension, RM > &rhs) const |
(Inefficient) shorthand compare two arrays. | |
bool | operator<= (const MemoryBase< V, P2, Dimension, RM > &rhs) const |
(Inefficient) shorthand compare two arrays. | |
bool | operator> (const MemoryBase< V, P2, Dimension, RM > &rhs) const |
(Inefficient) shorthand compare two arrays. | |
bool | operator>= (const MemoryBase< V, P2, Dimension, RM > &rhs) const |
(Inefficient) shorthand compare two arrays. | |
Static Public Member Functions | |
static constexpr size_t | rowsCount () |
static constexpr size_t | entriesCount () |
static constexpr size_t | vectorsCount () |
static constexpr size_t | rowsCount () |
static constexpr size_t | entriesCount () |
static constexpr size_t | vectorsCount () |
static constexpr size_t | rowsCount () |
static constexpr size_t | entriesCount () |
static constexpr size_t | vectorsCount () |
|
inline |
Allocate enough memory to access size
values of type V::EntryType
.
The allocated memory is aligned and padded correctly for fully vectorized access.
size | Determines how many scalar values will fit into the allocated memory. |
Definition at line 394 of file memory.h.
Referenced by Memory(), operator=(), operator=(), and swap().
|
inline |
|
inline |
|
inline |
Definition at line 456 of file memory.h.
Referenced by Memory(), Memory(), and operator=().
|
inline |
Definition at line 461 of file memory.h.
Referenced by Memory(), Memory(), and operator=().
|
inline |
Overwrite all entries with the values stored in rhs
.
rhs | The object to copy the data from. |
|
inline |
Overwrite all entries with the values stored in the memory at rhs
.
rhs | The array to copy the data from. |
rhs
. ( | size_t | i, | |
Flags | = Flags() ) |
i | Selects the offset, where the vector should be read. |
i-th
vector in the memory.The return value can be used as any other vector object. I.e. you can substitute something like
with
This function ensures that only aligned loads and stores are used. Thus it only allows to access memory at fixed strides. If access to known offsets from the aligned vectors is needed the vector(size_t, int) function can be used.
( | size_t | i, | |
Flags | = Flags() ) const |
Const overload of the above function.
i | Selects the offset, where the vector should be read. |
i-th
vector in the memory. ( | size_t | i, | |
ShiftT | shift, | ||
Flags | = Flags() ) |
i-th
vector + shift
in the memory.This function ensures that only unaligned loads and stores are used. It allows to access memory at any location aligned to the entry type.
i | Selects the memory location of the i-th vector. Thus if V::Size == 4 and i is set to 3 the base address for the load/store will be the 12th entry (same as &mem [12]). |
shift | Shifts the base address determined by parameter i by shift many entries. Thus vector(3, 1) for V::Size == 4 will load/store the 13th - 16th entries (same as &mem [13]). |
V::Size
will not result in aligned loads. You have to use the above vector(size_t) function for aligned loads instead.i
to 0 and use shift
as the parameter to select the memory address:
|
inlinestaticconstexpr |
|
inlinestaticconstexpr |
Size2
is not divisible by V::Size
.
|
inlinestaticconstexpr |
|
inline |
Copies the data from a different object.
rhs | The object to copy the data from. |
|
inline |
|
inline |
i | Selects the offset, where the vector should be read. |
i-th
vector in the memory.The return value can be used as any other vector object. I.e. you can substitute something like
with
This function ensures that only aligned loads and stores are used. Thus it only allows to access memory at fixed strides. If access to known offsets from the aligned vectors is needed the vector(size_t, int) function can be used.
Definition at line 89 of file memorybase.h.
|
inline |
Const overload of the above function.
i | Selects the offset, where the vector should be read. |
i-th
vector in the memory. Definition at line 89 of file memorybase.h.
|
inline |
i-th
vector + shift
in the memory.This function ensures that only unaligned loads and stores are used. It allows to access memory at any location aligned to the entry type.
i | Selects the memory location of the i-th vector. Thus if V::Size == 4 and i is set to 3 the base address for the load/store will be the 12th entry (same as &mem [12]). |
shift | Shifts the base address determined by parameter i by shift many entries. Thus vector(3, 1) for V::Size == 4 will load/store the 13th - 16th entries (same as &mem [13]). |
V::Size
will not result in aligned loads. You have to use the above vector(size_t) function for aligned loads instead.i
to 0 and use shift
as the parameter to select the memory address: Definition at line 89 of file memorybase.h.
|
inlinestaticconstexpr |
|
inlinestaticconstexpr |
Size2
is not divisible by V::Size
.
|
inlinestaticconstexpr |
|
inline |
Copies the data from a different object.
rhs | The object to copy the data from. |
|
inline |
|
inline |
i | Selects the offset, where the vector should be read. |
i-th
vector in the memory.The return value can be used as any other vector object. I.e. you can substitute something like
with
This function ensures that only aligned loads and stores are used. Thus it only allows to access memory at fixed strides. If access to known offsets from the aligned vectors is needed the vector(size_t, int) function can be used.
Definition at line 89 of file memorybase.h.
|
inline |
Const overload of the above function.
i | Selects the offset, where the vector should be read. |
i-th
vector in the memory. Definition at line 89 of file memorybase.h.
|
inline |
i-th
vector + shift
in the memory.This function ensures that only unaligned loads and stores are used. It allows to access memory at any location aligned to the entry type.
i | Selects the memory location of the i-th vector. Thus if V::Size == 4 and i is set to 3 the base address for the load/store will be the 12th entry (same as &mem [12]). |
shift | Shifts the base address determined by parameter i by shift many entries. Thus vector(3, 1) for V::Size == 4 will load/store the 13th - 16th entries (same as &mem [13]). |
V::Size
will not result in aligned loads. You have to use the above vector(size_t) function for aligned loads instead.i
to 0 and use shift
as the parameter to select the memory address: Definition at line 89 of file memorybase.h.
|
inlinestaticconstexpr |
|
inlinestaticconstexpr |
Size2
is not divisible by V::Size
.
|
inlinestaticconstexpr |
|
inline |
Copies the data from a different object.
rhs | The object to copy the data from. |
|
inline |
|
inline |
i | Selects the offset, where the vector should be read. |
i-th
vector in the memory.The return value can be used as any other vector object. I.e. you can substitute something like
with
This function ensures that only aligned loads and stores are used. Thus it only allows to access memory at fixed strides. If access to known offsets from the aligned vectors is needed the vector(size_t, int) function can be used.
Definition at line 89 of file memorybase.h.
|
inline |
Const overload of the above function.
i | Selects the offset, where the vector should be read. |
i-th
vector in the memory. Definition at line 89 of file memorybase.h.
|
inline |
i-th
vector + shift
in the memory.This function ensures that only unaligned loads and stores are used. It allows to access memory at any location aligned to the entry type.
i | Selects the memory location of the i-th vector. Thus if V::Size == 4 and i is set to 3 the base address for the load/store will be the 12th entry (same as &mem [12]). |
shift | Shifts the base address determined by parameter i by shift many entries. Thus vector(3, 1) for V::Size == 4 will load/store the 13th - 16th entries (same as &mem [13]). |
V::Size
will not result in aligned loads. You have to use the above vector(size_t) function for aligned loads instead.i
to 0 and use shift
as the parameter to select the memory address: Definition at line 89 of file memorybase.h.
|
inline |
Definition at line 384 of file memorybase.h.
|
inline |
Definition at line 389 of file memorybase.h.
|
inline |
i-th
scalar entry in the memory.Example:
i | Specifies the scalar entry from where the vector will be loaded/stored. I.e. the values scalar(i), scalar(i + 1), ..., scalar(i + V::Size - 1) will be read/overwritten. |
flags | You must take care to determine whether an unaligned load/store is required. Per default an unaligned load/store is used. If i is a multiple of V::Size you may want to pass Vc::Aligned here. |
Definition at line 475 of file memorybase.h.
|
inline |
Const overload of the above function.
i-th
scalar entry in the memory.i | Specifies the scalar entry from where the vector will be loaded/stored. I.e. the values scalar(i), scalar(i + 1), ..., scalar(i + V::Size - 1) will be read/overwritten. |
flags | You must take care to determine whether an unaligned load/store is required. Per default an unaligned load/store is used. If i is a multiple of V::Size you may want to pass Vc::Aligned here. |
Definition at line 492 of file memorybase.h.
|
inline |
This function is simply a shorthand for vector(0).
Definition at line 553 of file memorybase.h.
|
inline |
This function is simply a shorthand for vector(vectorsCount() - 1).
Definition at line 571 of file memorybase.h.
|
inline |
Definition at line 384 of file memorybase.h.
|
inline |
Definition at line 389 of file memorybase.h.
|
inline |
i-th
scalar entry in the memory.Example:
i | Specifies the scalar entry from where the vector will be loaded/stored. I.e. the values scalar(i), scalar(i + 1), ..., scalar(i + V::Size - 1) will be read/overwritten. |
flags | You must take care to determine whether an unaligned load/store is required. Per default an unaligned load/store is used. If i is a multiple of V::Size you may want to pass Vc::Aligned here. |
Definition at line 475 of file memorybase.h.
|
inline |
Const overload of the above function.
i-th
scalar entry in the memory.i | Specifies the scalar entry from where the vector will be loaded/stored. I.e. the values scalar(i), scalar(i + 1), ..., scalar(i + V::Size - 1) will be read/overwritten. |
flags | You must take care to determine whether an unaligned load/store is required. Per default an unaligned load/store is used. If i is a multiple of V::Size you may want to pass Vc::Aligned here. |
Definition at line 492 of file memorybase.h.
|
inline |
This function is simply a shorthand for vector(0).
Definition at line 553 of file memorybase.h.
|
inline |
This function is simply a shorthand for vector(vectorsCount() - 1).
Definition at line 571 of file memorybase.h.