.. index:: pair: group; Memory .. _doxid-group__dnnl__api__memory: Memory ====== .. toctree:: :hidden: enum_dnnl_data_type_t.rst enum_dnnl_format_kind_t.rst enum_dnnl_format_tag_t.rst enum_dnnl_memory_extra_flags_t.rst enum_dnnl_rnn_packed_memory_format_t.rst enum_dnnl_wino_memory_format_t.rst struct_dnnl_blocking_desc_t.rst struct_dnnl_memory.rst struct_dnnl_memory_desc_t.rst struct_dnnl_memory_extra_desc_t.rst struct_dnnl_rnn_packed_desc_t.rst struct_dnnl_wino_desc_t.rst struct_dnnl_memory-2.rst Overview ~~~~~~~~ A container that describes and stores data. :ref:`More...` .. ref-code-block:: cpp :class: doxyrest-overview-code-block // typedefs typedef int64_t :ref:`dnnl_dim_t`; typedef :ref:`dnnl_dim_t` :ref:`dnnl_dims_t`[DNNL_MAX_NDIMS]; typedef struct :ref:`dnnl_memory`* :ref:`dnnl_memory_t`; typedef const struct :ref:`dnnl_memory`* :ref:`const_dnnl_memory_t`; // enums enum :ref:`dnnl_data_type_t`; enum :ref:`dnnl_format_kind_t`; enum :ref:`dnnl_format_tag_t`; enum :ref:`dnnl_memory_extra_flags_t`; enum :ref:`dnnl_rnn_packed_memory_format_t`; enum :ref:`dnnl_wino_memory_format_t`; // structs struct :ref:`dnnl_blocking_desc_t`; struct :ref:`dnnl_memory`; struct :ref:`dnnl_memory_desc_t`; struct :ref:`dnnl_memory_extra_desc_t`; struct :ref:`dnnl_rnn_packed_desc_t`; struct :ref:`dnnl_wino_desc_t`; struct :ref:`dnnl::memory`; // global functions bool :target:`dnnl::operator ==` (:ref:`dnnl_data_type_t` a, :ref:`memory::data_type` b); bool :target:`dnnl::operator !=` (:ref:`dnnl_data_type_t` a, :ref:`memory::data_type` b); bool :target:`dnnl::operator ==` (:ref:`memory::data_type` a, :ref:`dnnl_data_type_t` b); bool :target:`dnnl::operator !=` (:ref:`memory::data_type` a, :ref:`dnnl_data_type_t` b); bool :target:`dnnl::operator ==` (:ref:`dnnl_format_tag_t` a, :ref:`memory::format_tag` b); bool :target:`dnnl::operator !=` (:ref:`dnnl_format_tag_t` a, :ref:`memory::format_tag` b); bool :target:`dnnl::operator ==` (:ref:`memory::format_tag` a, :ref:`dnnl_format_tag_t` b); bool :target:`dnnl::operator !=` (:ref:`memory::format_tag` a, :ref:`dnnl_format_tag_t` b); :ref:`dnnl_status_t` DNNL_API :ref:`dnnl_memory_desc_init_by_strides`( :ref:`dnnl_memory_desc_t`* memory_desc, int ndims, const :ref:`dnnl_dims_t` dims, :ref:`dnnl_data_type_t` data_type, const :ref:`dnnl_dims_t` strides ); :ref:`dnnl_status_t` DNNL_API :ref:`dnnl_memory_desc_init_by_tag`( :ref:`dnnl_memory_desc_t`* memory_desc, int ndims, const :ref:`dnnl_dims_t` dims, :ref:`dnnl_data_type_t` data_type, :ref:`dnnl_format_tag_t` tag ); :ref:`dnnl_status_t` DNNL_API :ref:`dnnl_memory_desc_init_submemory`( :ref:`dnnl_memory_desc_t`* memory_desc, const :ref:`dnnl_memory_desc_t`* parent_memory_desc, const :ref:`dnnl_dims_t` dims, const :ref:`dnnl_dims_t` offsets ); :ref:`dnnl_status_t` DNNL_API :ref:`dnnl_memory_desc_reshape`( :ref:`dnnl_memory_desc_t`* out_memory_desc, const :ref:`dnnl_memory_desc_t`* in_memory_desc, int ndims, const :ref:`dnnl_dims_t` dims ); :ref:`dnnl_status_t` DNNL_API :ref:`dnnl_memory_desc_permute_axes`( :ref:`dnnl_memory_desc_t`* out_memory_desc, const :ref:`dnnl_memory_desc_t`* in_memory_desc, const int* permutation ); int DNNL_API :ref:`dnnl_memory_desc_equal`( const :ref:`dnnl_memory_desc_t`* lhs, const :ref:`dnnl_memory_desc_t`* rhs ); size_t DNNL_API :ref:`dnnl_memory_desc_get_size`(const :ref:`dnnl_memory_desc_t`* memory_desc); size_t DNNL_API :ref:`dnnl_data_type_size`(:ref:`dnnl_data_type_t` data_type); :ref:`dnnl_status_t` DNNL_API :ref:`dnnl_memory_create`( :ref:`dnnl_memory_t`* memory, const :ref:`dnnl_memory_desc_t`* memory_desc, :ref:`dnnl_engine_t` engine, void* handle ); :ref:`dnnl_status_t` DNNL_API :ref:`dnnl_memory_get_memory_desc`( :ref:`const_dnnl_memory_t` memory, const :ref:`dnnl_memory_desc_t`** memory_desc ); :ref:`dnnl_status_t` DNNL_API :ref:`dnnl_memory_get_engine`( :ref:`const_dnnl_memory_t` memory, :ref:`dnnl_engine_t`* engine ); :ref:`dnnl_status_t` DNNL_API :ref:`dnnl_memory_map_data`( :ref:`const_dnnl_memory_t` memory, void** mapped_ptr ); :ref:`dnnl_status_t` DNNL_API :ref:`dnnl_memory_unmap_data`( :ref:`const_dnnl_memory_t` memory, void* mapped_ptr ); :ref:`dnnl_status_t` DNNL_API :ref:`dnnl_memory_get_data_handle`( :ref:`const_dnnl_memory_t` memory, void** handle ); :ref:`dnnl_status_t` DNNL_API :ref:`dnnl_memory_set_data_handle`( :ref:`dnnl_memory_t` memory, void* handle ); :ref:`dnnl_status_t` DNNL_API :ref:`dnnl_memory_set_data_handle_v2`( :ref:`dnnl_memory_t` memory, void* handle, :ref:`dnnl_stream_t` stream ); :ref:`dnnl_status_t` DNNL_API :ref:`dnnl_memory_destroy`(:ref:`dnnl_memory_t` memory); // macros #define :ref:`DNNL_MAX_NDIMS` #define :ref:`DNNL_MEMORY_ALLOCATE` #define :ref:`DNNL_MEMORY_NONE` #define :ref:`DNNL_RNN_MAX_N_PARTS` #define :ref:`DNNL_RUNTIME_DIM_VAL` #define :ref:`DNNL_RUNTIME_F32_VAL` #define :ref:`DNNL_RUNTIME_S32_VAL` #define :ref:`DNNL_RUNTIME_SIZE_VAL` .. _details-group__dnnl__api__memory: Detailed Documentation ~~~~~~~~~~~~~~~~~~~~~~ A container that describes and stores data. Memory objects can contain data of various types and formats. There are two levels of abstraction: #. 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 :ref:`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 :ref:`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:`Understanding Memory Formats `. The user can query the amount of memory required by a memory descriptor using the :ref:`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. #. Memory object an engine-specific object that handles the memory buffer and its description (a memory descriptor). For the CPU engine or with USM, the memory buffer handle is simply a pointer to ``void``. The memory buffer can be queried using :ref:`dnnl::memory::get_data_handle() ` and set using :ref:`dnnl::memory::set_data_handle() `. The underlying SYCL buffer, when used, can be queried using :ref:`dnnl::sycl_interop::get_buffer ` and set using :ref:`dnnl::sycl_interop::set_buffer `. A memory object can also be queried for the underlying memory descriptor and for its engine using :ref:`dnnl::memory::get_desc() ` and :ref:`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. Memory buffer of a zero-volume memory is never accessed. Typedefs -------- .. index:: pair: typedef; dnnl_dim_t .. _doxid-group__dnnl__api__memory_1ga872631b12a112bf43fba985cba24dd20: .. ref-code-block:: cpp :class: doxyrest-title-code-block typedef int64_t dnnl_dim_t A type to describe tensor dimension. .. index:: pair: typedef; dnnl_dims_t .. _doxid-group__dnnl__api__memory_1ga8331e1160e52a5d4babe96736464095a: .. ref-code-block:: cpp :class: doxyrest-title-code-block typedef :ref:`dnnl_dim_t` dnnl_dims_t[DNNL_MAX_NDIMS] A type to describe tensor dimensions. .. index:: pair: typedef; dnnl_memory_t .. _doxid-group__dnnl__api__memory_1ga2b79954bd7bb293e766a89189e8440fd: .. ref-code-block:: cpp :class: doxyrest-title-code-block typedef struct :ref:`dnnl_memory`* dnnl_memory_t A memory handle. .. index:: pair: typedef; const_dnnl_memory_t .. _doxid-group__dnnl__api__memory_1ga0f89ee8e9b55b302b3f5277d11302f7e: .. ref-code-block:: cpp :class: doxyrest-title-code-block typedef const struct :ref:`dnnl_memory`* const_dnnl_memory_t A constant memory handle. Global Functions ---------------- .. index:: pair: function; dnnl_memory_desc_init_by_strides .. _doxid-group__dnnl__api__memory_1ga77c4ac2c6c59730ade594b954c145f73: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`dnnl_status_t` DNNL_API dnnl_memory_desc_init_by_strides( :ref:`dnnl_memory_desc_t`* memory_desc, int ndims, const :ref:`dnnl_dims_t` dims, :ref:`dnnl_data_type_t` data_type, const :ref:`dnnl_dims_t` strides ) Initializes a memory descriptor using dimensions and strides. .. note:: As always, the logical order of dimensions corresponds to the ``abc...`` format tag, and the physical meaning of the dimensions depends on both the primitive that consumes the memory and the context of that consumption. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - memory_desc - Output memory descriptor. * - ndims - Number of dimensions * - dims - Array of dimensions. * - data_type - Elements data type. * - strides - Strides in each dimension. .. rubric:: Returns: :ref:`dnnl_success ` on success and a status describing the error otherwise. .. index:: pair: function; dnnl_memory_desc_init_by_tag .. _doxid-group__dnnl__api__memory_1gaff696e368aeefb3036a0419c508dc6be: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`dnnl_status_t` DNNL_API dnnl_memory_desc_init_by_tag( :ref:`dnnl_memory_desc_t`* memory_desc, int ndims, const :ref:`dnnl_dims_t` dims, :ref:`dnnl_data_type_t` data_type, :ref:`dnnl_format_tag_t` tag ) Initializes a memory descriptor using dimensions and memory format tag. .. note:: As always, the logical order of dimensions corresponds to the ``abc...`` format tag, and the physical meaning of the dimensions depends on both the primitive that consumes the memory and the context of that consumption. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - memory_desc - Output memory descriptor. * - ndims - Number of dimensions * - dims - Array of dimensions. * - data_type - Elements data type. * - tag - Memory format tag. Can be :ref:`dnnl_format_tag_any ` which would allow a primitive to chose the final memory format. In this case the format_kind field of the memory descriptor would be set to :ref:`dnnl_format_kind_any `. .. rubric:: Returns: :ref:`dnnl_success ` on success and a status describing the error otherwise. .. index:: pair: function; dnnl_memory_desc_init_submemory .. _doxid-group__dnnl__api__memory_1ga21b56f5755bb767c60b4f1b3dfc34445: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`dnnl_status_t` DNNL_API dnnl_memory_desc_init_submemory( :ref:`dnnl_memory_desc_t`* memory_desc, const :ref:`dnnl_memory_desc_t`* parent_memory_desc, const :ref:`dnnl_dims_t` dims, const :ref:`dnnl_dims_t` offsets ) Initializes a memory descriptor for a region inside an area described by an existing memory descriptor. .. warning:: Some combinations of physical memory layout and/or offsets or dims may result in a failure to create a submemory. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - memory_desc - Output memory descriptor. * - parent_memory_desc - An existing memory descriptor. * - dims - Sizes of the region. * - offsets - Offsets to the region from the encompassing memory object in each dimension .. rubric:: Returns: :ref:`dnnl_success ` on success and a status describing the error otherwise. .. index:: pair: function; dnnl_memory_desc_reshape .. _doxid-group__dnnl__api__memory_1ga5994f41ff7305a203aacce192d4eac35: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`dnnl_status_t` DNNL_API dnnl_memory_desc_reshape( :ref:`dnnl_memory_desc_t`* out_memory_desc, const :ref:`dnnl_memory_desc_t`* in_memory_desc, int ndims, const :ref:`dnnl_dims_t` dims ) Initializes a memory descriptor by reshaping an existing one. The new memory descriptor inherits the data type. This operation is valid only for memory descriptors that have format_kind set to :ref:`dnnl_blocked ` or :ref:`dnnl_format_kind_any `. The operation ensures the transformation of the physical memory format corresponds to the transformation of the logical dimensions. If such transformation is impossible, the function returns :ref:`dnnl_invalid_arguments `. The reshape operation can be described as a combination of the following basic operations: #. Add a dimension of size ``1``. This is always possible. #. Remove a dimension of size ``1``. This is possible only if the dimension has no padding (i.e. ``padded_dims[dim] == dims[dim] && dims[dim] == 1``). #. Split a dimension into multiple ones. This is possible only if the size of the dimension is exactly equal to the product of the split ones and the dimension does not have padding (i.e. ``padded_dims[dim] = dims[dim]``). #. Joining multiple consecutive dimensions into a single one. As in the cases above, this requires that the dimensions do not have padding and that the memory format is such that in physical memory these dimensions are dense and have the same order as their logical counterparts. This also assumes that these dimensions are not blocked. * Here, dense means: ``stride for dim[i] == (stride for dim[i + 1]) * dim[i + 1]``; * And same order means: ``i < j`` if and only if ``stride for dim[j] <= stride for dim[i]``. .. warning:: Some combinations of physical memory layout and/or offsets or dimensions may result in a failure to make a reshape. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - out_memory_desc - Output memory descriptor. * - in_memory_desc - An existing memory descriptor. Must have format_kind set to :ref:`dnnl_blocked ` or :ref:`dnnl_format_kind_any `. * - ndims - Number of dimensions for the output memory descriptor. * - dims - Dimensions for the output memory descriptor. .. rubric:: Returns: :ref:`dnnl_success ` on success and a status describing the error otherwise. .. index:: pair: function; dnnl_memory_desc_permute_axes .. _doxid-group__dnnl__api__memory_1ga415adf7b7053b88886431e949211e810: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`dnnl_status_t` DNNL_API dnnl_memory_desc_permute_axes( :ref:`dnnl_memory_desc_t`* out_memory_desc, const :ref:`dnnl_memory_desc_t`* in_memory_desc, const int* permutation ) Initializes a memory descriptor by permuting axes in an existing one. The physical memory layout representation is adjusted accordingly to maintain the consistency between the logical and physical parts of the memory descriptor. The new memory descriptor inherits the data type. This operation is valid only for memory descriptors that have format_kind set to :ref:`dnnl_blocked ` or :ref:`dnnl_format_kind_any `. The logical axes will be permuted in the following manner: .. ref-code-block:: cpp for (i: 0 .. in_memory_desc->ndims) out_memory_desc->dims[permutation[i]] = in_memory_desc->dims[i]; Example: .. ref-code-block:: cpp dnnl_memory_desc_t in_md, out_md, expect_out_md; const int permutation[] = {1, 0}; // swap the first and the second axes dnnl_dims_t in_dims = {2, 3}, out_dims = {3, 2}; dnnl_format_tag_t in_tag = dnnl_ab, out_tag = dnnl_ba; dnnl_memory_desc_init_by_tag( &in_md, 2, in_dims, data_type, in_tag); dnnl_memory_desc_init_by_tag( &expect_out_md, 2, out_dims, data_type, out_tag); dnnl_memory_desc_permute_axes(&out_md, in_md, permutation); assert(dnnl_memory_desc_equal(&out_md, &expect_out_md)); .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - out_memory_desc - Output memory descriptor. * - in_memory_desc - An existing memory descriptor. Must have format_kind set to :ref:`dnnl_blocked ` or :ref:`dnnl_format_kind_any `. * - permutation - Axes permutation (of size ``in_memory_desc->ndims``). .. rubric:: Returns: :ref:`dnnl_success ` on success and a status describing the error otherwise. .. index:: pair: function; dnnl_memory_desc_equal .. _doxid-group__dnnl__api__memory_1gaa734e01591b567ed6378df1f404058e2: .. ref-code-block:: cpp :class: doxyrest-title-code-block int DNNL_API dnnl_memory_desc_equal( const :ref:`dnnl_memory_desc_t`* lhs, const :ref:`dnnl_memory_desc_t`* rhs ) Compares two memory descriptors. Use this function to identify whether a reorder is required between the two memories .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - lhs - Left-hand side of the comparison. * - rhs - Right-hand side of the comparison. .. rubric:: Returns: 1 if the descriptors are the same. 0 if the descriptors are different. .. index:: pair: function; dnnl_memory_desc_get_size .. _doxid-group__dnnl__api__memory_1gaed039afa75d9f56763e2c1321f1563c4: .. ref-code-block:: cpp :class: doxyrest-title-code-block size_t DNNL_API dnnl_memory_desc_get_size(const :ref:`dnnl_memory_desc_t`* memory_desc) Returns the size of a memory descriptor. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - memory_desc - Memory descriptor. .. rubric:: Returns: The number of bytes required for memory described by a memory descriptor. .. index:: pair: function; dnnl_data_type_size .. _doxid-group__dnnl__api__memory_1ga2016d117865455e5d117173dae1b52cb: .. ref-code-block:: cpp :class: doxyrest-title-code-block size_t DNNL_API dnnl_data_type_size(:ref:`dnnl_data_type_t` data_type) Returns the size of data type. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - data_type - Data type. .. rubric:: Returns: The number of bytes occupied by data type. .. index:: pair: function; dnnl_memory_create .. _doxid-group__dnnl__api__memory_1ga52a9246bd7f4e498b08d61e75e689a0c: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`dnnl_status_t` DNNL_API dnnl_memory_create( :ref:`dnnl_memory_t`* memory, const :ref:`dnnl_memory_desc_t`* memory_desc, :ref:`dnnl_engine_t` engine, void* handle ) Creates 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 :ref:`dnnl_memory_set_data_handle() ` had been called. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - memory - Output memory object. * - memory_desc - Memory descriptor. * - engine - Engine to use. * - 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 :ref:`dnnl_memory ` without an underlying buffer. .. rubric:: Returns: :ref:`dnnl_success ` on success and a status describing the error otherwise. .. rubric:: See also: :ref:`dnnl_memory_set_data_handle() ` .. index:: pair: function; dnnl_memory_get_memory_desc .. _doxid-group__dnnl__api__memory_1ga59a447af4c51aba057856c7b596351d4: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`dnnl_status_t` DNNL_API dnnl_memory_get_memory_desc( :ref:`const_dnnl_memory_t` memory, const :ref:`dnnl_memory_desc_t`** memory_desc ) Returns the memory descriptor for a memory object. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - memory - Memory object. * - memory_desc - Output memory descriptor (a copy). .. rubric:: Returns: :ref:`dnnl_success ` on success and a status describing the error otherwise. .. index:: pair: function; dnnl_memory_get_engine .. _doxid-group__dnnl__api__memory_1ga583a4a06428de7d6c4251313e57ad814: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`dnnl_status_t` DNNL_API dnnl_memory_get_engine( :ref:`const_dnnl_memory_t` memory, :ref:`dnnl_engine_t`* engine ) Returns the engine of a memory object. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - memory - Memory object. * - engine - Output engine on which the memory is located. .. rubric:: Returns: :ref:`dnnl_success ` on success and a status describing the error otherwise. .. index:: pair: function; dnnl_memory_map_data .. _doxid-group__dnnl__api__memory_1gac9006cdf6816b8bef7be3455ab0ceb49: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`dnnl_status_t` DNNL_API dnnl_memory_map_data( :ref:`const_dnnl_memory_t` memory, void** mapped_ptr ) Maps a memory object and returns a host-side pointer to a memory buffer with a copy of its contents. Mapping enables explicit direct access to memory contents for the engines that do not support it implicitly. Mapping is an exclusive operation - a memory object cannot be used in other operations until this memory object is unmapped. .. note:: Any primitives working with ``memory`` should be completed before the memory is mapped. Use dnnl_stream_wait to synchronize the corresponding execution stream. .. note:: The :ref:`dnnl_memory_map_data() ` and :ref:`dnnl_memory_unmap_data() ` functions are mainly provided for debug and testing purposes, and their performance may be suboptimal. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - memory - Memory object. * - mapped_ptr - Output pointer to the mapped buffer. .. rubric:: Returns: :ref:`dnnl_success ` on success and a status describing the error otherwise. .. index:: pair: function; dnnl_memory_unmap_data .. _doxid-group__dnnl__api__memory_1ga46dd4eb02eade91cadd0b9f85b4eccd4: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`dnnl_status_t` DNNL_API dnnl_memory_unmap_data( :ref:`const_dnnl_memory_t` memory, void* mapped_ptr ) Unmaps a memory object and writes back any changes made to the previously mapped memory buffer. The pointer to the mapped buffer must be obtained via the :ref:`dnnl_memory_map_data() ` call. .. note:: The :ref:`dnnl_memory_map_data() ` and :ref:`dnnl_memory_unmap_data() ` functions are mainly provided for debug and testing purposes, and their performance may be suboptimal. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - memory - Memory object. * - mapped_ptr - Pointer to the mapped buffer that must have been obtained using the :ref:`dnnl_memory_map_data() ` function. .. rubric:: Returns: :ref:`dnnl_success ` on success and a status describing the error otherwise. .. index:: pair: function; dnnl_memory_get_data_handle .. _doxid-group__dnnl__api__memory_1ga71efa7bd0ac194fdec98fb908b8ba9c5: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`dnnl_status_t` DNNL_API dnnl_memory_get_data_handle( :ref:`const_dnnl_memory_t` memory, void** handle ) Returns memory object's data handle. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - memory - Memory object. * - 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. .. rubric:: Returns: :ref:`dnnl_success ` on success and a status describing the error otherwise. .. index:: pair: function; dnnl_memory_set_data_handle .. _doxid-group__dnnl__api__memory_1ga6888f8c17f272d6729c9bc258ed41fcf: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`dnnl_status_t` DNNL_API dnnl_memory_set_data_handle( :ref:`dnnl_memory_t` memory, void* handle ) Sets the underlying memory buffer. See the description of :ref:`dnnl_memory_set_data_handle_v2() ` for more details. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - memory - Memory object. * - handle - Data handle. For the CPU engine, the data handle is a pointer to the actual data. For OpenCL it is a ``cl_mem``. .. rubric:: Returns: :ref:`dnnl_success ` on success and a status describing the error otherwise. .. index:: pair: function; dnnl_memory_set_data_handle_v2 .. _doxid-group__dnnl__api__memory_1ga722a97a6fb834a4347deb3e70a240008: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`dnnl_status_t` DNNL_API dnnl_memory_set_data_handle_v2( :ref:`dnnl_memory_t` memory, void* handle, :ref:`dnnl_stream_t` stream ) Sets the underlying memory buffer. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - memory - Memory object. * - handle - Data handle. For the CPU engine, the data handle is a pointer to the actual data. For OpenCL it is a ``cl_mem``. * - stream - Stream to use to execute padding in. .. rubric:: Returns: :ref:`dnnl_success ` on success and a status describing the error otherwise. .. index:: pair: function; dnnl_memory_destroy .. _doxid-group__dnnl__api__memory_1gaa219225aae8e53489caab3fe1bc80a52: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`dnnl_status_t` DNNL_API dnnl_memory_destroy(:ref:`dnnl_memory_t` memory) Destroys a memory object. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - memory - Memory object to destroy. .. rubric:: Returns: :ref:`dnnl_success ` on success and a status describing the error otherwise. Macros ------ .. index:: pair: define; DNNL_MAX_NDIMS .. _doxid-group__dnnl__api__memory_1gaa9e648b617df0f0186143abdf78ca5f2: .. ref-code-block:: cpp :class: doxyrest-title-code-block #define DNNL_MAX_NDIMS Maximum number of dimensions a tensor can have. Only restricts the amount of space used for the tensor description. Individual computational primitives may support only tensors of certain dimensions. .. index:: pair: define; DNNL_MEMORY_ALLOCATE .. _doxid-group__dnnl__api__memory_1gaf19cbfbf1f0a9508283f2a25561ae0e4: .. ref-code-block:: cpp :class: doxyrest-title-code-block #define DNNL_MEMORY_ALLOCATE Special pointer value that indicates that the library needs to allocate an underlying buffer for a memory object. .. index:: pair: define; DNNL_MEMORY_NONE .. _doxid-group__dnnl__api__memory_1ga96c8752fb3cb4f01cf64bf56190b1343: .. ref-code-block:: cpp :class: doxyrest-title-code-block #define DNNL_MEMORY_NONE Special pointer value that indicates that a memory object should not have an underlying buffer. .. index:: pair: define; DNNL_RNN_MAX_N_PARTS .. _doxid-group__dnnl__api__memory_1ga13d8eca8d5e6c94573e1154b3407407f: .. ref-code-block:: cpp :class: doxyrest-title-code-block #define DNNL_RNN_MAX_N_PARTS Maximum number of parts of RNN weights tensor that require separate computation. .. index:: pair: define; DNNL_RUNTIME_DIM_VAL .. _doxid-group__dnnl__api__memory_1gaa596c5a6102df77a550bad98f0d5cc12: .. ref-code-block:: cpp :class: doxyrest-title-code-block #define DNNL_RUNTIME_DIM_VAL A wildcard value for dimensions that are unknown at a primitive creation time. .. index:: pair: define; DNNL_RUNTIME_F32_VAL .. _doxid-group__dnnl__api__memory_1gab16365c11b4dc88fbb453edb51f1979f: .. ref-code-block:: cpp :class: doxyrest-title-code-block #define DNNL_RUNTIME_F32_VAL A wildcard value for floating point values that are unknown at a primitive creation time. .. index:: pair: define; DNNL_RUNTIME_S32_VAL .. _doxid-group__dnnl__api__memory_1ga30139d5110e9e895ccd93fe503ca4c35: .. ref-code-block:: cpp :class: doxyrest-title-code-block #define DNNL_RUNTIME_S32_VAL A wildcard value for int32_t values that are unknown at a primitive creation time. .. index:: pair: define; DNNL_RUNTIME_SIZE_VAL .. _doxid-group__dnnl__api__memory_1ga61466fbd352b6c94b6541977fbe199b8: .. ref-code-block:: cpp :class: doxyrest-title-code-block #define DNNL_RUNTIME_SIZE_VAL A ``size_t`` counterpart of the DNNL_RUNTIME_DIM_VAL. For instance, this value is returned by :ref:`dnnl_memory_desc_get_size() ` if either of the dimensions or strides equal to :ref:`DNNL_RUNTIME_DIM_VAL `.