pub struct Buffer { /* private fields */ }Expand description
Data storring buffer.
Deletes data on drop.
Implementations§
Source§impl Buffer
Buffer creation section.
impl Buffer
Buffer creation section.
Sourcepub fn try_clone(&self) -> Result<Self, Error>
pub fn try_clone(&self) -> Result<Self, Error>
Try clone buffer content.
Note: If memory type is not Cpu, should be called in sync with cuda context pinned (check module level documentation for more info).
Sourcepub fn alloc<T: Sample>(
count: usize,
memory_type: MemoryType,
) -> Result<Self, Error>
pub fn alloc<T: Sample>( count: usize, memory_type: MemoryType, ) -> Result<Self, Error>
Allocate new buffer of requested memory type.
count: size of buffer in T units (i.e. 128 chunks of f32 (that has byte size 512) should be allocated with count=128).
memory_type: Cpu/Pinned/Gpu.
Note: If memory type is not Cpu, should be called in sync with cuda context pinned (check module level documentation for more info).
Sourcepub fn alloc_with_data_type(
count: usize,
memory_type: MemoryType,
data_type: DataType,
) -> Result<Self, Error>
pub fn alloc_with_data_type( count: usize, memory_type: MemoryType, data_type: DataType, ) -> Result<Self, Error>
Allocate new buffer of requested memory type.
count: size of buffer in T units (i.e. 128 chunks of f32 (that has byte size 512) should be allocated with count=128).
memory_type: Cpu/Pinned/Gpu.
data_type: type of Samples.
Note: If memory type is not Cpu, should be called in sync with cuda context pinned (check module level documentation for more info).
Source§impl Buffer
Buffer data permutation section.
impl Buffer
Buffer data permutation section.
Sourcepub fn copy_from_slice<S: AsRef<[T]>, T: Sample>(
&mut self,
offset: usize,
source: S,
) -> Result<(), Error>
pub fn copy_from_slice<S: AsRef<[T]>, T: Sample>( &mut self, offset: usize, source: S, ) -> Result<(), Error>
Copy source content to self from the offset position.
Returns error if offset + size_of_val(source) > self.size().
offset: offset (in bytes) from the beginning of the Buffer to location to copy source to.
source: slice of Samples.
Note: If self.memory_type is not Cpu, should be called in sync with cuda context pinned (check module level documentation for more info).
Sourcepub fn copy_from_cuda_array(
&mut self,
offset: usize,
source: CudaArray,
) -> Result<(), Error>
pub fn copy_from_cuda_array( &mut self, offset: usize, source: CudaArray, ) -> Result<(), Error>
Copy source content to self from the offset position.
Returns error if offset + source.len > self.size().
offset: offset (in bytes) from the beginning of the Buffer to location to copy source to.
source: cuda array.
Note: This method should be called in sync with cuda context pinned (check module level documentation for more info).
Sourcepub fn into_cpu(self) -> Result<Self, Error>
pub fn into_cpu(self) -> Result<Self, Error>
Move this Buffer content to CPU memory.
Note: If self.memory_type() is not Cpu, method should be called in sync with cuda context pinned (check module level documentation for more info).
Sourcepub fn into_pinned(self) -> Result<Self, Error>
pub fn into_pinned(self) -> Result<Self, Error>
Move this Buffer content to Pinned memory.
Note: This method should be called in sync with cuda context pinned (check module level documentation for more info).
Source§impl Buffer
Obtaining buffer content section.
impl Buffer
Obtaining buffer content section.
Sourcepub fn bytes(&self) -> &[u8] ⓘ
pub fn bytes(&self) -> &[u8] ⓘ
Get buffer content as bytes.
Will return nothing if self.memory_type == Gpu. Use Buffer::get_owned_slice instead.
Sourcepub fn bytes_mut(&mut self) -> &mut [u8] ⓘ
pub fn bytes_mut(&mut self) -> &mut [u8] ⓘ
Get buffer mutable content as bytes.
Will return nothing if self.memory_type == Gpu. Buffer::get_cuda_array can be used instead to implement this logic.
Sourcepub fn get_owned_slice<Range: RangeBounds<usize> + Debug>(
&self,
range: Range,
) -> Result<Vec<u8>, Error>
pub fn get_owned_slice<Range: RangeBounds<usize> + Debug>( &self, range: Range, ) -> Result<Vec<u8>, Error>
Get content of the buffer as host located bytes.
range: part of the buffer to return.
Sourcepub unsafe fn get_cuda_array(&self) -> CudaArray
pub unsafe fn get_cuda_array(&self) -> CudaArray
Get content of the GPU based buffer.
§Panics
Panics if self.memory_type != Gpu.
§Safety
Returned struct points to the same location as buffer, so the rules are the same as sharing *mut on an object.
Be careful: Buffer will delete data on drop, so be afraid of double memory free.
Also any shinenigans with the data during the inference are forbidden: Triton must have exclusive write ascess to data during the inference.
Trait Implementations§
Source§impl From<Buffer> for CudaArray
Available on crate feature gpu only.
impl From<Buffer> for CudaArray
gpu only.Buffer destructor will not be invoked so data will be safe.
Source§impl From<CudaArray> for Buffer
Available on crate feature gpu only.Create GPU buffers of DataType::Uint8 from CudaArray.
Result memory type will be MemoryType::Gpu.
impl From<CudaArray> for Buffer
gpu only.Create GPU buffers of DataType::Uint8 from CudaArray. Result memory type will be MemoryType::Gpu.
Note that nothing is allocated on this call, meaning that result buffer will just point on data provided by argument.