A primitive to describe and store data. More...
Functions | |
dnnl_status_t DNNL_API | dnnl_memory_desc_init_by_strides (dnnl_memory_desc_t *memory_desc, int ndims, const dnnl_dims_t dims, dnnl_data_type_t data_type, const dnnl_dims_t strides) |
Initializes a memory_desc memory descriptor using ndims , dims , data_type , and strides . More... | |
dnnl_status_t DNNL_API | dnnl_memory_desc_init_by_tag (dnnl_memory_desc_t *memory_desc, int ndims, const dnnl_dims_t dims, dnnl_data_type_t data_type, dnnl_format_tag_t tag) |
Initializes a memory_desc memory descriptor using ndims , dims , data_type , and format tag . More... | |
dnnl_status_t DNNL_API | dnnl_memory_desc_init_submemory (dnnl_memory_desc_t *memory_desc, const dnnl_memory_desc_t *parent_memory_desc, const dnnl_dims_t dims, const dnnl_dims_t offsets) |
Initializes a memory_desc for a given parent_memory_desc , with dims sizes and offsets . More... | |
dnnl_status_t DNNL_API | dnnl_memory_desc_reshape (dnnl_memory_desc_t *out_memory_desc, const dnnl_memory_desc_t *in_memory_desc, int ndims, const dnnl_dims_t dims) |
Initializes an out_memory_desc with new ndims and dims from a in_memory_desc . More... | |
int DNNL_API | dnnl_memory_desc_equal (const dnnl_memory_desc_t *lhs, const dnnl_memory_desc_t *rhs) |
Compares two memory descriptors. More... | |
size_t DNNL_API | dnnl_memory_desc_get_size (const dnnl_memory_desc_t *memory_desc) |
Returns the size (in bytes) that is required for given memory_desc . | |
dnnl_status_t DNNL_API | dnnl_memory_create (dnnl_memory_t *memory, const dnnl_memory_desc_t *memory_desc, dnnl_engine_t engine, void *handle) |
Creates a memory for given memory_desc and engine . More... | |
dnnl_status_t DNNL_API | dnnl_memory_get_memory_desc (const_dnnl_memory_t memory, const dnnl_memory_desc_t **memory_desc) |
Returns a memory_desc associated with memory . | |
dnnl_status_t DNNL_API | dnnl_memory_get_engine (const_dnnl_memory_t memory, dnnl_engine_t *engine) |
Returns an engine associated with memory . | |
dnnl_status_t DNNL_API | dnnl_memory_map_data (const_dnnl_memory_t memory, void **mapped_ptr) |
For a memory , maps the data of the memory to mapped_ptr . More... | |
dnnl_status_t DNNL_API | dnnl_memory_unmap_data (const_dnnl_memory_t memory, void *mapped_ptr) |
For a memory , unmaps a mapped pointer to the data of the memory. More... | |
dnnl_status_t DNNL_API | dnnl_memory_get_data_handle (const_dnnl_memory_t memory, void **handle) |
For a memory , returns the data handle . More... | |
dnnl_status_t DNNL_API | dnnl_memory_set_data_handle (dnnl_memory_t memory, void *handle) |
For a memory , sets the data handle . | |
dnnl_status_t DNNL_API | dnnl_memory_get_ocl_mem_object (const_dnnl_memory_t memory, cl_mem *mem_object) |
For a memory returns the OpenCL memory object associated with it. | |
dnnl_status_t DNNL_API | dnnl_memory_set_ocl_mem_object (dnnl_memory_t memory, cl_mem mem_object) |
For a memory sets the OpenCL memory object associated with it. | |
dnnl_status_t DNNL_API | dnnl_memory_destroy (dnnl_memory_t memory) |
Deletes a memory . | |
A primitive to describe and store data.
The library supports various data types and formats. Memory hierarchy consists of three levels of abstraction:
void
. The data handle can be queried using dnnl_memory_get_data_handle() and set using dnnl_memory_set_data_handle(). The latter function always sets the memory in the padding region to zero, which is the invariant maintained by all the primitives in DNNL. See Understanding Memory Formats for more details. A memory can be created using dnnl_memory_create() function. A memory can also be queried for the underlying memory descriptor and engine using dnnl_memory_get_memory_desc() and dnnl_memory_get_engine() functions.Along with ordinary memory with all dimensions being positive, Intel DNNL supports zero-volume memory with one or more dimensions set to zero. This is to support the NumPy* convention. If a zero-volume memory is passed to a primitive, the primitive does not perform any computations on this memory. For example:
(0 batch, 3 input channels, 13 height, 13 width)
source and (16 output channels, 3 input channels, 3 height, 3 width)
weights would produce (0 batch, 16 output channels, 11 height, 11 width)
destination (assuming strides are 1
and paddings are zero) and perform zero multiply-add operations.(3, 4, 13, 13)
, (3, 0, 13, 13)
, and (3, 1, 13, 13)
along the second axis would produce the output of the shape (3, 5, 13, 13)
, effectively ignoring the second input (however, if the user created a concatenation primitive descriptor with three inputs they should also provide all three memories to the concatenation primitive, including the one with zero second dimension).Data handle of zero-volume memory is never accessed and hence can be unset (NULL in case of CPU engine).
dnnl_status_t DNNL_API dnnl_memory_desc_init_by_strides | ( | dnnl_memory_desc_t * | memory_desc, |
int | ndims, | ||
const dnnl_dims_t | dims, | ||
dnnl_data_type_t | data_type, | ||
const dnnl_dims_t | strides | ||
) |
Initializes a memory_desc
memory descriptor using ndims
, dims
, data_type
, and strides
.
The strides
might be NULL, which means the order of physical dimensions is the same as the order of logical ones.
dnnl_status_t DNNL_API dnnl_memory_desc_init_by_tag | ( | dnnl_memory_desc_t * | memory_desc, |
int | ndims, | ||
const dnnl_dims_t | dims, | ||
dnnl_data_type_t | data_type, | ||
dnnl_format_tag_t | tag | ||
) |
Initializes a memory_desc
memory descriptor using ndims
, dims
, data_type
, and format tag
.
tag
can be dnnl_format_tag_any, which allows a primitive to define the appropriate memory format. In this case, the format_kind
would be set to dnnl_format_kind_any
dnnl_status_t DNNL_API dnnl_memory_desc_init_submemory | ( | dnnl_memory_desc_t * | memory_desc, |
const dnnl_memory_desc_t * | parent_memory_desc, | ||
const dnnl_dims_t | dims, | ||
const dnnl_dims_t | offsets | ||
) |
Initializes a memory_desc
for a given parent_memory_desc
, with dims
sizes and offsets
.
May fail if layout used does not allow obtain desired submemory. In this case consider using extract
or insert
primitive
dnnl_status_t DNNL_API dnnl_memory_desc_reshape | ( | dnnl_memory_desc_t * | out_memory_desc, |
const dnnl_memory_desc_t * | in_memory_desc, | ||
int | ndims, | ||
const dnnl_dims_t | dims | ||
) |
Initializes an out_memory_desc
with new ndims
and dims
from a in_memory_desc
.
If in_memory_desc
and out_memory_desc
point to the same memory descriptor, then in_memory_desc
is re-initialized with new values. out_memory_desc
inherits data type from in_memory_desc
and has same blocked format_kind. Others format_kind's are not supported.
int DNNL_API dnnl_memory_desc_equal | ( | const dnnl_memory_desc_t * | lhs, |
const dnnl_memory_desc_t * | rhs | ||
) |
Compares two memory descriptors.
Use this function to identify whether a reorder is required between the two memories
dnnl_status_t DNNL_API dnnl_memory_create | ( | dnnl_memory_t * | memory, |
const dnnl_memory_desc_t * | memory_desc, | ||
dnnl_engine_t | engine, | ||
void * | handle | ||
) |
Creates a memory for given memory_desc
and engine
.
Also sets handle
to one of the following:
dnnl_status_t DNNL_API dnnl_memory_map_data | ( | const_dnnl_memory_t | memory, |
void ** | mapped_ptr | ||
) |
For a memory
, maps the data of the memory to mapped_ptr
.
Mapping allows to 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.
memory
should be completed before mapping the memory. Use dnnl_stream_wait to synchronize the corresponding execution stream.dnnl_status_t DNNL_API dnnl_memory_unmap_data | ( | const_dnnl_memory_t | memory, |
void * | mapped_ptr | ||
) |
For a memory
, unmaps a mapped pointer to the data of 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 dnnl_memory_map_data call.
dnnl_status_t DNNL_API dnnl_memory_get_data_handle | ( | const_dnnl_memory_t | memory, |
void ** | handle | ||
) |
For a memory
, returns the data handle
.
For the CPU engine, the data handle is a pointer to the actual data.