pub unsafe trait NDAllocator:
Send
+ Sync
+ 'static {
const MIN_ALIGN: usize;
// Required methods
unsafe fn alloc_data(&mut self, prototype: &DLTensor) -> *mut c_void;
unsafe fn free_data(&mut self, tensor: &DLTensor);
}Expand description
Allocates the data buffer of a tensor made by Tensor::from_nd_alloc.
§Safety
alloc_data must return a pointer aligned to MIN_ALIGN and valid for the
prototype’s data, numel() * bits * lanes bits rounded up to whole bytes
(sub-byte types are packed), and free_data must release
exactly what alloc_data returned. free_data may be called for a tensor
whose data is null, when alloc_data panicked, and must then do nothing.
Send + Sync: the tensor frees its data through the allocator when the
last reference drops, which may be on any thread.
Required Associated Constants§
Required Methods§
Sourceunsafe fn alloc_data(&mut self, prototype: &DLTensor) -> *mut c_void
unsafe fn alloc_data(&mut self, prototype: &DLTensor) -> *mut c_void
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.