Skip to main content

Memory

Struct Memory 

Source
pub struct Memory<T> {
    pub engine: Arc<Engine>,
    pub buffer_type: BufferType<T>,
    pub desc: MemoryDescriptor,
    /* private fields */
}

Fields§

§engine: Arc<Engine>§buffer_type: BufferType<T>§desc: MemoryDescriptor

Implementations§

Source§

impl<T> Memory<T>

Source

pub fn new_with_user_buffer( engine: Arc<Engine>, desc: MemoryDescriptor, buffer: AlignedBuffer<T>, ) -> Result<Self, DnnlError>

Creates a new memory object with a user-allocated buffer.

This function initializes a Memory instance using a buffer provided by the user. The library does not take ownership of the buffer; therefore, the user is responsible for ensuring that the buffer remains valid for the lifetime of the Memory object.

§Safety
  • The user must ensure that the buffer remains valid for the lifetime of the Memory object.
  • The buffer must be properly aligned and sized according to memory_desc.
§Parameters
  • engine: An Arc<Engine> instance representing the engine to associate with this memory.
  • desc: A MemoryDescriptor describing the memory layout.
  • buffer: A raw pointer to the user-allocated buffer.
§Returns
  • Ok(Memory) if the memory object is successfully created.
  • Err(DnnlError) if the creation fails.
§Example
use {
    onednnl::{
        engine::Engine,
        error::DnnlError,
        memory::{
            buffer::AlignedBuffer, data_type_size, descriptor::MemoryDescriptor,
            format_tag::abcdef, Memory,
        },
    },
    onednnl_sys::dnnl_data_type_t::dnnl_f32,
    std::{ffi::c_void, sync::Arc},
};

let engine = Arc::new(Engine::new(Engine::CPU, 0).unwrap());

let dims = [1, 3, 224, 224, 112, 112];

let mem_desc = MemoryDescriptor::new::<6, abcdef>(dims, dnnl_f32).unwrap();
let mut buffer =
    AlignedBuffer::<f32>::zeroed(mem_desc.get_size() / data_type_size(dnnl_f32)).unwrap();
let memory = Memory::new_with_user_buffer(Arc::clone(&engine), mem_desc, buffer);
assert!(memory.is_ok());
Source

pub fn new_with_library_buffer( engine: Arc<Engine>, desc: MemoryDescriptor, ) -> Result<Self, DnnlError>

Creates a new memory object with a library-allocated buffer.

§Example
use {
    onednnl::{
        engine::Engine,
        error::DnnlError,
        memory::{descriptor::MemoryDescriptor, format_tag::abcd, Memory},
    },
    onednnl_sys::dnnl_data_type_t::dnnl_f32,
    std::{ffi::c_void, sync::Arc},
};

let engine = Arc::new(Engine::new(Engine::CPU, 0).unwrap());

let dims = [1, 3, 224, 224];

let mem_desc = MemoryDescriptor::new::<4, abcd>(dims, dnnl_f32).unwrap();

let memory = Memory::<f32>::new_with_library_buffer(Arc::clone(&engine), mem_desc);
assert!(memory.is_ok());
Source

pub fn new_without_buffer( engine: Arc<Engine>, desc: MemoryDescriptor, ) -> Result<Self, DnnlError>

Creates a new memory object without an underlying buffer.

§Example
use {
    onednnl::{
        engine::Engine,
        error::DnnlError,
        memory::{descriptor::MemoryDescriptor, format_tag::abcdef, Memory},
    },
    onednnl_sys::dnnl_data_type_t::dnnl_f32,
    std::{ffi::c_void, sync::Arc},
};

let engine = Arc::new(Engine::new(Engine::CPU, 0).unwrap());

let dims = [1, 3, 224, 224, 112, 112];

let mem_desc = MemoryDescriptor::new::<6, abcdef>(dims, dnnl_f32).unwrap();

let memory = Memory::<f32>::new_without_buffer(Arc::clone(&engine), mem_desc);
assert!(memory.is_ok());
Source

pub fn to_vec(&self) -> Result<Vec<T>, DnnlError>
where T: Clone,

Trait Implementations§

Source§

impl<T: Debug> Debug for Memory<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Drop for Memory<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<T> Send for Memory<T>

Source§

impl<T> Sync for Memory<T>

Auto Trait Implementations§

§

impl<T> Freeze for Memory<T>
where BufferType<T>: Freeze,

§

impl<T> RefUnwindSafe for Memory<T>

§

impl<T> Unpin for Memory<T>
where BufferType<T>: Unpin,

§

impl<T> UnsafeUnpin for Memory<T>

§

impl<T> UnwindSafe for Memory<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.