Skip to content
API REFERENCEUsage guides →

cellpack::loader::BatchLease ​

struct

Module contract · All interfaces

At a glance ​

pub struct BatchLease { /* private fields */ }

Owned slot lease, suitable for foreign-runtime array base objects.

Read only rows() × bytes-per-row from region(schema). Keep the lease until every reader, including an asynchronous device copy, has finished.

Try it ​

FIXED EXAMPLE RUST / CPU

Deliver ordered batches

Two output schemas share each requested position. Missing dimensions use the schema default; present sparse zeros stay zero.

mod common;

use std::error::Error;
use std::sync::Arc;
use cellpack::loader::{
    DataSourceBuilder, Dtype, IoBackend, Loader, LoaderConfig,
    OutputSchema, Planning, Replicate, Ring,
};

fn main() -> Result<(), Box<dyn Error>> {
    let mut builder = DataSourceBuilder::new(5, 4096)?.direct_io(false);
    builder.add_cpk(common::fixture()?, &[0, 1, 2, 3])?;
    let source = Arc::new(builder.build()?);
    let schemas = vec![
        OutputSchema::dense(1, vec![3, 1, 4], Dtype::F32)?.with_default(f64::NAN),
        OutputSchema::dense(2, vec![0, 2], Dtype::F64)?,
    ];
    let loader = Loader::new(source, schemas, LoaderConfig {
        workers: 2, backend: IoBackend::Pread, slot_cells: 2,
        ..LoaderConfig::default()
    })?;
    let cells = [3u32, 0, 2, 3, 1];
    let accesses = Replicate::new(cells, 2)?;
    let ring = Arc::new(Ring::allocate(loader.ring_layout(2, 1))?);
    let run = loader.prepare(&accesses, ring, Planning::None)?;
    let stats = run.for_each_batch(|batch| {
        let panel: Vec<f32> = batch.region(0).chunks_exact(4)
            .map(|v| f32::from_ne_bytes(v.try_into().unwrap())).collect();
        println!("positions {}..{}: panel {panel:?}",
            batch.first_position(), batch.first_position() + batch.rows() as u64);
        Ok(())
    })?;
    println!("delivered: {} positions, {} accesses", cells.len(), stats.counters.accesses);
    Ok(())
}
OUTPUTExpected result
positions 0..2: panel [0.0, 8.0, NaN, 1.0, 2.0, NaN]
positions 2..4: panel [6.0, 0.0, NaN, 0.0, 8.0, NaN]
positions 4..5: panel [0.0, 0.0, NaN]
delivered: 5 positions, 10 accesses

Member index ​

9 of 9 members

  • generationThe run generation the lease was taken under.
  • indexThe batch number.
  • first_positionThe first position in the slot.
  • rowsPositions in the slot.
  • dataThe whole slot: every schema’s region plus padding, cut to the data actually mapped.
  • regionSchema s ’s outputs: rows × cell_bytes(s) compact bytes.
  • schemasSchemas in the slot, one region each.
  • cell_bytesBytes of one cell’s output for schema s .
  • region_offsetOffset of schema s ’s region within the slot (for consumers that compute their own addresses).

Methods and associated constants ​

generation ​

pub fn generation(&self) -> u64

The run generation the lease was taken under.

index ​

pub fn index(&self) -> u64

The batch number.

first_position ​

pub fn first_position(&self) -> u64

The first position in the slot.

rows ​

pub fn rows(&self) -> usize

Positions in the slot.

data ​

pub fn data(&self) -> &[u8] ⓘ

The whole slot: every schema’s region plus padding, cut to the data actually mapped.

region ​

pub fn region(&self, s: usize) -> &[u8] ⓘ

Schema s’s outputs: rows × cell_bytes(s) compact bytes.

schemas ​

pub fn schemas(&self) -> usize

Schemas in the slot, one region each.

cell_bytes ​

pub fn cell_bytes(&self, s: usize) -> usize

Bytes of one cell’s output for schema s.

region_offset ​

pub fn region_offset(&self, s: usize) -> usize

Offset of schema s’s region within the slot (for consumers that compute their own addresses).

Implemented traits ​

impl Drop for BatchLease

Contract reference ​

See the module reference for semantic input/output rules, units, allocation, mutation, failure behavior, and lifetime requirements. Declarations and documented members are synchronized from the crate source.

Definition