@Namespace(value="dnnl") @Properties(inherit=dnnl.class) public class memory extends dnnl_memory_handle
\addtogroup dnnl_api_memory Memory A container that describes and stores data. Memory objects can contain data of various types and formats. There are two levels of abstraction: 1. **Memory descriptor** -- engine-agnostic logical description of data (number of dimensions, dimension sizes, and data type), and, optionally, the information about the physical format of data in memory. If this information is not known yet, a memory descriptor can be created with #dnnl::memory::format_tag::any. This allows compute-intensive primitives to choose the best format for computation. The user is responsible for reordering the data into the chosen format when formats do not match. A memory descriptor can be initialized either by specifying dimensions and a memory format tag or strides for each of them, or by manipulating the dnnl_memory_desc_t structure directly. \warning The latter approach requires understanding how the physical data representation is mapped to the structure and is discouraged. This topic is discussed in \ref dev_guide_understanding_memory_formats. The user can query the amount of memory required by a memory descriptor using the #dnnl::memory::desc::get_size() function. The size of data in general cannot be computed as the product of dimensions multiplied by the size of the data type. So users are required to use this function for better code portability. Two memory descriptors can be compared using the equality and inequality operators. The comparison is especially useful when checking whether it is necessary to reorder data from the user's data format to a primitive's format. 2. **Memory object** -- an engine-specific object that handles the data and its description (a memory descriptor). For the CPU aengine, the data handle is simply a pointer to \c void. The data handle can be queried using #dnnl::memory::get_data_handle() and set using #dnnl::memory::set_data_handle(). A memory object can also be queried for the underlying memory descriptor and for its engine using #dnnl::memory::get_desc() and dnnl::memory::get_engine(). Along with ordinary memory descriptors with all dimensions being positive, the library supports *zero-volume* memory descriptors with one or more dimensions set to zero. This is used to support the NumPy\* convention. If a zero-volume memory is passed to a primitive, the primitive typically does not perform any computations with this memory. For example: - A concatenation primitive would ignore all memory object with zeroes in the concat dimension / axis. - A forward convolution with a source memory object with zero in the minibatch dimension would always produce a destination memory object with a zero in the minibatch dimension and perform no computations. - However, a forward convolution with a zero in one of the weights dimensions is ill-defined and is considered to be an error by the library because there is no clear definition of what the output values should be. Data handle of a zero-volume memory is never accessed. \{
Memory object. A memory object encapsulates a handle to a memory buffer allocated on a specific aengine, 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.
| Modifier and Type | Class and Description |
|---|---|
static class |
memory.data_type
Data type specification.
|
static class |
memory.desc
A memory descriptor.
|
static class |
memory.format_kind
Memory format kind
|
static class |
memory.format_tag
Memory format tag specification.
|
Pointer.CustomDeallocator, Pointer.Deallocator, Pointer.NativeDeallocator, Pointer.ReferenceCounter| Constructor and Description |
|---|
memory()
Default constructor.
|
memory(long size)
Native array allocator.
|
memory(memory.desc md,
engine aengine)
Constructs a memory object.
|
memory(memory.desc md,
engine aengine,
Pointer handle)
Constructs a memory object.
|
memory(Pointer p)
Pointer cast constructor.
|
| Modifier and Type | Method and Description |
|---|---|
static int |
convert_to_c(memory.data_type adata_type) |
static int |
convert_to_c(memory.format_tag format) |
Pointer |
get_data_handle()
Returns the underlying memory buffer.
|
memory.desc |
get_desc()
Returns the associated memory descriptor.
|
engine |
get_engine()
Returns the associated engine.
|
memory |
getPointer(long i) |
memory |
position(long position) |
void |
set_data_handle(Pointer handle)
Sets the underlying memory buffer.
|
void |
set_data_handle(Pointer handle,
stream astream)
Sets the underlying memory buffer.
|
void |
unmap_data(Pointer mapped_ptr)
Unmaps a memory object and writes back any changes made to the
previously mapped memory buffer.
|
asBoolean, asDnnl_memory, equals, get, get, notEquals, put, reset, resetaddress, asBuffer, asByteBuffer, availablePhysicalBytes, calloc, capacity, capacity, close, deallocate, deallocate, deallocateReferences, deallocator, deallocator, equals, fill, formatBytes, free, getPointer, getPointer, getPointer, hashCode, isNull, isNull, limit, limit, malloc, maxBytes, maxPhysicalBytes, memchr, memcmp, memcpy, memmove, memset, offsetof, offsetof, parseBytes, physicalBytes, position, put, realloc, referenceCount, releaseReference, retainReference, setNull, sizeof, sizeof, toString, totalBytes, totalCount, totalPhysicalBytes, withDeallocator, zeropublic memory(Pointer p)
Pointer.Pointer(Pointer).public memory(long size)
Pointer.position(long).public memory()
public memory(@Const @ByRef memory.desc md, @Const @ByRef engine aengine, Pointer handle)
md - Memory descriptor.aengine - Engine to store the data on.handle - Handle of the memory buffer to use as an underlying
storage.
- A pointer to the user-allocated buffer. In this case the library
doesn't own the buffer.
- The DNNL_MEMORY_ALLOCATE special value. Instructs the library to
allocate the buffer for the memory object. In this case the
library owns the buffer.
- DNNL_MEMORY_NONE to create dnnl_memory without an underlying
buffer.memory::set_data_handle()public memory position(long position)
position in class dnnl_memory_handlepublic memory getPointer(long i)
getPointer in class dnnl_memory_handle@ByVal public memory.desc get_desc()
public Pointer get_data_handle()
public void set_data_handle(Pointer handle, @Const @ByRef stream astream)
handle - Data handle. For the CPU aengine, the data handle
is a pointer to the actual data. For OpenCL it is a cl_mem.astream - Stream to use to execute padding in.public void set_data_handle(Pointer handle)
handle - Data handle. For the CPU aengine, the data handle
is a pointer to the actual data. For OpenCL it is a cl_mem.public void unmap_data(Pointer mapped_ptr)
mapped_ptr - A pointer previously returned by map_data().@Cast(value="dnnl_data_type_t") public static int convert_to_c(memory.data_type adata_type)
@Cast(value="dnnl_format_tag_t") public static int convert_to_c(memory.format_tag format)
Copyright © 2020. All rights reserved.