Visible to Intel only — GUID: GUID-09B5109E-7223-4574-A5FF-E4C2C201047A
Visible to Intel only — GUID: GUID-09B5109E-7223-4574-A5FF-E4C2C201047A
struct dnnl::memory
Overview
Memory object. More…
#include <dnnl.hpp> struct memory: public dnnl::handle { // typedefs typedef dnnl_dim_t dim; typedef std::vector<dim> dims; // enums enum data_type; enum format_kind; enum format_tag; // structs struct desc; // construction memory(); memory(const desc& md, const engine& aengine, void* handle); memory(const desc& md, const engine& aengine); // methods template <typename T> static void validate_dims( const std::vector<T>& v, int min_size = 0 ); static size_t data_type_size(data_type adata_type); static dnnl_data_type_t convert_to_c(data_type adata_type); static dnnl_format_tag_t convert_to_c(format_tag format); desc get_desc() const; engine get_engine() const; void* get_data_handle() const; void set_data_handle(void* handle) const; template <typename T = void> T* map_data() const; void unmap_data(void* mapped_ptr) const; handle(); handle(const handle<T, traits>&); handle(handle<T, traits>&&); handle(T t, bool weak = false); };
Inherited Members
public: // methods handle<T, traits>& operator = (const handle<T, traits>&); handle<T, traits>& operator = (handle<T, traits>&&); void reset(T t, bool weak = false); T get(bool allow_empty = false) const; operator T () const; operator bool () const; bool operator == (const handle<T, traits>& other) const; bool operator != (const handle& other) const;
Detailed Documentation
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.
Typedefs
typedef dnnl_dim_t dim
Integer type for representing dimension sizes and indices.
typedef std::vector<dim> dims
Vector of dimensions.
Implementations are free to force a limit on the vector’s length.
Construction
memory()
Default constructor.
Constructs an empty memory object, which can be used to indicate absence of a parameter.
memory(const desc& md, const engine& aengine, void* handle)
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 dnnl::memory::set_data_handle() had been called.
Parameters:
md |
Memory descriptor. |
aengine |
Engine to store the data on. |
handle |
Handle of the memory buffer to use.
|
See also:
memory(const desc& md, const engine& aengine)
Constructs a memory object.
The underlying buffer for the memory will be allocated by the library.
Parameters:
md |
Memory descriptor. |
aengine |
Engine to store the data on. |
Methods
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.
Throws if validation fails.
Parameters:
v |
Vector of dimensions. |
min_size |
Minimum expected size of the vector. |
static size_t data_type_size(data_type adata_type)
Returns size of data type in bytes.
Returns:
The number of bytes occupied by data type.
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.
On the CPU engine, or when using USM, this is a pointer to the allocated memory.
void set_data_handle(void* handle) const
Sets the underlying memory buffer.
Parameters:
handle |
Memory buffer to use. On the CPU engine or when USM is used, the memory buffer is a pointer to the actual data. For OpenCL it is a cl_mem. It must have at least dnnl::memory::desc::get_size() bytes allocated. |
template <typename T = void> T* map_data() const
Maps a memory object and returns a host-side pointer to a memory buffer with a copy of its contents.
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 it is unmapped via dnnl::memory::unmap_data() call.
Parameters:
T |
Data type to return a pointer to. |
Returns:
Pointer to the mapped memory.
void unmap_data(void* mapped_ptr) const
Unmaps a memory object and writes back any changes made to the previously mapped memory buffer.
Parameters:
mapped_ptr |
A pointer previously returned by dnnl::memory::map_data(). |
handle()
Constructs an empty handle object.
handle(const handle<T, traits>&)
Copy constructor.
handle(handle<T, traits>&&)
Move constructor.
handle(T t, bool weak = false)
Constructs a handle wrapper object from a C API handle.
Parameters:
t |
The C API handle to wrap. |
weak |
A flag specifying whether to construct a weak wrapper; defaults to false. |