Memory object. More...
#include <dnnl.hpp>
Classes | |
struct | desc |
A memory descriptor. More... | |
Public Types | |
enum | data_type |
Data type specification. More... | |
enum | format_kind |
Memory format kind. More... | |
enum | format_tag |
Memory format tag specification. More... | |
typedef dnnl_dim_t | dim |
Integer type for representing dimension sizes and indices. | |
typedef std::vector< dim > | dims |
Vector of dimensions. More... | |
Public Member Functions | |
memory (const desc &md, const engine &engine, void *handle) | |
Constructs a memory object. More... | |
memory (const desc &md, const engine &engine) | |
Constructs a memory object. More... | |
desc | get_desc () const |
Returns the associated memory descriptor. | |
engine | get_engine () const |
Returns the associated engine. | |
void * | get_data_handle () const |
Returns the underlying memory buffer. More... | |
void | set_data_handle (void *handle) const |
Sets memory buffer. More... | |
template<typename T = void> | |
T * | map_data () const |
Maps the data of the memory. More... | |
void | unmap_data (void *mapped_ptr) const |
Unmaps the previously mapped data for the memory. More... | |
cl_mem | get_ocl_mem_object () const |
Returns the OpenCL memory object associated with the memory. | |
void | set_ocl_mem_object (cl_mem mem_object) |
Sets the OpenCL memory object mem_object associated with the memory. More... | |
Public Member Functions inherited from dnnl::handle< dnnl_memory_t > | |
bool | operator== (const handle< dnnl_memory_t, handle_traits< dnnl_memory_t > > &other) const |
Equality operator. More... | |
bool | operator!= (const handle &other) const |
Inequality operator. More... | |
handle ()=default | |
Constructs an empty handle object. More... | |
handle (const handle< dnnl_memory_t, handle_traits< dnnl_memory_t > > &)=default | |
Copy constructor. | |
handle (handle< dnnl_memory_t, handle_traits< dnnl_memory_t > > &&)=default | |
Move constructor. | |
handle (dnnl_memory_t t, bool weak=false) | |
Constructs a handle wrapper object from a C API handle. More... | |
handle< dnnl_memory_t, handle_traits< dnnl_memory_t > > & | operator= (const handle< dnnl_memory_t, handle_traits< dnnl_memory_t > > &)=default |
Assignment operator. | |
handle< dnnl_memory_t, handle_traits< dnnl_memory_t > > & | operator= (handle< dnnl_memory_t, handle_traits< dnnl_memory_t > > &&)=default |
Move assignment operator. | |
void | reset (dnnl_memory_t t, bool weak=false) |
Resets the handle wrapper objects to wrap a new C API handle. More... | |
dnnl_memory_t | get (bool allow_empty=false) const |
Returns the underlying C API handle. More... | |
operator dnnl_memory_t () const | |
Converts a handle to the underlying C API handle type. More... | |
operator bool () const | |
Checks whether the object is empty. More... | |
Static Public Member Functions | |
template<typename T > | |
static void | validate_dims (const std::vector< T > &v, int min_size=0) |
Helper function that validates that an std::vector of dimensions can be safely converted to the C API array dnnl_dims_t. More... | |
Memory object.
A memory object encapsulates a handle to a memory buffer allocated on a specific engine, tensor dimensions, data type, and memory format, which is the way tensor indices map to offsets in linear memory space. Memory objects are passed to primitives during execution.
typedef std::vector<dim> dnnl::memory::dims |
Vector of dimensions.
Implementations are free to force a limit on the vector's length.
|
strong |
Data type specification.
|
strong |
Memory format kind.
Enumerator | |
---|---|
undef | Undefined memory format kind, used for empty memory descriptors. |
any | Unspecified format kind. The primitive selects a format automatically. |
blocked | A tensor in a generic format described by the stride and blocking values in each dimension. See dnnl_blocking_desc_t for more information. |
wino | Weights format used in 8bit Winograd convolution. |
packed | Packed weights format used in RNN. |
|
strong |
Memory format tag specification.
Memory format tags can be further divided into two categories:
a
to l
to denote logical dimensions and form the order in which the dimensions are laid in memory. For example, dnnl::memory::format_tag::ab is used to denote a 2D tensor where the second logical dimension (denoted as b
) is the innermost, i.e. has stride = 1, and the first logical dimension (a
) is laid out in memory with stride equal to the size of the second dimension. On the other hand, dnnl::memory::format_tag::ba is the transposed version of the same tensor: the outermost dimension (a
) becomes the innermost one.a
), and channels correspond to the second one (b
).The following domain-specific notation applies to memory format tags:
'n'
denotes the mini-batch dimension'c'
denotes a channels dimension'i'
and 'o'
denote dimensions of input and output channels'g'
denotes a groups dimension for convolution weights'd'
, 'h'
, and 'w'
denote spatial depth, height, and width respectivelySee dnnl_format_tag_t for a detailed description.
Enumerator | |
---|---|
undef | Undefined memory format tag. |
any | Placeholder memory format tag. Used to instruct the primitive to select a format automatically. |
a | plain 1D tensor |
ab | plain 2D tensor |
ba | permuted 2D tensor |
abc | plain 3D tensor |
acb | permuted 3D tensor |
bac | permuted 3D tensor |
bca | permuted 3D tensor |
cba | permuted 3D tensor |
abcd | plain 4D tensor |
acdb | permuted 4D tensor |
bacd | permuted 4D tensor |
bcda | permuted 4D tensor |
cdba | permuted 4D tensor |
abcde | plain 5D tensor |
abdec | permuted 5D tensor |
acbde | permuted 5D tensor |
acdeb | permuted 5D tensor |
bcdea | permuted 5D tensor |
cdeba | permuted 5D tensor |
decab | permuted 5D tensor |
abcdef | plain 6D tensor |
acbdef | plain 6D tensor |
defcab | plain 6D tensor |
x | 1D tensor; an alias for dnnl::memory::format_tag::a |
nc | 2D CNN activations tensor; an alias for dnnl::memory::format_tag::ab |
cn | 2D CNN activations tensor; an alias for dnnl::memory::format_tag::ba |
tn | 2D RNN statistics tensor; an alias for dnnl::memory::format_tag::ab |
nt | 2D RNN statistics tensor; an alias for dnnl::memory::format_tag::ba |
ncw | 3D CNN activations tensor; an alias for dnnl::memory::format_tag::abc |
nwc | 3D CNN activations tensor; an alias for dnnl::memory::format_tag::acb |
nchw | 4D CNN activations tensor; an alias for dnnl::memory::format_tag::abcd |
nhwc | 4D CNN activations tensor; an alias for dnnl::memory::format_tag::acdb |
chwn | 4D CNN activations tensor; an alias for dnnl::memory::format_tag::bcda |
ncdhw | 5D CNN activations tensor; an alias for dnnl::memory::format_tag::abcde |
ndhwc | 5D CNN activations tensor; an alias for dnnl::memory::format_tag::acdeb |
oi | 2D CNN weights tensor; an alias for dnnl::memory::format_tag::ab |
io | 2D CNN weights tensor; an alias for dnnl::memory::format_tag::ba |
oiw | 3D CNN weights tensor; an alias for dnnl::memory::format_tag::abc |
owi | 3D CNN weights tensor; an alias for dnnl::memory::format_tag::acb |
wio | 3D CNN weights tensor; an alias for dnnl::memory::format_tag::cba |
iwo | 3D CNN weights tensor; an alias for dnnl::memory::format_tag::bca |
oihw | 4D CNN weights tensor; an alias for dnnl::memory::format_tag::abcd |
hwio | 4D CNN weights tensor; an alias for dnnl::memory::format_tag::cdba |
ohwi | 4D CNN weights tensor; an alias for dnnl::memory::format_tag::acdb |
ihwo | 4D CNN weights tensor; an alias for dnnl::memory::format_tag::bcda |
iohw | 4D CNN weights tensor; an alias for dnnl::memory::format_tag::bacd |
oidhw | 5D CNN weights tensor; an alias for dnnl::memory::format_tag::abcde |
dhwio | 5D CNN weights tensor; an alias for dnnl::memory::format_tag::cdeba |
odhwi | 5D CNN weights tensor; an alias for dnnl::memory::format_tag::acdeb |
idhwo | 5D CNN weights tensor; an alias for dnnl::memory::format_tag::bcdea |
goiw | 4D CNN weights tensor with groups; an alias for dnnl::memory::format_tag::abcd |
goihw | 5D CNN weights tensor with groups; an alias for dnnl::memory::format_tag::abcde |
hwigo | 5D CNN weights tensor with groups; an alias for dnnl::memory::format_tag::decab |
giohw | 5D CNN weights tensor with groups; an alias for dnnl::memory::format_tag::acbde |
goidhw | 6D CNN weights tensor with groups; an alias for dnnl::memory::format_tag::abcdef |
giodhw | 6D CNN weights tensor with groups; an alias for dnnl::memory::format_tag::abcdef |
dhwigo | 6D CNN weights tensor with groups; an alias for dnnl::memory::format_tag::defcab |
tnc | 3D RNN data tensor in the format (seq_length, batch, input channels). |
ntc | 3D RNN data tensor in the format (batch, seq_length, input channels). |
ldnc | 4D RNN states tensor in the format (num_layers, num_directions, batch, state channels). |
ldigo | 5D RNN weights tensor in the format (num_layers, num_directions, input_channels, num_gates, output_channels).
|
ldgoi | 5D RNN weights tensor in the format (num_layers, num_directions, num_gates, output_channels, input_channels).
|
ldgo | 4D RNN bias tensor in the format (num_layers, num_directions, num_gates, output_channels).
|
aBcd8b | 4D tensor blocked by 2nd dimension with block size 8 |
ABcd8b8a | 4D tensor blocked by 1st and 2nd dimension with block size 8 |
Constructs a memory object.
Unless handle
is equal to DNNL_MEMORY_NONE, the constructed memory object will have the underlying buffer set. In this case, the buffer will be initialized as if memory::set_data_handle() had been called.
md | Memory descriptor. |
engine | Engine to store the data on. |
handle | Handle of the memory buffer to use as an underlying storage.
|
Constructs a memory object.
The underlying storage for the memory will be allocated by the library.
md | Memory descriptor. |
engine | Engine to store the data on. |
|
inlinestatic |
Helper function that validates that an std::vector
of dimensions can be safely converted to the C API array dnnl_dims_t.
Throws if validation fails.
v | Vector of dimensions. |
min_size | Minimum expected size of the vector. |
|
inline |
Returns the underlying memory buffer.
On the CPU engine this is a pointer to the allocated memory.
|
inline |
Sets memory buffer.
This function may write zeroes to the specified data handle
if the memory object has padding to maintain data consistency.
The write can be time consuming and happens each time the function is called. Furthermore, it is performed using an internal service stream in a blocking manner.
handle
parameter cannot and does not have a const qualifier.handle | Output data handle. For the CPU engine, the data handle is a pointer to the actual data. For OpenCL it is a cl_mem. |
|
inline |
Maps the data of the memory.
Mapping enables read/write directly from/to the memory contents for engines that do not support direct memory access.
Mapping is an exclusive operation - a memory object cannot be used in other operations until this memory object is unmapped.
T | Data type to return a pointer to. |
|
inline |
Unmaps the previously mapped data for the memory.
Any changes of the mapped data are synchronized back to the memory after the call is complete. The mapped pointer must be obtained through a map_data() call.
mapped_ptr | A pointer previously returned by map_data(). |
|
inline |
Sets the OpenCL memory object mem_object
associated with the memory.
For behavioral details see memory::set_data_handle().
mem_object | OpenCL cl_mem object to use as the underlying storage. It must have at least get_desc().get_size() bytes allocated. |