Rust · Memory Operations

Memory Operations

use stringzilla::UnifiedAllocator; 6.0.0-rc.1 · 91a27bdd

API

StructUnifiedAllocatorMemory the host and the devices of one capability group both address, for the columns and the outputs of their engines.2
types.rs:832 ↗
pub struct UnifiedAllocator<'stream>

It is the C library's sz_allocator_init_unified_best behind the standard Allocator, so Vec::new_in, a Strings and every other allocator-aware collection places its contents there. Every block lands on the device of the stream it borrows, the host heap for a CPU stream, and a block aligned less strictly than its layout asks is refused.

Examples

use stringzilla::{Capabilities, LevenshteinEngine, LevenshteinSymbol, Stream, Strings, StringsView, UnifiedAllocator};

let cpu = Stream::default(Capabilities::cpu_enabled());
let stream = Stream::new(Capabilities::cuda_enabled(0)?, 0)?;
let unified = UnifiedAllocator::new(&stream);
// The host gathers the slices, which a GPU cannot read, into memory the GPU reaches.
let candidates = Strings::copy_in(StringsView::from_slices(&["sitting", "kitten"]), unified, &cpu)?;
let mut distances = Vec::new_in(unified);
distances.resize(2, 0usize);

let mut engine = LevenshteinEngine::new(&["kitten"], LevenshteinSymbol::Bytes, &stream)?;
stream.scope(|scope| engine.distances(scope, candidates.view(), None, &mut distances, 2))?;
assert_eq!(distances[..], [3, 0]);

Implements

Clone, Copy, Debug, Allocator
newUnified memory on the device of stream, the host heap for a CPU stream.
types.rs:838 ↗
pub const fn new(stream: &'stream Stream) -> Self
capabilitiesThe capabilities whose memory every block comes from.
types.rs:843 ↗
pub fn capabilities(&self) -> Capabilities