use crate::compute::storage::cpu::{PINNED_MEMORY_ALIGNMENT, PinnedMemoryResource};
use cubecl_common::bytes::{AllocationController, AllocationProperty};
use cubecl_runtime::memory_management::SliceBinding;
pub struct PinnedMemoryManagedAllocController {
resource: PinnedMemoryResource,
_binding: SliceBinding,
}
impl PinnedMemoryManagedAllocController {
pub fn init(binding: SliceBinding, resource: PinnedMemoryResource) -> Self {
Self {
_binding: binding,
resource,
}
}
}
impl AllocationController for PinnedMemoryManagedAllocController {
fn alloc_align(&self) -> usize {
PINNED_MEMORY_ALIGNMENT
}
fn property(&self) -> AllocationProperty {
AllocationProperty::Pinned
}
unsafe fn memory_mut(&mut self) -> &mut [std::mem::MaybeUninit<u8>] {
unsafe {
std::slice::from_raw_parts_mut(
self.resource.ptr as *mut std::mem::MaybeUninit<u8>,
self.resource.size,
)
}
}
fn memory(&self) -> &[std::mem::MaybeUninit<u8>] {
unsafe {
std::slice::from_raw_parts(
self.resource.ptr as *mut std::mem::MaybeUninit<u8>,
self.resource.size,
)
}
}
}